Skip to content

simplify boundingbox kernels with jit compatible ellipsis #5861

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

Merged
merged 2 commits into from
Apr 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions torchvision/prototype/transforms/functional/_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,18 +401,16 @@ def pad_bounding_box(
) -> torch.Tensor:
left, _, top, _ = _FT._parse_pad_padding(padding)

shape = bounding_box.shape

bounding_box = convert_bounding_box_format(
bounding_box, old_format=format, new_format=features.BoundingBoxFormat.XYXY
).view(-1, 4)
)

bounding_box[:, 0::2] += left
bounding_box[:, 1::2] += top
bounding_box[..., 0::2] += left
bounding_box[..., 1::2] += top

return convert_bounding_box_format(
bounding_box, old_format=features.BoundingBoxFormat.XYXY, new_format=format, copy=False
).view(shape)
)


crop_image_tensor = _FT.crop
Expand All @@ -425,19 +423,17 @@ def crop_bounding_box(
top: int,
left: int,
) -> torch.Tensor:
shape = bounding_box.shape

bounding_box = convert_bounding_box_format(
bounding_box, old_format=format, new_format=features.BoundingBoxFormat.XYXY
).view(-1, 4)
)

# Crop or implicit pad if left and/or top have negative values:
bounding_box[:, 0::2] -= left
bounding_box[:, 1::2] -= top
bounding_box[..., 0::2] -= left
bounding_box[..., 1::2] -= top

return convert_bounding_box_format(
bounding_box, old_format=features.BoundingBoxFormat.XYXY, new_format=format, copy=False
).view(shape)
)


def crop_segmentation_mask(img: torch.Tensor, top: int, left: int, height: int, width: int) -> torch.Tensor:
Expand Down