Skip to content
Advertisement

PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object

I am trying to train my model (Image classification) using Tensorflow. I keep getting an error when I try to run the following cell:

JavaScript

Error is:

JavaScript

I tried changing from loss=’categorical_crossentropy’ to loss=’binary_crossentropy’ but still the issue persists. I wish to train the model but the Epoch keeps getting stuck.

Edit:

The train generator function and where it is used is as follows:

JavaScript

Output: ((32, 224, 224, 3), (32, 2))

JavaScript

Output: {‘off’: 0, ‘on’: 1}

Advertisement

Answer

There was an issue with one of the img that was causing an issue and was pointed out by @Lescurel. To view the img you can run the following:

JavaScript

You can also do the same for png or other formats. If there is an issue with your image, it will list it as soon as you run it

Advertisement