Linux常用技巧系列: TensorFlow / PyTorch安装( TensorFlow Cudnn Cuda版本兼容性问题)

(建议阅读30s)

安装完了Anaconda3 建议版本是5.20,TensorFlow和PyTorch对Python3.7版本都不太友好,会出一堆问题。

Anaconda3 安装请参考 <Linux常用技巧系列: anaconda3安装与配置>

安装TensorFlow,如果你的cuda不是10.0,建议安装1.12。注意和cudnn有关系。TensorFlow 1.12 和cudnn 7.14,cuda9,兼容性没问题。 TensorFlow 1.13和cudnn 7.3/4,cuda10,兼容性没问题。

pip3 install tensorflow_gpu==1.12.0

或者

conda install -c anaconda tensorflow-gpu==1.12

TensorFlow 安装测试程序如下:

import tensorflow as tf
a = tf.Variable(1, dtype=tf.float32)
b = tf.Variable(1, dtype=tf.float32)
c = a + b
sess = tf.Session()
sess.run(tf.global_variables_initializer())
sess.run(c)


安装PyTorch如下,这里cuda=8.0,如果你cuda9.0,改为9.0即可,cuda10.0同理。
 

conda install pytorch torchvision cudatoolkit=8.0 -c pytorch

打开ipython,PyTorch安装测试代码如下:

import torch

device = torch.device('cuda')

a = torch.randn([3, 5]).to(device)

b = torch.randn([3, 5]).to(device)

a + b

猜你喜欢

转载自blog.csdn.net/dongfangxiaozi_/article/details/89070395
今日推荐