将 Keras model.fit 的 `steps_per_epoch` 与 TensorFlow 的数据集 API 的 `batch()` 相结合
Combining Keras model.fit's `steps_per_epoch` with TensorFlow's Dataset API's `batch()`
我正在查看使用 Keras+TensorFlow 训练 CNN 模型期间的性能和 GPU 使用情况。类似于,我很难理解Kerasmodel.fit
的steps_per_epoch
和TensorFlow的DatasetAPI的.batch()
的组合使用:我在输入管道 dataset = dataset.batch(batch_size)
上设置了一定的批量大小,后来我使用
fit = model.fit(dataset, epochs=num_epochs, steps_per_epoch=training_set_size//batch_size)
但我看到实际上每个纪元可以设置任意数量的步数,甚至超过 training_set_size//batch_size
。从文档中我了解到,在 Keras 上,一个纪元不一定像往常一样遍历整个训练集,但无论如何我有点困惑,现在我不完全确定我是否正确使用它。
dataset.batch(batch_size)
+ steps_per_epoch=training_set_size//batch_size
是否定义了一个小批量 SGD,它通过 batch_size
个样本的小批量运行整个训练集?如果 steps_per_epoch
设置为多于 training_set_size//batch_size
,训练集的轮数是否大于一轮?
steps_per_epoch
是你设置的 batch size 是 运行 在一个 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再次通过
我正在查看使用 Keras+TensorFlow 训练 CNN 模型期间的性能和 GPU 使用情况。类似于model.fit
的steps_per_epoch
和TensorFlow的DatasetAPI的.batch()
的组合使用:我在输入管道 dataset = dataset.batch(batch_size)
上设置了一定的批量大小,后来我使用
fit = model.fit(dataset, epochs=num_epochs, steps_per_epoch=training_set_size//batch_size)
但我看到实际上每个纪元可以设置任意数量的步数,甚至超过 training_set_size//batch_size
。从文档中我了解到,在 Keras 上,一个纪元不一定像往常一样遍历整个训练集,但无论如何我有点困惑,现在我不完全确定我是否正确使用它。
dataset.batch(batch_size)
+ steps_per_epoch=training_set_size//batch_size
是否定义了一个小批量 SGD,它通过 batch_size
个样本的小批量运行整个训练集?如果 steps_per_epoch
设置为多于 training_set_size//batch_size
,训练集的轮数是否大于一轮?
steps_per_epoch
是你设置的 batch size 是 运行 在一个 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再次通过