Skip to content
class

RandAugment

extendsPhotometricTransform[_RandAugmentParams]
RandAugment(num_ops: int = 2, magnitude: int = 9, num_magnitude_bins: int = 31, interpolation: str | Interpolation = Interpolation.BILINEAR, fill: float = 0.0, p: float = 1.0)

RandAugment (Cubuk et al., 2020 — arXiv:1909.13719).

Each call samples num_ops ops uniformly with replacement from the 14-op vocabulary and applies them sequentially, all sharing the same magnitude MM (signed per-op for symmetric ops). Reduces AutoAugment's two-level search space (policy + magnitude) to two scalar hyper-parameters that can be tuned with a simple grid sweep.

Parameters

num_opsint= 2
Number of ops sampled per call (with replacement). The reference-framework default for ImageNet is 2.
magnitudeint= 9
Integer index into the magnitude lookup table; must satisfy 0 <= magnitude < num_magnitude_bins. Reference-framework recipes sweep this from 5 (small models) to 15 (large models).
num_magnitude_binsint= 31
Magnitude bin count — same convention as TrivialAugmentWide.
interpolationstr or Interpolation= "bilinear"
No description.
fillfloat= 0.0
No description.
pfloat= 1.0
No description.

Notes

Photometric (image-only) by Lucid convention — see the module docstring. The op draws are with replacement so a call may stack the same op twice (e.g. Rotate followed by Rotate); this is the reference-framework behaviour.

Examples

>>> import lucid
>>> from lucid.utils.transforms import RandAugment
>>> tf = RandAugment(num_ops=2, magnitude=9)
>>> x = lucid.rand(3, 224, 224)
>>> y = tf(x)
>>> tuple(y.shape)
(3, 224, 224)

Used by 2

Constructors

1
dunder

__init__

→None
__init__(num_ops: int = 2, magnitude: int = 9, num_magnitude_bins: int = 31, interpolation: str | Interpolation = Interpolation.BILINEAR, fill: float = 0.0, p: float = 1.0)

Instance methods

1
fn

make_params

→_RandAugmentParams
make_params(img: Tensor)

Sample per-call random parameters for RandAugment.

Parameters

Image tensor; not inspected, carried through for dispatch.

Returns

_RandAugmentParams

Carries ops — a length-num_ops tuple of (op_name, signed_magnitude) pairs. Op names are drawn uniformly with replacement from the 14-op vocabulary; the magnitude shared across all ops is fixed at the self.magnitude lookup index, with a random sign for ops in SIGNED_OPS.

Dunder methods

1