Keras 2 fit_generator 用户警告:“steps_per_epoch”与 Keras 1 参数“samples_per_epoch”不同
Keras 2 fit_generator UserWarning: `steps_per_epoch` is not the same as the Keras 1 argument `samples_per_epoch`
我在 Jupyter Notebook 中使用带有 Python 3 内核的 Keras 2.0.8。我的后端是 TensorFlow 1.3,我正在 Mac 上开发。
每当我使用 fit_generator() 时,我都会收到以下警告:
/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)
下面是我的模型的代码(简单的 MNIST 线性分类器,但我使用的每个模型都会收到此警告):
model = Sequential([
Lambda(normalize_input, input_shape=(1, 28, 28)),
Flatten(),
Dense(10, activation='softmax')
])
model.compile(Adam(),
loss='categorical_crossentropy',
metrics=['accuracy'])
这是我的 fit_generator() 调用:
model.fit_generator(batches,
steps_per_epoch=steps_per_epoch,
nb_epoch=1,
validation_data=test_batches,
nb_val_samples=test_batches.n)
我明白这个警告告诉我的意思。这对我来说不是问题。我怎样才能摆脱它?
如果您的函数调用中有任何 Keras 1.0 关键字,则会出现此警告。通过将 nb_epoch
替换为 epochs
并将 nb_val_samples
替换为 validation_steps
.
来更新您的函数调用
我在 Jupyter Notebook 中使用带有 Python 3 内核的 Keras 2.0.8。我的后端是 TensorFlow 1.3,我正在 Mac 上开发。
每当我使用 fit_generator() 时,我都会收到以下警告:
/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 argumentsamples_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. Similarlynb_val_samples
->validation_steps
andval_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 yourfit_generator
call to the Keras 2 API:fit_generator(<keras.pre..., steps_per_epoch=60000, validation_data=<keras.pre..., epochs=1, validation_steps=10000)
下面是我的模型的代码(简单的 MNIST 线性分类器,但我使用的每个模型都会收到此警告):
model = Sequential([
Lambda(normalize_input, input_shape=(1, 28, 28)),
Flatten(),
Dense(10, activation='softmax')
])
model.compile(Adam(),
loss='categorical_crossentropy',
metrics=['accuracy'])
这是我的 fit_generator() 调用:
model.fit_generator(batches,
steps_per_epoch=steps_per_epoch,
nb_epoch=1,
validation_data=test_batches,
nb_val_samples=test_batches.n)
我明白这个警告告诉我的意思。这对我来说不是问题。我怎样才能摆脱它?
如果您的函数调用中有任何 Keras 1.0 关键字,则会出现此警告。通过将 nb_epoch
替换为 epochs
并将 nb_val_samples
替换为 validation_steps
.