Your input ran out of data; interrupting training. Make sure that your dataset or generator can generate at least `steps_per_epoch

Viewed 3500

When i am training my self-driving car model it is giving me error in the first epoch. although when i reduced the batch_size it is working fine. But that is not giving me accuracy as i want.

I am trainning my model in Google Collab.

tensorflow version 2.3.1

Error:

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, 20000 batches). You may need to use the repeat() function when building your dataset.

My code:

def modified_model():
  model = Sequential()
  model.add(Conv2D(60, (5, 5), input_shape=(32, 32, 1), activation='relu'))
  model.add(Conv2D(60, (5, 5), activation='relu'))
  model.add(MaxPooling2D(pool_size=(2, 2)))
  
  model.add(Conv2D(30, (3, 3), activation='relu'))
  model.add(Conv2D(30, (3, 3), activation='relu'))
  model.add(MaxPooling2D(pool_size=(2, 2)))
  
  model.add(Flatten())
  model.add(Dense(500, activation='relu'))
  model.add(Dropout(0.5))
  model.add(Dense(43, activation='softmax'))
  
  model.compile(Adam(lr = 0.001), loss='categorical_crossentropy', metrics=['accuracy'])
  return model
model = modified_model()
print(model.summary())

history = model.fit_generator(datagen.flow(X_train, y_train, batch_size=50),
                            steps_per_epoch=2000,
                            epochs=10,
                            validation_data=(X_val, y_val), shuffle = 1)
1 Answers

When using generators, let the model figure out how many steps are practically there to cover a epoch otherwise you'll have to calculate steps_per_epoch=(data_samples/batch_size). Try running without the step_per_epoch parameter

Related