alibi_detect.utils.perturbation module

alibi_detect.utils.perturbation.apply_mask(X, mask_size=(4, 4), n_masks=1, coord=None, channels=[0, 1, 2], mask_type='uniform', noise_distr=(0, 1), noise_rng=(0, 1), clip_rng=(0, 1))[source]

Mask images. Can zero out image patches or add normal or uniformly distributed noise.

Parameters
  • X (numpy.ndarray) – Batch of instances to be masked.

  • mask_size (tuple) – Tuple with the size of the mask.

  • n_masks (int) – Number of masks applied for each instance in the batch X.

  • coord (Optional[tuple]) – Upper left (x,y)-coordinates for the mask.

  • channels (list) – Channels of the image to apply the mask to.

  • mask_type (str) – Type of mask. One of ‘uniform’, ‘random’ (both additive noise) or ‘zero’ (zero values for mask).

  • noise_distr (tuple) – Mean and standard deviation for noise of ‘random’ mask type.

  • noise_rng (tuple) – Min and max value for noise of ‘uniform’ type.

  • clip_rng (tuple) – Min and max values for the masked instances.

Return type

Tuple[numpy.ndarray, numpy.ndarray]

Returns

Tuple with masked instances and the masks.