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

Rewrite transforms v2 e2e example #7881

Merged
merged 10 commits into from
Aug 25, 2023
Merged

Conversation

NicolasHug
Copy link
Member

This is a light rewrite despite the seemingly big diff. I just extended it a little to include masks and to be a bit more descriptive / detailed.

@pytorch-bot
Copy link

pytorch-bot bot commented Aug 24, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/7881

Note: Links to docs will display an error until the docs builds have been completed.

❌ 33 New Failures

As of commit 980556d with merge base 92e4e9c (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@@ -1,5 +1,8 @@
import matplotlib.pyplot as plt
from torchvision.utils import draw_bounding_boxes
import torch
Copy link
Member Author

Choose a reason for hiding this comment

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

Changes in this file are only needed to support masks

@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 14:56 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 14:56 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 14:56 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 14:56 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 14:56 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 14:56 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 14:56 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 14:56 — with GitHub Actions Inactive
@@ -90,7 +90,7 @@

from torchvision import datapoints # we'll describe this a bit later, bare with us

bboxes = datapoints.BoundingBoxes(
boxes = datapoints.BoundingBoxes(
Copy link
Member Author

Choose a reason for hiding this comment

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

Dataset wrapper uses "boxes" instead of "bboxes". I don't have a pref, but we should align (hence the changes in this example)

Copy link
Contributor

Choose a reason for hiding this comment

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

The reason the dataset wrapper uses "boxes" is because our models require that:

for target in targets:
boxes = target["boxes"]
if isinstance(boxes, torch.Tensor):
torch._assert(
len(boxes.shape) == 2 and boxes.shape[-1] == 4,
f"Expected target boxes to be a tensor of shape [N, 4], got {boxes.shape}.",
)
else:
torch._assert(False, f"Expected target boxes to be of type Tensor, got {type(boxes)}.")

@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 14:57 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 14:57 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 14:57 — with GitHub Actions Inactive
``torchvision.transforms.v2`` enables jointly transforming images, videos, bounding boxes, and masks. This example
showcases an end-to-end object detection training using the stable ``torchvision.datasets`` and ``torchvision.models``
as well as the new ``torchvision.transforms.v2`` v2 API.
Object detection and segmentation tasks are natively supported:
Copy link
Member Author

Choose a reason for hiding this comment

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

Using "segmentation" loosely here (i.e. both instance and semantic). It's made more accurate a bit later in the example, the main point being that it doesn't matter which one you're targetting, the transforms work the same.

@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 14:59 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 14:59 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 14:59 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 14:59 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 15:11 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 15:11 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 15:12 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 15:12 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 24, 2023 15:28 — with GitHub Actions Inactive
``torchvision.transforms.v2`` enables jointly transforming images, videos,
bounding boxes, and masks.

This example showcases an end-to-end instance segmentation training case using
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
This example showcases an end-to-end instance segmentation training case using
This example showcases an end-to-end object detection / instance segmentation training case using

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's fine to keep as-is considering the sentence just below. Technically, it is an instance segmentation model.

Copy link
Contributor

@pmeier pmeier left a comment

Choose a reason for hiding this comment

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

Minor comment left, but LGTM nonetheless. Thanks Nicolas!

Comment on lines 38 to 40
img = draw_bounding_boxes(img, boxes, colors="yellow", width=3)
if masks is not None:
img = draw_segmentation_masks(img, masks.to(torch.bool), alpha=.65)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we maybe also make the masks yellow or some other color? I fell in the current version the masks is not completely obvious on the image.

Copy link
Member Author

Choose a reason for hiding this comment

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

hmmm looks like the color param is broken, I tried colors="green" and colors=["green"] * masks.shape[0], none of which had an effect. Might be worth looking into but I'll merge

Copy link
Member Author

Choose a reason for hiding this comment

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

maybe I was looking at the wrong output - it actually works fine and the masks are green (and very obvious)

@NicolasHug NicolasHug merged commit 224cbc8 into pytorch:main Aug 25, 2023
1 check passed
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:41 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:41 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:41 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:41 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:41 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:41 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:41 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:42 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:42 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:42 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:42 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:42 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:42 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:42 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:42 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:42 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:42 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:42 — with GitHub Actions Inactive
@NicolasHug NicolasHug temporarily deployed to pytorchbot-env August 25, 2023 08:47 — with GitHub Actions Inactive
facebook-github-bot pushed a commit that referenced this pull request Sep 6, 2023
Summary: (Note: this ignores all push blocking failures!)

Reviewed By: matteobettini

Differential Revision: D48900411

fbshipit-source-id: 2880b47b7029d33e09883243651ddffaed8f5d94
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.

4 participants