Anaconda创建虚拟环境安装pytorch-GPU
0、更改镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
1、创建虚拟环境并进入
(1)conda create -n 虚拟环境名 python=版本号
如: conda create -n to27 python=2.7
(2)进入虚拟环境
source activate to27
2、安装GPU版pytorch
conda install pillow pytorch=0.4.0 cuda90 cudatoolkit=9.0 six
3、安装torchvision
pip install torchvision
4、测试环境
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)
tor.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))