Skip to content

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

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

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

Conversation

@karttikjangid

@karttikjangid karttikjangid commented Apr 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #546

Following up on the discussion in #546, this PR adds a logging warning 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

@dpascualhe

Copy link
Copy Markdown
Collaborator

Hi @karttikjangid ! Will you make the requested changes? Otherwise we will close the PR for now

@karttikjangid

Copy link
Copy Markdown
Contributor Author

@dpascualhe Surely , I will make a pr with those changes in a day or two .Always happy to do Open Source 😊.

@karttikjangid karttikjangid changed the title Enhancement: Add explicit UserWarning for NaN classes in macro-averaged metrics Enhancement: Add explicit logging warning for NaN classes in macro-averaged metrics Sep 26, 2026
@karttikjangid

Copy link
Copy Markdown
Contributor Author

Both requested changes are pushed: the warning now uses logging.warning, and the average reuses per_class_values. The 20 existing metric tests pass locally. Please take another look.

This branch has not been deployed

No deployments
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