-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Conversation
@@ -1,5 +1,8 @@ | |||
import matplotlib.pyplot as plt | |||
from torchvision.utils import draw_bounding_boxes | |||
import torch |
There was a problem hiding this comment.
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
@@ -90,7 +90,7 @@ | |||
|
|||
from torchvision import datapoints # we'll describe this a bit later, bare with us | |||
|
|||
bboxes = datapoints.BoundingBoxes( | |||
boxes = datapoints.BoundingBoxes( |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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:
vision/torchvision/models/detection/ssd.py
Lines 333 to 341 in f7c7bdf
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)}.") |
``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: |
There was a problem hiding this comment.
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.
``torchvision.transforms.v2`` enables jointly transforming images, videos, | ||
bounding boxes, and masks. | ||
|
||
This example showcases an end-to-end instance segmentation training case using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
gallery/v2_transforms/helpers.py
Outdated
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
Summary: (Note: this ignores all push blocking failures!) Reviewed By: matteobettini Differential Revision: D48900411 fbshipit-source-id: 2880b47b7029d33e09883243651ddffaed8f5d94
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.