nvinfer is not populating 'confidence' field in NvDsObjectMeta (DS 4.0)

If anyone on this thread is trying to get detection probability values from PGIE plugin, please refer to the patch below -

diff --git a/sources/apps/sample_apps/deepstream-test1/deepstream_test1_app.c b/sources/apps/sample_apps/deepstream-test1/deepstream_test1_app.c
index 13d0b72..f6ba273 100644
--- a/sources/apps/sample_apps/deepstream-test1/deepstream_test1_app.c
+++ b/sources/apps/sample_apps/deepstream-test1/deepstream_test1_app.c
@@ -70,6 +70,7 @@ osd_sink_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info,
         for (l_obj = frame_meta->obj_meta_list; l_obj != NULL;
                 l_obj = l_obj->next) {
             obj_meta = (NvDsObjectMeta *) (l_obj->data);
+            printf("Object class : %d Object probability %f |", obj_meta->class_id, obj_meta->confidence);
             if (obj_meta->class_id == PGIE_CLASS_ID_VEHICLE) {
                 vehicle_count++;
                 num_rects++;
@@ -79,6 +80,7 @@ osd_sink_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info,
                 num_rects++;
             }
         }
+        printf("\n");
         display_meta = nvds_acquire_display_meta_from_pool(batch_meta);
         NvOSD_TextParams *txt_params  = &display_meta->text_params[0];
         display_meta->num_labels = 1;
diff --git a/sources/apps/sample_apps/deepstream-test1/dstest1_pgie_config.txt b/sources/apps/sample_apps/deepstream-test1/dstest1_pgie_config.txt
index 708b8f1..a27c45b 100644
--- a/sources/apps/sample_apps/deepstream-test1/dstest1_pgie_config.txt
+++ b/sources/apps/sample_apps/deepstream-test1/dstest1_pgie_config.txt
@@ -70,8 +70,10 @@ num-detected-classes=4
 interval=0
 gie-unique-id=1
 output-blob-names=conv2d_bbox;conv2d_cov/Sigmoid
+enable-dbscan=1
 
 [class-attrs-all]
 threshold=0.2
-eps=0.2
-group-threshold=1
+eps=0.7
+minBoxes=3
+#group-threshold=1
diff --git a/sources/gst-plugins/gst-nvinfer/gstnvinfer_meta_utils.cpp b/sources/gst-plugins/gst-nvinfer/gstnvinfer_meta_utils.cpp
index d50c799..f455bb3 100644
--- a/sources/gst-plugins/gst-nvinfer/gstnvinfer_meta_utils.cpp
+++ b/sources/gst-plugins/gst-nvinfer/gstnvinfer_meta_utils.cpp
@@ -80,7 +80,7 @@ attach_metadata_detector (GstNvInfer * nvinfer, GstMiniObject * tensor_out_objec
     obj_meta = nvds_acquire_obj_meta_from_pool (batch_meta);
 
     obj_meta->unique_component_id = nvinfer->unique_id;
-    obj_meta->confidence = 0.0;
+    obj_meta->confidence = obj.detectionConfidence;
 
     /* This is an untracked object. Set tracking_id to -1. */
     obj_meta->object_id = UNTRACKED_OBJECT_ID;
diff --git a/sources/includes/nvdsinfer_context.h b/sources/includes/nvdsinfer_context.h
index d4cd776..57907dd 100644
--- a/sources/includes/nvdsinfer_context.h
+++ b/sources/includes/nvdsinfer_context.h
@@ -369,6 +369,8 @@ typedef struct
     int classIndex;
     /* String label for the detected object. */
     char *label;
+    /* detection confidence of the object */
+    float detectionConfidence;
 } NvDsInferObject;
 
 /**
diff --git a/sources/libs/nvdsinfer/nvdsinfer_context_impl_output_parsing.cpp b/sources/libs/nvdsinfer/nvdsinfer_context_impl_output_parsing.cpp
index d50bddc..f5f9a55 100644
--- a/sources/libs/nvdsinfer/nvdsinfer_context_impl_output_parsing.cpp
+++ b/sources/libs/nvdsinfer/nvdsinfer_context_impl_output_parsing.cpp
@@ -282,6 +282,7 @@ NvDsInferContextImpl::clusterAndFillDetectionOutputDBSCAN(NvDsInferDetectionOutp
             object.label = nullptr;
             if (c < m_Labels.size() && m_Labels[c].size() > 0)
                 object.label = strdup(m_Labels[c][0].c_str());
+            object.detectionConfidence = m_PerClassObjectList[c][i].detectionConfidence;
             output.numObjects++;
         }
     }

Once you have applied the patch above, follow these steps -

$ cd sources/libs/nvdsinfer/
$ sudo CUDA_VER=<add version here> make install
$ cd ../../gst-plugins/gst-nvinfer/
$ sudo CUDA_VER=<add version here> make install

Now the nvinfer plugin libraries have been updated to attach probability metadata, but keep in mind it’s currently available only for DBSCAN clustering algorithm. So this needs to be enabled in the PGIE config and the parameters need to be tuned for your test videos (Please refer to the patch above to see how to enable DBSCAN) The patch also modifies test1 app to show how to do this for the sample stream. To try it out follow these steps -

$ cd sources/apps/sample_apps/deepstream-test1/
$ CUDA_VER=<add version here> make
$ ./deepstream-test1-app ../../../../samples/streams/sample_720p.h264

You should now be able to see all the object probabilities along with the object count being printed on the console.

2 Likes