Skip to content

Conversation

pmeier
Copy link
Contributor

@pmeier pmeier commented Oct 19, 2021

This adds a few improvements:

  1. Add the ability to select which annotations to load, e.g. instances (default) or captions. None is a special value that will only load the images which is much faster if the annotations are not needed. This is for example useful for unsupervised training.

  2. Provide categories for each bounding box.

  3. Add tests.

  4. Add support for segmentation masks. Now you can do something like this:

    from torchvision.prototype import datasets
    from torchvision.utils import draw_segmentation_masks
    
    for sample in datasets.load("coco"):
        draw_segmentation_masks(sample["image"], sample["segmentations"])
        break

    foo

cc @pmeier @bjuncek

@pmeier pmeier marked this pull request as draft October 20, 2021 06:34
@pmeier pmeier requested review from datumbox and fmassa November 15, 2021 15:26
@pmeier pmeier marked this pull request as ready for review November 15, 2021 15:26
@pmeier
Copy link
Contributor Author

pmeier commented Nov 16, 2021

The new implementation is working, but is a major perf regression. Cold start now takes ~20 minutes on my system. With minmal fake data warm up is minimal, so I'm guessing one or more things I used in the implementation does not scale to more inputs.

@pmeier pmeier requested a review from ejguan November 16, 2021 08:05
@pmeier
Copy link
Contributor Author

pmeier commented Nov 18, 2021

I've added COCO to the benchmarks. Running

python -m torchvision.prototype.datasets.benchmark -n1 --no-start coco

with the patch described in #4650 (comment) gives:

################################################################################
coco (instances)
legacy iteration 185.052 it/s
new iteration 152.523 it/s
################################################################################
coco (captions)
legacy iteration 240.053 it/s
new iteration 198.828 it/s

@pmeier pmeier requested a review from fmassa November 25, 2021 18:36
Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

),
areas=torch.tensor([ann["area"] for ann in anns]),
crowds=torch.tensor([ann["iscrowd"] for ann in anns], dtype=torch.bool),
bounding_boxes=BoundingBox(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a future PR, I think it might be preferable to rename the class to BoundingBoxes as we hold more than one box now.

Comment on lines +114 to +119
segmentations=torch.stack(
[
self._segmentation_to_mask(ann["segmentation"], is_crowd=ann["iscrowd"], image_size=image_size)
for ann in anns
]
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can even have a custom class that holds the raw polygons, and knows how to convert itself if needed. But can be discussed at a separate stage.

@fmassa
Copy link
Member

fmassa commented Nov 30, 2021

ONNX-test error seems suspicious, but probably unrelated. I'm merging this but let's keep an eye on it

@fmassa fmassa merged commit 39cf02a into main Nov 30, 2021
@fmassa fmassa deleted the datasets/improve-coco branch November 30, 2021 16:59
facebook-github-bot pushed a commit that referenced this pull request Dec 2, 2021
Summary:
* improve COCO prototype

* test 2017 annotations

* add option to include captions

* fix categories and add tests

* cleanup

* add correct image size to bounding boxes

* fix annotation collation

* appease mypy

* add benchmark

* always use image as reference

* another refactor

* add support for segmentations

* add support for segmentations

* fix CI dependencies

Reviewed By: NicolasHug

Differential Revision: D32759200

fbshipit-source-id: 9033e959a1014761541ec2959ec5647eaccf5d0a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants