TensorFlow:使用批处理或在线推断CPU时的结果不同

发布于 2025-02-08 17:38:06 字数 885 浏览 2 评论 0原文

我正在对简单的Keras模型进行一些推理测试。

在面临一些奇怪的错误之后,我意识到,有时,当我同时推断多个数据或仅一个数据时,我的结果略有不同。

这是我确定的特定行的一个小例子,向您展示问题:

predicted_all = np.round(self.network.predict(warm_up,         verbose=0).flatten() * raw_data_std + raw_data_mean).astype(np.int32)
predicted_121 = np.round(self.network.predict(warm_up[121, :], verbose=0).flatten() * raw_data_std + raw_data_mean).astype(np.int32)

print('Batch prediction: ',  predicted_all[121])
print('Single prediction: ', predicted_121[0])

基本上,我应该获得相同的结果,因为我推断了harm_up矩阵的相同行。 结果:

Batch prediction:  264
Single prediction:  265

我确切地说,这两条线都在同一CPU上运行,并带有选项os.environ [“ cuda_visible_devices”] =“ -1”。所有以前的推论都是相等的。运行测试时,错误似乎随机出现。

我正在使用TensorFlow 2.9.1,Cudnn 8.1,Python 3.9.12在Windows 11上。

此处发生的事情有什么想法吗?

I was running some inference tests on simple Keras model.

After facing some strange errors, I realize that sometimes, my results were slightly different when I was performing inference of multiple data at the same time or just one data.

This is a little example with a specific line I identified, to show you the issue:

predicted_all = np.round(self.network.predict(warm_up,         verbose=0).flatten() * raw_data_std + raw_data_mean).astype(np.int32)
predicted_121 = np.round(self.network.predict(warm_up[121, :], verbose=0).flatten() * raw_data_std + raw_data_mean).astype(np.int32)

print('Batch prediction: ',  predicted_all[121])
print('Single prediction: ', predicted_121[0])

Basically, I should obtain the same results since I'm infering the same lines of my warm_up matrix.
Result :

Batch prediction:  264
Single prediction:  265

I precise that both lines are running on the same CPU, with the option os.environ["CUDA_VISIBLE_DEVICES"] = "-1". All previous inferences were equal. When running my test, the error seems to appear randomly.

I'm using tensorflow 2.9.1, CudNN 8.1, Python 3.9.12 on Windows 11.

Any idea of what's happening here ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文