Skip to content

Commit c82b86d

Browse files
pmeierdatumbox
andauthored
simplify boundingbox kernels with jit compatible ellipsis (#5861)
Co-authored-by: Vasilis Vryniotis <[email protected]>
1 parent c66da5e commit c82b86d

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

torchvision/prototype/transforms/functional/_geometry.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -401,18 +401,16 @@ def pad_bounding_box(
401401
) -> torch.Tensor:
402402
left, _, top, _ = _FT._parse_pad_padding(padding)
403403

404-
shape = bounding_box.shape
405-
406404
bounding_box = convert_bounding_box_format(
407405
bounding_box, old_format=format, new_format=features.BoundingBoxFormat.XYXY
408-
).view(-1, 4)
406+
)
409407

410-
bounding_box[:, 0::2] += left
411-
bounding_box[:, 1::2] += top
408+
bounding_box[..., 0::2] += left
409+
bounding_box[..., 1::2] += top
412410

413411
return convert_bounding_box_format(
414412
bounding_box, old_format=features.BoundingBoxFormat.XYXY, new_format=format, copy=False
415-
).view(shape)
413+
)
416414

417415

418416
crop_image_tensor = _FT.crop
@@ -425,19 +423,17 @@ def crop_bounding_box(
425423
top: int,
426424
left: int,
427425
) -> torch.Tensor:
428-
shape = bounding_box.shape
429-
430426
bounding_box = convert_bounding_box_format(
431427
bounding_box, old_format=format, new_format=features.BoundingBoxFormat.XYXY
432-
).view(-1, 4)
428+
)
433429

434430
# Crop or implicit pad if left and/or top have negative values:
435-
bounding_box[:, 0::2] -= left
436-
bounding_box[:, 1::2] -= top
431+
bounding_box[..., 0::2] -= left
432+
bounding_box[..., 1::2] -= top
437433

438434
return convert_bounding_box_format(
439435
bounding_box, old_format=features.BoundingBoxFormat.XYXY, new_format=format, copy=False
440-
).view(shape)
436+
)
441437

442438

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

0 commit comments

Comments
 (0)