Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras 2 fit_generator UserWarning: `steps_per_epoch` is not the same as the Keras 1 argument `samples_per_epoch`

I'm using Keras 2.0.8 with Python 3 kernel in Jupyter Notebook. My backend is TensorFlow 1.3 and I'm developing on Mac.

Whenever I'm using fit_generator() I'm getting following warning:

/Users/username/anaconda/envs/tensorflow/lib/python3.6/site-packages/ipykernel/main.py:5: UserWarning: The semantics of the Keras 2 argument steps_per_epoch is not the same as the Keras 1 argument samples_per_epoch. steps_per_epoch is the number of batches to draw from the generator at each epoch. Basically steps_per_epoch = samples_per_epoch/batch_size. Similarly nb_val_samples->validation_steps and val_samples->steps arguments have changed. Update your method calls accordingly. /Users/username/anaconda/envs/tensorflow/lib/python3.6/site-packages/ipykernel/main.py:5: UserWarning: Update your fit_generator call to the Keras 2 API: fit_generator(<keras.pre..., steps_per_epoch=60000, validation_data=<keras.pre..., epochs=1, validation_steps=10000)

Below is the code for my model (simple MNIST linear classifier but I'm getting this warning for every model I use):

model = Sequential([
    Lambda(normalize_input, input_shape=(1, 28, 28)),
    Flatten(),
    Dense(10, activation='softmax')
])
model.compile(Adam(),
              loss='categorical_crossentropy',
              metrics=['accuracy'])

And this is my fit_generator() call:

model.fit_generator(batches, 
                 steps_per_epoch=steps_per_epoch, 
                 nb_epoch=1, 
                 validation_data=test_batches, 
                 nb_val_samples=test_batches.n)

I understand what this warning is telling me. This is not a problem in my case. How can I get rid of it?

like image 647
Jan Slominski Avatar asked Sep 20 '17 05:09

Jan Slominski


1 Answers

This warning occurs if there's any Keras 1.0 keyword in your function call. Update your function call by replacing nb_epoch with epochs, and nb_val_samples with validation_steps.

like image 143
Yu-Yang Avatar answered Oct 09 '22 23:10

Yu-Yang