简体   繁体   中英

Keras model.predict() not predicting classes for some images

I have trained a ResNet50 using Keras for classication. For testing, I used the ImageDataGenerator flow_from_directory() method to pass input to the model. Here's the code for that:

testdata_generator = keras.preprocessing.image.ImageDataGenerator(
    preprocessing_function=tf.keras.applications.resnet.preprocess_input
)

testgen = testdata_generator.flow_from_directory(
    './test',
    shuffle=False,
    target_size=(224,224),
    color_mode='rgb',
    batch_size=32,
    class_mode=None
)
Found 18223 images belonging to 1 classes.

However when I test the model on the test images, it doesn't predict for a few images.

pred = model.predict(
    testgen,
    batch_size=32,
    steps=testgen.n//testgen.batch_size
)
print(len(pred))
18208

Anyone help?

You should try removing steps=testgen.n//testgen.batch_size , since calculating the steps results in a different number of samples, when you have a remainder by dividing samples // batch_size .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM