duan8/yolov5
2022-09-29 18:48:29 +08:00
..
calibrator.cpp fix coding style 2022-09-29 18:48:29 +08:00
calibrator.h fix coding style 2022-09-29 18:48:29 +08:00
CMakeLists.txt Yolov5 classification model support (#1082) 2022-08-30 18:52:34 +08:00
common.hpp fix coding style 2022-09-29 18:48:29 +08:00
cuda_utils.h fix and optimize 2021-01-29 16:20:48 +08:00
gen_wts.py add gen wts choices 2022-09-06 19:52:31 +08:00
logging.h create macros.h for yolov5 2021-08-05 11:57:48 +00:00
macros.h create macros.h for yolov5 2021-08-05 11:57:48 +00:00
preprocess.cu reformat preprocess code of yolov5 2021-10-19 11:49:37 +00:00
preprocess.h reformat preprocess code of yolov5 2021-10-19 11:49:37 +00:00
README.md yolov5 cls cpp postprocessing 2022-09-07 14:58:12 +08:00
samples optimize yolov5 cmdline args 2021-02-28 14:30:15 +08:00
utils.h fix and optimize 2021-01-29 16:20:48 +08:00
yololayer.cu Fix a potential bug in detection number reset between each inference (#733) 2021-09-22 19:22:28 +08:00
yololayer.h create macros.h for yolov5 2021-08-05 11:57:48 +00:00
yolov5_cls_trt.py yolov5 cls cpp postprocessing 2022-09-07 14:58:12 +08:00
yolov5_cls.cpp yolov5 cls cpp postprocessing 2022-09-07 14:58:12 +08:00
yolov5_trt_cuda_python.py Replace pycuda api with cuda-python (#1002) 2022-05-26 09:37:06 +08:00
yolov5_trt.py Fix wrong use of copyMakeBorder (#883) 2022-01-28 11:34:59 +08:00
yolov5.cpp fix code style 2022-09-23 15:43:36 +08:00

yolov5

The Pytorch implementation is ultralytics/yolov5.

Different versions of yolov5

Currently, we support yolov5 v1.0, v2.0, v3.0, v3.1, v4.0, v5.0, v6.0, v6.2.

  • For yolov5 v6.2, download .pt from yolov5 release v6.2, git clone -b v6.2 https://github.com/ultralytics/yolov5.git and git clone -b yolov5-v6.2 https://github.com/wang-xinyu/tensorrtx.git, then follow how-to-run in current page.
  • For yolov5 v6.0, download .pt from yolov5 release v6.0, git clone -b v6.0 https://github.com/ultralytics/yolov5.git and git clone -b yolov5-v6.0 https://github.com/wang-xinyu/tensorrtx.git, then follow how-to-run in tensorrtx/yolov5-v6.0.
  • For yolov5 v5.0, download .pt from yolov5 release v5.0, git clone -b v5.0 https://github.com/ultralytics/yolov5.git and git clone -b yolov5-v5.0 https://github.com/wang-xinyu/tensorrtx.git, then follow how-to-run in tensorrtx/yolov5-v5.0.
  • For yolov5 v4.0, download .pt from yolov5 release v4.0, 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.
  • For yolov5 v3.1, download .pt from yolov5 release v3.1, 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.
  • For yolov5 v3.0, download .pt from yolov5 release v3.0, 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.
  • For yolov5 v2.0, download .pt from yolov5 release v2.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.
  • For yolov5 v1.0, download .pt from yolov5 release v1.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.

Config

  • Choose the model n/s/m/l/x/n6/s6/m6/l6/x6 from command line arguments.
  • Input shape defined in yololayer.h
  • Number of classes defined in yololayer.h, DO NOT FORGET TO ADAPT THIS, If using your own model
  • INT8/FP16/FP32 can be selected by the macro in yolov5.cpp, INT8 need more steps, pls follow How to Run first and then go the INT8 Quantization below
  • GPU id can be selected by the macro in yolov5.cpp
  • NMS thresh in yolov5.cpp
  • BBox confidence thresh in yolov5.cpp
  • Batch size in yolov5.cpp

How to Run, yolov5s as example

  1. generate .wts from pytorch with .pt, or download .wts from model zoo
// clone code according to above #Different versions of yolov5
// download https://github.com/ultralytics/yolov5/releases/download/v6.0/yolov5s.pt
cp {tensorrtx}/yolov5/gen_wts.py {ultralytics}/yolov5
cd {ultralytics}/yolov5
python gen_wts.py -w yolov5s.pt -o yolov5s.wts
// a file 'yolov5s.wts' will be generated.
  1. build tensorrtx/yolov5 and run
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] [n/s/m/l/x/n6/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
  1. check the images generated, as follows. _zidane.jpg and _bus.jpg

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

// install python-tensorrt, pycuda, etc.
// ensure the yolov5s.engine and libmyplugins.so have been built
python yolov5_trt.py

// Another version of python script, which is using CUDA Python instead of pycuda.
python yolov5_trt_cuda_python.py
  1. optional, run yolov5 classification models with similar steps

INT8 Quantization

  1. Prepare calibration images, you can randomly select 1000s images from your train set. For coco, you can also download my calibration images coco_calib from GoogleDrive or BaiduPan pwd: a9wh

  2. unzip it in yolov5/build

  3. set the macro USE_INT8 in yolov5.cpp and make

  4. serialize the model and test

More Information

See the readme in home page.