首先需要卸载运行环境安装的tensorflow-cpu:
pip uninstall tensorflow
conda remove tensorflow
检查运行环境的cuda,注意不是系统默认的python环境:
查询当前环境下的库的版本号可使用以下命令:
conda list cudnn
conda list cuda
conda list tensorflow
以下两行命令都是查询本机默认环境的CUDA:
nvcc -V
cat /usr/local/cuda/version.txt
参考官网安装对应版本的cuda和cudnn:
https://tensorflow.google.cn/install/gpu
https://www.tensorflow.org/install
安装对应版本的tensorflow-gpu:
pip install tensorflow-gpu==1.12.0
检查是否已经安装完毕:
测试代码:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))