Deepstream 自定义检测Yolo v5模型吞吐量测试

主要参考:

​https://zhuanlan.zhihu.com/p/365191541​

在步骤六已经在tensorrtx/yolov5/build目录下编译生成best.engine文件,接下来将原始文件car/JPEGImages/复制到对应文件夹内,这里我放置在dataset/文件夹下。

在build文件夹内测试代码:

./yolov5 -d yolov5s.engine ../../dataset/car/JPEGImages/

输出结果直接保存在build文件夹内。

使用python代码测试

4. optional, load and run the tensorrt model in python

// install python-tensorrt, pycuda, etc.
// ensure the yolov5s.engine and libmyplugins.so have been built
//运行yolov5_trt.py对照片进行检测
python yolov5_trt.py

测试前需要安装pycuda包:

pip3 install pycuda

报错error: cuda.h: No such file or directory aarch64-linux-gnu-gcc failed


pip3 install pycuda

仍然出错error: cuda.h: No such file or directory

参考:https://cloud-atlas.readthedocs.io/zh_CN/latest/machine_learning/jetson/develop/jetson_pycuda.html

尝试:

在 /etc/profile 中添加:
export CUDA_HOME=/usr/local/cuda
export CPATH=${CUDA_HOME}/include:${CPATH}
export LIBRARY_PATH=${CUDA_HOME}/lib64:$LIBRARY_PATH

仍然失败error: cuda.h: No such file or directory

参考:https://forums.developer.nvidia.com/t/pycuda-installation-failure-on-jetson-nano/77152

尝试:

在 /etc/profile 中添加:
export CPATH=$CPATH:/usr/local/cuda-10.2/targets/aarch64-linux/include
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda-10.2/targets/aarch64-linux/lib

仍然失败error: cuda.h: No such file or directory


尝试:

sudo su
export PATH=/usr/local/cuda-10.2/bin:/usr/local/cuda/bin:$PATH    // 即 cuda 的路径这里在root 模式下再包含一遍即可
pip3 install pycuda

安装成功,退出root模式,python yolov5_trt.py运行成功。

尝试视频检测:

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

修改labels.txt为一个类 car

将测试用的car.mp4放在samples streams下面,然后修改deepstream_app_config.txt中的视频位置。

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

吞吐量测试结果:

测试数据:20190729-113131 south port 12.6km.mp4

batchsize

FPS(Avg)

1

20

2

19.5

4

21

8

17

参考操作步骤:

1.修改tensorrtx/yolov5/yolov5.cpp中的BATCH_SIZE

2.Build tensorrtx/yolov5

cd tensorrtx/yolov5
mkdir build(删除build里的内容)
cd build
cmake ..
make

3.Move generated yolov5s.wts file to tensorrtx/yolov5 folder (example for YOLOv5s)

cp yolov5/yolov5s.wts tensorrtx/yolov5/build/yolov5s.wts

4.Convert to TensorRT model (yolov5s.engine file will be generated in tensorrtx/yolov5/build folder)

sudo ./yolov5 -s best.wts best_BS2.engine m

5.删除nvdsinfer_custom_impl_Yolo中之前生成的三个文件,复制best_BS2.engine到/opt/nvidia/deepstream/deepstream-5.1/sources/yolov5文件夹

修改config_infer_primary.txt文件

  • model-engine-file=best_BS2.engine
  • num-detected-classes=1

修改deepstream_app_config.txt文件

  • batch-size=2
cd /opt/nvidia/deepstream/deepstream-5.1/sources/yolov5
export CUDA_VER=10.2
make -C nvdsinfer_custom_impl_Yolo

修改labels.txt为一个类 car

将测试用的car.mp4放在samples streams下面,然后修改deepstream_app_config.txt中的视频位置。

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