Keras模型的predict和predict_on_batch方法之间有什么区别? [英] What is the difference between the predict and predict_on_batch methods of a Keras model?
问题描述
根据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_out
的numpy.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屋!