Jetson 安装 Pytorch\torchvision
一、 安装方法
不同于其他平台,需要安装对应arch64平台的预编译版本,见链接:
https://forums.developer.nvidia.com/t/pytorch-for-jetson-version-1-11-now-available/72048
- Pytorch
pytorch可以直接从该网页下载安装包,然后pip安装。一下以某个版本为例,可以需要根据实际情况替换版本。
wget https://nvidia.box.com/shared/static/p57jwntv436lfrd78inwl7iml6p13fzh.whl -O torch-1.8.0-cp36-cp36m-linux_aarch64.whl
sudo apt-get install python3-pip libopenblas-base libopenmpi-dev libomp-dev
pip3 install Cython
pip3 install numpy torch-1.8.0-cp36-cp36m-linux_aarch64.whl
- Torchvison
---更新时间- 2022-08-16:
建议直接安装编译好的安装包,链接:https://github.com/Qengineering/PyTorch-Raspberry-Pi-64-OS/blob/main/README.md 比下面的方式更方便
torchvison 需要从源码编译。切换到torch对应的torchvision版本,具体对应关系可以看上述链接描述。
$ sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libavcodec-dev libavformat-dev libswscale-dev
$ git clone --branch <version> https://github.com/pytorch/vision torchvision # see below for version of torchvision to download
$ cd torchvision
$ export BUILD_VERSION=0.x.0 # where 0.x.0 is the torchvision version
$ python3 setup.py install --user
$ cd ../ # attempting to load torchvision from build dir will result in import error
$ pip install 'pillow<7' # always needed for Python 2.7, not needed torchvision v0.5.0+ with Python 3.6
二、BUG
在torchvison编译时遇到一个错误,torchvision subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1. The above exception was the direct cause of the following exception:
. 如下:
-解决办法:
将setup.py中的“cmdclass={'build_ext': BuildExtension}”这一行改为“cmdclass={'build_ext': BuildExtension.with_options(use_ninja=False)}”,pytorch默认使用ninjia作为backend,这里把它禁用掉就好了.
三、Dockfile 参考安装例子
来自 pytorch_vision_spacy_torchtext_jetson_nano.sh
#!/bin/bash
# This script will install pytorch, torchvision, torchtext and spacy on nano.
# If you have any of these installed already on your machine, you can skip those.
sudo apt-get -y update
sudo apt-get -y upgrade
#Dependencies
sudo apt-get install python3-setuptools
#Installing PyTorch
#For latest PyTorch refer original Nvidia Jetson Nano thread - https://devtalk.nvidia.com/default/topic/1049071/jetson-nano/pytorch-for-jetson-nano/.
wget https://nvidia.box.com/shared/static/ncgzus5o23uck9i5oth2n8n06k340l6k.whl -O torch-1.4.0-cp36-cp36m-linux_aarch64.whl
sudo apt-get install python3-pip libopenblas-base
sudo pip3 install Cython
sudo pip3 install numpy torch-1.4.0-cp36-cp36m-linux_aarch64.whl
#Installing torchvision
#For latest torchvision refer original Nvidia Jetson Nano thread - https://devtalk.nvidia.com/default/topic/1049071/jetson-nano/pytorch-for-jetson-nano/.
sudo apt-get install libjpeg-dev zlib1g-dev
git clone --branch v0.5.0 https://github.com/pytorch/vision torchvision # see below for version of torchvision to download
cd torchvision
sudo python setup.py install
cd ../ # attempting to load torchvision from build dir will result in import error
#Installing spaCy
#Installing dependency sentencepiece
sudo apt-get install cmake build-essential pkg-config libgoogle-perftools-dev
git clone https://github.com/google/sentencepiece.git
cd sentencepiece
mkdir build
cd build
cmake ..
make -j $(nproc)
sudo make install
sudo ldconfig -v
cd python
python3 setup.py build
sudo python3 setup.py install
cd ../../
git clone https://github.com/explosion/spaCy
cd spaCy/
export PYTHONPATH=`pwd`
export BLIS_ARCH=generic
sudo pip3 install -r requirements.txt
sudo python3 setup.py build_ext --inplace
sudo python3 setup.py install
python3 -m spacy download en_core_web_sm
cd ../
#Installing torchtext
git clone https://github.com/pytorch/text.git
cd text
sudo pip3 install -r requirements.txt
sudo python3 setup.py install
cd ../
echo "done installing PyTorch, torchvision, spaCy, torchtext"
————————————————
参考自: