Image corruption during model training

Hi Guys
I am getting this error while training my model:
File “/usr/local/lib/python3.9/site-packages/keras/src/preprocessing/image.py”, line 156, in next
return self.next(*args, **kwargs)

File “/usr/local/lib/python3.9/site-packages/keras/src/preprocessing/image.py”, line 168, in next
return self._get_batches_of_transformed_samples(index_array)

File “/usr/local/lib/python3.9/site-packages/keras/src/preprocessing/image.py”, line 370, in _get_batches_of_transformed_samples
img = image_utils.load_img(

File “/usr/local/lib/python3.9/site-packages/keras/src/utils/image_utils.py”, line 479, in load_img
img = img.resize(width_height_tuple, resample)

File “/usr/local/lib/python3.9/site-packages/PIL/Image.py”, line 2163, in resize
self.load()

File “/usr/local/lib/python3.9/site-packages/PIL/ImageFile.py”, line 266, in load
raise OSError(msg)

OSError: image file is truncated (136 bytes not processed)

     [[{{node PyFunc}}]]
     [[IteratorGetNext]] [Op:__inference_train_function_20953]

Could you guys tell me the possible cause of this issue.

1 Like

Hi @Soap, The error was thrown by PIL libray. could you please try by adding

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

Thank You.

Ya it works, Thank you so much :slight_smile: