Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use COCO Mask Parsing from pycocotools #8630

Open
david-csnmedia opened this issue Sep 3, 2024 · 1 comment
Open

Use COCO Mask Parsing from pycocotools #8630

david-csnmedia opened this issue Sep 3, 2024 · 1 comment

Comments

@david-csnmedia
Copy link

🚀 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

@NicolasHug
Copy link
Member

Thanks for opening the issue @david-csnmedia . I'm happy for you to open a PR and see if the tests are passing

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

No branches or pull requests

2 participants