jetson系产品安装pytorch

该安装方式适用于JetPack版本在4.2以上的英特尔系产品:

  • Jetson Nano,
  • Jetson TX1/TX2
  • Jetson Xavier NX/AGX

安装镜像环境

英特尔官方提供的镜像环境在国内下载依赖包速度较慢,可以对镜像进行更改
打开镜像文件

sudo gedit /etc/apt/sources.list

删除原文件,添加以下文件
清华镜像:

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse

中科大镜像

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.ustc.edu.cn/ubuntu-ports bionic main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports bionic main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu-ports bionic-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports bionic-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu-ports bionic-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports bionic-backports main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu-ports bionic-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports bionic-security main restricted universe multiverse

添加后save保存
在终端使用下列命令更新:

sudo apt update
sudo apt upgrade -y

安装python环境及依赖包

jetpack自带python2.7和python3.6,无需加载
若需要使用python3.6,使用python3命令
在终端输入命令:

sudo apt-get install git cmake python3-dev
sudo apt-get install libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev
 sudo apt-get install python3-pip
 sudo pip3 install -U pip testresources setuptools

安装pytorch依赖包

sudo apt-get install libopenblas-base libopenmpi-dev
sudo pip3 install mpi4py
sudo pip3 install Cython

pytorch官方包下载

NVIDIA官网:https://forums.developer.nvidia.com/t/pytorch-for-jetson-version-1-7-0-now-available/72048
进入后选择自己需要的pytorch版本
jetson系产品安装pytorch_第1张图片由于此处登的是外网,需要梯子下载,附上pytorch1.7百度网盘:
链接:https://pan.baidu.com/s/1aKma-EJzLiMmEo2-g3tkbw
提取码:dfgs
下载后在文件对应位置打开终端

sudo pip3 install torch-1.7.0-cp36-cp36m-linux_aarch64.whl

安装torchvision

安装依赖包

 sudo apt-get install libjpeg-dev zlib1g-dev

参考pytorch对应torchvision版本
jetson系产品安装pytorch_第2张图片

git clone --branch  v0.6.0 https://github.com/pytorch/vision torchvision

这里克隆git库速度可能很慢。可以参考这个老哥骚操作
接着

 cd torchvision
 sudo python3 setup.py install

问题

出现错误:

error: command 'aarch64-linux-gnu-gcc' failed with exit status 1

往上翻,发现是

fatal error: libavcodec/avcodec.h: No such file or directory

FFmpeg出现版本错误,打开setup.py
if has_ffmpeg 改为if False保存即可

你可能感兴趣的:(jetson,pytorch,深度学习)