Attaching a new NvDsObjectMeta to batch meta in python

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU) : Jetson
• DeepStream Version : 5.0.1
• JetPack Version (valid for Jetson only) : 4.4
• TensorRT Version
• NVIDIA GPU Driver Version (valid for GPU only)
• Issue Type( questions, new requirements, bugs) : Question
• How to reproduce the issue ? (This is for bugs. Including which sample app is using, the configuration files content, the command line used and other details for reproducing) : NA
• Requirement details( This is for new requirement. Including the module name-for which plugin or for which sample application, the function description)

Hi, I was trying to write a custom pad probe handler so that I can implement my own NMS. (One of the given algorithm seems to have a small issue in my use case). So I set the cluster mode in 4 ( No Cluster Algorithm), and then wrote a custom NMS function that removes all the NvDsObjectMeta in a NvDsFrameMeta and creates new NvDsObjectMetas that hold valid predictions only. However, it seems like newly created NvDsObjectMeta isn’t linked to FrameMeta properly.

Am I missing something?

def tracker_sink_pad_buffer_probe(buffer, user_data):
    print('new batch start')
    # Retrieve batch metadata from the gst_buffer
    batch_meta = pyds.gst_buffer_get_nvds_batch_meta(buffer)
    l_frame = batch_meta.frame_meta_list # s
    frame_num = 0
    while l_frame is not None:
        preds_per_frame = []
        out_meta_data_list = []
            # Note that needs a cast to pyds.NvDsFrameMeta
            # The casting is done by pyds.glist_get_nvds_frame_meta()
            # The casting also keeps ownership of the underlying memory
            # in the C code, so the Python garbage collector will leave
            # it alone.
            frame_meta = pyds.glist_get_nvds_frame_meta(
        except StopIteration:

        # predictions per frame
        pred_list_per_frame = []
        preds_before_nms = f''
        preds_after_nms = f''

        # while disp_meta is not None:
        while l_obj is not None:
                # Casting to pyds.NvDsObjectMeta
            except StopIteration:

            # loops Bounding Box Params
            conf = obj_meta.confidence
            cls_ = obj_meta.class_id
            bbox_height = obj_meta.rect_params.height
            bbox_left = obj_meta.rect_params.left
            bbox_top =
            bbox_width = obj_meta.rect_params.width
            attrs = [attr for attr in dir(obj_meta) if (not attr.startswith('__') and (not attr == 'mask_params'))]
            values = {}

            for attr in attrs:
                a = f'obj_meta.{attr}'
                values[attr] = eval(a)

            pred_list_per_frame.append([conf, cls_, bbox_left, bbox_top, bbox_left+bbox_width, bbox_top+bbox_height, values])
                pyds.nvds_remove_obj_meta_from_frame(frame_meta, obj_meta)
            except StopIteration:
        if len(pred_list_per_frame) > 0:

            preds = nms(pred_list_per_frame, box_format="corners")  # applying my custom nms

            for pred in preds:
                # out_meta_data = pyds.NvDsObjectMeta()
                frame_meta.bInferDone = True
                out_meta_data = pyds.nvds_acquire_obj_meta_from_pool(batch_meta)

                tmp = pyds.NvDsObjectMeta()

                # for k, v in pred[-1].items():
                #     out_meta_data[k] = v

       = int(pred[-1]['rect_params'].top)
                out_meta_data.rect_params.left = int(pred[-1]['rect_params'].left)
                out_meta_data.rect_params.width = int(pred[-1]['rect_params'].width)
                out_meta_data.rect_params.height = int(pred[-1]['rect_params'].height)

                out_meta_data.parent = pred[-1]['parent']
                out_meta_data.confidence = pred[-1]['tracker_confidence']
                out_meta_data.class_id = pred[-1]['class_id']
                out_meta_data.object_id = pred[-1]['object_id']
                out_meta_data.unique_component_id = pred[-1]['unique_component_id']

       = int(pred[-1]['rect_params'].top)
                tmp.rect_params.left = int(pred[-1]['rect_params'].left)
                tmp.rect_params.width = int(pred[-1]['rect_params'].width)
                tmp.rect_params.height = int(pred[-1]['rect_params'].height)

                tmp.parent = pred[-1]['parent']
                tmp.confidence = pred[-1]['tracker_confidence']
                tmp.class_id = pred[-1]['class_id']
                tmp.object_id = pred[-1]['object_id']
                tmp.unique_component_id = pred[-1]['unique_component_id']

                pyds.nvds_add_obj_meta_to_frame(frame_meta, out_meta_data, out_meta_data['parent'])
            print('try ran')
            frame_num += 1
        except StopIteration:
    return True

Was there something wrong where I instantiated a ObjectMeta?

Hi @junghyun.hwang , have you tried to run the demo belowing in your env?

1 Like

Thanks, it is working now!!

One quick question thou,
What attributes must be defined when displaying bboxes on a window?

I am quite positive that I have defined most of attributes in NvDsObjectMeta, but it doesn’t draw bboxes. It outputs a text box thou.

Hi @junghyun.hwang , you could use the osd plugin to draw the bboxes.
Also, if you have any other questions that have no related to this topic, please open a new topic. Thanks

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