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

查看:45
本文介绍了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)))

(a numpy.ndarray 形状 (n, d_out)

推荐答案

不同之处在于,当你将大于一批的数据作为 x 传递时.

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

预测 将遍历所有数据,逐批,预测标签.因此,它在内部进行分批拆分和一次进料.

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天全站免登陆