【nvidia jetson xavier】Deepstream Yolox,Yolov4,Yolov5模型部署

Deepstream YoloX 模型部署

https://github.com/Megvii-BaseDetection/YOLOX
https://github.com/nanmi/YOLOX-deepstream

Deepstream Yolov4 模型部署

https://github.com/NVIDIA-AI-IOT/yolov4_deepstream

Deepstream Yolov5 模型部署

https://github.com/DanaHan/Yolov5-in-Deepstream-5.0
https://blog.csdn.net/zong596568821xp/article/details/109444343
这里主要以yolov5为例,其他两个可以是同样的流程。

Geneate yolov5 engine model

1.在Jetson 平台安装Yolov5环境

https://www.runoob.com/w3cnote/python-pip-install-usage.html

安装pip

sudo apt-get install python-pip

升级pip

pip install -U pip
【报错】python 2.7版本不符合requirements.txt中包的版本

ubuntu 修改python默认版本,系统级修改

https://blog.csdn.net/White_Idiot/article/details/78240298

基于软链接:

先删除默认的Python软链接:

sudo rm /usr/bin/python

然后创建一个新的软链接指向需要的Python版本:

sudo ln -s /usr/bin/python3.5 /usr/bin/python

安装requirements.txt遇到报错,重新安装pip:

sudo apt-get install python-pip

根据安装提示卸载多余包

sudo apt autoremove

再次尝试还是失败,尝试卸载pip重装:

sudo apt remove python-pip

仍然报错:

ImportError: No module named pip

尝试:

sudo apt-get install python3-pip

成功安装pip3,然后执行:

pip3 install -r requirements.txt

配置yolov5运行环境

【报错】matplotlab无法安装:
更换yolov5配置方法:

https://github.com/marcoslucianops/DeepStream-Yolo/blob/master/YOLOv5-5.0.md

配置yolov5 Requirements

Matplotlib (for Jetson plataform)

sudo apt-get install python3-matplotlib

PyTorch (for Jetson plataform)

wget https://nvidia.box.com/shared/static/p57jwntv436lfrd78inwl7iml6p13fzh.whl -O torch-1.8.0-cp36-cp36m-linux_aarch64.whl 
#如果因为网络问题无法下载,可以先下载好torch-1.8.0-cp36-cp36m-linux_aarch64.whl,然后复制过去
sudo apt-get install python3-pip libopenblas-base libopenmpi-dev
pip3 install Cython
pip3 install numpy torch-1.8.0-cp36-cp36m-linux_aarch64.whl

TorchVision (for Jetson platform)

sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libavcodec-dev libavformat-dev libswscale-dev
git clone --branch v0.9.0 https://github.com/pytorch/vision torchvision
cd torchvision
export BUILD_VERSION=0.9.0
python3 setup.py install --user
Convert PyTorch model to wts file
  1. Download repositories
git clone https://github.com/wang-xinyu/tensorrtx.git
git clone https://github.com/ultralytics/yolov5.git
  1. Download latest YoloV5 (YOLOv5s, YOLOv5m, YOLOv5l or YOLOv5x) weights to yolov5 folder (example for YOLOv5s)
wget https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt -P yolov5/
  1. Copy gen_wts.py file (from tensorrtx/yolov5 folder) to yolov5 (ultralytics) folder
cp tensorrtx/yolov5/gen_wts.py yolov5/gen_wts.py
  1. Generate wts file
cd yolov5
python3 gen_wts.py yolov5s.pt

yolov5s.wts file will be generated in yolov5 folder

【错误】No module named tqdm

pip install tqdm

【错误】No module named seaborn

pip3 install seaborn

因matplotlib无法正常安装导致seaborn无法安装,尝试:

python --version
python -m pip install seaborn

再次因matplotlib失败

尝试:

https://toptechboy.com/

https://blog.csdn.net/LYiiiiiii/article/details/119052823

sudo apt-get install python3-seaborn

再次执行

python3 gen_wts.py yolov5s.pt

成功!

Convert wts file to TensorRT model

