TensorRT/YoloV4
< TensorRT
This page will provide some FAQs about using the TensorRT to do inference for the YoloV4 model, which can be helpful if you encounter similar problems.
FAQ
1. How to convert YoloV4 DarkNet model into ONNX
- Step1: Download pretrained YOLOv4 model
- Model definition can be downloaded from here
- https://raw.githubusercontent.com/AlexeyAB/darknet/master/cfg/yolov4.cfg
- Pretrained weights can be downloaded from here
- https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights
- Step2: Open file yolov4.cfg and set values of hight and width at header part of the cfg file
- The following are input hight and width options and corresponding output sizes
Input size Output 1 Output 2 Output 3 Size Option 1 3x608x608 255x76x76 255x38x38 255x19x19 Size Option 2 3x512x512 255x64x64 255x32x32 255x16x16 Size Option 3 3x416x416 255x52x52 255x26x26 255x13x13 Size Option 4 3x320x320 255x40x40 255x20x20 255x10x10
- Step3: Clone from https://github.com/Tianxiaomo/pytorch-YOLOv4.git that can help you convert YOLOv4 from DarkNet to ONNX
git clone https://github.com/Tianxiaomo/pytorch-YOLOv4.git
- Step4: Follow README.md of this repository to convert DarkNet into ONNX
- Step5: Transform ONNX model into TensorRT model
- Generate TensorRT engine in fp16 mode:
./trtexec --onnx=<onnx_file> --workspace=4096 --saveEngine=<engine_file> --fp16 --explicitBatch
- Generate TensorRT engine in int8 mode:
./trtexec --onnx=<onnx_file> --workspace=4096 --saveEngine=<engine_file> --int8 --explicitBatch