question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incompatibility to pytorch: Some transformations return lists for singe Image

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
lukas-schottcommented, 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()])))
0reactions
genghisuncommented, Aug 6, 2020

Hi~ Is this problem fixed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Incompatibility to pytorch: Some transformations return lists for singe ...
The pipeline is not compatible with pytorch because the operations return lists [ ] but expect as input: Here a minimalistic example, where...
Read more >
Transforming and augmenting images - PyTorch
Most transformations accept both PIL images and tensor images, although some transformations are PIL-only and some are tensor-only.
Read more >
torchvision.transforms — Torchvision master documentation
Parameters: transforms (list of Transform objects) – list of transforms to ... This transform returns a tuple of images and there may be...
Read more >
Transforms — MONAI 1.1.0 Documentation
Return a Composition with a simple list of transforms, as opposed to any nested Compositions. ... requires pytorch >= 1.10 for best compatibility....
Read more >
Data Augmentation in PyTorch - Stack Overflow
Crop the given image into four corners and the central crop. This transform returns a tuple of images and there may be a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found