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
12 changes: 12 additions & 0 deletions perceptionmetrics/utils/segmentation_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@ def get_averaged_metric(
"""
metric = getattr(self, f"get_{metric_name}")
if method == "macro":
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:
import warnings

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise the warning as part of logging (you can check out logging.warning in line 60 of rellis3d.py). At some point we will do a project-wide effort to actually settle down on a proper logging system

# 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."
)
warnings.warn(msg, UserWarning)
return float(np.nanmean(metric(per_class=True)))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reuse here the per_class_values variable to avoid computing the metric twice

if method == "micro":
return float(metric(per_class=False))
Expand Down
Loading