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

Incompatibility to pytorch: Some transformations return lists for singe Image #109

Open
lukas-schott opened this issue Apr 25, 2018 · 5 comments

Comments

@lukas-schott
Copy link

The pipeline is not compatible with pytorch because the operations return lists
[ <PIL.Image.Image image mode=L size=28x28 at 0x7F4C6F113A90>]
but expect as input:
<PIL.Image.Image image mode=L size=28x28 at 0x7F4C6F113A90>

Here a minimalistic example, where I show what the MNIST dataloader does internally and why it fails..

import Augmentor
from torchvision import datasets, transforms
from torch.utils import data

loader = data.DataLoader(datasets.MNIST('./../data', download=True, transform=transforms.Compose([transforms.ToTensor()])))

p1 = Augmentor.Pipeline()
p1.zoom(probability=1, min_factor=1.1, max_factor=1.5)
p1 = p1.torch_transform()

p2 = Augmentor.Pipeline()
p2.shear(probability=1, max_shear_left=5, max_shear_right=5)
p2 = p2.torch_transform()
# test it
for i, (batch, label) in enumerate(loader):
    batch = transforms.ToPILImage()(batch[0])
    batch = p1(batch)  
    print(batch)           # prints [<PIL.Image.Image image mode=L size=28x28 at 0x7F4BE1BF9470>]
    batch = p2(batch)      # expects list --> fails, works if I do p2(batch[0])
    print('batch', batch)
    break
@lukas-schott
Copy link
Author

lukas-schott commented Apr 25, 2018

workaround:

def from_list(x):
    if isinstance(x, list):
        return x[0]
    else:
        return x


loader = data.DataLoader(datasets.MNIST('./../data', download=True, transform=transforms.Compose([
                p1, from_list, p2, from_list, transforms.ToTensor()])))

@StuckinPhD
Copy link

This bug still exists.

p.torch_transform() expects an image array but gets a list.

I dont really understand how the workaround works, Im using the pytorch implementation as mentioned in the docs:

 p = Augmentor.Pipeline()
p.flip_left_right(probability=0.5)
p.flip_top_bottom(probability=0.5)
p.random_distortion(probability=0.5, grid_width=8, grid_height=8, magnitude=8)


transforms_ = torchvision.transforms.Compose([
    p.torch_transform(),
    torchvision.transforms.ToTensor()
])

In Operations.py this line expects the size of an image:

w, h = images[0].size
but since image[0] is a list it returns the number of elements in the array =/

@Samyssmile
Copy link

This bug still exists.

p.torch_transform() expects an image array but gets a list.

I dont really understand how the workaround works, Im using the pytorch implementation as mentioned in the docs:

 p = Augmentor.Pipeline()
p.flip_left_right(probability=0.5)
p.flip_top_bottom(probability=0.5)
p.random_distortion(probability=0.5, grid_width=8, grid_height=8, magnitude=8)


transforms_ = torchvision.transforms.Compose([
    p.torch_transform(),
    torchvision.transforms.ToTensor()
])

In Operations.py this line expects the size of an image:

w, h = images[0].size
but since image[0] is a list it returns the number of elements in the array =/

Hi did you solved this ?

@StuckinPhD
Copy link

This bug still exists.
p.torch_transform() expects an image array but gets a list.
I dont really understand how the workaround works, Im using the pytorch implementation as mentioned in the docs:

 p = Augmentor.Pipeline()
p.flip_left_right(probability=0.5)
p.flip_top_bottom(probability=0.5)
p.random_distortion(probability=0.5, grid_width=8, grid_height=8, magnitude=8)


transforms_ = torchvision.transforms.Compose([
    p.torch_transform(),
    torchvision.transforms.ToTensor()
])

In Operations.py this line expects the size of an image:
w, h = images[0].size
but since image[0] is a list it returns the number of elements in the array =/

Hi did you solved this ?

I just stopped using p.torch_transform() and went the normal route of saving the generated images to a directory and then loading them in my Dataset class

@genghisun
Copy link

Hi~ Is this problem fixed?

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

4 participants