Skip to content

resizing

Resizing layers API

This module provides classes to build resizing layers.

Classes:

Classes

Resizing1D

Resizing1D(duration: int, **kwargs)

1D resizing layer

Parameters:

  • duration (int) –

    The new duration of the samples

Source code in neuralspot_edge/layers/preprocessing/resizing.py
def __init__(self, duration: int, **kwargs):
    """1D resizing layer

    Args:
        duration (int): The new duration of the samples

    """
    super().__init__(**kwargs)
    self.duration = duration

Functions

augment_samples
augment_samples(inputs) -> keras.KerasTensor

Resize a batch of samples during training.

Source code in neuralspot_edge/layers/preprocessing/resizing.py
def augment_samples(self, inputs) -> keras.KerasTensor:
    """Resize a batch of samples during training."""
    samples = inputs[self.SAMPLES]

    # Add height dimension
    samples = keras.ops.expand_dims(samples, axis=1)
    samples = keras.ops.image.resize(
        samples,
        size=(1, self.duration),
        interpolation="bicubic",
        crop_to_aspect_ratio=False,
        data_format=self.data_format,
    )
    # Remove height dimension
    samples = keras.ops.squeeze(samples, axis=1)
    return samples
compute_output_shape
compute_output_shape(input_shape, *args, **kwargs)

Compute output shape.

Source code in neuralspot_edge/layers/preprocessing/resizing.py
def compute_output_shape(self, input_shape, *args, **kwargs):
    """Compute output shape."""
    output_shape = list(input_shape)
    output_shape[self.data_axis] = self.duration
    return tuple(output_shape)
get_config
get_config()

Serialize the configuration.

Source code in neuralspot_edge/layers/preprocessing/resizing.py
def get_config(self):
    """Serialize the configuration."""
    config = super().get_config()
    config.update(
        duration=self.duration,
        data_format=self.data_format,
    )
    return config

Resizing2D

Resizing2D(height: int, width: int, interpolation: str = 'bicubic', **kwargs)
Source code in neuralspot_edge/layers/preprocessing/resizing.py
def __init__(self, height: int, width: int, interpolation: str = "bicubic", **kwargs):
    """"""
    super().__init__(**kwargs)
    self.height = height
    self.width = width

Functions

augment_samples
augment_samples(inputs) -> keras.KerasTensor

Resize a batch of samples during training.

Source code in neuralspot_edge/layers/preprocessing/resizing.py
def augment_samples(self, inputs) -> keras.KerasTensor:
    """Resize a batch of samples during training."""
    samples = inputs[self.SAMPLES]
    samples = keras.ops.image.resize(
        samples,
        size=(self.height, self.width),
        interpolation="bicubic",
        crop_to_aspect_ratio=False,
        data_format=self.data_format,
    )
    return samples
compute_output_shape
compute_output_shape(input_shape, *args, **kwargs)

Compute output shape.

Source code in neuralspot_edge/layers/preprocessing/resizing.py
def compute_output_shape(self, input_shape, *args, **kwargs):
    """Compute output shape."""
    output_shape = list(input_shape)
    output_shape[self.height_axis] = self.height
    output_shape[self.width_axis] = self.width
    return tuple(output_shape)
get_config
get_config()

Serialize the configuration.

Source code in neuralspot_edge/layers/preprocessing/resizing.py
def get_config(self):
    """Serialize the configuration."""
    config = super().get_config()
    config.update(
        height=self.height,
        width=self.width,
    )
    return config