我正在查看使用 Keras+TensorFlow 训练 CNN 模型期间的性能和 GPU 使用情况。类似于 this question ,我很难理解Keras的组合使用model.fit
的 steps_per_epoch
和 TensorFlow 的数据集 API .batch()
: 我在输入管道上设置了一定的批量大小 dataset = dataset.batch(batch_size)
后来我用
fit = model.fit(dataset, epochs=num_epochs, steps_per_epoch=training_set_size//batch_size)
但我看到实际上可以为每个 epoch 设置任意数量的步数,甚至超过
training_set_size//batch_size
.从文档中我了解到,在 Keras 上,一个 epoch 并不一定像往常一样通过整个训练集,但无论如何我有点困惑,现在我不完全确定我是否正确使用它。是
dataset.batch(batch_size)
+ steps_per_epoch=training_set_size//batch_size
定义一个小批量 SGD,它通过 batch_size
的小批量在整个训练集上运行 sample ?如果 steps_per_epoch
,训练集的迭代次数是否大于一次设置为大于 training_set_size//batch_size
?
最佳答案
steps_per_epoch
是在一个时期内通过网络运行的设定批次大小的批次数。
您已设置您的 steps_per_epoch
成为 training_set_size//batch_size
有充分的理由。这确保所有数据都在一个时期内进行训练,提供数字精确除法(如果不是,则由//运算符舍入)。
也就是说,如果您的批次大小为 10,训练集大小为 30,则 steps_per_epoch = 3
确保使用所有数据。
并引用你的问题:
"Are epochs larger than one pass over the training set if steps_per_epoch is set to more than training_set_size//batch_size?"
是的。一些数据会在同一个 epoch 中再次通过。
关于tensorflow - 将 Keras model.fit 的 `steps_per_epoch` 与 TensorFlow 的 Dataset API 的 `batch()` 相结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54575714/