Fix COCO export instance segmentation coordinates out of bounds#7225
Fix COCO export instance segmentation coordinates out of bounds#7225qianchongyang wants to merge 1 commit intovoxel51:developfrom
Conversation
When exporting polylines to COCO format, segmentation polygon points that fall outside the computed bounding box are now clipped to the bbox boundaries. This prevents OOB (out of bounds) errors when the segmentation extends beyond the bounding box. Fixes voxel51#2847
WalkthroughThe changes fix an out-of-bounds segmentation issue in COCO exports by adding bbox clipping logic to the polyline-to-COCO-segmentation conversion. When Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment Tip You can get early access to new features in CodeRabbit.Enable the |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
fiftyone/utils/coco.py (1)
2253-2277: 🧹 Nitpick | 🔵 TrivialLGTM — clipping implementation is correct.
The logic properly clips absolute pixel coordinates to the bbox bounds using consistent
int()truncation. The optionalbboxparameter maintains backwards compatibility, and theiscrowdearly-return path correctly skips clipping since it uses RLE representation.One optional improvement: add a return type annotation per the static analysis hint.
🔧 Optional: Add return type annotation
def _polyline_to_coco_segmentation( polyline, frame_size, iscrowd="iscrowd", bbox=None -): +) -> list:🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@fiftyone/utils/coco.py` around lines 2253 - 2277, Add an explicit return type annotation to _polyline_to_coco_segmentation: change its signature to include a Union return type reflecting COCO segmentation outputs (e.g. Union[List[List[int]], Dict[str, Any]]), and add the necessary typing imports (from typing import List, Dict, Any, Union) at the top of the module; keep the existing parameters (polyline, frame_size, iscrowd="iscrowd", bbox=None) unchanged so behavior and compatibility remain the same.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@fiftyone/utils/coco.py`:
- Around line 2253-2277: Add an explicit return type annotation to
_polyline_to_coco_segmentation: change its signature to include a Union return
type reflecting COCO segmentation outputs (e.g. Union[List[List[int]], Dict[str,
Any]]), and add the necessary typing imports (from typing import List, Dict,
Any, Union) at the top of the module; keep the existing parameters (polyline,
frame_size, iscrowd="iscrowd", bbox=None) unchanged so behavior and
compatibility remain the same.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: a24aa8d7-c46e-496a-ae15-24bc2d7ba742
📒 Files selected for processing (1)
fiftyone/utils/coco.py
|
Thanks for the PR @qianchongyang! There is a proposed fix #6904 from February of this year, and the conversation ended with a pause on merging those changes, to reconcile with voxel51/eta/pull/693. As far as I can tell, there's still some deliberation happening, so you may want to take a look at the other PRs and chime in with your perspective |
Problem
When exporting datasets to COCO format, instance segmentation masks have coordinates that exceed the bounds of their bounding boxes. This causes data integrity issues in exported annotations.
Solution
Added clipping logic to ensure segmentation polygon coordinates are clipped to their corresponding bounding box bounds before export.
Validation
Fixes #2847
Summary by CodeRabbit