mindspore.dataset.audio.MaskAlongAxisIID

class mindspore.dataset.audio.MaskAlongAxisIID(mask_param, mask_value, axis)[source]

Apply a mask along axis . Mask will be applied from indices [mask_start, mask_start + mask_width) , where mask_width is sampled from uniform[0, mask_param] , and mask_start from uniform[0, max_length - mask_width] , max_length is the number of columns of the specified axis of the spectrogram.

Parameters
  • mask_param (int) – Number of columns to be masked, will be uniformly sampled from [0, mask_param], must be non negative.

  • mask_value (float) – Value to assign to the masked columns.

  • axis (int) – Axis to apply mask on (1 for frequency and 2 for time).

Raises
  • TypeError – If mask_param is not of type int.

  • ValueError – If mask_param is a negative value.

  • TypeError – If mask_value is not of type float.

  • TypeError – If axis is not of type int.

  • ValueError – If axis is not in range of [1, 2].

  • RuntimeError – If input tensor is not in shape of <…, freq, time>.

Supported Platforms:

CPU

Examples

>>> import numpy as np
>>> import mindspore.dataset as ds
>>> import mindspore.dataset.audio as audio
>>>
>>> # Use the transform in dataset pipeline mode
>>> waveform= np.random.random([5, 20, 20])  # 5 samples
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data=waveform, column_names=["audio"])
>>> transforms = [audio.MaskAlongAxisIID(5, 0.5, 2)]
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms, input_columns=["audio"])
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
...     print(item["audio"].shape, item["audio"].dtype)
...     break
(20, 20) float64
>>>
>>> # Use the transform in eager mode
>>> waveform = np.random.random([20, 20])  # 1 sample
>>> output = audio.MaskAlongAxisIID(5, 0.5, 2)(waveform)
>>> print(output.shape, output.dtype)
(20, 20) float64
Tutorial Examples: