Skip to content
class

XYMasking

extendsPhotometricTransform[BandParams]
XYMasking(num_masks_x: int = 0, num_masks_y: int = 0, mask_x_length: int = 10, mask_y_length: int = 10, fill_value: float = 0.0, p: float = 0.5)

Mask random horizontal and vertical bands of the image (Albumentations XYMasking).

Samples num_masks_x vertical column-bands of width mask_x_length and num_masks_y horizontal row-bands of height mask_y_length, each placed at a uniformly-sampled offset. All sampled bands are unioned into a single multiplicative keep-mask and applied via the standard mask + fill pattern. Equivalent to SpecAugment-style time / frequency masking but for spatial inputs.

Parameters

num_masks_xint= 0
Number of vertical (column-direction) bands to sample.
num_masks_yint= 0
Number of horizontal (row-direction) bands to sample.
mask_x_lengthint= 10
Width in pixels of each vertical band.
mask_y_lengthint= 10
Height in pixels of each horizontal band.
fill_valuefloat= 0.0
Value written into the masked bands.
pfloat= 0.5
Probability of applying the transform.

Examples

>>> import lucid
>>> import lucid.utils.transforms as T
>>> tf = T.XYMasking(num_masks_x=2, num_masks_y=2, mask_x_length=8, mask_y_length=8, p=1.0)
>>> out = tf(T.Image(lucid.rand(3, 32, 32))).data
>>> tuple(out.shape)
(3, 32, 32)

Used by 1

Constructors

1
dunder

__init__

→None
__init__(num_masks_x: int = 0, num_masks_y: int = 0, mask_x_length: int = 10, mask_y_length: int = 10, fill_value: float = 0.0, p: float = 0.5)

Instance methods

1
fn

make_params

→BandParams
make_params(img: Tensor)

Sample per-call random parameters for XYMasking.

Parameters

Image tensor; its spatial size is read to bound the uniformly-sampled band start positions.

Returns

BandParams

Carries rows (num_masks_y horizontal band intervals) and cols (num_masks_x vertical band intervals), each interval (start, stop) with width mask_y_length / mask_x_length (clipped to the image edge).

Dunder methods

1