Skip to content

Enhancement: Add explicit UserWarning for NaN classes in macro-averaged metrics#558

Open
karttikjangid wants to merge 4 commits into
JdeRobot:masterfrom
karttikjangid:fix/warnings
Open

Enhancement: Add explicit UserWarning for NaN classes in macro-averaged metrics#558
karttikjangid wants to merge 4 commits into
JdeRobot:masterfrom
karttikjangid:fix/warnings

Conversation

@karttikjangid

Copy link
Copy Markdown
Contributor

Fixes #546

Following up on the discussion in #546, this PR adds a UserWarning during macro-averaged metric calculation.

When per-class metric values are NaN (for example, denominator-zero cases such as classes missing from the confusion matrix), they are ignored by np.nanmean as intended. This PR now surfaces a warning indicating how many classes were dropped for that metric so researchers are explicitly aware of the macro-average context.

All existing metric formulas and public APIs are unchanged. Feedback on the warning text format is welcome.

@karttikjangid

Copy link
Copy Markdown
Contributor Author

Hi team, the CI is failing on LiDAR tests due to an isinstance check against a mocked Open3D class in the headless runner. My changes are limited to metrics; would you like me to include a small guard to fix this CI bottleneck?

@karttikjangid

Copy link
Copy Markdown
Contributor Author

I have reinstated the original poetry files for reference in the last commit

@dpascualhe dpascualhe left a comment

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.

Upon fixing the issues raised we will merge 😄

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

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

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.

[Enhancement + Bug] Better error handling for data ingestion and missing classes

2 participants