Fix inconsistent force_masks across dataset formats#265
Fix inconsistent force_masks across dataset formats#265Borda merged 14 commits intoroboflow:developfrom
force_masks across dataset formats#265Conversation
|
Hi, @kirilllzaitsev! 👋🏻 I marked this PR as a @hardikdava and @artyaltanzaya could you take a look at the PR in the meantime? |
|
@capjamesg @yeldarby I think you should know we are working on those changes. They might influence Autodistill. |
|
Hi, @kirilllzaitsev 👋🏻! Sorry for not being overly active on this PR. I was a bit busy. Any chance you could provide Google Colab to test the updated version? 🙏🏻 |
|
@SkalskiP sure, I will prepare it a bit later today |
|
Awesome! Thanks a lot @kirilllzaitsev 🙏🏻 |
artyaltanzaya
left a comment
There was a problem hiding this comment.
thanks for the contribution! added minor suggestions for clarity.
|
@SkalskiP here is the colab link. Current behavior in COCO and VOC differs if the force_masks is True, but there are no masks: VOC proceeds with an empty annotation.mask, while COCO errors out with a KeyError (at this point, I would handle the case of force_masks=True and no masks with a warning and no error. What are your thoughts? |
|
Hi, @kirilllzaitsev 👋🏻! Will you have time to resolve conflicts in this branch today? |
|
Hey @SkalskiP , sure, done |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #265 +/- ##
======================================
Coverage 73% 74%
======================================
Files 61 61
Lines 7390 7395 +5
======================================
+ Hits 5422 5447 +25
+ Misses 1968 1948 -20 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR aims to make force_masks behave consistently across dataset formats by enabling masks when the flag is set or when masks are present in the annotations, instead of using force_masks as a strict on/off switch for parsing masks in COCO.
Changes:
- In
pascal_voc.py, introduces a_with_maskhelper and updatesdetections_from_xml_objto use it when deciding whether to include masks. - In
coco.py, updatesload_coco_annotationsto computewith_masksbased onforce_masksor the presence of asegmentationfield and passes this intococo_annotations_to_detections, adding a_with_maskhelper for COCO annotations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| supervision/dataset/formats/pascal_voc.py | Refactors mask detection into a _with_mask helper and adjusts detections_from_xml_obj mask-flag logic to align with other formats. |
| supervision/dataset/formats/coco.py | Changes load_coco_annotations to infer with_masks from force_masks plus annotation content via a new _with_mask helper and passes the result into detection conversion. |
Comments suppressed due to low confidence (2)
supervision/dataset/formats/pascal_voc.py:245
- The
with_masksflag is overwritten on each object inside the loop and then only used once when constructingDetections, so if an earlier object has a polygon and a later object does not, previously computed masks will be discarded becausewith_masksreflects only the last object processed. To make mask handling consistent and avoid silently dropping masks, consider computingwith_masksbased on whether any object in the image has a polygon (or onforce_masks) outside the loop, or otherwise ensuring it accumulates mask presence across objects rather than just mirroring the last one.
with_masks = force_masks or _with_mask(obj)
for polygon in obj.findall("polygon"):
polygon = parse_polygon_points(polygon)
# https://github.com/roboflow/supervision/issues/144
supervision/dataset/formats/pascal_voc.py:245
detections_from_xml_objhas mask-handling logic controlled byforce_masksand_with_mask, but the existing tests intest/dataset/formats/test_pascal_voc.py::test_detections_from_xml_objonly cover bounding boxes and never exercise objects with<polygon>elements orforce_masks=True. Adding tests that cover polygon masks and theforce_masksflag would help ensure that future changes to this code (including the new_with_maskhelper) behave as intended.
with_masks = force_masks or _with_mask(obj)
for polygon in obj.findall("polygon"):
polygon = parse_polygon_points(polygon)
# https://github.com/roboflow/supervision/issues/144
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…stency and clarity. Rename helper functions for better readability. Add parametrized test cases with descriptive IDs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…d tests for mixed annotations and mask inference logic.
…illlzaitsev/supervision into fix/inconsistent_force_masks
Description
load_coco_annotationsusedforce_masksas a flag that indicates if masks should be parsed or not. On the contrary, YOLO and VOC enforce parsing masks if this flag is set, or parse masks in case they are present in annotations. Current change homogenizes the behavior, setting it to the second option.Type of change
Please delete options that are not relevant.
How has this change been tested, please provide a testcase or example of how you tested the change?
Does not impact anything.
Any specific deployment considerations
For example, documentation changes, usability, usage/costs, secrets, etc.
Docs