Skip to content Skip to sidebar Skip to footer

Unknown Image File Format. One Of Jpeg, Png, Gif, Bmp Required

I built a simple CNN model and it raised below errors: Epoch 1/10 235/235 [==============================] - ETA: 0s - loss: 540.2643 - accuracy: 0.4358 ---------------------------

Solution 1:

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.

from pathlib import Path
import imghdr

data_dir = "/home/louis/datasets/sample_skeleton_rgb/"
image_extensions = [".png", ".jpg"]  # add there all your images file extensions

img_type_accepted_by_tf = ["bmp", "gif", "jpeg", "png"]
for filepath in Path(data_dir).rglob("*"):
    if filepath.suffix.lower() in image_extensions:
        img_type = imghdr.what(filepath)
        if img_type isNone:
            print(f"{filepath} is not an image")
        elif img_type notin img_type_accepted_by_tf:
            print(f"{filepath} is a {img_type}, not accepted by TensorFlow")

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.

Post a Comment for "Unknown Image File Format. One Of Jpeg, Png, Gif, Bmp Required"