From eLinux.org
Jump to: navigation, search

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.


1. How to convert YoloV4 DarkNet model into ONNX
Step1: Download pretrained YOLOv4 model
Model definition can be downloaded from here
Pretrained weights can be downloaded from here
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