albumentations.augmentations.dropout.xy_masking


Apply horizontal or vertical masking strips to simulate occlusion. Useful for spectrograms (spectral/frequency masking).

Members

XYMaskingclass

XYMasking(
    num_masks_x_range: tuple[int, int] = (0, 0),
    num_masks_y_range: tuple[int, int] = (0, 0),
    mask_x_length_range: tuple[int, int] = (0, 0),
    mask_y_length_range: tuple[int, int] = (0, 0),
    fill: tuple[float, ...] | float | random | random_uniform | inpaint_telea | inpaint_ns = 0,
    fill_mask: tuple[float, ...] | float | None,
    p: float = 0.5
)

Apply horizontal or vertical masking strips to simulate occlusion. Useful for spectrograms (spectral/frequency masking). Useful for training with varied visibility conditions; spectral and frequency masking can improve model robustness (e.g. SpecAugment-style). At least one of `max_x_length` or `max_y_length` must be specified, dictating the mask's maximum size along each axis.

Parameters

NameTypeDefaultDescription
num_masks_x_rangetuple[int, int](0, 0)Range of horizontal regions to mask. Defaults to (0, 0).
num_masks_y_rangetuple[int, int](0, 0)Range of vertical regions to mask. Defaults to (0, 0).
mask_x_length_rangetuple[int, int](0, 0)Range (min, max) of mask length along the X (horizontal) axis. The length is randomly chosen within this range for each mask. Defaults to (0, 0).
mask_y_length_rangetuple[int, int](0, 0)Range (min, max) of mask height along the Y (vertical) axis. The height is randomly chosen within this range for each mask. Defaults to (0, 0).
fill
One of:
  • tuple[float, ...]
  • float
  • random
  • random_uniform
  • inpaint_telea
  • inpaint_ns
0Value for the dropped pixels. Can be: - int or float: all channels are filled with this value - tuple: tuple of values for each channel - 'random': each pixel is filled with random values - 'random_uniform': each hole is filled with a single random color - 'inpaint_telea': uses OpenCV Telea inpainting method - 'inpaint_ns': uses OpenCV Navier-Stokes inpainting method Default: 0
fill_mask
One of:
  • tuple[float, ...]
  • float
  • None
-Fill value for dropout regions in the mask. If None, mask regions corresponding to image dropouts are unchanged. Default: None
pfloat0.5Probability of applying the transform. Defaults to 0.5.

Notes

Either `mask_x_length_range` or `mask_y_length_range` or both must have a positive max.