Skip to content

torchvision transforms to take list of PIL images instead of a single PIL image #610

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

Closed
quantummole opened this issue Sep 24, 2018 · 2 comments

Comments

@quantummole
Copy link

For some problems like segmentation we would like the same random transform to be applied on the input and the masks.
Is it possible to add a check inside the call method to check if the input is a list then apply the same transformation(with same values) for each element of the list

@sotte
Copy link
Contributor

sotte commented Oct 2, 2018

Functional transforms can be reused. It's easy to create transform pipelines for segmentation tasks:

import torchvision.transforms.functional as TF
import random

def my_segmentation_transforms(image, segmentation):
    if random.random() > 5:
        angle = random.randint(-30, 30)
        image = TF.rotate(image, angle)
        segmentation = TF.rotate(segmentation, angle)
    # more transforms ...
    return image, segmentation

Maybe not quite as convenient as Compose but very flexible. You could write a little function that maps through multiple inputs:

def emap(fn, iterable):
    """eager map because I'm lazy and don't want to type."""
    return list(map(fn, iterable))

sample = image, mask

rotate = partial(TF.rotate, angle=random.randint(-45, 45))
sample = emap(rotate, sample)

resize = partia(TF.resize, size=299)
sample = emap(rotate, sample)

@datumbox
Copy link
Contributor

datumbox commented Jan 6, 2021

This issue appears to be stale, so I'm closing it. If you think it should remain open, feel free to reopen it.

@datumbox datumbox closed this as completed Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants