How to get bboxes and confidence from metadata inferred by the model in python?

Please provide complete information as applicable to your setup.

**• Hardware Platform (Jetson / GPU)**Jetson
• DeepStream Version5.1
• JetPack Version (valid for Jetson only)
• TensorRT Version
• NVIDIA GPU Driver Version (valid for GPU only)
• Issue Type( questions, new requirements, bugs)
• 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)
In test1 of python api.
I tried to use my pretrained Yolov5 model on deepstream. When I tried to get some results inferred by the model in deepstream, the results seemed wrong. I just modified the function osd_sink_pad_buffer_probe in test1 and changed the model to yolov5. I tried to get information from NvDsObjectMeta.detector_bbox_info but it said there was no attribute called this. Then I turned to rect_params, but this gave me wrong datas, which were too big. (btw, input video was created with 1024×1024 images)
Also, I’ve tried to add_probe to the pgie’s sink. This gave me even none data. I’m not sure but I guess it’s the video-convertor’s cause. However, where should I get the true results inferred by my model from? Of course, the confidence was also very big with an average of more than 200.
• Requirement details( This is for new requirement. Including the module name-for which plugin or for which sample application, the function description)
Here is my sink_pad_buffer_probe

def pgie_sink_pad_buffer_probe(self,pad,info,u_data):
        frame_number=0
        num_rects=0

        gst_buffer = info.get_buffer()
        if not gst_buffer:
            print("Unable to get GstBuffer ")
            return

        # Retrieve batch metadata from the gst_buffer
        # Note that pyds.gst_buffer_get_nvds_batch_meta() expects the
        # C address of gst_buffer as input, which is obtained with hash(gst_buffer)
        batch_meta = pyds.gst_buffer_get_nvds_batch_meta(hash(gst_buffer))
        l_frame = batch_meta.frame_meta_list
        while l_frame is not None:
            try:
                # Note that l_frame.data 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(l_frame.data)
            except StopIteration:
                break
            
            frame_number=frame_meta.frame_num 
            num_rects = frame_meta.num_obj_meta
            l_obj=frame_meta.obj_meta_list 
            res={'time':frame_number,'numofobjects':num_rects,'objects':[]}
            while l_obj is not None:
                try:
                    # Casting l_obj.data to pyds.NvDsObjectMeta
                    obj_meta=pyds.glist_get_nvds_object_meta(l_obj.data)
                except StopIteration:
                    break
                #obj_counter[obj_meta.class_id] += 1
                bbox={'xmin':obj_meta.rect_params.left,'xmax':obj_meta.rect_params.left+obj_meta.rect_params.width,'ymin':obj_meta.rect_params.top+obj_meta.rect_params.height,'ymax':obj_meta.rect_params.top}
                res['objects'].append({'label':obj_meta.obj_label[obj_meta.class_id],'confidence':obj_meta.confidence,'bbox':bbox.copy()})
                #END
                try: 
                    l_obj=l_obj.next
                except StopIteration:
                    break
            self.resq.put(json.dumps(res))
            
            try:
                l_frame=l_frame.next
            except StopIteration:
                break
        return Gst.PadProbeReturn.OK

And I tried to add_probe to pgie,nvosd…

        osdsinkpad = pgie.get_static_pad("sink")
        if not osdsinkpad:
            sys.stderr.write(" Unable to get sink pad of pgie \n")
        osdsinkpad.add_probe(Gst.PadProbeType.BUFFER, 
                    self.pgie_sink_pad_buffer_probe, 0)

So, what should I do to get my bboxes and confidence?
Thanks.

My pyds only get a version of 0.5 but the deepstream is 5.1.
Maybe the fault is here.

Now I can get the real bbox from rect_params but the confidence is always -0.1. How can this be?

Alright, now I know that this was because I had chosen the group rectangles in config file. It works well when I chose not use this.

Good to know issue fixed. Thanks

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