Try to get the result of SGIE result, failed

• Hardware Platform (GPU)
**• DeepStream Version 6.1
**• TensorRT Version 8.2E
**• NVIDIA GPU Driver Version 515
Dear professor:

I try to get the result of secondary engine. But I failde.
My configure file as below:
[application]
enable-perf-measurement=1
perf-measurement-interval-sec=5

[tiled-display]
enable=1
rows=1
columns=1
width=1920
height=1080
gpu-id=0
nvbuf-memory-type=0

[source0]
enable=1
type=3
uri=file:/opt/nvidia/deepstream/deepstream-6.1/sources/CoalSummary/stream/sample_1080p_h264.mp4
num-sources=1
gpu-id=0
cudadec-memtype=0

[source1]
enable=0
type=4
uri=rtsp://admin:AA123456@192.168.1.3
num-sources=1
gpu-id=0
cudadec-memtype=0

[ds-example]
enable=1
processing-width=1024
processing-height=768
full-frame=0
batch-size=1
unique-id=15
gpu-id=0
blur-objects=1
nvbuf-memory-type=3

[sink0]
enable=1
type=4
codec=1
enc-type=0
sync=0
#iframeinterval=10
bitrate=400000
profile=0
rtsp-port=8559
udp-port=5410

[osd]
enable=1
gpu-id=0
border-width=1
text-size=15
text-color=1;1;1;1;
text-bg-color=0.3;0.3;0.3;1
font=Serif
show-clock=0
clock-x-offset=800
clock-y-offset=820
clock-text-size=12
clock-color=1;0;0;0
nvbuf-memory-type=0

[streammux]
gpu-id=0
live-source=0
buffer-pool-size=4
batch-size=4
batched-push-timeout=40000
width=1920
height=1080
enable-padding=0
nvbuf-memory-type=0

[primary-gie]
enable=1
gpu-id=0
model-engine-file=./Primary_Detector/resnet10.caffemodel_b4_gpu0_int8.engine
batch-size=4
bbox-border-color0=1;0;0;1
bbox-border-color1=0;1;1;1
bbox-border-color2=0;0;1;1
bbox-border-color3=0;1;0;1
interval=0
gie-unique-id=1
nvbuf-memory-type=0
config-file=config_infer_primary.txt

[secondary-gie0]
enable=1
model-engine-file=./Secondary_CarColor/resnet18.caffemodel_b16_gpu0_int8.engine
batch-size=16
gpu-id=0
gie-unique-id=5
operate-on-gie-id=1
operate-on-class-ids=0;
config-file=config_infer_secondary_carcolor.txt

[tracker]
enable=1
tracker-width=640
tracker-height=384
ll-lib-file=/opt/nvidia/deepstream/deepstream/lib/libnvds_nvmultiobjecttracker.so
ll-config-file=config_tracker_NvDCF_perf.yml
gpu-id=0
enable-batch-process=1
enable-past-frame=1
display-tracking-id=1

[tests]
file-loop=1

I accorde to “deesptream_infer_tensor_meta_test.cpp → sgie_pad_buffer_probe”, And add the code to dsexample-> gst_dsexample_tranform_ip as below:

static GstFlowReturn
gst_dsexample_transform_ip (GstBaseTransform * btrans, GstBuffer * inbuf)
{
GstDsExample *dsexample = GST_DSEXAMPLE (btrans);
GstMapInfo in_map_info;
GstFlowReturn flow_ret = GST_FLOW_ERROR;
gdouble scale_ratio = 1.0;
DsExampleOutput *output;
NvBufSurface *surface = NULL;
NvDsBatchMeta *batch_meta = NULL;
NvDsFrameMeta *frame_meta = NULL;
NvDsMetaList * l_frame = NULL;
guint i = 0;
CHECK_CUDA_STATUS (cudaSetDevice (dsexample->gpu_id), “Unable to set cuda device”);

memset (&in_map_info, 0, sizeof (in_map_info));
if (!gst_buffer_map (inbuf, &in_map_info, GST_MAP_READ)) {
g_print (“Error: Failed to map gst buffer\n”);
goto error;
}

nvds_set_input_system_timestamp (inbuf, GST_ELEMENT_NAME (dsexample));
surface = (NvBufSurface *) in_map_info.data;
GST_DEBUG_OBJECT (dsexample,
“Processing Frame %” G_GUINT64_FORMAT " Surface %p\n",
dsexample->frame_num, surface);

if (CHECK_NVDS_MEMORY_AND_GPUID (dsexample, surface))
goto error;

batch_meta = gst_buffer_get_nvds_batch_meta (inbuf);
if (batch_meta == nullptr) {
GST_ELEMENT_ERROR (dsexample, STREAM, FAILED,
(“NvDsBatchMeta not found for input buffer.”), (NULL));
return GST_FLOW_ERROR;
}

if (1)
{
/* Using object crops as input to the algorithm. The objects are detected by
* the primary detector */
NvDsMetaList * l_obj = NULL;
NvDsObjectMeta *obj_meta = NULL;

for (l_frame = batch_meta->frame_meta_list; l_frame != NULL; l_frame = l_frame->next)
{
  frame_meta = (NvDsFrameMeta *) (l_frame->data);

  for (l_obj = frame_meta->obj_meta_list; l_obj != NULL;  l_obj = l_obj->next)
  {
    obj_meta = (NvDsObjectMeta *) (l_obj->data);
     /* Iterate user metadata in object to search SGIE's tensor data */
     cout<<"obj_meta->obj_user_meta_list="<< obj_meta->obj_user_meta_list <<endl;
    for (NvDsMetaList * l_user = obj_meta->obj_user_meta_list; l_user != NULL;  l_user = l_user->next)
    {
        //======= Here I hope to print=====//
        cout<<"I am here"<<endl;

        NvDsUserMeta *user_meta = (NvDsUserMeta *) l_user->data;

        if (user_meta->base_meta.meta_type != NVDSINFER_TENSOR_OUTPUT_META)
          continue;
    }


    output = DsExampleProcess (dsexample->dsexamplelib_ctx,
        (unsigned char *)dsexample->inter_buf->surfaceList[0].mappedAddr.addr[0]);


    /* Attach labels for the object */
    attach_metadata_object (dsexample, obj_meta, output);
    free (output);
  }

}

}
flow_ret = GST_FLOW_OK;
error:
nvds_set_output_system_timestamp (inbuf, GST_ELEMENT_NAME (dsexample));
gst_buffer_unmap (inbuf, &in_map_info);
return flow_ret;
}

I hope to print the “obj_meta->obj_user_meta_list”, but result is 0.

What is wrong?

My secondary engine confige as below:

[property]
gpu-id=0
net-scale-factor=1
model-file=./Secondary_CarColor/resnet18.caffemodel
proto-file=./Secondary_CarColor/resnet18.prototxt
model-engine-file=./Secondary_CarColor/resnet18.caffemodel_b16_gpu0_int8.engine
int8-calib-file=./Secondary_CarColor/cal_trt.bin
mean-file=./Secondary_CarColor/mean.ppm
labelfile-path=./Secondary_CarColor/labels.txt
force-implicit-batch-dim=1
batch-size=16
model-color-format=1
process-mode=2

0=FP32, 1=INT8, 2=FP16 mode

network-mode=1
is-classifier=1
output-blob-names=predictions/Softmax
classifier-async-mode=0
classifier-threshold=0.51
input-object-min-width=60
input-object-min-height=60
operate-on-gie-id=1
operate-on-class-ids=0
classifier-type=carcolor
#scaling-filter=0
#scaling-compute-hw=0

Please help me. Thank you very much.

I find the pipeline structure because the dsexample is not behind secondary engine. And actually, there is nothing behind sgie.

I modify the deepstream-app.c->create_common_elements . as below, I hope to create the pipelines SGIE->dsexampel.

my code:
static gboolean
create_common_elements (NvDsConfig * config, NvDsPipeline * pipeline,
GstElement ** sink_elem, GstElement ** src_elem,
bbox_generated_callback bbox_generated_post_analytics_cb)
{
gboolean ret = FALSE;
*sink_elem = *src_elem = NULL;

if (config->primary_gie_config.enable)
{
if (config->dsexample_config.enable)
{
if (!create_dsexample_bin (&config->dsexample_config, &pipeline->dsexample_bin))
{ goto done; }
// Add dsexample bin to instance bin
gst_bin_add (GST_BIN (pipeline->pipeline), pipeline->dsexample_bin.bin);
if (!*src_elem)
{ *src_elem = pipeline->dsexample_bin.bin; }
if (*sink_elem)
{ NVGSTDS_LINK_ELEMENT (pipeline->dsexample_bin.bin, *sink_elem); }
*sink_elem = pipeline->dsexample_bin.bin;
}
//-----secondary engine----//
if (config->num_secondary_gie_sub_bins > 0)
{
if (!create_secondary_gie_bin (config->num_secondary_gie_sub_bins,
config->primary_gie_config.unique_id,
config->secondary_gie_sub_bin_config,
&pipeline->common_elements.secondary_gie_bin))
{
goto done;
}
gst_bin_add (GST_BIN (pipeline->pipeline), pipeline->common_elements.secondary_gie_bin.bin);
if (!*src_elem)
{
*src_elem = pipeline->common_elements.secondary_gie_bin.bin;
}
if (*sink_elem)
{
NVGSTDS_LINK_ELEMENT (pipeline->common_elements.secondary_gie_bin.bin, *sink_elem);
}
*sink_elem = pipeline->common_elements.secondary_gie_bin.bin;
}
}

if (config->dsanalytics_config.enable) {
if (!create_dsanalytics_bin (&config->dsanalytics_config,
&pipeline->common_elements.dsanalytics_bin)) {
g_print (“creating dsanalytics bin failed\n”);
goto done;
}
gst_bin_add (GST_BIN (pipeline->pipeline), pipeline->common_elements.dsanalytics_bin.bin);

  if (!*src_elem) {
    *src_elem = pipeline->common_elements.dsanalytics_bin.bin;
  }
  if (*sink_elem) {
    NVGSTDS_LINK_ELEMENT (pipeline->common_elements.dsanalytics_bin.bin,
        *sink_elem);
  }
*sink_elem = pipeline->common_elements.dsanalytics_bin.bin;

}

if (config->tracker_config.enable)
{
if (!create_tracking_bin (&config->tracker_config,
&pipeline->common_elements.tracker_bin)) {
g_print (“creating tracker bin failed\n”);
goto done;
}
gst_bin_add (GST_BIN (pipeline->pipeline),
pipeline->common_elements.tracker_bin.bin);
if (!*src_elem) {
*src_elem = pipeline->common_elements.tracker_bin.bin;
}
if (*sink_elem) {
NVGSTDS_LINK_ELEMENT (pipeline->common_elements.tracker_bin.bin,
*sink_elem);
}
*sink_elem = pipeline->common_elements.tracker_bin.bin;
}

if (config->primary_gie_config.enable)
{
if (!create_primary_gie_bin (&config->primary_gie_config,
&pipeline->common_elements.primary_gie_bin)) {
goto done;
}
gst_bin_add (GST_BIN (pipeline->pipeline),
pipeline->common_elements.primary_gie_bin.bin);
if (*sink_elem) {
NVGSTDS_LINK_ELEMENT (pipeline->common_elements.primary_gie_bin.bin,
*sink_elem);
}
*sink_elem = pipeline->common_elements.primary_gie_bin.bin;
if (!*src_elem) {
*src_elem = pipeline->common_elements.primary_gie_bin.bin;
}
NVGSTDS_ELEM_ADD_PROBE (pipeline->common_elements.
primary_bbox_buffer_probe_id,
pipeline->common_elements.primary_gie_bin.bin, “src”,
gie_primary_processing_done_buf_prob, GST_PAD_PROBE_TYPE_BUFFER,
pipeline->common_elements.appCtx);
}

if (config->preprocess_config.enable)
{
if (!create_preprocess_bin (&config->preprocess_config,
&pipeline->common_elements.preprocess_bin)) {
g_print (“creating preprocess bin failed\n”);
goto done;
}
gst_bin_add (GST_BIN (pipeline->pipeline), pipeline->common_elements.preprocess_bin.bin);

  if (!*src_elem) {
    *src_elem = pipeline->common_elements.preprocess_bin.bin;
  }
  if (*sink_elem) {
    NVGSTDS_LINK_ELEMENT (pipeline->common_elements.preprocess_bin.bin,
        *sink_elem);
  }

*sink_elem = pipeline->common_elements.preprocess_bin.bin;

}

if(*src_elem)
{
NVGSTDS_ELEM_ADD_PROBE (pipeline->common_elements.
primary_bbox_buffer_probe_id,
*src_elem, “src”,
analytics_done_buf_prob, GST_PAD_PROBE_TYPE_BUFFER,
&pipeline->common_elements);

/* Add common message converter */
if (config->msg_conv_config.enable) 
{
  NvDsSinkMsgConvBrokerConfig *convConfig = &config->msg_conv_config;
  pipeline->common_elements.msg_conv = gst_element_factory_make (NVDS_ELEM_MSG_CONV, "common_msg_conv");
  if (!pipeline->common_elements.msg_conv) 
  {
    NVGSTDS_ERR_MSG_V ("Failed to create element 'common_msg_conv'");
    goto done;
  }

  g_object_set (G_OBJECT (pipeline->common_elements.msg_conv),
                "config", convConfig->config_file_path,
                "msg2p-lib", (convConfig->conv_msg2p_lib ? convConfig->conv_msg2p_lib : "null"),
                "payload-type", convConfig->conv_payload_type,
                "comp-id", convConfig->conv_comp_id,
                "debug-payload-dir", convConfig->debug_payload_dir,
                "multiple-payloads", convConfig->multiple_payloads, NULL);
  gst_bin_add (GST_BIN (pipeline->pipeline),
               pipeline->common_elements.msg_conv);

  NVGSTDS_LINK_ELEMENT (*src_elem, pipeline->common_elements.msg_conv);
  *src_elem = pipeline->common_elements.msg_conv;
}

pipeline->common_elements.tee = gst_element_factory_make (NVDS_ELEM_TEE, "common_analytics_tee");
if (!pipeline->common_elements.tee)
{
  NVGSTDS_ERR_MSG_V ("Failed to create element 'common_analytics_tee'");
  goto done;
}

gst_bin_add (GST_BIN (pipeline->pipeline),
      pipeline->common_elements.tee);

NVGSTDS_LINK_ELEMENT (*src_elem, pipeline->common_elements.tee);
*src_elem = pipeline->common_elements.tee;

}

ret = TRUE;
done:
return ret;
}

