A C++ implementation of Yolov5 to detect peaple smoking running in Jetson Xavier nx and Jetson nano.In Jetson Xavier Nx, it can achieve 33 FPS.
You can see video play in BILIBILI, or YOUTUBE.
If you want to try to train your own model, you can see yolov5-smoke-detection-python. Follow the readme to get your own model.
if you have problem in this project, you can see this CSDN artical.
Whole process time from read image to finish process (include every img preprocess and postprocess). And all results can get in Jetson Xavier nx. For python model and code, you can find them in this yolov5-smoke-detection-python
Backbone | before TensorRT | TensortRT(detection) | FPS(detection) |
---|---|---|---|
Yolov5s-640-float16 | 100ms | 60-70ms | 14 ~ 18 |
Yolov5m-640-float16 | 120ms | 70-75ms | 13 ~ 14 |
Yolov5s-640-int8 | 30-40ms | 25 ~ 33 | |
Yolov5m-640-int8 | 50-60ms | 16 ~ 20 |
git clone https://github.com/RichardoMrMu/yolov5-smoking-detect
cd yolov5-smoking-detect
mkdir build
cmake ..
make
if you meet some errors in cmake and make, please see this artical or see Attention.
You need two model, one is yolov5 model, for detection, generating from tensorrtx.
For yolov5 detection model, I choose yolov5s, and choose yolov5s.pt->yolov5s.wts->yolov5s.engine
Note that, used models can get from yolov5 and use this yolov5-smoke-detection-python to get your model.
You can also see tensorrtx official readme
Note that, here uses the official pertained model.And I use yolov5-5, v5.0. So if you train your own model, please be sure your yolov5 code is v5.0.
git clone -b v5.0 https://github.com/ultralytics/yolov5.git
cd yolov5
mkdir weights
cd weights
// download https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt
wget https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt
git clone https://github.com/wang-xinyu/tensorrtx
cp tensorrtx/gen_wts.py yolov5/
cd yolov5
python3 gen_wts.py -w ./weights/yolov5s.pt -o ./weights/yolov5s.wts
// a file 'yolov5s.wts' will be generated.
You can get yolov5s.wts model in yolov5/weights/
cd tensorrtx/yolov5
// update CLASS_NUM to 2 in yololayer.h
// nc: 1 # number of classes
// names: ['smoke'] # class names
mkdir build
cd build
cp {ultralytics}/yolov5/yolov5s.wts {tensorrtx}/yolov5/build
cmake ..
make
// yolov5s
sudo ./yolov5 -s yolov5s.wts yolov5s.engine s
// test your engine file
sudo ./yolov5 -d yolov5s.engine ../samples
Then you get the yolov5s.engine, and you can put yolov5s.engine
in My project. For example
cd {yolov5-smoking-detect}
mkdir resources
cp {tensorrtx}/yolov5/build/yolov5s.engine {yolov5-smoking-detect}/resources
You may face some problems in getting yolov5s.engine, you can upload your issue in github or csdn artical.
Currently, tensorrt support yolov5 v1.0(yolov5s only), v2.0, v3.0, v3.1, v4.0 and v5.0.
git clone -b v5.0 https://github.com/ultralytics/yolov5.git
and git clone https://github.com/wang-xinyu/tensorrtx.git
, then follow how-to-run in current page.git clone -b v4.0 https://github.com/ultralytics/yolov5.git
and git clone -b yolov5-v4.0 https://github.com/wang-xinyu/tensorrtx.git
, then follow how-to-run in tensorrtx/yolov5-v4.0.git clone -b v3.1 https://github.com/ultralytics/yolov5.git
and git clone -b yolov5-v3.1 https://github.com/wang-xinyu/tensorrtx.git
, then follow how-to-run in tensorrtx/yolov5-v3.1.git clone -b v3.0 https://github.com/ultralytics/yolov5.git
and git clone -b yolov5-v3.0 https://github.com/wang-xinyu/tensorrtx.git
, then follow how-to-run in tensorrtx/yolov5-v3.0.git clone -b v2.0 https://github.com/ultralytics/yolov5.git
and git clone -b yolov5-v2.0 https://github.com/wang-xinyu/tensorrtx.git
, then follow how-to-run in tensorrtx/yolov5-v2.0.git clone -b v1.0 https://github.com/ultralytics/yolov5.git
and git clone -b yolov5-v1.0 https://github.com/wang-xinyu/tensorrtx.git
, then follow how-to-run in tensorrtx/yolov5-v1.0.How to Run
first and then go the INT8 Quantization
belowYou may need train your own model and transfer your trained-model to tensorRT. So you can follow the following steps.
Generate yolov5 model
to get yolov5 and tensorrt rep, next step is to transfer your pytorch model to tensorrt.
Before this, you need to change yololayer.h file 20,21 and 22 line(CLASS_NUM,INPUT_H,INPUT_W) to your own parameters.// before
static constexpr int CLASS_NUM = 80; // 20
static constexpr int INPUT_H = 640; // 21 yolov5's input height and width must be divisible by 32.
static constexpr int INPUT_W = 640; // 22
// after
// if your model is 2 classfication and image size is 416*416
static constexpr int CLASS_NUM = 2; // 20
static constexpr int INPUT_H = 416; // 21 yolov5's input height and width must be divisible by 32.
static constexpr int INPUT_W = 416; // 22
cd {tensorrtx}/yolov5/
// update CLASS_NUM in yololayer.h if your model is trained on custom dataset
mkdir build
cd build
cp {ultralytics}/yolov5/yolov5s.wts {tensorrtx}/yolov5/build
cmake ..
make
sudo ./yolov5 -s [.wts] [.engine] [s/m/l/x/s6/m6/l6/x6 or c/c6 gd gw] // serialize model to plan file
sudo ./yolov5 -d [.engine] [image folder] // deserialize and run inference, the images in [image folder] will be processed.
// For example yolov5s
sudo ./yolov5 -s yolov5s.wts yolov5s.engine s
sudo ./yolov5 -d yolov5s.engine ../samples
// For example Custom model with depth_multiple=0.17, width_multiple=0.25 in yolov5.yaml
sudo ./yolov5 -s yolov5_custom.wts yolov5.engine c 0.17 0.25
sudo ./yolov5 -d yolov5.engine ../samples
In this way, you can get your own tensorrt yolov5 model. Enjoy it!
It has some diffirence between float16 tensorrt engine file and int8. Just like tensorrtx readme, Int8 engine file needs calibration images.
For official yolov5 model , you need to downlowd coco_calid.zip
from this google drive url or BAIDUYUN --- a9wh
. And unzip to {project}/build/
.
Then change yolov5.cpp
's 10 line from USE_FLOAT16
to USE_INT8
.And run this :
cmake ..
make
// yolov5s
sudo ./yolov5 -s yolov5s.wts yolov5s-int8.engine s
// testyour engine file
sudo ./yolov5 -d yolov5s-int8.engine ../samples
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型