das.kapre.utils

class das.kapre.utils.AmplitudeToDB(*args, **kwargs)[source]

Converts spectrogram values to decibels.

Examples

Adding dB conversion after a spectrogram:

>>> model.add(Spectrogram(return_decibel=False))
>>> model.add(AmplitudeToDB())
which is the same as:
>>> model.add(Spectrogram(return_decibel=True))

Args: amin (float, optional): Noise floor. Defaults to 1e-10 (dB). top_db (float, optional): Dynamic range of output. Defaults to 80.0 (dB).

call(x, mask=None)[source]

This is where the layer’s logic lives.

Note here that call() method in tf.keras is little bit different from keras API. In keras API, you can pass support masking for layers as additional arguments. Whereas tf.keras has compute_mask() method to support masking.

Parameters
  • inputs – Input tensor, or list/tuple of input tensors.

  • *args – Additional positional arguments. Currently unused.

  • **kwargs – Additional keyword arguments. Currently unused.

Returns

A tensor or list/tuple of tensors.

get_config()[source]

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns

Python dictionary.

class das.kapre.utils.Normalization2D(*args, **kwargs)[source]

Normalizes input along an axis.

Examples

A frequency-axis normalization after a spectrogram:

>>> model.add(Spectrogram())
>>> model.add(Normalization2D(str_axis='freq'))

[summary]

Parameters
  • str_axis (Optional[str], optional) – Axis name along which mean/std is computed (batch, data_sample, channel, freq, time). Recommended over int_axis because it provides more meaningful and image data format-robust interface. Defaults to None.

  • int_axis (Optional[int], optional) –

    Axis index along which mean/std is computed.
    • 0 for per data sample, -1 for per batch.

    • 1, 2, 3 for channel, row, col (if channels_first)

    Defaults to None.

  • image_data_format (str, optional) – ‘channels_first’ (c,x,y,) or ‘channels_last’ (x,y,c) or TF ‘default’. Defaults to ‘default’.

  • eps (float, optional) – Small numerical value added to avoid divide by zero. Defaults to 1e-10.

call(x, mask=None)[source]

This is where the layer’s logic lives.

Note here that call() method in tf.keras is little bit different from keras API. In keras API, you can pass support masking for layers as additional arguments. Whereas tf.keras has compute_mask() method to support masking.

Parameters
  • inputs – Input tensor, or list/tuple of input tensors.

  • *args – Additional positional arguments. Currently unused.

  • **kwargs – Additional keyword arguments. Currently unused.

Returns

A tensor or list/tuple of tensors.

get_config()[source]

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns

Python dictionary.