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

UnboundLocalError in PIL/JpegImagePlugin.py #3769

Closed
Deanamic opened this issue Apr 4, 2019 · 4 comments · Fixed by #3771 or Hearst-Hatchery/pillow-simd#2
Closed

UnboundLocalError in PIL/JpegImagePlugin.py #3769

Deanamic opened this issue Apr 4, 2019 · 4 comments · Fixed by #3771 or Hearst-Hatchery/pillow-simd#2
Labels

Comments

@Deanamic
Copy link

Deanamic commented Apr 4, 2019

What did you do?

Run the Pytorch transfer Learning tutorial

What did you expect to happen?

The code executes correctly

What actually happened?

an unboundlocalerror ocurred

File "/home/.../.venv/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop 
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/.../.venv/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in <listcomp>
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/.../.venv/lib/python3.7/site-packages/torchvision/datasets/folder.py", line 132, in __getitem__
 sample = self.loader(path)
File "/home/.../.venv/lib/python3.7/site-packages/torchvision/datasets/folder.py", line 178, in default_loader
 return pil_loader(path)
File "/home/.../.venv/lib/python3.7/site-packages/torchvision/datasets/folder.py", line 160, in pil_loader
 img = Image.open(f)
File "/home/.../.venv/lib/python3.7/site-packages/PIL/Image.py", line 2690, in open
 im = _open_core(fp, filename, prefix)
File "/home/.../.venv/lib/python3.7/site-packages/PIL/Image.py", line 2676, in _open_core
 im = factory(fp, filename)
File "/home/.../.venv/lib/python3.7/site-packages/PIL/JpegImagePlugin.py", line 783, in jpeg_factory
 im = JpegImageFile(fp, filename)
File "/home/.../.venv/lib/python3.7/site-packages/PIL/ImageFile.py", line 103, in __init__
 self._open()
File "/home/.../.venv/lib/python3.7/site-packages/PIL/JpegImagePlugin.py", line 373, in _open                
handler(self, i)
File "/home/.../TransferLearning-Torch/.venv/lib/python3.7/site-packages/PIL/JpegImagePlugin.py", line 139, in APP
 self.info["photoshop"] = photoshop
UnboundLocalError: local variable 'photoshop' referenced before assignment

What are your OS, Python and Pillow versions?

  • OS: Manjaro Linux
  • Python: 3.7.3
  • Pillow: 6.0.0

I can consistently reproduce this by running the script on the tutorial above. The issue doesn't occur if I downgrade to Pillow 5.4.1

@radarhere
Copy link
Member

Thanks for reporting this. I've created PR #3771 to resolve it.

@Emma0928
Copy link

Thank you for sharing this solution.
How can I downgrade my pillow version?

@hugovk
Copy link
Member

hugovk commented May 23, 2019

Downgrade with something like pip install "pillow==x.y.z" where x.y.z is the version you want.

@Emma0928
Copy link

Downgrade with something like pip install "pillow==x.y.z" where x.y.z is the version you want.

Thank you for your reply!! It worked~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment