Ubuntu 16.04上源码编译和安装pytorch教程,并编写C Demo CMakeLists.txt

本文首发于个人博客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源非常慢,用清华源代替。

see tsinghua anaconda

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值