Error while Running Transer learning tutorial

While Running Pytorch Transfer learning tutorial I am getting following error.
Please tell the problem

Traceback (most recent call last):
  File "transfer_learning_tutorial.py", line 121, in <module>
    inputs, classes = next(iter(dset_loaders['train']))
  File "/usr/local/lib/python2.7/dist-packages/torch/utils/data/dataloader.py", line 201, in __next__
    return self._process_next_batch(batch)
  File "/usr/local/lib/python2.7/dist-packages/torch/utils/data/dataloader.py", line 221, in _process_next_batch
    raise batch.exc_type(batch.exc_msg)
AttributeError: Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/torch/utils/data/dataloader.py", line 40, in _worker_loop
    samples = collate_fn([dataset[i] for i in batch_indices])
  File "build/bdist.linux-x86_64/egg/torchvision/datasets/folder.py", line 116, in __getitem__
    img = self.loader(path)
  File "build/bdist.linux-x86_64/egg/torchvision/datasets/folder.py", line 63, in default_loader
    return pil_loader(path)
  File "build/bdist.linux-x86_64/egg/torchvision/datasets/folder.py", line 45, in pil_loader
    with Image.open(f) as img:
  File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 528, in __getattr__
    raise AttributeError(name)
AttributeError: __exit__

Something is wrong with loading images. Either your Pillow package is outdated or your images are not at right location.

The same problem.
I’ve extracted data to current dir and Pillow==4.0.0

if it was me, to go fruther with this, I might:

  • hack the library file at “build/bdist.linux-x86_64/egg/torchvision/datasets/folder.py”, line 116, to print the value of path
  • try loading this file using Pillow.Image directly
  • => if it’s a pillow issue, then, it’s probably out of scope for pytorch
  • otherwise, report back to pytorch that pillow itself is working ok, yada yada
1 Like