安装TensorFlow-gpu版本踩了好多坑,还好终于解决了。
1 版本对应及选择
我的台式机上的显卡型号如下:(查看方式NIVIDA控制面板->帮助->系统信息->组件)
在TensorFlow官网中查看对应版本:
我安装的是TensorFlow-gpu1.14.0版本,最终成功的版本信息如下:
tensorflow-gpu==1.14.0
cuda == 10.0
cudnn == 7.6.5
2 安装过程
参考The Best Way to Install TensorFlow with GPU Support on Windows 10 (Without Installing CUDA),以下是我提炼出来的简单安装过程:
- step1 :下载Anaconda(python 3.6)并安装
- step2: 升级base Anaconda packages(这里我只执行了前两个)
conda update conda
conda update anaconda
conda update python
conda update --all
- step3:使用conda为TensorFlow创建Python的虚拟环境(tf-gpu是虚拟环境名)并激活
conda create -n tf-gpu
activate tf-gpu
得到如下界面:
- step4:安装TensorFlow-gpu1.14.0
conda install tensorflow-gpu==1.14.0
- step5:测试是否可用
3 报错记录
安装完成测试通过,但是在训练数据是报如下错误:
tensorflow.python.framework.errors_impl.UnknownError: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.
找了很多解决办法,需要添加gpu设置如下:
import tensorflow as tf
config = tf.compat.v1.ConfigProto(gpu_options=tf.compat.v1.GPUOptions(allow_growth=True))
sess = tf.compat.v1.Session(config=config)
添加完成,依旧报错。还有说是cudnn版本不对应,使用如下命令升级:
conda install -c anaconda cudnn
升级完成后重新训练,即可成功!