MaskBase

Base class for Mask objects. Contains many common utilities used for accessing masks. The mask itself is represented under the hood as a three dimensional numpy ndarray object. The dimensions are [NUM_FREQ, NUM_HOPS, NUM_CHAN]. Safe accessors for these array indices are in constants as well as below.

Right now only spectrogram-like masks are supported (note the shape of the mask property), but in future releases nussl will support masks for representations with different dimensionality requirements.

class nussl.separation.masks.mask_base.MaskBase(input_mask=None, mask_shape=None)

Bases: object

Parameters:input_mask (np.ndarray) – A 2- or 3-dimensional numpy ndarray representing a mask.
mask

PROPERTY

The actual mask. This is represented as a three dimensional numpy ndarray object. The input gets validated by _validate_mask(). In the case of separation.masks.binary_mask.BinaryMask the validation checks that the values are all 1 or 0 (or bools), in the case of separation.masks.soft_mask.SoftMask the validation checks that all values are within the domain [0.0, 1.0].

This base class will throw a NotImplementedError if instantiated directly.

Raises:
  • ValueError if mask.ndim is less than 2 or greater than 3, or if values fail validation.
  • NotImplementedError if instantiated directly.
get_channel(n)

Gets mask channel n and returns it as a 2D np.ndarray

Parameters:

n (int) – Channel index to return (0-based).

Returns:

np.array with the mask channel

Raises:
  • AttributeError if mask is None
  • ValueError if n is less than 0 or greater than the number of channels that this mask object has.
length

(int) Number of time hops that this mask represents.

height

(int) Number of frequency bins this mask has.

num_channels

(int) Number of channels this mask has.

shape

(tuple) Returns the shape of the whole mask. Identical to np.ndarray.shape().

dtype

(str) Returns the data type of the values of the mask.

classmethod ones(shape)

Makes a mask with all ones with the specified shape. Exactly the same as np.ones(). :param shape: Shape of the resultant mask. :type shape: tuple

Returns:

classmethod zeros(shape)

Makes a mask with all zeros with the specified shape. Exactly the same as np.zeros(). :param shape: Shape of the resultant mask. :type shape: tuple

Returns:

invert_mask()

Returns:

inverse_mask()

Alias for invert_mask()

See also

invert_mask()

Returns:

to_json()

Returns:

classmethod from_json(json_string)

Creates a new MaskBase object from the parameters stored in this JSON string.

Parameters:json_string (str) – A JSON string containing all the data to create a new MaskBase object.
Returns:(SeparationBase) A new MaskBase object from the JSON string.

See also

to_json() to make a JSON string to freeze this object.

class nussl.separation.masks.mask_base.MaskBaseDecoder(mask_class)

Bases: json.decoder.JSONDecoder

Object to decode a MaskBase-derived object from JSON serialization. You should never have to instantiate this object by hand.