How to change class ID immediately after inference is finished?

Please provide complete information as applicable to your setup.

**• Orin NX 16g
**• DeepStream Version : 6.3


I’m working based on deepstream-app.
How can I change the class ID right after the inference is done?
For example, my label.txt looks like this

///////////////////////////////
my label.txt

car
suv
van
/////////////////////////////

I don’t want to manage sub and van as separate class IDs, but as one class ID (car).
This is because I need to keep only one type of class, car, to handle obj_meta->object_id.

However, my current pre-trained model is made of three different class types as shown in label.txt above.

So I tried this inside process_meta(), gie_primary_processing_done_buf_prob() in deepstreamp-app.c

{
for (NvDsMetaList * l_frame = batch_meta->frame_meta_list; l_frame != NULL; l_frame = l_frame->next)
{
NvDsFrameMeta frame_meta = (NvDsFrameMeta)l_frame->data;
for (NvDsMetaList * l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next)
{
NvDsObjectMeta *obj = (NvDsObjectMeta *) l_obj->data;

  obj->class_id = 0;  <------------

  ..............

}

However, the above method does not seem to change the class id right after the initial inference.

Is there any way to change the class id of suv(1), van(2) to car(0) in the step before class_id and object_id are bound to NvDsFrameMeta.

I’m looking at gst-nvinfer but I’m stumped.
If someone could help me out, it would be appreciated.

It should work. gie_primary_processing_done_buf_prob() is right after the PGIE inferencing.

Thank you, Fiona.Chen

I tried the following in gie_primary_processing_done_buf_prob().

gie_primary_processing_done_buf_prob (GstPad * pad, GstPadProbeInfo * info,
gpointer u_data)
{
GstBuffer *buf = (GstBuffer *) info->data;
AppCtx *appCtx = (AppCtx *) u_data;
NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta (buf);
if (!batch_meta) {
NVGSTDS_WARN_MSG_V (“Batch meta not found for buffer %p”, buf);
return GST_PAD_PROBE_OK;
}

//write_kitti_output (appCtx, batch_meta);

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

for (NvDsMetaList * l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next) 
{
  NvDsObjectMeta *obj = (NvDsObjectMeta *) l_obj->data;

 if( obj->class_id == 1 || obj->class_id == 2 ) obj->class_id = 0;   <-----

}

}

return GST_PAD_PROBE_OK;
}

In gie_primary_processing_done_buf_prob(), I changed the class id of suv and van to car.

If you look at the output inside nvdsanalytics_src_pad_buffer_probe(), you will see that obj->class_id is actually replaced with 0.

nvdsanalytics_src_pad_buffer_probe ()
{

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

for (NvDsMetaList * l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next) 
{
  NvDsObjectMeta *obj = (NvDsObjectMeta *) l_obj->data;

 printfobj>class_id:%d\n", obj->class_id);  <-- All class ids have been changed to 0.

}

}

return GST_PAD_PROBE_OK;

}

However, the labels of the detected suv and van in the actual output image are not changed to car, but maintain the text of suv and van.

And obj->object_id is also assigned according to each class of car, suv, and van.

How can I assign obj->object_id consistently to one class (car → 0) without distinguishing the type of vehicle?

I would appreciate your help.

The object_id will be used and set by nvtracker. You can’t change the value.

Why do you want to set the object_id value by yourself?

There is no update from you for a period, assuming this is not an issue anymore. Hence we are closing this topic. If need further support, please open a new one. Thanks

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