.predict()即使在GPU可用的情况下也只能在CPU上运行 [英] .predict() runs only on CPU even though GPU is available

查看:279
本文介绍了.predict()即使在GPU可用的情况下也只能在CPU上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了此脚本来训练模型&在安装并启用了GPU的计算机上进行预测,并且在预测阶段似乎仅使用CPU.

I used this script to train a model & predict on a machine with GPU installed and enabled and it seems that it's using only the CPU in the prediction stage.

.predict()部分中看到的设备放置日志如下:

The device placement log I'm seeing during the .predict() part is the following:

2020-09-01 06:08:19.085400: I tensorflow/core/common_runtime/eager/execute.cc:573] Executing op RangeDataset in device /job:localhost/replica:0/task:0/device:CPU:0
2020-09-01 06:08:19.085617: I tensorflow/core/common_runtime/eager/execute.cc:573] Executing op RepeatDataset in device /job:localhost/replica:0/task:0/device:CPU:0
2020-09-01 06:08:19.089558: I tensorflow/core/common_runtime/eager/execute.cc:573] Executing op MapDataset in device /job:localhost/replica:0/task:0/device:CPU:0
2020-09-01 06:08:19.090003: I tensorflow/core/common_runtime/eager/execute.cc:573] Executing op PrefetchDataset in device /job:localhost/replica:0/task:0/device:CPU:0
2020-09-01 06:08:19.097064: I tensorflow/core/common_runtime/eager/execute.cc:573] Executing op FlatMapDataset in device /job:localhost/replica:0/task:0/device:CPU:0
2020-09-01 06:08:19.097647: I tensorflow/core/common_runtime/eager/execute.cc:573] Executing op TensorDataset in device /job:localhost/replica:0/task:0/device:CPU:0
2020-09-01 06:08:19.097802: I tensorflow/core/common_runtime/eager/execute.cc:573] Executing op RepeatDataset in device /job:localhost/replica:0/task:0/device:CPU:0
2020-09-01 06:08:19.097957: I tensorflow/core/common_runtime/eager/execute.cc:573] Executing op ZipDataset in device /job:localhost/replica:0/task:0/device:CPU:0
2020-09-01 06:08:19.101284: I tensorflow/core/common_runtime/eager/execute.cc:573] Executing op ParallelMapDataset in device /job:localhost/replica:0/task:0/device:CPU:0
2020-09-01 06:08:19.101865: I tensorflow/core/common_runtime/eager/execute.cc:573] Executing op ModelDataset in device /job:localhost/replica:0/task:0/device:CPU:0

即使我跑步时也是如此:

even though that when I run:

print(tf.config.experimental.list_physical_devices('GPU'))

我收到:

[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU'), PhysicalDevice(name='/physical_device:GPU:1', device_type='GPU'), PhysicalDevice(name='/physical_device:GPU:2', device_type='GPU')]

我使用的代码可在此处找到. 完整的输出日志可以在此处查看.

更多上下文:
Python:3.7.7
Tensorflow:2.1.0
GPU:Nvidia Tesla V100-PCIE-16GB
CPU:Intel Xeon Gold 5218 CPU @ 2.30GHz
RAM:394851272 KB
操作系统:Linux

More context:
Python: 3.7.7
Tensorflow: 2.1.0
GPU: Nvidia Tesla V100-PCIE-16GB
CPU: Intel Xeon Gold 5218 CPU @ 2.30GHz
RAM: 394851272 KB
OS: Linux

推荐答案

可以从tensorflow.python呼叫keras吗?

Can you please call keras from tensorflow.python?

像;

from tensorflow.python.keras.models import Sequential

另外,请检查CUDA和CuDNN版本. Cuda和CuDNN版本必须与tensorflow版本兼容.您可以在此处进行检查.由于您的张量流版本为2.1,因此CUDA和CuDNN版本必须为10.1& ;; 7.6.

Also, please check CUDA and CuDNN version. Cuda and CuDNN versions have to be compatible with tensorflow version. You can check from here. As your tensorflow version is 2.1, CUDA and CuDNN versions are have to be 10.1 & 7.6 respectively.

这篇关于.predict()即使在GPU可用的情况下也只能在CPU上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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