tensorflow - 将 Keras model.fit 的 `steps_per_epoch` 与 TensorFlow 的 Dataset API 的 `batch()` 相结合

标签 tensorflow keras tensorflow-datasets

我正在查看使用 Keras+TensorFlow 训练 CNN 模型期间的性能和 GPU 使用情况。类似于 this question ,我很难理解Keras的组合使用model.fitsteps_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/

相关文章:

python - 如何将映射函数应用于 tf.Tensor

neural-network - 使用 keras 进行 facenet 三元组损失

python - 在 Keras Tensorflow 中将 TimeseriesGenerator 与多元数据集结合使用

tensorflow - 使用 Estimator 构建 LSTM 网络

python - PyTorch 的 `no_grad` 函数在 TensorFlow/Keras 中的等价物是什么?

python - 可以在 Keras 的卷积层中进行对称填充吗?

tensorflow - Tensorflow 数据集 API 中的内存管理

带有 HDFS 的 TensorFlow 数据集 API

python - 如何将 TensorFlow 对象检测标签和边界框导出为 CSV 文件?

python - 多输入模型keras的K.function