Skip to content

Conversation

@uahroberto
Copy link

Before submitting
  • Self-reviewed the code
  • Updated documentation, follow Google-style
  • Added docs entry for autogeneration (if new functions/classes)
  • Added/updated tests
  • All tests pass locally

Description

Refactors the supervision/metrics module 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

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update
  • 🧪 Test update
  • 🔨 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🔧 Chore (dependencies, configs, etc.)

Motivation and Context

  • Modernization: To align with modern Python standards, type hints should reside in the function signature, not the docstring. This improves IDE support and static analysis.
  • Compatibility: NumPy 2.0 removed np.trapz, causing crashes in detection.py.
  • Bug Fix: In MeanAveragePrecision, the area provided in data was 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

  • Strict Typing: Moved type hints from docstrings to function signatures in all metrics modules (core, detection, f1_score, precision, recall, mean_average_precision, mean_average_recall).
  • Docstring Sanitization: Removed redundant (type) declarations in Args and Returns docstrings.
  • NumPy 2.0 Fix: Replaced the deprecated np.trapz with a conditional check for np.trapezoid in detection.py.
  • Logic Fix: Updated MeanAveragePrecision to prioritize data['area'] if available, falling back to bbox area calculation only when necessary.

Testing

  • I have tested this code locally
  • I have added unit tests that prove my fix is effective or that my feature works
  • All new and existing tests pass

Details:
Verified with mypy (strict analysis on modified files) and passed all metric-related unit tests using python -m pytest test/metrics (33 passed).

@uahroberto uahroberto requested a review from SkalskiP as a code owner February 1, 2026 01:41
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@uahroberto uahroberto force-pushed the refactor/metrics-typing branch from 70a21ab to cd93a9d Compare February 1, 2026 02:05
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.

3 participants