Skip to content

fix(analysis): pnp_metrics crashes with no possible PnP (+1 more) - #35

Open
andrewwhitecdw wants to merge 1 commit into
NVlabs:masterfrom
andrewwhitecdw:bugfix/analysis-assorted-3b40372c
Open

fix(analysis): pnp_metrics crashes with no possible PnP (+1 more)#35
andrewwhitecdw wants to merge 1 commit into
NVlabs:masterfrom
andrewwhitecdw:bugfix/analysis-assorted-3b40372c

Conversation

@andrewwhitecdw

@andrewwhitecdw andrewwhitecdw commented Jul 27, 2026

Copy link
Copy Markdown

Small fixes in dream/analysis.py:

fix: pnp_metrics crashes with no possible PnP and returns NaN ADD stats

Fix: Replace:

def pnp_metrics(
    pnp_add,
    num_inframe_projs_gt,
    num_min_inframe_projs_gt_for_pnp=4,
    add_auc_threshold=0.1,
    pnp_magic_number=-999.0,
):
    pnp_add = np.array(pnp_add)
    num_inframe_projs_gt = np.array(num_inframe_projs_gt)

    idx_pnp_found = np.where(pnp_add > pnp_magic_number)[0]
    add_pnp_found = pnp_add[idx_pnp_found]
    num_pnp_found = len(idx_pnp_found)

    mean_add = np.mean(add_pnp_found)
    median_add = np.median(add_pnp_found)
    std_add = np.std(add_pnp_found)

    num_pnp_possible = len(
        np.where(num_inframe_projs_gt >= num_min_inframe_projs_gt_for_pnp)[0]
    )
    num_pnp_not_found = num_pnp_possible - num_pnp_found

    delta_threshold = 0.00001
    add_threshold_values = np.arange(0.0, add_auc_threshold, delta_threshold)

    counts = []
    for value in add_threshold_values:
        under_threshold = len(np.where(add_pnp_found <= value)[0]) / float(
            num_pnp_possible
        )
        counts.append(under_threshold)

    auc = np.trapz(counts, dx=delta_threshold) / float(add_auc_threshold)

    metrics = {
        "num_pnp_found": num_pnp_found,
        "num_pnp_not_found": num_pnp_not_found,
        "num_pnp_possible": num_pnp_possible,
        "num_min_inframe_projs_gt_for_pnp": num_min_inframe_projs_gt_for_pnp,
        "pnp_magic_number": pnp_magic_number,
        "add_mean": mean_add,
        "add_median": median_add,
        "add_std": std_add,
        "add_auc": auc,
        "add_auc_thresh": add_auc_threshold,
    }
    return metrics

with:

def pnp_metrics(
    pnp_add,
    num_inframe_projs_gt,
    num_min_inframe_projs_gt_for_pnp=4,
    add_auc_threshold=0.1,
    pnp_magic_number=-999.0,
):
    pnp_add = np.array(pnp_add)
    num_inframe_projs_gt = np.array(num_inframe_projs_gt)

    idx_pnp_found = np.where(pnp_add > pnp_magic_number)[0]
    add_pnp_found = pnp_add[idx_pnp_found]
    num_pnp_found = len(idx_pnp_found)

    num_pnp_possible = len(
        np.where(num_inframe_projs_gt >= num_min_inframe_projs_gt_for_pnp)[0]
    )
    num_pnp_not_found = num_pnp_possible - num_pnp_found

    if num_pnp_found > 0:
        mean_add = np.mean(add_pnp_found)
        median_add = np.median(add_pnp_found)
        std_add = np.std(add_pnp_found)
    else:
        mean_add = None
        median_add = None
        std_add = None

    if num_pnp_possible > 0:
        delta_threshold = 0.00001
        add_threshold_values = np.arange(0.0, add_auc_threshold, delta_threshold)

        counts = []
        for value in add_threshold_values:
            under_threshold = len(np.where(add_pnp_found <= value)[0]) / float(
                num_pnp_possible
            )
            counts.append(under_threshold)

        auc = np.trapz(counts, dx=delta_threshold) / float(add_auc_threshold)
    else:
        auc = None

    metrics = {
        "num_pnp_found": num_pnp_found,
        "num_pnp_not_found": num_pnp_not_found,
        "num_pnp_possible": num_pnp_possible,
        "num_min_inframe_projs_gt_for_pnp": num_min_inframe_projs_gt_for_pnp,
        "pnp_magic_number": pnp_magic_number,
        "add_mean": mean_add,
        "add_median": median_add,
        "add_std": std_add,
        "add_auc": auc,
        "add_auc_thresh": add_auc_threshold,
    }
    return metrics

fix: PILImage.BILINEAR removed in Pillow 10+

Fix: Replace:

            belief_map_image_upscaled = belief_map_images[n].resize(
                net_input_res_inf, resample=PILImage.BILINEAR
            )

with:

            resample_mode = getattr(PILImage, "Resampling", PILImage).BILINEAR
            belief_map_image_upscaled = belief_map_images[n].resize(
                net_input_res_inf, resample=resample_mode
            )

Files changed

  • dream/analysis.py

@andrewwhitecdw
andrewwhitecdw marked this pull request as ready for review August 3, 2026 22:10
@andrewwhitecdw

Copy link
Copy Markdown
Author

Closing this sweep-generated PR: sole commit is missing a valid Signed-off-by trailer. It does not meet the sweep requirements (single signed-off commit).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant