Skip to content

Commit 18a62f0

Browse files
committed
Improved segmentation model testing by adapting the weight of bg-only patches in avg metric score
1 parent b54aa84 commit 18a62f0

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
type: segmentation
22
compatible_adaptation_types: ["frozen", "lora"]
33
base_embeddings_folder: ${oc.env:THUNDER_BASE_DATA_FOLDER}/embeddings/
4+
no_bg_only_weight_test: 16.0

src/thunder/tasks/train_eval_probe.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,14 +664,24 @@ def train_eval(
664664
for o, l in zip(all_out[i], all_label)
665665
if len(l) > 0
666666
]
667-
weights = [len(l) for l in all_label if len(l) > 0]
667+
weights = np.array([len(l) for l in all_label if len(l) > 0]).astype(
668+
np.float32
669+
)
670+
671+
# Finding background-only masks
672+
bg_only = np.array([l.sum().item() == 0 for l in all_label])
673+
freq_bg_only = bg_only.sum().item() / len(bg_only)
674+
no_bg_only_weight = max(
675+
1.0, freq_bg_only * cfg.task.no_bg_only_weight_test
676+
)
677+
weights[~bg_only] *= no_bg_only_weight
668678

669-
# Averagin per-image performance and computing confidence intervals
679+
# Averaging per-image performance and computing confidence intervals
670680
all_metrics_out = {}
671681
for key in all_metrics[0]:
672682
metric_vals = [d[key]["metric_score"] for d in all_metrics]
673683
all_metrics_out[key] = compute_metric(
674-
weights,
684+
weights.tolist(),
675685
metric_vals,
676686
lambda weights, metric_vals: np.average(
677687
metric_vals, weights=weights

0 commit comments

Comments
 (0)