Skip to content

Fix horizontal YOLO-OBB box targets and batch-size loss scale - #5

Closed
jeffaudi wants to merge 1 commit into
mainfrom
cursor/yolo-obb-horizontal-loss-a82c
Closed

jeffaudi wants to merge 1 commit into
mainfrom
cursor/yolo-obb-horizontal-loss-a82c

Conversation

@jeffaudi

Copy link
Copy Markdown
Contributor

Problem

Horizontal COCO training held the predicted angle at 0 and then applied CIoU to (cx, cy, w, h). Ground truth still arrived in le90 form, where a taller-than-wide box is stored as (long side, short side, −π/2). CIoU ignores angle, so that target is the transposed rectangle. Distribution focal loss was asked for the same swapped distances. A 20×80 object had CIoU loss 0 on the 80×20 box and loss above 1 on the correct box.

The loss gains (box 7.5, cls 0.5, DFL 1.5) match Ultralytics, but the value sent to backward was only the soft-target mean. Ultralytics multiplies that mean by the batch size. At batch 64 the step was 64× smaller than the recipe those gains were tuned for.

Change

When use_ciou is on, each ground-truth box is converted to image-axis width and height before assignment. DFL targets and CIoU both use that rectangle. Decode for this path does not pass through the le90 swap. Oriented ProbIoU training is unchanged aside from the shared scale below.

Every YOLO-OBB loss term is the soft-target mean multiplied by the number of images in the forward, for both horizontal and oriented runs.

Tests

tests/test_ciou.py checks that a tall le90 box prefers the image-axis prediction over the transpose, and that doubling the batch doubles the loss once the soft-target sum is above the clamp of 1. tests/test_yolo_obb.py and tests/test_ciou.py: 18 passed.

The live 500-epoch process is still the code it started with. This change applies on the next launch.

Open in Web Open in Cursor 

le90 boxes were trained with angle held at 0, so CIoU treated a tall
rectangle as its transpose. Horizontal mode now assigns, applies DFL,
and computes CIoU on image-axis width and height. The returned loss is
the soft-target mean multiplied by the image count, matching the
Ultralytics step size at the same nominal learning rate.
@jeffaudi jeffaudi closed this Oct 27, 2026
@jeffaudi
jeffaudi deleted the cursor/yolo-obb-horizontal-loss-a82c branch October 27, 2026 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant