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

cannot identify image file <_io.BytesIO object at 0x7f2d80b2e770> #22

Open
zzw1123 opened this issue Jun 7, 2018 · 5 comments
Open

Comments

@zzw1123
Copy link

zzw1123 commented Jun 7, 2018

Thanks for your contribution!
But when I run the code, an error occurs:

Traceback (most recent call last):
File "runtime.py", line 42, in
trainer.train(args.cls)
File "/home/zzw/program/text2img/text-to-Image-Synthesis-pytorch/trainer.py", line 65, in train
self._train_wgan(cls)
File "/home/zzw/program/text2img/text-to-Image-Synthesis-pytorch/trainer.py", line 103, in _train_wgan
sample = next(data_iterator)
File "/home/zzw/.local/lib/python2.7/site-packages/torch/utils/data/dataloader.py", line 281, in next
return self._process_next_batch(batch)
File "/home/zzw/.local/lib/python2.7/site-packages/torch/utils/data/dataloader.py", line 301, in _process_next_batch
raise batch.exc_type(batch.exc_msg)
IOError: Traceback (most recent call last):
File "/home/zzw/.local/lib/python2.7/site-packages/torch/utils/data/dataloader.py", line 55, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/zzw/program/text2img/text-to-Image-Synthesis-pytorch/txt2image_dataset.py", line 46, in getitem
right_image = Image.open(io.BytesIO(right_image)).resize((64, 64))
File "/home/zzw/.local/lib/python2.7/site-packages/PIL/Image.py", line 2590, in open
% (filename if filename else fp))
IOError: cannot identify image file <_io.BytesIO object at 0x7f1be1801770>

My Pillow version is 5.1.0, and it seems like something related to the version.
Could anyone help me out?

@Rakshith-Manandi
Copy link

Were you able to fix this? I'm facing the same issue.

@jingliao132
Copy link

I modified 'data=np.void(img)' in convert_cub_to_hd5_script.py(line 63) to 'data=np.array(img)', and reinstall the pil, then it works. I think the problem is related to the content of 'right_image' in hdf5 file. You can run a simple test on your hdf5 file:

dataset = h5py.File(PATH_TO_HDF5FILE, 'r') # PATH_TO_HDF5FILE is the path of birds.hdf5
dataset_keys = [str(k) for k in dataset['train'].keys()]
example_name = self.dataset_keys[0]
example = self.dataset['train'][example_name]
byte_image = bytes(np.array(example['img']))
image = Image.open(io.BytesIO(byte_image))
image.show()

Hope it can help

@Hanzy1996
Copy link

I had the same question. But bug disappears when I use python3.5.

@s-a-c-h-i-n
Copy link

Run the code in python3.

@abdulla19851985
Copy link

Were you able to fix this? I'm facing the same issue

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

6 participants