-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Simplify query_bounding_boxes logic #7786
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
Changes from all commits
62d0a98
b7dc5be
df15439
0676b08
5ca3bde
c5190d5
d360904
513f4b1
0619801
0189a6b
b962a4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -26,6 +26,12 @@ class BoundingBoxFormat(Enum): | |||||
| class BoundingBoxes(Datapoint): | ||||||
| """[BETA] :class:`torch.Tensor` subclass for bounding boxes. | ||||||
|
|
||||||
| .. note:: | ||||||
| There should be only one :class:`~torchvision.datapoints.BoundingBoxes` | ||||||
| instance per sample e.g. ``{"img": img, "bbox": BoundingBoxes(...)}``, | ||||||
| although one :class:`~torchvision.datapoints.BoundingBoxes` object can | ||||||
| contain multiple bounding boxes. | ||||||
|
|
||||||
| Args: | ||||||
| data: Any data that can be turned into a tensor with :func:`torch.as_tensor`. | ||||||
| format (BoundingBoxFormat, str): Format of the bounding box. | ||||||
|
|
@@ -43,6 +49,10 @@ class BoundingBoxes(Datapoint): | |||||
|
|
||||||
| @classmethod | ||||||
| def _wrap(cls, tensor: torch.Tensor, *, format: Union[BoundingBoxFormat, str], canvas_size: Tuple[int, int]) -> BoundingBoxes: # type: ignore[override] | ||||||
| if tensor.ndim == 1: | ||||||
| tensor = tensor.unsqueeze(0) | ||||||
| elif tensor.ndim != 2: | ||||||
| raise ValueError(f"Expected a 1D or 2D tensor, got {tensor.ndim}D") | ||||||
|
Comment on lines
+52
to
+55
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have a super strong opinion on that and I don't mind removing it, but IMO passing other number of dims indicates a user mistake upstream. We don't support batches of bounding boxes (i.e. we can't batch BoundingBoxes objects where
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Due to this, the following check is obsolete: vision/torchvision/transforms/v2/_misc.py Lines 392 to 393 in 9b82df4
I've removed it and the (now failing) test for it in b962a4b. If we decide to not go with this, make sure to revert the commit as well. |
||||||
| if isinstance(format, str): | ||||||
| format = BoundingBoxFormat[format.upper()] | ||||||
| bounding_boxes = tensor.as_subclass(cls) | ||||||
|
|
||||||
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.
Driveby