Skip to content

Keep the crowd flag of COCO and YouTube-VIS instance segmentations - #93

Closed
lorinczszabolcs wants to merge 1 commit into
lightly-ai:mainfrom
lorinczszabolcs:fix-coco-rle-iscrowd
Closed

lorinczszabolcs wants to merge 1 commit into
lightly-ai:mainfrom
lorinczszabolcs:fix-coco-rle-iscrowd

Conversation

@lorinczszabolcs

Copy link
Copy Markdown
Contributor

What has changed and why?

Proposed fix for lightly-ai/lightly-studio#2959. I am open to other approaches, see the open questions below.

  • COCO and YouTube-VIS output set iscrowd from the mask encoding, so every RLE mask is written as a crowd. Tools that store single objects as RLE, like LightlyStudio or maskpair with segmentation_type="rle", export files in which COCO evaluation ignores every object.
  • COCO input chooses the decoder from iscrowd. An RLE mask with iscrowd: 0 fails with ValueError: could not convert string to float.
  • This PR adds is_crowd: bool = False to SingleInstanceSegmentation and SingleInstanceSegmentationTrack. COCO and YouTube-VIS input read it from iscrowd, and the output writes it back as 0 or 1.
  • COCO input now chooses the decoder from the segmentation type (dict for RLE, list for polygons), as YouTube-VIS input already does.

Open questions

  • get_coco_segmentation no longer returns the crowd flag, because that value came from the encoding. The function is not exported in labelformat/__init__.py or in the docs, and I found no caller in the lightly-ai repositories. If you prefer to keep the signature, I can keep the third value and not use it.
  • maskpair to COCO with RLE masks now writes iscrowd: 0, because each mask is one object. Before, it wrote true.
  • Add confidence to SingleInstanceSegmentation #90 adds confidence to the same dataclass and changes the same lines in coco.py. The PR that merges second needs a small rebase.

How has it been tested?

  • New tests: COCO input for RLE and polygons with iscrowd 0 and 1, a COCO round trip that keeps iscrowd for both encodings, and a YouTube-VIS round trip with an RLE track that is not a crowd and a polygon track that is a crowd. These tests fail on main for the bug cases.
  • Updated tests: the YouTube-VIS input test expects is_crowd, and the maskpair RLE test expects iscrowd: 0.
  • make all-checks on Python 3.8 and 3.14: 184 passed, 1 skipped.
  • With lightly-studio 1.2.0 and this branch, the reproduction of [BUG] COCO mask export sets iscrowd to true on every annotation, so COCO evaluation ignores all objects lightly-studio#2959 exports iscrowd: 0, and pycocotools gives AP 1.0 instead of -1.0.
  • Files with "iscrowd": true, as labelformat 0.1.17 writes them, still read as crowds.

@JonasWurst

Copy link
Copy Markdown

/review

@JonasWurst

Copy link
Copy Markdown

Thank you @lorinczszabolcs! We have discussed your approach internally. We'd like to not modify the label base class with some format specific details such as the crowded flag from coco. Happy to discuss alternatives

@lorinczszabolcs

Copy link
Copy Markdown
Contributor Author

Thanks @JonasWurst, makes sense. As an alternative I would keep the crowd flag inside the COCO and YouTube-VIS format code, for example in format-specific subclasses, so the base classes stay unchanged and both formats still keep crowds on a round trip. Would that work for you?

@JonasWurst

Copy link
Copy Markdown

@lorinczszabolcs at a high level your proposal sounds good. Will you open a new PR?

@lorinczszabolcs

Copy link
Copy Markdown
Contributor Author

@JonasWurst Opened #94 with the format-specific subclasses. Closing this one in favor of it.

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.

2 participants