Image Data Generator Keras out of data

Viewed 360
train_datagen = image.ImageDataGenerator(
        rescale=1./255,
        shear_range=0.1,
        zoom_range=0.1,
        horizontal_flip=False,
        width_shift_range=0.1,  # randomly shift images horizontally (fraction of total width)
        height_shift_range=0.1)  # randomly shift images vertically (fraction of total height))

test_datagen = image.ImageDataGenerator(rescale=1./255) 

train_it = train_datagen.flow_from_directory(r"...", batch_size=16, target_size=(224, 224), shuffle = True, class_mode='categorical')
test_it = test_datagen.flow_from_directory(r"...", batch_size=16, target_size=(224, 224), shuffle = True, class_mode='categorical')

trans = tf.keras.applications.MobileNetV2(input_shape=(224,224,3), include_top=False, weights='imagenet')
trans.trainable = False

modell = tf.keras.Sequential([
    trans,
    layers.GlobalAveragePooling2D(),
    layers.Dropout(0.5),
    layers.Dense(2),
    layers.Activation("softmax")
])
modell.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["acc"])

modell.fit_generator(
            train_it,
            steps_per_epoch=2000,
            epochs=50,
            verbose=1,
            validation_data=test_it,
            validation_steps=50)

The training works fine when I set steps_per_epoch to 200 and the validation_steps to 10. But any higher number (e.g. 50) yields this error:

WARNING:tensorflow:Your input ran out of data; interrupting training. Make sure that your dataset or generator can generate at least steps_per_epoch * epochs batches (in this case, 50 batches). You may need to use the repeat() function when building your dataset.

To my knowledge, since I'm using DataAugmentation here, it shouldn't be possible at all that the generator runs out of data.

What's wrong here? Might that be connected to the MobileNet?

0 Answers
Related