marcoslucianops / DeepStream-Yolo

NVIDIA DeepStream SDK 7.0 / 6.4 / 6.3 / 6.2 / 6.1.1 / 6.1 / 6.0.1 / 6.0 / 5.1 implementation for YOLO models
MIT License
1.45k stars 357 forks source link

yolov8n has no detection with int8 calibration. #389

Closed shao77622 closed 1 year ago

shao77622 commented 1 year ago

Following this repo https://github.com/marcoslucianops/DeepStream-Yolo/blob/master/docs/INT8Calibration.md deepstream app was successfully generated model_b4_gpu0_int8.engine and ran, but there is no detection. here is the config file. thank you

[property] gpu-id=0 net-scale-factor=0.0039215697906911373 model-color-format=0

onnx-file=/opt/nvidia/deepstream/deepstream-6.2/sources/aiBox/deepstream/models/yolov8n.onnx

model-engine-file=/opt/nvidia/deepstream/deepstream-6.2/sources/aiBox/model_b4_gpu0_int8.engine int8-calib-file=calib.table labelfile-path=/opt/nvidia/deepstream/deepstream-6.2/sources/aiBox/deepstream/models/labels.txt batch-size=1 network-mode=1 num-detected-classes=80 interval=0 gie-unique-id=1 process-mode=1 network-type=0 cluster-mode=2 maintain-aspect-ratio=1 symmetric-padding=1

force-implicit-batch-dim=1

workspace-size=1000

parse-bbox-func-name=NvDsInferParseYolo

parse-bbox-func-name=NvDsInferParseYoloCuda

custom-lib-path=/opt/nvidia/deepstream/deepstream-6.2/sources/aiBox/deepstream/lib/libnvdsinfer_custom_impl_Yolo.so engine-create-func-name=NvDsInferYoloCudaEngineGet

[class-attrs-all] nms-iou-threshold=0.45 pre-cluster-threshold=0.05 topk=300

shao77622 commented 1 year ago

I found out that this problem was caused by the env "export INT8_CALIB_BATCH_SIZE=1" , so if the batch size of deepstream app is dynamic, then every time the batch size changes, the calib.table must be deleted, and the calibration process with 1000 images always need to rerun ?

shao77622 commented 1 year ago

Another problem is every time I rerun the deepstream app without anything changes, the Tensorrt Engine will do rebuilding process, and errors below, how to set the "maxBatchSize" ?

0:00:05.883173517 16014 0x7f398c0beb20 WARN nvinfer gstnvinfer.cpp:677:gst_nvinfer_logger: NvDsInferContext[UID 1]: Warning from NvDsInferContextImpl::checkBackendParams() [UID = 1]: Backend has maxBatchSize 1 whereas 2 has been requested

marcoslucianops commented 1 year ago

So if the batch size of deepstream app is dynamic, then every time the batch size changes, the calib.table must be deleted, and the calibration process with 1000 images always need to rerun ?

I need to do some tests to check it.

Another problem is every time I rerun the deepstream app without anything changes, the Tensorrt Engine will do rebuilding process, and errors below, how to set the "maxBatchSize" ?

If you generated the ONNX model with --dynamic you can use any batch-size value to build the engine file. If you don't set --dynamic, you need to set the --batch according to the batch-size you want to generate the engine.

shao77622 commented 1 year ago

Solved it by setting large batch size for .engine build, make sure batch size inference <= maxBatchSize. And the calibration.txt only need to generate onces for different batch size .