Yolov3 detector with python apps

Dear folks,
I want to run ds python apps with yolov3 detector (not familier with C/C++). I found the “deepstream_test1_rtsp_out.py” in python bindings just fit my purpose. The configuration file for its pgie looks like this:

[property]
gpu-id=0
net-scale-factor=0.0039215697906911373
model-file=../../../../samples/models/Primary_Detector/resnet10.caffemodel
model-engine-file=../../../../samples/models/Primary_Detector/resnet10.caffemodel_b1_gpu0_int8.engine
proto-file=../../../../samples/models/Primary_Detector/resnet10.prototxt
labelfile-path=../../../../samples/models/Primary_Detector/labels.txt
int8-calib-file=../../../../samples/models/Primary_Detector/cal_trt.bin
batch-size=1
network-mode=1
num-detected-classes=4
interval=0
gie-unique-id=1
output-blob-names=conv2d_bbox;conv2d_cov/Sigmoid

[class-attrs-all]
threshold=0.2
eps=0.2
group-threshold=1

The C deepstream-app has an example config called “config_infer_primary_yoloV3.txt”, looking like this:

[property]
gpu-id=0
net-scale-factor=0.0039215697906911373
#0=RGB, 1=BGR
model-color-format=0
custom-network-config=yolov3.cfg
model-file=yolov3.weights
#model-engine-file=yolov3_b1_gpu0_int8.engine
labelfile-path=labels.txt
int8-calib-file=yolov3-calibration.table.trt7.0
## 0=FP32, 1=INT8, 2=FP16 mode
network-mode=1
num-detected-classes=80
gie-unique-id=1
network-type=0
is-classifier=0
## 0=Group Rectangles, 1=DBSCAN, 2=NMS, 3= DBSCAN+NMS Hybrid, 4 = None(No clustering)
cluster-mode=2
maintain-aspect-ratio=1
parse-bbox-func-name=NvDsInferParseCustomYoloV3
custom-lib-path=nvdsinfer_custom_impl_Yolo/libnvdsinfer_custom_impl_Yolo.so
engine-create-func-name=NvDsInferYoloCudaEngineGet
#scaling-filter=0
#scaling-compute-hw=0

[class-attrs-all]
nms-iou-threshold=0.3
threshold=0.7

If I want to use python bindings to run the yolov3 detector, what should I do to deal with the configuration file?

**• Hardware Platform (Jetson / GPU)**GPU titanV
• DeepStream Version5.0
• JetPack Version (valid for Jetson only)
• TensorRT Version 7.0.0.11
• NVIDIA GPU Driver Version (valid for GPU only) 440.33

You could run with the yolo config using python sample, but need to change the file location accordingly.
custom-network-config
model-file
labelfile-path
int8-calib-file
custom-lib-path

Ok. Got it. It is working now! The yolov3 runs very well. Thanks for the instruction.
A follow-up question is that if I want to use 8bit precision, how can I do the calibiration and obtain the calibration table?
I see there is a calibration file :“yolov3-calibration.table.trt7.0”, but it is for coco dataset. I have a custom dataset, is there any way to do the calibration and get this table?

Thanks.

for INT8 calibration, you may refer to TRT documentation,
Developer Guide :: NVIDIA Deep Learning TensorRT Documentation

OK. Thanks. I will see to it.

When I ran my customed yolov3 with coco dataset, it always pop up an error. Though it does stop running, I still want to know how this happens:

Frame Number=1318 Number of Objects=6 Vehicle_count=2 Person_count=4
Traceback (most recent call last):
  File "deepstream_test1_rtsp_out.py", line 84, in osd_sink_pad_buffer_probe
    obj_counter[obj_meta.class_id] += 1
KeyError: 7
Frame Number=1320 Number of Objects=5 Vehicle_count=2 Person_count=3
Traceback (most recent call last):
  File "deepstream_test1_rtsp_out.py", line 84, in osd_sink_pad_buffer_probe
    obj_counter[obj_meta.class_id] += 1
KeyError: 7
Traceback (most recent call last):
  File "deepstream_test1_rtsp_out.py", line 84, in osd_sink_pad_buffer_probe
    obj_counter[obj_meta.class_id] += 1
KeyError: 7

I does not notice any problem regarding the code. Any idea?

        frame_number=frame_meta.frame_num
    num_rects = frame_meta.num_obj_meta
    l_obj=frame_meta.obj_meta_list
    while l_obj is not None:
        try:
            # Casting l_obj.data to pyds.NvDsObjectMeta
            obj_meta=pyds.NvDsObjectMeta.cast(l_obj.data)
        except StopIteration:
            break
        obj_counter[obj_meta.class_id] += 1
        try: 
            l_obj=l_obj.next
        except StopIteration:
            break

code clip seems correct, how many classes your customized model have?

I think it is the classes num causes this problem. You are right! I have more than 10 classes, but the object counter only has 4:

    #Intiallizing object counter with 0.
obj_counter = {
    PGIE_CLASS_ID_VEHICLE:0,
    PGIE_CLASS_ID_PERSON:0,
    PGIE_CLASS_ID_BICYCLE:0,
    PGIE_CLASS_ID_ROADSIGN:0
}
num_rects=0

I need to add all classes here, right?

Can you change num-detected-classes=4 in config to class numbers of your model?

Yeap, I see. This works fine.
The problem is I have more than 4 classes to detect, say, 16 classes. So If I change it like this, it may not display the detections of more than 4 classes.

See inline.

I have figured it out.
This issue could be closed, and thanks for your patience @Amycao

Thanks for let us knowing.