Skip to content
class

RandomScale

extendsGeometricTransform[ScaleParam]
RandomScale(scale_limit: float | tuple[float, float] = 0.1, interpolation: int | str | Interpolation = 1, p: float = 0.5)

Resize by a random factor, aspect preserved (Albumentations RandomScale).

Samples s uniformly from scale_limit and resizes the image to (round(H * (1 + s)), round(W * (1 + s))). Image uses the requested interpolation, masks use nearest, boxes and keypoints scale exactly.

Parameters

scale_limitfloat or (float, float)= 0.1
Scale-delta range; a scalar v expands to (-v, v) so the effective scale lies in [1 - v, 1 + v].
interpolationint or str or Interpolation= 1
Image resampling mode (OpenCV codes accepted).
pfloat= 0.5
Probability of applying the transform.

Examples

>>> import lucid, lucid.utils.transforms as T
>>> tf = T.RandomScale(scale_limit=0.1, p=1.0)
>>> out = tf(T.Image(lucid.rand(3, 32, 32))).data
>>> 28 <= out.shape[1] <= 36
True
The size cannot be written down here because it follows the sampled
scale and differs run to run — which is the thing to know about this
transform. Put a Resize after it when the batch has to
stack.

Used by 1

Constructors

1
dunder

__init__

→None
__init__(scale_limit: float | tuple[float, float] = 0.1, interpolation: int | str | Interpolation = 1, p: float = 0.5)

Instance methods

1
fn

make_params

→ScaleParam
make_params(img: Tensor)

Sample per-call random parameters for RandomScale.

Parameters

Image tensor; its spatial size is read to compute the target (new_h, new_w) after scaling.

Returns

ScaleParam

Carries the target new_h and new_w, each at least 1, derived from a single scale factor 1 + uniform(scale_limit) applied to the input height and width.

Dunder methods

1