Keras: IOError: Image File is truncated

Created on 22 Feb 2017  路  5Comments  路  Source: keras-team/keras

I'm getting the following error while training the inception V3 model on my own data.

Traceback (most recent call last):
File "/usr/lib64/python2.7/threading.py", line 813, in __bootstrap_inner
self.run()
File "/usr/lib64/python2.7/threading.py", line 766, in run
self.__target(self.__args, *self.__kwargs)
File "/usr/local/lib/python2.7/site-packages/Keras-1.2.2-py2.7.egg/keras/engine/training.py", line 429, in data_generator_task
generator_output = next(self._generator)
File "/usr/local/lib/python2.7/site-packages/Keras-1.2.2-py2.7.egg/keras/preprocessing/image.py", line 832, in next
target_size=self.target_size)
File "/usr/local/lib/python2.7/site-packages/Keras-1.2.2-py2.7.egg/keras/preprocessing/image.py", line 300, in load_img
img = img.convert('RGB')
File "/usr/lib64/python2.7/dist-packages/PIL/Image.py", line 653, in convert
self.load()
File "/usr/lib64/python2.7/dist-packages/PIL/ImageFile.py", line 192, in load
raise IOError("image file is truncated (%d bytes not processed)" % len(b))

Most helpful comment

I have added the following lines before my fit_generator :

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

as suggested in the second solution in the following link: http://stackoverflow.com/questions/12984426/python-pil-ioerror-image-file-truncated-with-big-images

It solved the problem for me.

All 5 comments

I get the same error, I'm using the Inception V3 model and stacking some layers on top.

Using keras==1.2.2 & Pillow==4.0.0

Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "<path>/local/lib/python2.7/site-packages/keras/engine/training.py", line 429, in data_generator_task
    generator_output = next(self._generator)
  File "<path>/local/lib/python2.7/site-packages/keras/preprocessing/image.py", line 832, in next
    target_size=self.target_size)
  File "<path>/local/lib/python2.7/site-packages/keras/preprocessing/image.py", line 300, in load_img
    img = img.convert('RGB')
  File "<path>/local/lib/python2.7/site-packages/PIL/Image.py", line 844, in convert
    self.load()
  File "<path>/local/lib/python2.7/site-packages/PIL/ImageFile.py", line 226, in load
    "(%d bytes not processed)" % len(b))
IOError: image file is truncated (49 bytes not processed)

I have added the following lines before my fit_generator :

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

as suggested in the second solution in the following link: http://stackoverflow.com/questions/12984426/python-pil-ioerror-image-file-truncated-with-big-images

It solved the problem for me.

@gibbidi yeah that worked for me as well.
Can you close the issue?

I have added the following lines before my fit_generator :

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

as suggested in the second solution in the following link: http://stackoverflow.com/questions/12984426/python-pil-ioerror-image-file-truncated-with-big-images

It solved the problem for me.

It also worked for me.Thanks !

Was this page helpful?
0 / 5 - 0 ratings