gpt4 book ai didi

python - Keras 2 fit_generator 用户警告 : `steps_per_epoch` is not the same as the Keras 1 argument `samples_per_epoch`

转载 作者:太空狗 更新时间:2023-10-30 02:16:03 25 4
gpt4 key购买 nike

我在 Jupyter Notebook 中使用 Keras 2.0.8 和 Python 3 内核。我的后端是 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 来更新您的函数调用。

关于python - Keras 2 fit_generator 用户警告 : `steps_per_epoch` is not the same as the Keras 1 argument `samples_per_epoch` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46314003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com