ubuntu GPU服务器安装tensorflow和pytorch

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)) 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值