Getting this error Unknown: UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7fe286131e90>

Hi,

Can someone please help me with this error.
Unknown: UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7fe286131e90>
I checked few stackoverflow links.

But seems in keras it is used internally

Below is the colab notebook for reproducibilty

Thanks and Regards,
Subho

@Subhobrata_Mukharjee I ran your note book after some debugging seems like there is issue with some of your image files encodings. I didn’t debug enough to figure out which ones but that should be a clue. PIL seems to throw that error in between training so, that’s another point towards image encoding errors.

1 Like

Hi Sid,
Thanks for the information.
Actually few of the images were corrupted therefore this issue occurred.
After removing the corrupt images it ran fine

How would you find the corrupted image?

Hi Arun_kumar!

I had somthing similar and I check my images one by one with this code to verify the integrity! Try it!

from os import listdir
from PIL import Image

for filename in listdir(‘/content/dataset/your_file’):
if filename.endswith(‘.png’):
try:
img = Image.open(‘/content/dataset/your_file/’+filename) # open the image file
img.verify() # verify that it is, in fact an image
except (IOError) as e:
print(‘Bad file:’, filename)