ubuntu GPU服务器安装tensorflow和pytorch

  • Post author:
  • Post category:其他






pytorch相关




pytorch、cuda、cudnn对应关系


https://blog.csdn.net/caiguanhong/article/details/112184290

pip 安装:

pip install torch==1.6.0+cu101 torchvision==0.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html

注意:pip 或者conda 按照以上方法安装的torch,可能还是报错或gpu跑不起来。

建议

去下面链接里找对应正确的torch 和torchvision 的 whl包安装(torch的版本需要对应的cuda,python,系统等)

torch/torchvision 各个版本链接(重要!!!!):


https://download.pytorch.org/whl/torch_stable.html


检查pytorch gpu是否安装好:

import torchvision 
print(torch.__version__) 
print(torchvision.__version__) 
print(torch.cuda.is_available()) 





tensorflow相关





虚拟环境安装tensorflow(通过指定镜像源)


pip3 install -i

Simple Index

–upgrade tensorflow-gpu==2.4.1


# 当遇到“Could not fetch URL

Links for tensorflow-gpu

: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833) – skippin”的报错时 :


pip install tensorflow-gpu==1.13.2 -i

Simple Index

–trusted-host

pypi.tuna.tsinghua.edu.cn



安装对应版本的tensorflow

:(不同镜像源的速度不同,可以选用最快的一个)


pip install tensorflow-gpu==2.3.0 -i

Simple Index



测试安装的 tensorflow 是否可用


测试一:

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


测试二:

print(tf.test.is_gpu_available())

测试三:

import tensorflow as tf 
tf.compat.v1.disable_eager_execution() 
config = tf.compat.v1.ConfigProto(allow_soft_placement=True) 
sess = tf.compat.v1.Session(config=config) 
with tf.device('/gpu:0'): 
    a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a') 
    b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b') 
    c = tf.matmul(a, b) 
    print(sess.run(c)) 



版权声明:本文为Lee_queenie原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。