PIL.UnidentifiedImageError

Viewed 220

Ran into this error while training. Any ideas what to do? Using python 3.7.8

UnknownError                              Traceback (most recent call last)
<ipython-input-6-391a2df601c1> in <module>
     26      train_generator,
     27      steps_per_epoch=nb_train_samples // batch_size,
---> 28      epochs=epochs)
     29 
     30 model.save('base_model')

    "cannot identify image file %r" % (filename if filename else fp)

And at the bottom is :

PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x2ba086f75410>

 [[{{node PyFunc}}]]
     [[IteratorGetNext]] [Op:__inference_train_function_7009]

Function call stack:
train_function

This is the code I have:

train_data_dir = 'data/trainingset'

nb_train_samples = 475719
epochs = 50
batch_size = 32

model.compile(loss='categorical_crossentropy',
              optimizer= 'adam',
              metrics=['accuracy'])

    train_datagen = ImageDataGenerator(
        rescale=1. / 255,
        shear_range=0.2,
        zoom_range=0.2,
        horizontal_flip=True)
    
    train_generator = train_datagen.flow_from_directory(
        train_data_dir,
        target_size=(img_width, img_height),
        batch_size=batch_size,
        class_mode='categorical')
    
    #starts training
    model.fit(
         train_generator,
         steps_per_epoch=nb_train_samples // batch_size,
         epochs=epochs)
0 Answers
Related