Skip to content

fix(augment): normalise scalar Affine translate_percent and scale for Kornia - #1444

Open
JESUSROYETH wants to merge 1 commit into
roboflow:developfrom
JESUSROYETH:fix/kornia-affine-scalar-translate
Open

fix(augment): normalise scalar Affine translate_percent and scale for Kornia#1444
JESUSROYETH wants to merge 1 commit into
roboflow:developfrom
JESUSROYETH:fix/kornia-affine-scalar-translate

Conversation

@JESUSROYETH

Copy link
Copy Markdown
Contributor

What is wrong

On a real COCO photograph, translate_percent=0.1 moved horizontally in 0/200 draws on the Kornia backend before this fix. After the fix it moved in 138–145/200, exactly matching the existing (-0.1, 0.1) pair across five seeds.

The same Affine config can behave differently between RF-DETR's Albumentations and Kornia backends. RF-DETR forwards scalar translate_percent directly to Kornia (source). Kornia reads 0.1 as [0.0, 0.1], using zero for the horizontal limit and 0.1 for the vertical limit. Training continues without an error, but one axis is silently disabled.

Scalar scale fails in the same factory. Albumentations accepts scale=1.1 as (1.1, 1.1), while Kornia calls len() on the forwarded float and raises TypeError during pipeline construction.

What changes

_make_affine now normalises only numeric scalar values before creating K.RandomAffine:

  • scalar translate_percent becomes the same non-negative limit for both axes;
  • scalar scale becomes the fixed range (v, v);
  • existing list and tuple inputs keep their current behaviour;
  • unsupported values, including strings, still reach Kornia's validation instead of being silently converted.

The translation path uses _as_symmetric_range, matching ShiftScaleRotate, before taking the per-axis magnitude. The change does not widen the shared helpers or affect other augmentation factories. The backend mapping table and changelog now document the corrected scalar behaviour.

Validation

  • TDD red on develop@c301e473: 4 failed, 5 passed.
  • Focused regression coverage: 9 passed.
  • Entire test_kornia_transforms.py: 152 passed, 1 skipped.
  • Full tests/datasets: 847 passed, 3 skipped.
  • bin/rfdetr_precommit.sh: 19/19 hooks passed, including strict mypy.
  • Real COCO photograph, five seeds and 200 draws each: scalar translation moved horizontally in 0/200 draws per seed before the fix and 138–145/200 after it, exactly matching the existing pair.
  • The public CUDA pipeline ran on an RTX 4060 with scalar translation and scale active; the output stayed on CUDA and its box changed.
  • Earlier evidence through the real L4 DataModule route changed horizontal/vertical span from 0/76 before to 76/76 after the same scalar normalisation.

No mAP or speed change is claimed. The conversion runs once when the augmentation pipeline is built.

@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87%. Comparing base (c301e47) to head (89d043e).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #1444   +/-   ##
=======================================
  Coverage       87%     87%           
=======================================
  Files          117     117           
  Lines        15260   15263    +3     
=======================================
+ Hits         13214   13219    +5     
+ Misses        2046    2044    -2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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