I'm trying to follow this Keras tutorial for image segmentation. It seems to run fine in Colab, but running locally, I get the following error:
for j, path in enumerate(batch_target_img_paths):
img = load_img(path, target_size=self.img_size, color_mode="grayscale")
...
Exception has occurred: UnidentifiedImageError
cannot identify image file <_io.BytesIO object at 0x0000020130390400>
File "C:\Computer Vision\main_tutorial.py", line 203, in __getitem__
img = load_img(path, target_size=self.img_size, color_mode="grayscale")
File "C:\Computer Vision\main_tutorial.py", line 102, in main
model.fit(train_gen, epochs=epochs, validation_data=val_gen, callbacks=callbacks)
File "C:\Computer Vision\main_tutorial.py", line 211, in <module>
main()
I've verified the path is correct:
C:\Computer Vision\oxford-iiit-pet\train\annotations\._Abyssinian_10.png
The file in question ._Abyssinian_10.png doesn't appear to be a valid image (I believe it's a target mask) and can't be opened in a regular image viewing application.
Is there an environment or platform issue I'm missing?
If you are facing this error then the image is probably corrupted or of
NoneType.You cannot salvage this image in my experience and you are better off just removing it with the code below which checks if the image is valid as a
PNGand if it isn't then remove the image. If you haveJPEGimages then you can just usejpeginstead.You would have to run this over the entire directory of your images.