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.
The
call()
method may not create state (except in its first invocation, wrapping the creation of variables or other resources intf.init_scope()
). It is recommended to create state, includingtf.Variable
instances and nestedLayer
instances,in
__init__()
, or in thebuild()
method that iscalled automatically before
call()
executes for the first time.- Parameters
inputs –
Input tensor, or dict/list/tuple of input tensors. The first positional
inputs
argument is subject to special rules: -inputs
must be explicitly passed. A layer cannot have zeroarguments, and
inputs
cannot be provided via the default value of a keyword argument.NumPy array or Python scalar values in
inputs
get cast as tensors.Keras mask metadata is only collected from
inputs
.Layers are built (
build(input_shape)
method) using shape info frominputs
only.input_spec
compatibility is only checked againstinputs
.Mixed precision input casting is only applied to
inputs
. If a layer has tensor arguments in*args
or**kwargs
, their casting behavior in mixed precision should be handled manually.The SavedModel input specification is generated using
inputs
only.Integration with various ecosystem packages like TFMOT, TFLite, TF.js, etc is only supported for
inputs
and not for tensors in positional and keyword arguments.
*args – Additional positional arguments. May contain tensors, although this is not recommended, for the reasons above.
**kwargs –
Additional keyword arguments. May contain tensors, although this is not recommended, for the reasons above. The following optional keyword arguments are reserved: -
training
: Boolean scalar tensor of Python boolean indicatingwhether the
call
is meant for training or inference.mask
: Boolean input mask. If the layer’scall()
method takes amask
argument, its default value will be set to the mask generated forinputs
by the previous layer (ifinput
did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support).
- 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 overint_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.
The
call()
method may not create state (except in its first invocation, wrapping the creation of variables or other resources intf.init_scope()
). It is recommended to create state, includingtf.Variable
instances and nestedLayer
instances,in
__init__()
, or in thebuild()
method that iscalled automatically before
call()
executes for the first time.- Parameters
inputs –
Input tensor, or dict/list/tuple of input tensors. The first positional
inputs
argument is subject to special rules: -inputs
must be explicitly passed. A layer cannot have zeroarguments, and
inputs
cannot be provided via the default value of a keyword argument.NumPy array or Python scalar values in
inputs
get cast as tensors.Keras mask metadata is only collected from
inputs
.Layers are built (
build(input_shape)
method) using shape info frominputs
only.input_spec
compatibility is only checked againstinputs
.Mixed precision input casting is only applied to
inputs
. If a layer has tensor arguments in*args
or**kwargs
, their casting behavior in mixed precision should be handled manually.The SavedModel input specification is generated using
inputs
only.Integration with various ecosystem packages like TFMOT, TFLite, TF.js, etc is only supported for
inputs
and not for tensors in positional and keyword arguments.
*args – Additional positional arguments. May contain tensors, although this is not recommended, for the reasons above.
**kwargs –
Additional keyword arguments. May contain tensors, although this is not recommended, for the reasons above. The following optional keyword arguments are reserved: -
training
: Boolean scalar tensor of Python boolean indicatingwhether the
call
is meant for training or inference.mask
: Boolean input mask. If the layer’scall()
method takes amask
argument, its default value will be set to the mask generated forinputs
by the previous layer (ifinput
did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support).
- 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.