Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion perceptionmetrics/utils/segmentation_metrics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import defaultdict
import logging
import math
from typing import List, Optional, Union

Expand Down Expand Up @@ -255,7 +256,18 @@ def get_averaged_metric(
"""
metric = getattr(self, f"get_{metric_name}")
if method == "macro":
return float(np.nanmean(metric(per_class=True)))
per_class_values = metric(per_class=True)
nan_mask = np.isnan(per_class_values)
missing_count = int(np.sum(nan_mask))

if missing_count > 0:
# Use implicit string concatenation to keep lines short
msg = (
f"Warning: {missing_count} class(es) were missing from the confusion matrix. "
f"Their {metric_name.upper()} evaluated to NaN and will be ignored in the macro-average."
)
logging.warning(msg)
return float(np.nanmean(per_class_values))
if method == "micro":
return float(metric(per_class=False))
if method == "weighted":
Expand Down
Loading