SemSegEvaluator#
- class SemSegEvaluator(write_cls_iou=False, every_n_steps=0, ignore_index=-1, macro_ignore_class_ids=None, per_instance_metrics=False)[source]#
Bases:
HookBaseEvaluate point-wise semantic segmentation on the validation loader.
Runs the model over
trainer.val_loader, argmaxes the semantic logits (seg_logitsorsem_logits), and accumulates per-class intersection/union/target counts (all-reduced across ranks). It reports mIoU, mAcc, allAcc and macro precision/recall/F1 plus a per-class table, and publishesmIoUas the checkpoint-selection metric viatrainer.comm_info["current_metric_value"]/["current_metric_name"]. Whenorigin_coordis present, predictions are interpolated back to the original (pre-grid) points with a kNN query. Optionally computes majority-vote per-instance class metrics. Runs after every step whenevery_n_steps > 0(on iterations where(global_iter + 1) % every_n_steps == 0), otherwise after each epoch; only whencfg.evaluateis true. Registered asSemSegEvaluator(use astypein ahooks=[...]entry).- Parameters:
write_cls_iou (bool) – Also log per-class IoU/F1/precision/recall to the writer. Defaults to
False.every_n_steps (int) – Step cadence;
0evaluates once per epoch. Defaults to0.ignore_index (int) – Label id ignored when computing per-instance majority-vote metrics. Defaults to
-1.macro_ignore_class_ids (Sequence[int] | None) – Class ids excluded from macro (mean) metrics; deduplicated and sorted. Defaults to
None.per_instance_metrics (bool) – Compute majority-vote per-event instance class metrics when instance labels are available. Defaults to
False.
Note
The selection metric is
mIoU(higher is better). Per-instance metrics additionally require instance labels in the batch and per-event boundary tracking; they are logged but do not change the selection metric.Example
Add to
cfg.hooksbefore the checkpoint saver; everyevery_n_stepsit validates and sets the selection metric:hooks = [ dict(type="SemSegEvaluator", every_n_steps=1000, write_cls_iou=True), ] # → every 1000 steps logs val/loss, val/mIoU, val/mAcc, val/allAcc, # val/mPrecision, val/mRecall, val/mF1 (+ per-class IoU/F1/Precision/ # Recall with write_cls_iou) and sets the checkpoint-selection metric # to mIoU