Skip to content

layer_normalization

Layer Normalization Layer API

This module provides classes to build layer normalization layers.

Classes:

Classes

LayerNormalization1D

LayerNormalization1D(epsilon: float = 1e-06, name=None, **kwargs)

Apply Layer Normalization to the input.

Parameters:

  • epsilon (float, default: 1e-06 ) –

    Small value to avoid division by zero.

Source code in neuralspot_edge/layers/preprocessing/layer_normalization.py
def __init__(
    self,
    epsilon: float = 1e-6,
    name=None,
    **kwargs,
):
    """Apply Layer Normalization to the input.

    Args:
        epsilon (float): Small value to avoid division by zero.
    """
    super().__init__(name=name, **kwargs)
    self.epsilon = epsilon

Functions

augment_samples
augment_samples(inputs) -> keras.KerasTensor

Augment a batch of samples during training.

Source code in neuralspot_edge/layers/preprocessing/layer_normalization.py
def augment_samples(self, inputs) -> keras.KerasTensor:
    """Augment a batch of samples during training."""

    samples = inputs[self.SAMPLES]

    mean = keras.ops.mean(samples, axis=self.data_axis, keepdims=True)
    variance = keras.ops.var(samples, axis=self.data_axis, keepdims=True)
    outputs = (samples - mean) / keras.ops.sqrt(variance + self.epsilon)

    return outputs  # (batch, duration, channels)

LayerNormalization2D

LayerNormalization2D(epsilon: float = 1e-06, name=None, **kwargs)

Apply Layer Normalization to the input.

Parameters:

  • epsilon (float, default: 1e-06 ) –

    Small value to avoid division by zero.

Source code in neuralspot_edge/layers/preprocessing/layer_normalization.py
def __init__(
    self,
    epsilon: float = 1e-6,
    name=None,
    **kwargs,
):
    """Apply Layer Normalization to the input.

    Args:
        epsilon (float): Small value to avoid division by zero.
    """
    super().__init__(name=name, **kwargs)
    self.epsilon = epsilon

Functions

augment_samples
augment_samples(inputs) -> keras.KerasTensor

Augment a batch of samples during training.

Source code in neuralspot_edge/layers/preprocessing/layer_normalization.py
def augment_samples(self, inputs) -> keras.KerasTensor:
    """Augment a batch of samples during training."""

    samples = inputs[self.SAMPLES]
    axis = (self.height_axis, self.width_axis)
    mean = keras.ops.mean(samples, axis=axis, keepdims=True)
    variance = keras.ops.var(samples, axis=axis, keepdims=True)
    outputs = (samples - mean) / keras.ops.sqrt(variance + self.epsilon)

    return outputs  # (batch, duration, channels)