Lasse Harde
Lasse Harde

Reputation: 37

Data Augmentation with keras running out of data

Why is this code not working, its taken directly from the book "Deep Learning with Python".. Im getting the error message:

"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."

Heres a snippet of the relevant code:

train_datagen = ImageDataGenerator(
    rescale=1./255,
    rotation_range=40,
    width_shift_range=0.2,
    height_shift_range=0.2,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True,)

test_datagen = ImageDataGenerator(rescale=1./255)

train_generator = train_datagen.flow_from_directory(
        train_dir,
        target_size=(150, 150),
        batch_size=32,
        class_mode='binary')

validation_generator = test_datagen.flow_from_directory(
        validation_dir,
        target_size=(150, 150),
        batch_size=32,
        class_mode='binary')

history = model.fit_generator(
      train_generator,
      steps_per_epoch=100,
      epochs=100,
      validation_data=validation_generator,
      validation_steps=50)

I dont understand why it want me to change the batch-size or steps_per_epoch, when it worked in the book.

Upvotes: 1

Views: 604

Answers (1)

Nicolas Gervais
Nicolas Gervais

Reputation: 36624

Here's something you can try:

steps_per_epoch=train_generator.n//train_generator.batch_size

And:

validation_steps=validation_generator.n//validation_generator.batch_size

Upvotes: 1

Related Questions