为什么预测需要Keras中的批量大小? [英] Why does prediction needs batch size in Keras?
问题描述
在Keras中,为了预测数据测试的类别,使用了predict_classes()
.
In Keras, to predict class of a datatest, the predict_classes()
is used.
例如:
classes = model.predict_classes(X_test, batch_size=32)
我的问题是,我知道batch_size
在训练中的用法,但是为什么需要batch_size
进行预测?如何运作?
My question is, I know the usage of batch_size
in training, but why does it need a batch_size
for prediction? how does it work?
推荐答案
Keras可以同时预测多个值,就像输入100个元素的向量一样,Keras可以为每个元素计算一个预测,从而提供100个输出.此计算也可以按batch_size定义的批次进行.
Keras can predict multiple values at the same time, like if you input a vector of 100 elements, Keras can compute one prediction for each element, giving 100 outputs. This computation can also be done in batches, defined by the batch_size.
这是为了防止您无法同时将所有数据容纳在CPU/GPU RAM中并且需要批处理的情况.
This is just in case you cannot fit all the data in the CPU/GPU RAM at the same time and batch processing is needed.
这篇关于为什么预测需要Keras中的批量大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!