ubantu18.04 RTX2070使用anaconda3安装pytorch

pytorch安装参考https://blog.csdn.net/sinat_41563673/article/details/97402059

https://blog.csdn.net/excellent_sun/article/details/88830687

1、anaconda3安装方法见https://blog.csdn.net/qq_42412214/article/details/94917609

2、创建名为torch的anaconda虚拟环境:

conda create -n torch python=3.6.5

3、安装pytorch

1)添加anaconda国内源,使anaconda安装环境更快

将以下配置文件写在~/.condarc中(初始为空文件)
sudo gedit ~/.condarc

channels:
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
  - https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  - defaults
show_channel_urls: true

2)在pytorch官网找到对应版本安装命令https://pytorch.org/get-started/locally/

选择本机CUDA10.0  conda安装的版本

# CUDA 10.0
conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0 -c pytorch

3)进入conda虚拟环境torch,使用上述命令安装

4)安装成功后import torch,没有报错

5)继续测试

python tor.py
python torgpu.py

tor.py代码:

# -*- coding: utf-8 -*-
"""
Created on Sun Feb  4 14:26:59 2018

@author: admin
"""

import torch #引用torch包

x = torch.Tensor(2,3)
print(x)

torgpu.py代码:

# CUDA TEST
import torch
x = torch.Tensor([1.0])
xx = x.cuda()
print(xx)

# CUDNN TEST
from torch.backends import cudnn
print(cudnn.is_acceptable(xx))


 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章