本文首发于个人博客https://kezunlin.me/post/54e7a3d8/,欢迎阅读最新内容!
tutorial to compile and use pytorch on ubuntu 16.04
PyTorch for Python
install pytorch from anaconda
conda info --envs
conda activate py35
# newest version
# 1.1.0 pytorch/0.3.0 torchvision
conda install pytorch torchvision cudatoolkit=9.0 -c pytorch
# old version [NOT]
# 0.4.1 pytorch/0.2.1 torchvision
conda install pytorch=0.4.1 cuda90 -c pytorch
output
The following NEW packages will be INSTALLED:
pytorch pytorch/linux-64::pytorch-1.1.0-py3.5_cuda9.0.176_cudnn7.5.1_0
torchvision pytorch/linux-64::torchvision-0.3.0-py35_cu9.0.176_1
download from channel
pytorch
will cost much time!下载
pytorch/linux-64::pytorch-1.1.0-py3.5_cuda9.0.176_cudnn7.5.1_0
速度非常慢!
install pytorch from tsinghua
add tsinghua pytorch channels
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
# for legacy win-64
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/
conda config --set show_channel_urls yes
使用anaconda官方pytorch源非常慢,用清华源代替。
cat ~/.condarc
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
- defaults
install pytorch from tsinghua
conda create --name torch python==3.7
conda activate torch
conda install -y pytorch torchvision
conda install -y scikit-learn scikit-image pandas matplotlib pillow opencv
The following NEW packages will be INSTALLED:
pytorch anaconda/cloud/pytorch/linux-64::pytorch-1.1.0-py3.5_cuda9.0.176_cudnn7.5.1_0
torchvision anaconda/cloud/pytorch/linux-64::torchvision-0.3.0-py35_cu9.0.176_1
test pytorch
import torch
print(torch.__version__)
'1.1.0'
or
python -c 'import torch; print(torch.cuda.is_available())'
True
pre-trained models
pre-trained model saved to /home/kezunlin/.cache/torch/checkpoints/
Downloading: "https://download.pytorch.org/models/shufflenetv2_x0.5-f707e7126e.pth" to /home/kezunlin/.cache/torch/checkpoints/shufflenetv2_x0.5-f707e7126e.pth
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
PyTorch for C
download LibTorch
download from LibTorch
compile from source
compile pytorch
# method 1
git clone --recursive https://github.com/pytorch/pytorch
cd pytorch
# method 2, if you are updating an existing checkout
git clone https://github.com/pytorch/pytorch
cd pytorch
git submodule sync
g