RandAugment default policy: posterize blacks the image out for m < 7.5; translate_x/y are applied as sub-pixel values
Summary
RandAugment writes lo + (hi - lo) * m / 30 straight into the wrapped op's parameter. For two entries of the default policy that value has the wrong unit or is truncated:
1. posterize blacks the image out for m < 7.5. The default entry is ("posterize", 0.0, 4); the mapped value is truncated with .long(), so small m gives 0 bits.
import torch; from kornia.augmentation.auto import RandAugment
x = torch.rand(4, 3, 32, 32)
for m in (3, 7, 8, 29):
torch.manual_seed(0); r = RandAugment(1, m, policy=[[("posterize", 0.0, 4)]]); y = r(x)
print(m, r._params[0].data[0].data["bits_factor"].tolist(), y.unique().numel())
# 3 [0,0,0,0] 1 | 7 [0,0,0,0] 1 | 8 [1,1,1,1] 2 | 29 [3,3,3,3] 8With the default policy every forward that draws posterize at m <= 7 returns an all-black image. (And m=29 gives 3 bits where the linear value is 3.87.)
2. translate_x / translate_y are applied in pixels, not as a fraction.
torch.manual_seed(0); r = RandAugment(1, 29, policy=[[("translate_x", -0.5, 0.5)]]); r(x)
print(r._params[0].data[0].data["translate_x"].tolist()) # [-0.483, 0.483, -0.483, 0.483] -> half a pixel on a 32 px imageThe same tuple under AutoAugment (bin 9) translates by 13.3–15.4 px and under TrivialAugment by up to 6.4 px: there the value is a fraction of the width. So the default ("translate_x", -0.1, 0.1) is a ≤0.1 px no-op in RandAugment.
Related but distinct: #4441 (shear/rotate magnitudes via the PolicySequential bypass).
Measured on main @ c643312a3 merged with #4634 (docs-only), torch 2.14.0, CPU, macOS arm64. Found while reviewing #4634 (batch 6d of #4407).
Posted on behalf of @ducha-aiki by Claude (Fable 5.1).
Source: kornia/kornia