NVIDIA Jetson Xavier NX入门(3)——pytorch和torchvision安装

NVIDIA Jetson Xavier NX入门(3)——pytorch和torchvision安装

1.安装pytorch

NVIDIA下载pytorch官方网址是:https://forums.developer.nvidia.com/t/pytorch-for-jetson-version-1-9-0-now-available/72048
NVIDIA Jetson Xavier NX入门(3)——pytorch和torchvision安装_第1张图片
下载好后,在下载文件目录下输入指令:

pip3 install torch-1.8.0-cp36-cp36m-linux_aarch64.whl

安装完毕后可以在终端输入以下命令检验PyTorch是否正确安装:

python -c 'import torch; print(torch.cuda.is_available())'

正常来说,会返回True。

出现报错1:博主本人在安装后出现错误(NVIDIA Jetson Xavier NX安装pytorch时import torch时报OSError: libmpi_cxx.so.20: cannot open shared object file: No such file or directory)

import torch
Traceback (most recent call last):
File “”, line 1, in
File “/home/*/.local/lib/python3.6/site-packages/torch/init.py”, line 188, in
_load_global_deps()
File “/home/*/.local/lib/python3.6/site-packages/torch/init.py”, line 141, in _load_global_deps
ctypes.CDLL(lib_path, mode=ctypes.RTLD_GLOBAL)
File “/usr/lib/python3.6/ctypes/init.py”, line 348, in init
self._handle = _dlopen(self._name, mode)
OSError: libmpi_cxx.so.20: cannot open shared object file: No such file or directory

有库没有安装,输入指令:

sudo apt-get install libopenblas-base libopenmpi-dev 

出现报错2:Illegal instruction (core dumped)如果出现Illegal instruction (core dumped)的错误,这是由于numpy 1.19.5和OpenBLAS冲突引起的,修改其中一项即可。选择以下两种做法之一:
(1)降低numpy版本:

pip3 install -U numpy==1.19.4

(2)设置OpenBLAS

vim ~/.bashrc

加入:

export OPENBLAS_CORETYPE=ARMV8

激活.bashrc:

source ~/.bashrc

2. 安装torchvision

Pytorch除了torch包之外还需要安装对应的torchvision才能运行,两者的版本对应关系如下图:
NVIDIA Jetson Xavier NX入门(3)——pytorch和torchvision安装_第2张图片
输入指令:

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

NVIDIA Jetson Xavier NX入门(3)——pytorch和torchvision安装_第3张图片

到此NVIDIA Jetson Xavier NX环境的基本配置已经完成,当出现无法定位软件包(Unable to locate package)的情况,首先使用sudo apt-get update指令。

你可能感兴趣的:(Jetson,Xavier,NX,pytorch,深度学习,python)