Inaccurate SGIE classification

Please provide complete information as applicable to your setup.

**• Hardware Platform (Jetson / GPU) Jetson Orin Nano
**• DeepStream Version: Deepstream 6.3
**• TensorRT Version: 8.5.2.1

Good day, I have been struggling with deploying my custom classification model (yolov8-cls) on Deepsteam.
When I run the pipeline, the SGIE was built successfully, and the program is able to run. I can see that the SGIE has in influence, because I can see that there is a label that is added to the text of the bounding boxes. Please see the image below that demonstrates this:


I also added a few print statements in the shared library that displays the attribute that has the highest confidence (Attributes are either Male of Female) and its confidence. I saw that every single classification has a confidence of 1 and every classification is a male…I am not sure what the issue is because I used a different script to test the onnx model and it works perfectly. Below is a description of all relevant information (how the model has been trained, the configuration file for the SGIE, the C++ script that creates the shared library and also the onnx model itself.)

Here is how I have trained and exported the onnx model:

train_onnx.zip (861 Bytes)

I’ve created the configuration files for the SGIE. The configuration files can be found below:

sgie_config_YOLO_GENDER_CLASSIFICATION.txt (791 Bytes)

Here is the C++ file that was used to create the shared library:
nvdsinfer_customparser.zip (31.7 KB)
[please note: I adjusted the Makefile so that the “SRCFILES” only contains the “nvdsinfer_customclassifierparser.cpp” file. I also adjusted the labels in the “nvdsinfer_customclassifierparser.cpp” file so that the labels are “male” and “female”. I also added two print statements that prints the confidence score of both the classes.]

And finally, here is the onnx file that I trained:
genderClassification.zip (

I suggest testing the sgie model directly. please refer to this FAQ. please use the same input picture when compare script and DeepStream.

Hello, sorry for taking so long to reply. When I tried this I got this error:

aizatron@aizatron-desktop:~$ gst-launch-1.0 filesrc location=blueCar.jpg ! jpegdec ! videoconvert ! video/x-raw,format=I420 ! nvvideoconvert ! video/x-raw(memory:NVMM),format=NV12 ! mux.sink_0 nvstreammux name=mux batch-size=1 width=1280 height=720 ! nvinfer config-file-path=./dstest_appsrc_config.txt ! nvvideoconvert ! video/x-raw(memory:NVMM),format=RGBA ! nvdsosd ! nvvideoconvert ! video/x-raw,format=I420 ! jpegenc ! filesink location=out.jpg
Unknown or legacy key specified ‘is-classifier’ for group [property]
Setting pipeline to PAUSED …
0:00:11.063903349 4712 0xaaaae005d670 INFO nvinfer gstnvinfer.cpp:682:gst_nvinfer_logger: NvDsInferContext[UID 1]: Info from NvDsInferContextImpl::deserializeEngineAndBackend() <nvdsinfer_context_impl.cpp:1988> [UID = 1]: deserialized trt engine from :/home/aizatron/repos/RnD-video-tracking/models/Onnx/genderClassification.onnx_b16_gpu0_fp32.engine
INFO: [FullDims Engine Info]: layers num: 2
0 INPUT kFLOAT images 3x320x320 min: 1x3x320x320 opt: 16x3x320x320 Max: 16x3x320x320
1 OUTPUT kFLOAT output0 2 min: 0 opt: 0 Max: 0

ERROR: [TRT]: 3: Cannot find binding of given name: predictions/Softmax
0:00:11.265900727 4712 0xaaaae005d670 WARN nvinfer gstnvinfer.cpp:679:gst_nvinfer_logger: NvDsInferContext[UID 1]: Warning from NvDsInferContextImpl::checkBackendParams() <nvdsinfer_context_impl.cpp:1955> [UID = 1]: Could not find output layer ‘predictions/Softmax’ in engine
0:00:11.265956408 4712 0xaaaae005d670 INFO nvinfer gstnvinfer.cpp:682:gst_nvinfer_logger: NvDsInferContext[UID 1]: Info from NvDsInferContextImpl::generateBackendContext() <nvdsinfer_context_impl.cpp:2091> [UID = 1]: Use deserialized engine model: /home/aizatron/repos/RnD-video-tracking/models/Onnx/genderClassification.onnx_b16_gpu0_fp32.engine
0:00:11.421424000 4712 0xaaaae005d670 ERROR nvinfer gstnvinfer.cpp:676:gst_nvinfer_logger: NvDsInferContext[UID 1]: Error in NvDsInferContextImpl::readMeanImageFile() <nvdsinfer_context_impl.cpp:189> [UID = 1]: Mismatch between ppm mean image resolution(224 x 224) and network resolution(320 x 320)
0:00:11.421471553 4712 0xaaaae005d670 ERROR nvinfer gstnvinfer.cpp:676:gst_nvinfer_logger: NvDsInferContext[UID 1]: Error in NvDsInferContextImpl::allocateResource() <nvdsinfer_context_impl.cpp:253> [UID = 1]: Failed to read mean image file
0:00:11.421490721 4712 0xaaaae005d670 ERROR nvinfer gstnvinfer.cpp:676:gst_nvinfer_logger: NvDsInferContext[UID 1]: Error in NvDsInferContextImpl::preparePreprocess() <nvdsinfer_context_impl.cpp:1032> [UID = 1]: preprocessor allocate resource failed
ERROR: Infer Context prepare preprocessing resource failed., nvinfer error:NVDSINFER_CONFIG_FAILED
0:00:11.430064057 4712 0xaaaae005d670 WARN nvinfer gstnvinfer.cpp:898:gst_nvinfer_start: error: Failed to create NvDsInferContext instance
0:00:11.430648388 4712 0xaaaae005d670 WARN nvinfer gstnvinfer.cpp:898:gst_nvinfer_start: error: Config file path: ./dstest_appsrc_config.txt, NvDsInfer Error: NVDSINFER_CONFIG_FAILED
ERROR: Pipeline doesn’t want to pause.
ERROR: from element /GstPipeline:pipeline0/GstNvInfer:nvinfer0: Failed to create NvDsInferContext instance
Additional debug info:
/dvs/git/dirty/git-master_linux/deepstream/sdk/src/gst-plugins/gst-nvinfer/gstnvinfer.cpp(898): gst_nvinfer_start (): /GstPipeline:pipeline0/GstNvInfer:nvinfer0:
Config file path: ./dstest_appsrc_config.txt, NvDsInfer Error: NVDSINFER_CONFIG_FAILED
Setting pipeline to NULL …
Freeing pipeline …

The only changes that I have made to the config file (dstest_appsrc_config.txt) is to change the path to the model_engine_file (model-engine-file=/home/aizatron/repos/RnD-video-tracking/models/Onnx/genderClassification.onnx_b16_gpu0_fp32.engine) and I changed the number of detected classes to 2 (num-detected-classes=2)

please update the content of sgie_config_YOLO_GENDER_CLASSIFICATION.txt to dstest_appsrc_config.txt mentioned in the FAQ .