Skip to content
Advertisement

Unknown image file format. One of JPEG, PNG, GIF, BMP required

I built a simple CNN model and it raised below errors:

JavaScript

The code I wrote is quite simple and standard. Most of them are just directly copied from the official website. It raised this error before the first epoch finish. I am pretty sure that the images are all png files. The train folder does not contain anything like text, code, except imgages. I am using Colab. The version of tensorlfow is 2.5.0. Appreciate for any help.

JavaScript

Advertisement

Answer

Some of your files in the validation folder are not in the format accepted by Tensorflow ( JPEG, PNG, GIF, BMP), or may be corrupted. The extension of a file is indicative only, and does not enforce anything on the content of the file.

You might be able to find the culprit using the imghdr module from the python standard library, and a simple loop.

JavaScript

This should print out whether you have files that are not images, or that are not what their extension says they are, and not accepted by TF. Then you can either get rid of them or convert them to a format that TensorFlow supports.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement