Offset bounding box 1024x1024 Yolov8s

Hello everyone, I’ve been experimenting with Yolov8s training and have trained it to detect a 50x50 cm red ball. My resolution 1024x1024, I configurate more YAML file to resolution 1024х1024

results = model.train(
data=f’{dataset_dir}/data.yaml’,
epochs=50,
imgsz=1024,
device=“0,1”,
batch=8,
name=‘Ball1024’
)
После этого я преобразовал в onnx и с помощью hailomz конвертировал в .hef

hailomz compile
–ckpt runs/detect/Ball10243/weights/best.onnx
–calib-path Ball_cvat/valid/images
–yaml hailo_model_zoo/hailo_model_zoo/cfg/networks/yolov8s.yaml
–classes 1
–end-node-names /model.22/cv2.0/cv2.0.2/Conv /model.22/cv3.0/cv3.0.2/Conv /model.22/cv2.1/cv2.1.2/Conv /model.22/cv3.1/cv3.1.2/Conv /model.22/cv2.2/cv2.2.2/Conv /model.22/cv3.2/cv3.2.2/Conv
–hw-arch hailo8

Then I ran hailo-apps/hailo_apps/python/pipeline_apps/detection/detection.py at main · hailo-ai/hailo-apps · GitHub

My final goal is to make the red ball detect at higher resolution, 1024x1024, but I have a bounding box that is moving, more precisely, the model detects the ball but the bounding box is shifted down to the right, how can I fix this? I would greatly appreciate your help!!!

Hi @Andrey_Inozemtsev,

One thing worth checking is the NMS postprocess section in the YAML - it’s possible some parameters there are still based on 640x640.

The yolov8s.yaml has an alls / postprocess / nms section that may contain grid sizes or feature map dimensions tied to the original resolution. For 640x640 those grids would be [80, 40, 20] (strides [8, 16, 32]), and for 1024x1024 they’d need to be [128, 64, 32]. A mismatch there could explain the “shifted down-right” behavior you’re seeing.

It might be worth double-checking if any hardcoded image_dims, grid dimensions, or output shapes in that section still reference 640. If you’d like, feel free to share your modified YAML and I can take a look.

Thanks,

I have the same problem, and I would really appreciate it if you could take a look at my files.

yolo8s.yaml

base:

- base/yolov8.yaml

postprocessing:

  device_pre_post_layers:

    nms: true

  hpp: true

network:

  network_name: yolov8s

paths:

  network_path:

  - models_files/ObjectDetection/Detection-COCO/yolo/yolov8s/2023-02-02/yolov8s.onnx

  alls_script: yolov8s.alls

  url: https://hailo-model-zoo.s3.eu-west-2.amazonaws.com/ObjectDetection/Detection-COCO/yolo/yolov8s/2023-02-02/yolov8s.zip

info:

  task: object detection

  input_shape: 1024x1024x3

  output_shape: 80x5x100

  operations: 28.6G

  parameters: 11.2M

  framework: pytorch

  training_data: coco train2017

  validation_data: coco val2017

  eval_metric: mAP

  full_precision_result: 44.58

  source: 


  license_url: 


  license_name: AGPL-3.0

  supported_hw_arch:

  - hailo15h

  - hailo15l

  - hailo10h

yolo8s.alls

normalization1 = normalization([0.0, 0.0, 0.0], [255.0, 255.0, 255.0])
change_output_activation(conv42, sigmoid)
change_output_activation(conv53, sigmoid)
change_output_activation(conv63, sigmoid)
nms_postprocess("../../postprocess_config/yolov8s_nms_config_1024.json", meta_arch=yolov8, engine=cpu)

performance_param(optimize_for_power=True)
context_switch_param(auto_partition_to_buckets=False)

yolov8s_nms_config_1024.json

{
    "nms_scores_th": 0.2,
    "nms_iou_th": 0.7,
    "image_dims": [
        1024,
        1024
    ],
    "max_proposals_per_class": 100,
    "classes": 80,
    "regression_length": 16,
    "background_removal": false,
    "background_removal_index": 0,
    "bbox_decoders": [
        {
            "name": "bbox_decoder41",
            "stride": 128,
            "reg_layer": "conv41",
            "cls_layer": "conv42"
        },
        {
            "name": "bbox_decoder52",
            "stride": 64,
            "reg_layer": "conv52",
            "cls_layer": "conv53"
        },
        {
            "name": "bbox_decoder62",
            "stride": 32,
            "reg_layer": "conv62",
            "cls_layer": "conv63"
        }
    ]
}

(venv_hailo_apps) seg@seg:~/hailo-apps $ hailortcli parse-hef resources/models/hailo8/yolov8s_1024_stride.hef 
Architecture HEF was compiled for: HAILO8
Network group name: yolov8s, Single Context
    Network name: yolov8s/yolov8s
        VStream infos:
            Input  yolov8s/input_layer1 UINT8, NHWC(1024x1024x3)
            Output yolov8s/yolov8_nms_postprocess FLOAT32, HAILO NMS BY CLASS(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
                Max bboxes per class: 100
                Image height: 640

But bounding box is not normal

Hi @Andrey_Inozemtsev,

  1. Strides might be wrong in the NMS config JSON. Strides are fixed YOLOv8 architecture constants - they should be 8, 16, 32, not 128, 64, 32. Maybe you’ve swapped the strides with the grid dimensions? Solution:
"bbox_decoders": [
    { "name": "bbox_decoder41", "stride": 8,  "reg_layer": "conv41", "cls_layer": "conv42" },
    { "name": "bbox_decoder52", "stride": 16, "reg_layer": "conv52", "cls_layer": "conv53" },
    { "name": "bbox_decoder62", "stride": 32, "reg_layer": "conv62", "cls_layer": "conv63" }
]
  1. Image height: 640 in the HEF despite image_dims: [1024, 1024] in your JSON. This means the compiled NMS layer is still normalizing bboxes against 640, not 1024. This is likely being overridden by the base YAML (base/yolov8.yaml). Check that file for any hardcoded image dimensions and make sure nothing overrides your 1024 setting.

Thanks,

Thanks, I rebuild Hailo Model Zoo with my Yaml file and Yolov8s working 1024x1024

1 Like

@Andrey_Inozemtsev happy to hear!