jetson平台的pytorch版本
注意这里的 v0.9.0 和pytorch版本1.8对应
sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libavcodec-dev libavformat-dev libswscale-dev
# 注意这里的 v0.9.0 和pytorch版本1.8对应
git clone --branch v0.9.0 https://github.com/pytorch/vision torchvision
cd torchvision
export BUILD_VERSION=0.9.0
# 注意 pillow<7
pip install pillow==6.2.2
python3 setup.py install --user
出现错误
OSError: libmpi_cxx.so.20: cannot open shared object file
解决
apt-get install libopenblas-base libopenmpi-dev
在Jetson Xavier NX上安装torchvision编译报错:fatal error: libavcodec/avcodec.h: No such file or directory
deepstream6.1
下载相应版本的deepstream
jetson平台安装deepstream5.1,参考:Install Jetson SDK components
x86平台安装deepstream6.1,参考:dGPU Setup for Ubuntu
yolov5s_v5.0.pt
yolov5s_v6.1.pt
训练自己的模型略
DeepStream-Yolo
下载到 deepstream/source
目录下git clone https://github.com/marcoslucianops/DeepStream-Yolo.git
git clone https://github.com/ultralytics/yolov5.git
# 切换到对应分支,这里以最新版v6.1分支为例
git checkout v6.1
把 DeepStream-Yolo/utils
中的 gen_wts_yoloV5.py
文件复制到 yolov5
项目根目录;并且把刚才下载好的 yolov5s_v6.1.pt
yolov5s_v6.1.pt 或者自己训练的模型,复制进 yolov5
项目根目录,执行以下命令会生成对应的 .cfg
文件和 .wts
文件
python gen_wts_yoloV5.py -w yolov5s_v6.1.pt
把生成的yolov5s_v6.1.wts
复制到 DeepStream-Yolo
项目根目录
执行命令生成 .so
文件
CUDA_VER=11.1 make -C nvdsinfer_custom_impl_Yolo
config_infer_primary_yoloV5.txt
[property]
...
custom-network-config=yolov5s.cfg
model-file=yolov5s.wts
...
...
[primary-gie]
...
config-file=config_infer_primary_yoloV5.txt
修改 config_infer_primary_yoloV5.txt
[property]
gpu-id=0
net-scale-factor=0.0039215697906911373
##0=RGB, 1=BGR
model-color-format=0
custom-network-config=yolov5sv6_fire.cfg
model-file=yolov5sv6_fire.wts
model-engine-file=model_b1_gpu0_fp32.engine
#int8-calib-file=calib.table
labelfile-path=labels.txt
batch-size=1
##0=FP32, 1=INT8, 2=FP16 mode
network-mode=0
##检测类别数
num-detected-classes=2
interval=0
gie-unique-id=1
process-mode=1
network-type=0
##1=DBSCAN, 2=NMS, 3= DBSCAN+NMS Hybrid, 4 = None(No clustering)
cluster-mode=4
maintain-aspect-ratio=1
parse-bbox-func-name=NvDsInferParseYolo
custom-lib-path=nvdsinfer_custom_impl_Yolo/libnvdsinfer_custom_impl_Yolo.so
engine-create-func-name=NvDsInferYoloCudaEngineGet
[class-attrs-all]
##几项阈值
pre-cluster-threshold=0
配置相应的 labels
文件
deepstream-app -c deepstream_app_config.txt
cankao:Jetson Xavier NX使用yolov5对比GPU模型下的pt、onnx、engine 、 DeepStream 加速性能
NX上使用deepstream5.0框架运行yolov5检测视频
一、NX上运行yolov5步骤:
1.基本命令
#set python Version
#常用软件
#apt-get如何查看已安装的软件包
dpkg -l或dpkg --get-selections |less
#pip3 如何查看已安装的软件包
pip3 list
#驱动版本
head -n 1 /etc/nv_tegra_release
#内核版本
uname -r
#操作系统
lsb_release -i -r
#CUDA版本
nvcc -V
#cuDNN版本
dpkg -l libcudnn8
#opencv版本
dpkg -l libopencv / pkg-config opencv --modversion
#Tensorrt版本
dpkg -l tensorrt
2.基本配置
#添加CUDA环境变量
#cuda
sudo vi ~/.bashrc
#添加
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda
#保存并刷新
source ~/.bashrc
3换源
#备份原有软件源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vi /etc/apt/sources.list
#清华源
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
#更新没问题
sudo apt-get update
4 pip/python3
#查看python版本是否最新
sudo apt-get install python3-pip python3-dev
python3 -m pip install --upgrade pip
Jetson-stats
#查看系统使用情况,类似top
sudo -H pip3 install jetson-stats
#使用
jtop
5配置python环境
sudo pip3 install -U pip testresources setuptools
sudo apt-get install libopenblas-base libopenmpi-dev
sudo pip3 install mpi4py
sudo pip3 install Cython
6安装pytorchy
sudo pip3 install torch-1.6.0-cp36-cp36m-linux_aarch64.whl
7. torchvision安装
git clone --branch v0.7.0 https://github.com/pytorch/vision torchvision
cd torchvision
export BUILD_VERSION=0.7.0
sudo python3 setup.py install
8 配置YOLOv5开源代码
(1) 代码仓库git clone https://github.com/ultralytics/yolov5 (慎重:下载权重文件,代码和权重我已经下载好了,在weights下)
***此处有一个坑:yolov5更新频繁,兼容torch1.6和torchvision0.7的是5-3.0版本,如果现在最新的yolov5会出现torchvision0.7版本不匹配等问题。
(2) 安装依赖(torch和torchvision上面已经安装完成)
cd yolov5
sudo pip3 install -r requirements.txt
***此处有一个坑:
对于PyYAML的更新问题:如果卸载不掉可以使用命令:直接安装新的版本
pip3 install PyYAML -i https://mirrors.aliyun.com/pypi/simple/ --ignore-installed
***此处还有一个更大的坑:
安装上边的依赖有可能会更显numpy到1.19.5版本,该版本再arm64的pyhon3.6下会出现:Illegal Instruction。解决方法是卸载后,重装1.19.3
(3) 测试是否成功
sudo python3 detect.py --source inference/images/ --weights weights/yolov5s.pt --conf-thres 0.7
成功会在inference/output下生产检测结果
(4) 使用自己的数据集
二、 NX上使用tensorrt加速yolov5步骤:
# 参考网址:
# https://blog.csdn.net/m0_37426155/article/details/108254714
#https://github.com/wang-xinyu/tensorrtx/tree/master/yolov5
# 1.下载大牛的yolov5转换tensorrt的开源代码。
git clone https://github.com/wang-xinyu/tensorrtx
#2.针对我的yolov5-2.0下载对应分支。
cd tensorrtx/yolov5
git checkout 5cfa444 #
# 3.先把 yolov5s.pt转换成yolov5s.wts
cd yolov5
cp ../tensorrtx/yolov5/gen_wts.py .
#ensure the file name is yolov5s.pt and yolov5s.wts in gen_wts.py
python gen_wts.py
#a file 'yolov5s.wts' will be generated.
4.最后把yolov5s.wts 转化成yolov5.engine
mv yolov5s.wts ../tensorrtx/yolov5/
cd ../tensorrtx/yolov5
#ensure the macro NET in yolov5.cpp is s
mkdir build
cd build
cmake ..
make
sudo ./yolov5 -s // serialize model to plan file i.e. 'yolov5s.engine'
sudo ./yolov5 -d ../samples // deserialize plan file and run inference, the images in samples will be processed.
三、NX上使用deepstream集成yolov5步骤:
源码编译安装,亲测通过
# 提前在jetson nx上编译安装opencv opencv-contrib-python 参考..
git clone https://github.com/PaddlePaddle/PaddleOCR.git
# opencv-contrib-python==4.4.0.46 版本
pip install -r requirements.txt
python setup install
参考:Jetson Xavier NX部署PaddleOCR
h5py
wget https://github.com/yihuajack/h5py-aarch64/raw/main/h5py-3.1.0-cp36-cp36m-linux_aarch64.whl
2. 安装onnx
sudo apt-get install protobuf-compiler libprotoc-dev
pip3 install onnx -i https://pypi.doubanio.com/simple/
如果安装失败,尝试下面的命令
sudo apt-get install protobuf-compiler libprotobuf-dev
pip install pybind11[global]
pip install onnx==1.9.0
sentencepiece
sudo apt-get install cmake build-essential pkg-config libgoogle-perftools-dev
git clone https://github.com/google/sentencepiece
cd sentencepiece/
mkdir build
cd build/
cmake ..
make -j4
sudo make install
sudo ldconfig -v
nccl
git clone https://github.com/NVIDIA/nccl.git
cd nccl/
make -j4
sudo make install
下载jetson平台的paddlepaddle_gpu,
paddlepaddle_gpu-2.2.1-cp36-cp36m-linux_aarch64.whl
pip install paddlepaddle_gpu-2.2.1-cp36-cp36m-linux_aarch64.whl
参考Jetson AGX Xavier配置cuDNN流程
sudo nvpmodel -m 1
sudo nvpmodel -m 2
设置完后,都要运行
sudo /usr/bin/jetson_clocks
参考:Jetson 系列——jetson xavier nx和nano设置工作模式设置功率
sudo apt-get update
sudo visudo
icir ALL=(ALL) NOPASSWD:ALL
首先 添加dns服务器
vi /etc/resolv.conf
#在文件中添加如下两行:
nameserver 8.8.8.8
nameserver 8.8.4.4
更新系统时间
# 首先安装 ntpdate 命令:
sudo apt-get install -y ntpdate
# 接着执行如下命令开始同步:
sudo ntpdate 0.asia.pool.ntp.org
# 最后执行如下命令将系统时间同步到硬件,防止系统重启后时间被还原。
sudo hwclock --systohc
export DISPLAY=:0
xhost +
xhost + 192.168.70.234
sudo apt-get update
#安装桌面软件
sudo apt-get install ubuntu-desktop
#重启
reboot
dpkg -l | grep TensorRT
sudo apt-get update
sudo apt-get install gstreamer1.0-tools gstreamer1.0-alsa gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-good1.0-dev libgstreamer-plugins-bad1.0-dev
sudo apt-get install libjson-glib-1.0-0 libjson-glib-dev
Illegal instruction (core dumped)
# 临时修改
export OPENBLAS_CORETYPE=ARMV8
# 永久修改
将“export OPENBLAS_CORETYPE=ARMV8”加入到“~/.bashrc”中
error: libhdf5.so: cannot open shared object file: No such file or directory
sudo apt install libhdf5-dev