< >
Home » TX2入门教程软件篇 » TX2入门教程软件篇-安装PyTorch(Caffe2)v1.2.0(jetpack3.3)

TX2入门教程软件篇-安装PyTorch(Caffe2)v1.2.0(jetpack3.3)

TX2入门教程软件篇-安装PyTorch(Caffe2)v1.2.0(jetpack3.3)

说明:

  • 介绍如何在tx2 jetpack3.3安装PyTorch(Caffe2)v1.2.0
  • 环境

步骤:

  • 新建目录
mkdir -p ~/dl/PyTorch
cd ~/dl/PyTorch
  • 最大性能
$ sudo nvpmodel -m 0
$ sudo ~/jetson_clocks.sh
  • 下载源码
$ git clone --recursive http://github.com/pytorch/pytorch
$ cd pytorch
# if you are updating an existing checkout
$ git submodule sync
$ git submodule update --init --recursive
  • 配置环境变量
$ export USE_NCCL=0
$ export USE_DISTRIBUTED=0
$ export TORCH_CUDA_ARCH_LIST="5.3;6.2"
  • 构建wheel 针对python2
$ sudo apt-get install python-pip cmake
$ pip install -U pip

$ sudo pip install -U setuptools
$ sudo pip install -r requirements.txt

$ pip install scikit-build --user

$ python setup.py bdist_wheel
  • 构建wheel 针对python3
$ sudo apt-get install python3-pip cmake

$ sudo pip3 install -U setuptools
$ sudo pip3 install -r requirements.txt

$ pip3 install scikit-build --user

$ python3 setup.py bdist_wheel
  • 编译完成后的whl文件位置
$ cd ~/dl/PyTorch/pytorch/dist
$ ls
torch-1.2.0a0+54a63e0-cp35-cp35m-linux_aarch64.whl
  • 安装whell
# Python 2.7 (download pip wheel from above)
$ pip install torch-1.2.0a0+8554416-cp27-cp27mu-linux_aarch64.whl --user

# Python 3.6 (download pip wheel from above)
$ pip3 install torch-1.2.0a0+54a63e0-cp35-cp35m-linux_aarch64.whl --user
  • pip安装
 pip3 install torchvision --user
  • 源码安装torchvision
$ git clone https://github.com/pytorch/vision
$ cd vision
$ git checkout -b v0.4.0
$ sudo python3 setup.py install

测试:

  • 测试cuda和torch
ubuntu@AiROS:~$ python3
Python 3.5.2 (default, Jul 10 2019, 11:58:48) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.__version__)
1.2.0a0+54a63e0
>>> print(torch.cuda.is_available())
True
>>> a = torch.cuda.FloatTensor(2)
>>> print(a)
tensor([0., 0.], device='cuda:0')
>>> b = torch.randn(2).cuda()
>>> print(b)
tensor([ 1.3568, -1.6426], device='cuda:0')
>>> c = a + b
>>> print(c)
tensor([ 1.3568, -1.6426], device='cuda:0')
>>> 
  • 测试vision
import torchvision

参考:

  • https://pytorch.org/
  • https://github.com/pytorch/pytorch
  • https://elinux.org/Jetson_Zoo#PyTorch_.28Caffe2.29

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: tx2入门教程软件篇