pytorch / pytorch/vision

Use COCO Mask Parsing from pycocotools

Open
#8,630 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

🚀 The feature

The CocoDetection v2 transform wrapper attempts to decode the mask itself, but pycocotools provides a high performance implementation already. We have had to copy from master, this _dataset_wrapper.py because of a bug related to the handling of these masks that was fixed in master but not installable using pip yet.

https://github.com/pytorch/vision/blob/main/torchvision/tv_tensors/_dataset_wrapper.py#L402

Seeing torchvision.datasets.CocoDetection has self.coco as a COCO() object, let's use it.

       coco_ann = dataset.coco.imgToAnns[image_id]

        if "masks" in target_keys:
            target["masks"] = tv_tensors.Mask(
                    torch.stack([
                        torch.from_numpy(dataset.coco.annToMask(ann))
                        for ann in coco_ann
                    ])
                )
Motivation, pitch

There have already been bugs related to this, and there's no need to reinvent the wheel. Instead, let's use the existing implementation.

Alternatives

No response

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in torchvision/tv_tensors/_dataset_wrapper.py around the referenced mask-decoding logic and inspect the CocoDetection dataset entry point. Verify how dataset.coco.imgToAnns and annToMask provide the annotations, then run the relevant existing dataset or transform tests; done means mask targets are decoded through pycocotools without changing expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.