循环调用适合与批量大小适合之间有区别吗 [英] Is there a difference between calling fit in a loop vs fit with batch size

查看:101
本文介绍了循环调用适合与批量大小适合之间有区别吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我的内存中有32个训练示例(批量大小为32).在for循环中调用fitbatch_size=1分别进行32次之间有区别吗?还是将所有经验集中在一个数组中并调用fit一次但以batch_size=32作为参数?结果或效果会有所不同吗?

Let's say, I have 32 training example in memory (batch size will be 32). Is there a difference between calling fit in a for loop for 32 times with batch_size=1 for examples one by one; or getting all experiences together in an array and calling fit once but with batch_size=32 as the parameter? Will there be any difference in results or performance?

推荐答案

for i in range(32):
    model.fit(X,y,batch_size=1)

不要以这种方式训练您的模型!您仅对最后一批进行有效的培训(对于您的最后一个样本)

Don't train your model this way.! Your effectively training only on your last batch (In your case last sample)

但是,下面的方法将确保您对所有样本都进行了模型训练.因此,始终以这种方式进行训练.

But, the below method will assure you that the model is trained on all the samples. So always train it this way.

model.fit(X,y,batch_size=32)

如果您因为无法一次将所有样本都放入内存而考虑使用"for循环",则应尝试fit_generator或fit_on_batch方法.

If you thought about using "for loop" because you couldn't fit all the sample's into memory at once, You should try fit_generator or fit_on_batch methods.

这篇关于循环调用适合与批量大小适合之间有区别吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