This problem has been bothering me for days. Please somebody give me a hand.
Thank you very much.

if did not print “I am here” , it means no object detected , please comment out some code to narrow down this issue, please refer to deepstream sample.

Thank you for your response and give me a light.

I tried many times.
for (l_frame = batch_meta->frame_meta_list; l_frame != NULL; l_frame = l_frame->next)
{
frame_meta = (NvDsFrameMeta *) (l_frame->data);

for (l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next)
{
obj_meta = (NvDsObjectMeta ) (l_obj->data);
/
Iterate user metadata in object to search SGIE’s tensor data */
cout<<“obj_id=”<<obj_meta->class_id<<endl;
for (NvDsMetaList * l_user = obj_meta->obj_user_meta_list; l_user != NULL; l_user = l_user->next)
{
//======= Here I hope to print=====//
cout<<“I am here”<<endl;
}
}
}

I can get the first cout the object-id, but I can not get the second cout.

I am fusion now that: I use the default pipeline.

In this way, the out put of secondary engine is not feed to dexsample. I hope to know:
(1)whether the default pipeline can get raw result of secondary engine or not?

(2) Do I need modify the pipeline to feed the dsexample with sgie out?

Thank you very very much. Wating for your reply.

from your pipeline, sgie only add meta to object meta, it will not delete meta, so you can access object meta if add probe function to sgie, please refer to deepstream-test2.

Thank you very very much. I will try

Thank you fazh.
I add the probe function to sgie. and get my first aim. I attach the code, it maybe helpful to someone as me.

The code is added in “deepstream-app.c”
(1) in the process_meta function, I add the gst_pad_add_probe()

if (appCtx->pipeline.common_elements.secondary_gie_bin.bin)
{
GstPad *my_pad = gst_element_get_static_pad (appCtx->pipeline.common_elements.secondary_gie_bin.bin, “src”);
if (!my_pad)
NVGSTDS_ERR_MSG_V (“Unable to get SGIE src pad\n”);
else
{
gst_pad_add_probe (my_pad, GST_PAD_PROBE_TYPE_BUFFER,
sgie_pad_buffer_probe, NULL, NULL);
gst_object_unref (my_pad);
}
}

(2) define the sgie_pad_buffer_probe function

static GstPadProbeReturn
sgie_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info, gpointer u_data)
{
NvDsBatchMeta batch_meta = gst_buffer_get_nvds_batch_meta (GST_BUFFER (info->data));
/
Iterate each frame metadata in batch */
for(NvDsMetaList * l_frame = batch_meta->frame_meta_list; l_frame != NULL; l_frame = l_frame->next)
{
printf(“========================frame list========================\n”);
NvDsFrameMeta *frame_meta = (NvDsFrameMeta *) l_frame->data;
for(NvDsMetaList * l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next)
{
printf(“---------------------list obj--------------------------\n”);
NvDsObjectMeta *obj_meta = (NvDsObjectMeta *) l_obj->data;
printf(“l_obj id = %d\n”, obj_meta->class_id);
for(NvDsMetaList *l = obj_meta->classifier_meta_list; l != NULL; l = l->next)
{
printf(“-------classifer_list-----\n”);
NvDsClassifierMeta * classifierMeta = (NvDsClassifierMeta *) (l->data);
for (NvDsMetaList * n = classifierMeta->label_info_list; n != NULL; n = n->next)
{
NvDsLabelInfo labelInfo = (NvDsLabelInfo) (n->data);
printf("label: %s \n ", &labelInfo->result_label[0]);
}
}
}
}
return GST_PAD_PROBE_OK;
}

thanks for your share, did you still meet any deepstream issue?

Thank you very very much.
Yes, I meet another problem. I create a new topic:

Thank you very very much.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.