跑测试代码会显示GPU:false 测试代码如下:
import tensorflow as tf import os os.environ['TF_CPP_MIN_LOG_LEVEL']='2' a = tf.constant(1.) b = tf.constant(2.) print(a+b) print('GPU:', tf.test.is_gpu_available())
报如下错误:
D:\Anaconda3\envs\tf2.1.0\python.exe “C:/Users/1/Desktop/Gesture Recognition/EDenseNet/test2.py”
2021-05-15 17:20:13.842076: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library ‘cudart64_101.dll’; dlerror: cudart64_101.dll not found
2021-05-15 17:20:13.842233: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2021-05-15 17:20:15.299935: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2021-05-15 17:20:16.004743: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1555] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce MX350 computeCapability: 6.1
coreClock: 1.468GHz coreCount: 5 deviceMemorySize: 2.00GiB deviceMemoryBandwidth: 52.21GiB/s
2021-05-15 17:20:16.005776: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library ‘cudart64_101.dll’; dlerror: cudart64_101.dll not found
2021-05-15 17:20:16.088248: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2021-05-15 17:20:16.128756: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2021-05-15 17:20:16.142859: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2021-05-15 17:20:16.194405: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
tf.Tensor(3.0, shape=(), dtype=float32)
2021-05-15 17:20:16.225556: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2021-05-15 17:20:16.226581: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library ‘cudnn64_7.dll’; dlerror: cudnn64_7.dll not found
2021-05-15 17:20:16.226706: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1592] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices…
2021-05-15 17:20:16.227360: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2021-05-15 17:20:16.227895: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1096] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-05-15 17:20:16.227996: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102]
WARNING:tensorflow:From C:/Users/1/Desktop/Gesture Recognition/EDenseNet/test2.py:10: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.config.list_physical_devices('GPU')
instead.
2021-05-15 17:20:16.230236: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1555] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce MX350 computeCapability: 6.1
coreClock: 1.468GHz coreCount: 5 deviceMemorySize: 2.00GiB deviceMemoryBandwidth: 52.21GiB/s
2021-05-15 17:20:16.231241: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library ‘cudart64_101.dll’; dlerror: cudart64_101.dll not found
2021-05-15 17:20:16.231361: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2021-05-15 17:20:16.231450: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2021-05-15 17:20:16.231538: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2021-05-15 17:20:16.231627: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2021-05-15 17:20:16.231719: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2021-05-15 17:20:16.232770: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library ‘cudnn64_7.dll’; dlerror: cudnn64_7.dll not found
2021-05-15 17:20:16.232900: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1592] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices…
GPU: False
2021-05-15 17:20:16.746028: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1096] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-05-15 17:20:16.746122: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] 0
2021-05-15 17:20:16.746174: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] 0: N
Process finished with exit code 0
由上图看出虽然装的是GPU版,但是程序并不能调用到GPU。
后来发现可以一个方法可以安装TensorFlow-GPU版:
之前我一直都是在本地计算机安装cuda和cudnn,后面发现不在本地安装cuda和cudnn,而是在anaconda新建的虚拟Python环境文件夹安装cuda和cudnn,然后再安装对应的TensorFlow-GPU版本,可以work。现记录下来,给别人一个参考,也方便以后自己查看。
1.打开Anaconda Prompt
2.建立一个名为tf2.1(该名称可随便取)的环境,使用Python3.7
conda create --name tf2.1 python=3.7
3.进入tf2.1环境
activate tf2.1
4.安装cuda10.1(因为这里安的TensorFlow是2.1版本,对应的cuda版本是10.1,cudnn版本是7.6,如果要安装别的版本的TensorFlow,需安装对应的cuda和cudnn版本。)
conda install cudatoolkit=10.1
5.安装cudnn7.6
conda install cudnn=7.6
6.安装TensorFlow-GPU2.1
pip install tensorflow-gpu==2.1