feat(augment): support ShiftScaleRotate on the Kornia backend - #1370
Open
adhavan18 wants to merge 2 commits into
Open
feat(augment): support ShiftScaleRotate on the Kornia backend#1370adhavan18 wants to merge 2 commits into
adhavan18 wants to merge 2 commits into
Conversation
adhavan18
requested review from
Borda,
SkalskiP,
isaacrob and
probicheaux
as code owners
August 19, 2026 05:07
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1370 +/- ##
=======================================
Coverage 86% 86%
=======================================
Files 114 114
Lines 14880 14896 +16
=======================================
+ Hits 12835 12851 +16
Misses 2045 2045 🚀 New features to boost your workflow:
|
Closes another name from roboflow#1252. It maps onto the same K.RandomAffine that Affine already uses, which is what makes it safe: the output resolution is preserved, so the padding-mask constraint that keeps the crops unsupported does not apply here. The limits are not pass-through, which is why this needs its own builder rather than an alias. Albumentations biases scale_limit by 1, sampling from (1 + low, 1 + high), so the documented default (-0.1, 0.1) means a scale between 0.9 and 1.1. Forwarding it unchanged would ask Kornia to scale the image to between a tenth of its size and nothing at all. All three limits also read a scalar v as the symmetric (-v, v) rather than the degenerate (v, v) _as_range gives. shift_limit_x and shift_limit_y map onto Kornia's per-axis translate. The six options with no equivalent warn instead of vanishing. Albumentations deprecates this name in favour of Affine; noted in the docs, mapped anyway because the CPU path still accepts it and the same config otherwise trains on a CPU box and raises on a GPU box.
adhavan18
force-pushed
the
feat/kornia-shift-scale-rotate
branch
from
August 26, 2026 10:21
abea476 to
670f5ae
Compare
Contributor
Author
|
Bumping this since it's been quiet for a couple weeks — just rebased onto current develop, CI green across the full matrix, no conflicts. Happy to address anything if it needs another look. |
Member
|
Hi, apologies for delay, I was off last week but I have on my radar for later this week... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
ShiftScaleRotateto the Kornia GPU augmentation backend. Follow-up to #1330 and #1277, same issue (#1252).Why
ShiftScaleRotateis one of the namesaug_configsdocuments andtransforms.pyaccepts on the CPU path, while the Kornia registry rejects it. Backend selection is automatic, so the sameaug_configtrains on a CPU box and raises on a GPU box:It is safe to add for the same reason
Perspectivewas: it preserves the output resolution. The GPU path rebuilds each batch asNestedTensor(img_aug, samples.mask), reusing the pre-augmentation padding mask, so a transform that resizes leaves the mask describing a different shape. That is why the crops stay unsupported, and it does not apply here.I should correct something I wrote in #1330 while I am here. The doc block excluded this name along with the crops, on the grounds that the group "move boxes and masks". That reason does not hold for this one:
Affinemoves boxes too and has always been supported. Resolution change is the real constraint, andShiftScaleRotatedoes not change resolution.The part that is not a pass-through
Albumentations calls this "a special case of Affine transform", so an alias to
_make_affinelooks obvious. It would be wrong, because the limits are deltas rather than absolute ranges.scale_limitis biased by 1 — from the Albumentations docstring:So the documented default
(-0.1, 0.1)means a scale between0.9and1.1. Kornia'sscaleis the absolute multiplier, so forwarding the raw value would ask it to scale the image to between a tenth of its size and nothing at all. Confirmed against the installed Albumentations rather than trusting the docstring:The pivot is applied here, the same way
_make_sharpenalready pivotsalphaat1.0.Two smaller differences in the same vein:
scale_limitscale=(1 + low, 1 + high)shift_limittranslate, Kornia's non-negative per-axis maximum, as_make_affinealready does fortranslate_percentshift_limit_x/shift_limit_ytranslate=(tx, ty)expresses this directlyrotate_limitdegreesAll three limits also read a scalar
vas the symmetric(-v, v), not the degenerate(v, v)that_as_rangegives, so they go through a small_as_symmetric_rangehelper instead.interpolation,border_mode,mask_interpolation,fill,fill_maskandrotate_methodhave noRandomAffineequivalent and are ignored with a warning, matching howToGrayandSharpenalready report their dropped parameters.One thing worth your call
Albumentations deprecates this name. Constructing it emits:
I mapped it anyway because the CPU path in this repo still accepts it, so the parity gap is real for any config already using it, and
albumentations<3.0.0is pinned. But if you would rather close this name out ofaug_configsand point users atAffine— which this backend already supports — that is a reasonable call and I am happy to send that PR instead. The docs note added here says new configs should preferAffine.Tests
14 cases in
TestShiftScaleRotateFactory, covering the delta semantics (scalar and asymmetric pair), symmetric scalar expansion, the Albumentations defaults, per-axis shifts, each ignored option warning, no spurious warning on an ordinary config, resolution preservation, and boxes moving with the image.Reading the resolved ranges needs
RandomAffine._param_generator—flagscarries only the resampling options — so there is a helper that fails with an actionable message if a future Kornia release changes that shape, mirroring the existing_sharpness_sampler_range.