AI摘要:本文介绍了Jetson开发板的设置方法,包括修改启动路径、换源、自动调节风扇转速、安装nomachine、pip换源、增加swapfile、安装vscode和Tensorflow等。同时,还提供了解决常见问题的方法,如自动调节风扇转速、nomachine黑屏解决方法、pip换源、增加swapfile、Tensorflow安装过程中的常见问题等。最后,还介绍了如何使用polygraphy工具进行TensorRT引擎的构建和运行。

Powered by AISummary.

Jetson设置

修改启动路径

sudo vi /boot/extlinux/extlinux.conf

找到语句APPEND ${cbootargs} quiet root=/dev/mmcblk0p1 rw rootwait rootfstype=ext4 console=ttyS0,115200n8 console=tty0,将mmcblk0p1修改为mmcblk1保存

换源

1.先备份原本的source.list文件

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

2.修改source

进入source.list

sudo vi /etc/apt/sources.list

按"i"开始输入,然后删除所有内容,复制进下面的

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

“Esc”结束输入,“:wq!”保存退出

3.更新软件列表,保存在本地

sudo apt-get update

如果需要,可以更新软件:(尽量不要操作,否则更新后可能导致WiFi无法使用)
sudo apt-get upgrade
若出现以下错误
E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/
执行
rm /var/lib/apt/lists/lock

自动调节风扇转速

网址:点击这里:Pyrestone/jetson-fan-ctl

下载下来之后进入文件夹:

michael@michael-desktop:~/Desktop/zyq/jetson-fan-ctl$ ls
automagic-fan.service fanctl.py LICENSE uninstall.sh
config.json install.sh README.md

按照readme里面的指示安装,这个需要先安装python3

sudo apt install python3-dev

然后运行

sudo ./install.sh

现在你的风扇就可以按照温度自动调整运行速度了
风扇的一些设置在/etc/automagic-fan/config.json目录下。

vim /etc/automagic-fan/config.json

{
“FAN_OFF_TEMP”:20,
“FAN_MAX_TEMP”:50,
“UPDATE_INTERVAL”:2,
“MAX_PERF”:1
}

安装nomachine

下载ARMV8版本:https://downloads.nomachine.com/download/?id=116&distro=ARM
sudo dpkg -i nomachine_8.2.3_3_arm64.deb

nomachine黑屏解决方法:

在服务器上手动关闭X server,采用Nomachine自带的显示服务,运行命令如下:

sudo systemctl stop gdm3
sudo /etc/NX/nxserver --restart

客户端重新连接远程桌面 

pip换源

方案一:修改配置文件

首先在当前用户目录下建立文件夹.pip,然后在文件夹中创建pip.conf文件,再将源地址加进去即可。

mkdir ~/.pip
vim ~/.pip/pip.conf
然后将下面这两行复制进去就好了
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

--------------------------------------------------------------------

国内其他pip源

清华:https://pypi.tuna.tsinghua.edu.cn/simple
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
豆瓣:http://pypi.douban.com/simple/

增加swapfile

sudo fallocate -l 10G /var/swap
sudo chmod 600 /var/swap
sudo mkswap /var/swap
sudo swapon /var/swap
sudo vi /etc/fstab

/var/swap swap swap defaults 0 0

install dphys-swapfile:
sudo apt-get install dphys-swapfile

enlarge the boundary (4.5.2 and higher):
sudo vi /sbin/dphys-swapfile

CONF_MAXSWAP=2048改为10240

give the required memory size:
sudo vi /etc/dphys-swapfile
CONF_MAXSWAP=2048改为10240

reboot afterwards:
sudo reboot

安装vscode

下载ARM64版本:https://code.visualstudio.com/docs/?dv=linuxarm64_deb

安装Tensorflow

Setup Jetson Nano

因为Nano是Arm架构,所以相比x86_64架构的配置流程有所区别。

解决BUG部分请直接跳到本文最后。

Arm的许多源是与x86_64源不同的,所以除非很有把握,最好保持Nvidia出厂配置的源不变,轻易不改变软件源。

  1. Setup Python Env.

Python既可以使用apt安装在系统目录中,也可以使用conda安装在用户目录中。
2.1 安装到系统

sudo apt update
sudo apt install python3-pip
sudo pip3 install -U pip

完成后使用which python和python -V确认版本。
2.2 安装到用户主目录
2.2.1 Install conda with miniforge

传统架构中,经常使用anaconda或miniconda管理python环境,但arm架构中需要使用miniforge代替:

