Skip to content

Conversation

@CharlesCNorton
Copy link
Member

@CharlesCNorton CharlesCNorton commented Oct 10, 2025

Fixes MongoDB BSON error with numpy >= 2.0 by converting numpy scalars to Python floats in KeypointOutputProcessor (line 1565). Wraps p[0]/width and p[1]/height in float().

What changes are proposed in this pull request?

Changes line 1565 in fiftyone/utils/torch.py from points.append((p[0] / width, p[1] / height)) to points.append((float(p[0] / width), float(p[1] / height))) to convert numpy scalar types to Python native floats before MongoDB serialization.

How is this patch tested? If it is not, please explain why.

Reproduced bug with vitpose and numpy 2.3.3. Verified fix resolves the issue. Confirmed backwards compatibility with numpy 1.26.4. Tested other output processors with numpy 2.3.3 to confirm issue is isolated to KeypointOutputProcessor.

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • Yes. Give a description of this change to be included in the release notes for FiftyOne users.

Fixed MongoDB serialization error when running keypoint detection with numpy >= 2.0.

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • Bug Fixes
    • Ensures detector output keypoint coordinates are consistently floats, improving reliability across downstream processing, visualizations, and exports. This prevents occasional type inconsistencies that could cause rounding or compatibility issues when consuming normalized bounding box points, leading to more predictable results and smoother integrations. No changes to workflows or settings required.

Fixes MongoDB BSON error with numpy >= 2.0 by converting numpy scalars to Python floats in KeypointOutputProcessor (line 1565). Wraps p[0]/width and p[1]/height in float().
@CharlesCNorton CharlesCNorton self-assigned this Oct 10, 2025
@CharlesCNorton CharlesCNorton requested a review from a team as a code owner October 10, 2025 19:12
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 10, 2025

Walkthrough

Adjusted keypoint coordinate normalization in fiftyone/utils/torch.py to explicitly cast both point components to float when appending, ensuring float types for normalized bounding box points. No control flow, interface, or error handling changes.

Changes

Cohort / File(s) Summary
Torch utils: keypoint float casting
fiftyone/utils/torch.py
Explicitly casts both normalized keypoint coordinates to float before appending; logic and flow unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A hop, a skip, a cast to float—
My whiskers twitch at tidy code.
Two points now glide in decimal light,
Bounding boxes set just right.
Thump-thump! I stamp, review complete—
Carrots awarded for types so neat. 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly and concisely describes the key change to ensure compatibility with numpy >= 2.0 by fixing serialization in KeypointOutputProcessor and uses a single sentence focusing on the main impact of the patch.
Description Check ✅ Passed The pull request description follows the repository template by detailing the changes made, summarizing test procedures with versions and compatibility checks, providing clear release notes with a user-facing change description, and specifying the affected area as Core, fulfilling all required sections of the template.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-numpy-bson-serialization

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1585ac6 and 0ebbc6b.

📒 Files selected for processing (1)
  • fiftyone/utils/torch.py (1 hunks)
🔇 Additional comments (1)
fiftyone/utils/torch.py (1)

1593-1593: LGTM! Correct fix for numpy >= 2.0 BSON serialization.

The explicit conversion to Python native float types prevents MongoDB BSON serialization errors when using numpy >= 2.0. This approach is consistent with the existing use of float("nan") on lines 1588 and 1591 within the same method.

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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