windows10 安装GPU 教程查看我上一篇博客>>window10安装GPU 版本 TensorFlow 安装指南

检测是否开启GPU

import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))

运行结果:

Num GPUs Available:  0

现状:之前安装好了tensorflow_gpu ,也安装了tensorflow ,显卡驱动,cuda,cudnn 等之类的所有具备条件。
其实不需要tensorflow ,这是CPU版本安装的,不知道什么时候安装的。

分析:显卡驱动过旧,先升级显卡驱动。到nvidia 官方网站去下载最新的驱动。驱动下载

驱动更新没问题。

驱动安装好了之后,去卸载tensorflow,tensorflow_gpu 重新安装即可。

pip uninstall tensorflow 
pip uninstall tensorflow_gpu

tensorflow 、tensorfow_gpu、tensorboard 卸载好后,安装tensorflow_gpu==2.0.0

pip install -i https://pypi.tuna.tsinghua.edu/simple --trusted-host pypi.tuna.tsinghua.edu tensorflow==2.0.0

上面都安装好之后,再来检测GPU 是都开启,

import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))

运行结果:

D:\Programs\Python\Python3.7\python.exe D:/PycharmProjects/Myproject/tensorflow实战/开启GPU.py
2021-11-22 10:55:32.512296: I tensorflow/stream_executor/platform/default/dso_loader:44] Successfully opened dynamic library cudart64_100.dll
2021-11-22 10:55:37.384735: I tensorflow/stream_executor/platform/default/dso_loader:44] Successfully opened dynamic library nvcuda.dll
Num GPUs Available:  1
2021-11-22 10:55:38.468478: I tensorflow/core/common_runtime/gpu/gpu_device:1618] Found device 0 with properties: 
name: NVIDIA GeForce GTX 1650 major: 7 minor: 5 memoryClockRate(GHz): 1.56
pciBusID: 0000:01:00.0
2021-11-22 10:55:38.469059: I tensorflow/stream_executor/platform/default/dlopen_checker_stub:25] GPU libraries are statically linked, skip dlopen check.
2021-11-22 10:55:38.469853: I tensorflow/core/common_runtime/gpu/gpu_device:1746] Adding visible gpu devices: 0

Process finished with exit code 0

此时成功了。Num GPUs Available: 1

跑一个深度学习的程序试试:

没问题。问题解决。

更多推荐

【深度学习 走进tensorflow2.0】Num GPUs Available: 0问题解决