Skip to content

Conversation

@pmeier
Copy link
Contributor

@pmeier pmeier commented Aug 15, 2022

import torch
from torchvision.prototype import features, transforms


image = features.EncodedImage.from_path("test/assets/fakedata/logos/rgb_pytorch.png").decode()

bounding_boxes = features.BoundingBox(
    [[60, 30, 15, 15]],
    format=features.BoundingBoxFormat.CXCYWH,
    image_size=(100, 100),
    dtype=torch.float,
)

segmentation_masks = torch.zeros((1, 100, 100), dtype=torch.bool)
segmentation_masks[..., 24:36, 55:66] = True
segmentation_masks = features.SegmentationMask(segmentation_masks)

target = dict(
    boxes=bounding_boxes,
    masks=segmentation_masks,
)
sample = image, target

transform = transforms.RandomShortestSize(min_size=[30, 50, 70], max_size=150)

torch.manual_seed(0)

for i in range(6):
    transformed_image, transformed_target = transform(sample)
    transformed_bounding_boxes = transformed_target["boxes"]
    transformed_segmentation_masks = transformed_target["masks"]

1 2 3 4 0

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, thanks! We will probably some tests, not sure if you plan to add these in follow ups.

@pmeier pmeier merged commit c3573c8 into pytorch:main Aug 16, 2022
facebook-github-bot pushed a commit that referenced this pull request Aug 24, 2022
…type transforms (#6418)

Summary:
* port `RandomShortestSize` from detection references to prototype transforms

* mypy

* add test

Reviewed By: datumbox

Differential Revision: D38824228

fbshipit-source-id: a9d9bbad5fc4ffa7ad376f121be42f8d432bae2f
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