Skip to content
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