为什么在 Keras 中预测需要批量大小? [英] Why does prediction needs batch size in Keras?

查看:31
本文介绍了为什么在 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屋!

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