Keras模型的predict和predict_on_batch方法之间有什么区别? [英] What is the difference between the predict and predict_on_batch methods of a Keras model?

查看:1816
本文介绍了Keras模型的predict和predict_on_batch方法之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据keras 文档:

predict_on_batch(self, x)
Returns predictions for a single batch of samples.

但是,当批量调用标准的predict方法时,无论是一个元素还是多个元素,似乎都没有什么区别.

However, there does not seem to be any difference with the standard predict method when called on a batch, whether it being with one or multiple elements.

model.predict_on_batch(np.zeros((n, d_in)))

model.predict(np.zeros((n, d_in)))

(形状为(n, d_outnumpy.ndarray)

推荐答案

不同之处在于,当您以大于一批的数据作为x数据进行传递时.

The difference lies in when you pass as x data that is larger than one batch.

predict 将通过所有数据,逐批,用于预测标签. 因此,它在内部分批进行分批处理,并且一次进给一批.

predict will go through all the data, batch by batch, predicting labels. It thus internally does the splitting in batches and feeding one batch at a time.

predict_on_batch ,在另一方面,假设您传入的数据恰好是一批,因此将其馈送到网络.它不会尝试拆分它(如果阵列很大,则取决于您的设置,这可能会给您的GPU内存带来问题)

predict_on_batch, on the other hand, assumes that the data you pass in is exactly one batch and thus feeds it to the network. It won't try to split it (which, depending on your setup, might prove problematic for your GPU memory if the array is very big)

这篇关于Keras模型的predict和predict_on_batch方法之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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