python 3.10版本如下,后续需要降级
cd ~
wget https://github.com/conda-forge/miniforge/releases/download/22.9.0-2/Miniforge3-22.9.0-2-Linux-aarch64.sh
bash Miniforge3-22.9.0-2-Linux-aarch64.sh

安装过程中,按q跳过用户协议,其它过程根据提示输入yes或Enter即可。

安装完毕后,使用. .bashrc**conda环境。
2.2.2 Decrease python version to 3.6

因为Nvidia提供的Tensorflow 2.X是在python 3.6环境下编译的,因此需要对conda的默认python降级。

如果不想改变默认python版本,也可以使用conda create -n py3.6 python=3.6来创建新环境。

sudo conda install python=3.6

若碰到sudo无法使用,如下操作:
(1) vim ~/.bashrc

               添加如下内容:

               alias sudo="sudo env PATH=$PATH"

(2)source ~/.bashrc

完成后使用which python和python -V确认版本。

  1. Install System Dependencies

因为Arm下许多库都要从源编译,因此需要安装一些编译过程用到的库。

如果第2节是按2.1步骤将python与pip安装到系统,那后续使用pip3时都要先加上sudo。

sudo apt-get install libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev liblapack-dev libblas-dev gfortran
pip3 install -U pip
pip3 install -U CPython testresources setuptools

  1. Install Python Libraries

pip3 install -U numpy==1.16.1 future==0.17.1 mock==3.0.5 h5py==2.9.0 keras_preprocessing==1.0.5 keras_applications==1.0.8 gast==0.2.2 futures protobuf pybind11

编译安装时间会很长(1小时以上),注意不要断网断电。

  1. Install Tensorflow

访问Nvidia再发行版Tensorflow官网,选择合适的版本下载安装。此处以tf_gpu-2.2.0+nv20.6-py3为例:

cd
wget https://developer.download.nvidia.com/compute/redist/jp/v461/tensorflow/tensorflow-2.7.0+nv22.1-cp36-cp36m-linux_aarch64.whl
pip3 install tensorflow-2.7.0+nv22.1-cp36-cp36m-linux_aarch64.whl

部分依赖项的编译时间较长。

JetPack的版本可以根据手中Jetson的CUDA版本确定。运行ls /usr/local/cuda*及cat /usr/local/cuda-*/version.txt可查看本机CUDA版本。

JetPack4.4中CUDA版本为10.2,JetPack4.2/4.3中CUDA版本为10.0。

h5py编译出错 需要先手动安装CPython再编译。
ERROR: Failed building wheel for h5py

解决方法:

  • sudo apt-get install libhdf5-dev
  • sudo pip install Cython
  • sudo pip install h5py

其他问题:

  • 找不到xlocale.h 创建指向locale.h的软链接:sudo ln -s /usr/include/locale.h /usr/include/xlocale.h
  • cannot allocate memory in static TLS block 在.bashrc中加入export LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libgomp.so.1,并source ~/.bashrc
  • 亦可尝试,将其放在import tensorflow以及import keras之前
  • scikit-learn未正确编译 从源码安装:pip3 install git+https://github.com/scikit-learn/scikit-learn.git。 系统级:sudo apt install python-sklearn sklearn

英伟达Jetson平台使用polygraphy时的出现“Illegal instruction(cpre dumped)”错误

pip3 install nvidia-pyindex
pip3 install polygraphy
将“export OPENBLAS_CORETYPE=ARMV8”加入到“~/.bashrc”中

polygraphy应用

使用上面生成的 model.onnx 构建 TensorRT 引擎,使用 FP32 精度同时在 TensorRT 和 onnxruntime 中运行
输出所有层的计算结果作对比:onnx-outputs mark all和trt-outputs mark all

polygraphy run model.onnx \
    --onnxrt --trt \
    --workspace 100000000 \
    --save-engine=model_FP32_MarkAll.plan \
    --atol 1e-3 --rtol 1e-3 \
    --verbose \
    --onnx-outputs mark all \
    --trt-outputs mark all \
    --trt-min-shapes 'x:0:[1,1,28,28]' \
    --trt-opt-shapes 'x:0:[4,1,28,28]' \
    --trt-max-shapes 'x:0:[16,1,28,28]' \
    --input-shapes 'x:0:[4,1,28,28]' \
    > result-run-FP32-MarkAll.txt
Last modification:April 25, 2024
文章免费,无需打赏