Xavier入门教程软件篇-编译安装PyTorchv1.3.0(jetpack.4.2.3)
Xavier入门教程软件篇-编译安装PyTorch(Caffe2)v1.3.0(jetpack.4.2.3)
说明:
- 介绍如何在Xavier安装PyTorch v1.3.0
- PyTorch已经包含caffe2
- 环境:Jeppack 4.2.3
步骤:
- 新建目录
mkdir -p ~/dl/PyTorch
cd ~/dl/PyTorch
- 最大性能
$ sudo nvpmodel -m 0
$ sudo ~/jetson_clocks.sh
- 下载源码
$ git clone --recursive --branch v1.3.0 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;7.2"
$ export PYTORCH_BUILD_NUMBER=1
$ export PYTORCH_BUILD_VERSION=1.3.0
- 构建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
$ sudo pip3 install scikit-build
$ python3 setup.py bdist_wheel
- 编译完成后的whl文件位置
$ cd ~/dl/PyTorch/pytorch/dist
$ ls
torch-1.3.0a0+54a63e0-cp36-cp36m-linux_aarch64.whl
- 安装whell
# Python 2.7 (download pip wheel from above)
$ pip install torch-1.3.0a0+8554416-cp27-cp27mu-linux_aarch64.whl --user
# Python 3.6 (download pip wheel from above)
$ pip3 install torch-1.3.0a0+54a63e0-cp36-cp36m-linux_aarch64.whl --user
- PyTorch v1.3 对应 torchvision v0.5.0
- 源码安装torchvision
$ git clone https://github.com/pytorch/vision
$ cd vision
$ git checkout -b v0.5.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
- https://devtalk.nvidia.com/default/topic/1049071/jetson-nano/pytorch-for-jetson-nano/
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号