Skip to content

Conversation

@vfdev-5
Copy link
Contributor

@vfdev-5 vfdev-5 commented May 9, 2022

Related to #5514

Description:

  • Added functional center_crop_bounding_box op
  • Added tests

Results on synthetic images/bboxes:

Code
import numpy as np

import torch
import torchvision
from torchvision.prototype import features
from torchvision.prototype.transforms.functional import center_crop_bounding_box, center_crop_image_tensor

size = (64, 76)
# xyxy format
in_boxes = [
    [10, 15, 25, 35],
    [50, 5, 70, 22],
    [45, 46, 56, 62],
    [size[1] // 2 - 3, size[0] // 2 - 3, size[1] // 2 + 3, size[0] // 2 + 3]
]
labels = [1, 2, 3, 4]

im1 = 255 * np.ones(size + (3, ), dtype=np.uint8)
for in_box, label in zip(in_boxes, labels):
    im1[in_box[1]:in_box[3], in_box[0]:in_box[2], :] = (127, 127, 127)
    
in_im = torch.tensor(im1).permute(2, 0, 1).view(1, 3, *size)

in_boxes = features.BoundingBox(
    in_boxes, format=features.BoundingBoxFormat.XYXY, image_size=size
)

output_size = (45, 50)
    
out_boxes = center_crop_bounding_box(
    in_boxes, 
    in_boxes.format,
    output_size=output_size,
    image_size=in_boxes.image_size
)

out_im = center_crop_image_tensor(in_im, output_size)

image

Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on the kernel side.

@pmeier any thoughts on the testing strategy?

Edit: The annotation check is failing. Can you please resolve?

@vfdev-5 vfdev-5 force-pushed the proto-bbox-center-crop branch from b56b5e1 to 0a15c08 Compare May 9, 2022 11:23
@datumbox
Copy link
Contributor

datumbox commented May 9, 2022

I've checked with Philip offline and 👎 means no issue from his side. Therefore I merged.

@datumbox datumbox merged commit 7d0d7fd into pytorch:main May 9, 2022
@vfdev-5 vfdev-5 deleted the proto-bbox-center-crop branch May 9, 2022 12:30
@vfdev-5
Copy link
Contributor Author

vfdev-5 commented May 9, 2022

Yeah, 👍 is yes (there is something to add) and 👎 is no issues :)

facebook-github-bot pushed a commit that referenced this pull request May 11, 2022
Summary:
* [proto] Added `center_crop_bounding_box` functional op

* Fixed mypy issue

* Added one more test case

* More test cases

Reviewed By: YosuaMichael

Differential Revision: D36281607

fbshipit-source-id: dd6a822ecb439e07e115d4d854e9a8ce7a53873d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants