Is there a limitation on the number of results per class in object detection?

I am using a YOLOv8n model that I have retrained. The model now only detects a specific class of objects. When there are fewer than 100 objects in the image, all objects are detected. However, if there are more than 100 objects in the image, only 100 objects are detected.

When I run the model on the GPU, all objects are detected.

What could be causing this?

Is there a parameter that limits the number of detected objects per class?

Hey @martin.werner

Welcome to the Hailo Community!

Yes, there are detection limits per class. This is controlled by parameters like max_bboxes_per_class in HailoRT’s Non-Maximum Suppression (NMS) settings. For YOLO models specifically, you can modify these limits in the post-processing configuration files, which contain parameters like:

  • max_det: Controls total detections per frame
  • max_bboxes_per_class: Sets the maximum objects detected per class

You can adjust these values in the JSON configuration files to match your needs. If you’re hitting a 100-detection limit, check and modify these settings in your model’s configuration files.

Hello @omria, thank you for your response.

I am not clear which JSON files you mean and where I can find them.

I am taking the following steps:

I am creating a Yolov8n.pt file, which I then convert into the ONNX format.

After that, I create a .hef file using the command hailomz compile yolov8n --ckpt=best.onnx --hw-arch hailo8 --calib-path Yolo/train/images --classes 1 --performance.

Then I call the command hailortcli parse-hef yolov8n.hef.

I receive the following output:

Architecture HEF was compiled for: HAILO8
Network group name: yolov8n, Single Context
Network name: yolov8n/yolov8n
VStream infos:
Input yolov8n/input_layer1 UINT8, NHWC(640x640x3)
Output yolov8n/yolov8_nms_postprocess FLOAT32, HAILO NMS(number of classes: 1, maximum bounding boxes per class: 100, maximum frame size: 2004)
Operation:
Op YOLOV8
Name: YOLOV8-Post-Process
Score threshold: 0.200
IoU threshold: 0.70
Classes: 1
Cross classes: false
Max bboxes per class: 100
Image height: 640
Image width: 640

In the output, we see that the maximum number of bboxes per class is limited to 100.

Do I need to adjust the file default_nms_config_yolov8.json in the path /local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_sdk_client/tools/core_postprocess (I am using the Docker container)?

When is the number of boxes limited? During the creation of the .pt file, during the creation of the ONNX file, or during the creation of the .hef file?

Below, I will explain how I solved the problem.

  1. Modify JSON file

I have modified the file yolov8n_nms_config.json in the path /local/workspace/hailo_model_zoo/hailo_model_zoo/cfg/postprocess_config/

Here, I have added the following values:

  • max_proposals_per_class: 250
  • max_det: 250
  • max_bboxes_per_class: 250

My JSON file looked as follows afterward:

{
“nms_scores_th”: 0.2,
“nms_iou_th”: 0.7,
“image_dims”: [
640,
640
],
“max_proposals_per_class”: 250,
“max_det”: 250,
“max_bboxes_per_class”: 250,
“classes”: 80,
“regression_length”: 16,
“background_removal”: false,
“bbox_decoders”: [
{
“name”: “yolov8n/bbox_decoder41”,
“stride”: 8,
“reg_layer”: “yolov8n/conv41”,
“cls_layer”: “yolov8n/conv42”
},
{
“name”: “yolov8n/bbox_decoder52”,
“stride”: 16,
“reg_layer”: “yolov8n/conv52”,
“cls_layer”: “yolov8n/conv53”
},
{
“name”: “yolov8n/bbox_decoder62”,
“stride”: 32,
“reg_layer”: “yolov8n/conv62”,
“cls_layer”: “yolov8n/conv63”
}
]
}

  1. Create .hef-File

After that, I create a .hef file using the command hailomz compile yolov8n --ckpt=best.onnx --hw-arch hailo8 --calib-path Yolo/train/images --classes 1 --performance.

  1. Parse .hef-File
    Then I call the command hailortcli parse-hef yolov8n.hef

Architecture HEF was compiled for: HAILO8
Network group name: yolov8n, Single Context
Network name: yolov8n/yolov8n
VStream infos:
Input yolov8n/input_layer1 UINT8, NHWC(640x640x3)
Output yolov8n/yolov8_nms_postprocess FLOAT32, HAILO NMS(number of classes: 1, maximum bounding boxes per class: 250, maximum frame size: 5004)
Operation:
Op YOLOV8
Name: YOLOV8-Post-Process
Score threshold: 0.200
IoU threshold: 0.70
Classes: 1
Cross classes: false
Max bboxes per class: 250
Image height: 640
Image width: 640

The value for maximum bounding boxes per class has been changed to 250.
The value for maximum frame size has been changed to 5004.

  1. Edit source code.

In my source code, I adjusted the size of hailo_output_vstream.
std::vector<float32_t> vstream_output_data(5004);

I based my work on this example: Hailo-Application-Code-Examples/runtime/windows/yolov8/yolov8_example.cpp at main · hailo-ai/Hailo-Application-Code-Examples · GitHub

1 Like