我是在项目中使用 keras 的新手。我一直在我的模型中使用generator
。
我真的很困惑我应该输入什么值
1) In fit_generator : steps_per_epoch & validation_steps ?
2) evaluate_generator : steps ?
3) predict_generator : steps ?
我已提及keras documentation和其他一些stack1 , stack2问题。我无法理解。 更好的是,我可以提供我的数据示例,塑造我当前正在工作的内容,并相应地遵循我的问题。另外,如果我的理解有误,请指正
model.fit_generator(trainGen, steps_per_epoch=25, epochs = 100, validation_data=ValGen, validation_steps= 4)
Q1:对于每个时期,都有25 个步骤
。对于每个步骤,trainGen
都会生成一个形状为 (244*100*4, 244*100*2)
的元组并执行训练。
What will be my
batch_size
andbatches
if mysteps_per_epoch is 25
?
第二季度:
据我了解,val_acc 和 val_loss
将在纪元的第 25 步
结束时计算。我选择我的 validation_steps = 4
。因此,ValGen
在一个纪元的第 25 步结束时产生一个形状为 (30*100*4, 30*100*2) 4 次的元组
I have chosen arbitrarily
validation_steps = 4.
But how to choose correct number ofvalidation_steps
? How doesval_loss & val_acc
calculated ? (calculate the mean 4 times either as single batch or using batch_size)
第三季度:
例如,在 evaluate_generator 和 Predict_generator
中,我的生成器为两者生成一个元组形状 (30*100*4, 30*100*2)
。
How to choose the correct number for
steps
argument for bothevaluate_generator & predict_generator
? In keras document it is mentioned as Total number of steps (batches of samples) to yield from generator before stopping ?In my case what will the batches of samples ?
如果需要任何其他信息,请告诉我。
最佳答案
步骤不是您“选择”的参数,您可以将其计算为:
steps = number of samples / batch size
因此,这里您可以自由选择的唯一参数是批量大小,该值被选择为模型在训练时不会耗尽内存的值。典型值在 32 到 64 之间。
对于训练集,您使用训练集的样本数除以训练批量大小;对于验证集,您使用验证集中的样本数除以验证批量大小。两个批量大小可以相等。
这适用于所有使用生成器的函数。
关于python - 了解fit_generator(steps_per_epoch)、validation_steps、evaluate_generator(步骤)和predict_generator(步骤),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57254669/