根据https://github.com/DanaHan/Yolov5-in-Deepstream-5.0的说明,在Build tensorrtx/yolov5之前还需要:

Important Note:

You should replace yololayer.cu and hardswish.cu file in tensorrtx/yolov5

  1. Build tensorrtx/yolov5
cd tensorrtx/yolov5
mkdir build
cd build
cmake ..
make
  1. Move generated yolov5s.wts file to tensorrtx/yolov5 folder (example for YOLOv5s)
cp yolov5/yolov5s.wts tensorrtx/yolov5/build/yolov5s.wts
  1. Convert to TensorRT model (yolov5s.engine file will be generated in tensorrtx/yolov5/build folder)
sudo ./yolov5 -s yolov5s.wts yolov5s.engine s
  1. Create a custom yolo folder and copy generated file (example for YOLOv5s)
mkdir /opt/nvidia/deepstream/deepstream-5.1/sources/yolo
cp yolov5s.engine /opt/nvidia/deepstream/deepstream-5.1/sources/yolo/yolov5s.engine

Note: by default, yolov5 script generate model with batch size = 1 and FP16 mode.

#define USE_FP16  // set USE_INT8 or USE_FP16 or USE_FP32
#define DEVICE 0  // GPU id
#define NMS_THRESH 0.4
#define CONF_THRESH 0.5
#define BATCH_SIZE 1

Edit yolov5.cpp file before compile if you want to change this parameters.

We can get ‘yolov5s.engine’ and ‘libmyplugin.so’ here for the future use.

【!】切换使用https://github.com/DanaHan/Yolov5-in-Deepstream-5.0的deepstream配置进行之后的nvdsinfer_custom_impl_yolo plugin等操作(也可以按https://github.com/marcoslucianops/DeepStream-Yolo/blob/master/YOLOv5-5.0.md继续)

在Yolov5-in-Deepstream-5.0/Deepstream 5.0下执行

CUDA_VER=10.2 make -C nvdsinfer_custom_impl_Yolo

并将deepstream_app_config_yoloV5.txt文件中的deepstream-5.0全部修改为deepstream-5.1

Testing model
【报错】无labels.txt文件

在/opt/nvidia/deepstream/deepstream-5.1/sources/objectDetector_Yolo文件夹下找到labels.txt文件复制到Yolov5-in-Deepstream-5.0/Deepstream 5.0

【报错】原因config_infer_primary_yoloV5.txt中出现路径错误

修改config_infer_primary_yoloV5.txt中的custom-lib-path,删除 ‘objectDetector_Yolo_V5/’

执行

deepstream-app -c deepstream_app_config_yoloV5.txt
【报错】有关engine文件

将之前生成的yolov5s.engine文件复制到Yolov5-in-Deepstream-5.0/Deepstream 5.0

仍然报错…

【报错】关于config_infer_primary_yoloV5.txt文件:NVDSINFER_CONFIG_FAILED

未知错误,不知道如何修改,更换部署方法:

【更换部署方法】https://github.com/marcoslucianops/DeepStream-Yolo/blob/master/YOLOv5-5.0.md
Compile nvdsinfer_custom_impl_Yolo
  1. Run command
sudo chmod -R 777 /opt/nvidia/deepstream/deepstream-5.1/sources/
  1. Donwload my external/yolov5-5.0 folder and move files to created yolo folder
  2. Compile lib
  • x86 platform
cd /opt/nvidia/deepstream/deepstream-5.1/sources/yolo
CUDA_VER=11.1 make -C nvdsinfer_custom_impl_Yolo
  • Jetson platform
cd /opt/nvidia/deepstream/deepstream-5.1/sources/yolo
CUDA_VER=10.2 make -C nvdsinfer_custom_impl_Yolo

Testing model

Use my edited deepstream_app_config.txt and config_infer_primary.txt files available in my external/yolov5-5.0 folder

Run command

deepstream-app -c deepstream_app_config.txt

YoloV5部署成功!

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

智慧地球(AI·Earth)社区

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值