yolov5-lite/README.md
Detection training code link
TensorRT: 8.6.1.6 CUDA: 12.6 CUDNN: 8.9.0 OpenCV:4.10.0
Before starting, you need to modify parameters in include/yololayer.h to match your training configuration (example at include/yololayer.h):
static constexpr int MAX_OUTPUT_BBOX_COUNT = 1000;
static constexpr int CLASS_NUM = 80; // number of classes
static constexpr int INPUT_H = 640; // input height for yolov5-lite (must be divisible by 32)
static constexpr int INPUT_W = 640; // input width for yolov5-lite (must be divisible by 32)
static constexpr int DEVICE = 0;
static constexpr float NMS_THRESH = 0.4;
static constexpr float CONF_THRESH = 0.45;
static constexpr int BATCH_SIZE = 1;
const char* INPUT_BLOB_NAME = "data";
const char* OUTPUT_BLOB_NAME = "prob";
This step must be performed inside the yolov5-lite folder:
cd yolov5-lite
git clone https://gitcode.com/open-source-toolkit/ac70a.git
unzip your zip file
python gen_wts.py -w v5lite-s.pt -o v5lite-s.wts
python gen_wts.py -w v5lite-e.pt -o v5lite-e.wts
python gen_wts.py -w v5lite-g.pt -o v5lite-g.wts
a. First, set CLASS_NUM in include/yololayer.h to match your dataset class count — this is important, otherwise you will get errors.
b. Run the following commands:
mkdir build
cd build
cmake ..
make
./v5lite -s ../v5lite-s.wts v5lite-s.engine s
./v5lite -s ../v5lite-g.wts v5lite-g.engine g
./v5lite -s ../v5lite-e.wts v5lite-e.engine e
./v5lite -s ../v5lite-c.wts v5lite-c.engine c
(samples is the folder containing your images):
./v5lite -d v5lite-s.engine ../samples
You can also use yolov5-lite-trt.py (in the repository root) for inference.
Collect calibration images (recommended ~1000 images)
Put the images in a calibration folder (for example: tensorrtx-int8calib-data/coco_calib)
Modify the macro in v5lite.cpp:
Change:
// #define USE_FP16 // set USE_INT8 or USE_FP16 or USE_FP32
// #define USE_INT8 // set USE_INT8 or USE_FP16 or USE_FP32
To:
// #define USE_FP16 // set USE_INT8 or USE_FP16 or USE_FP32
#define USE_INT8 // set USE_INT8 or USE_FP16 or USE_FP32
Update the data path in the code to point to your calibration images
Rebuild and generate the engine, then run inference (repeat step 2)