mindspore.dataset.audio.MaskAlongAxis

View Source On Gitee
class mindspore.dataset.audio.MaskAlongAxis(mask_start, mask_width, mask_value, axis)[source]

Apply a mask along axis . Mask will be applied from indices [mask_start, mask_start + mask_width) .

Parameters
  • mask_start (int) – Starting position of the mask, which must be non negative.

  • mask_width (int) – The width of the mask, which must be larger than 0.

  • 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
  • ValueError – If mask_start is invalid (< 0).

  • ValueError – If mask_width is invalid (< 1).

  • ValueError – If axis is not type of int or not within [1, 2].

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.MaskAlongAxis(0, 10, 0.5, 1)]
>>> 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.MaskAlongAxis(0, 10, 0.5, 1)(waveform)
>>> print(output.shape, output.dtype)
(20, 20) float64
Tutorial Examples: