fix(coco): robust duplicate-filename frames + scored segmentation → predicted#481
Open
talmo wants to merge 1 commit into
Open
fix(coco): robust duplicate-filename frames + scored segmentation → predicted#481talmo wants to merge 1 commit into
talmo wants to merge 1 commit into
Conversation
…predicted Two COCO reader follow-ups (see #479 follow-ups): - Distinct `images` entries that share a `file_name` no longer crash. Each entry now gets its own frame index (its position within its shape group), assigned by image_id during grouping, replacing the path-reverse-lookup that collided on duplicate filenames and raised KeyError. - A COCO `score` on a detection annotation now yields predicted segmentation: PredictedSegmentationMask / PredictedROI carrying the score (unscored stays User), mirroring the existing bbox predicted/user split. The keypoint path keeps segmentation as User. ROI.to_mask is now polymorphic: a PredictedROI rasterizes to a PredictedSegmentationMask with its score (UserROI unchanged; BoundingBox.to_mask unaffected since to_roi returns UserROI). Tests cover the 3x duplicate-filename case, predicted RLE/polygon/ROI variants with .slp round-trip, the user fallback, and PredictedROI.to_mask. Docs note the predicted-vs-user behavior. Reviewed via an adversarial multi-agent pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #481 +/- ##
=======================================
Coverage 92.97% 92.97%
=======================================
Files 54 54
Lines 19439 19441 +2
Branches 4394 4391 -3
=======================================
+ Hits 18073 18076 +3
Misses 651 651
+ Partials 715 714 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Docs Preview
Changed pages: API changes detected - View API Reference This preview will be removed when the PR is closed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Two COCO-reader follow-ups from #479, in one PR:
file_namecrash fixed. Distinctimagesentries that share afile_nameno longer raiseKeyError.scoreon a detection annotation now producesPredictedSegmentationMask/PredictedROI, mirroring the existingbboxpredicted/user split.Key Changes
Fix #1 — duplicate filenames (correctness bug)
The reader built its frame-index map by reverse-matching resolved image paths to
image_ids andbreaking on the first match. Twoimagesentries pointing at the samefile_nameresolved to the same path, so both frames mapped to the firstimage_idand the second raisedKeyError. Each entry now gets its own frame index — its position within its shape group — assigned byimage_idduring grouping, and the buggy path-reverse-lookup loop is removed. Eachimagesentry becomes its ownLabeledFrame, as documented.Fix #3 — scored segmentation → predicted
_decode_segmentationgained ascoreparameter. Whenscore is not None, it buildsPredictedSegmentationMask/PredictedROIcarrying the score; otherwise theUser*variants (unchanged default). The detection path passesscore=annotation.get("score"); the keypoint path keeps segmentation asUser(itsscorebelongs to the pose instance), matching how the keypoint-pathbboxis alwaysUser.ROI.to_maskis now polymorphic: aPredictedROIrasterizes to aPredictedSegmentationMaskwith itsscore; any other ROI still yields aUserSegmentationMask.BoundingBox.to_maskis unaffected (BoundingBox.to_roireturns aUserROI).Example
Predicted masks round-trip through
.slp(class + score preserved).API Changes
ROI.to_mask()now returns aPredictedSegmentationMask(carryingscore) when called on aPredictedROI; behavior forUserROIis unchanged.coco._decode_segmentation(private) gained ascorekeyword. No public-signature changes;read_labels/load_cocobehavior only changes for annotations that carry ascore.Testing
tests/io/test_coco.py: 3× duplicate-file_nameentries load as distinct frames; scored polygon/RLE → predicted, scored ROI-mode →PredictedROI, unscored →User*, with.slpround-trip preserving class + score.tests/model/test_roi.py:PredictedROI.to_mask→PredictedSegmentationMaskwith score;UserROI.to_maskstaysUserSegmentationMask.to_maskdocstring copy-paste typo) was fixed.ruff check/format --checkclean; full suite green; docs guard green.🤖 Generated with Claude Code