refactor(metrics): enforce strict typing, sanitize docs & fix numpy 2.0 compat #2121
+580
−522
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before submitting
Description
Refactors the
supervision/metricsmodule to enforce Signature as the Single Source of Truth for types, removing redundant type hints from docstrings. This PR also addresses a compatibility issue with NumPy 2.0 and fixes a logic bug in area calculation for mAP.Type of Change
Motivation and Context
np.trapz, causing crashes indetection.py.MeanAveragePrecision, the area provided indatawas being ignored in favor of the bounding box area, which is incorrect for datasets like COCO where segmentation area differs from bbox area.Part of #2088
Changes Made
metricsmodules (core,detection,f1_score,precision,recall,mean_average_precision,mean_average_recall).(type)declarations in Args and Returns docstrings.np.trapzwith a conditional check fornp.trapezoidindetection.py.MeanAveragePrecisionto prioritizedata['area']if available, falling back to bbox area calculation only when necessary.Testing
Details:
Verified with
mypy(strict analysis on modified files) and passed all metric-related unit tests usingpython -m pytest test/metrics(33 passed).