Skip to content

convolutional

Convolutional Layers API

This module provides classes to build convolutional layers.

Functions:

  • conv1d

    1D convolutional layer using 2D convolutional layer

  • conv2d

    2D convolutional layer

Please refer to Keras Convolutional Layers for additional layers.

Functions

conv2d

conv2d(filters: int, kernel_size: int | tuple[int, int] = 3, strides: int | tuple[int, int] = 1, padding: str = 'same', use_bias: bool = False, groups: int = 1, dilation: int = 1, name: str | None = None) -> keras.Layer

2D convolutional layer

Parameters:

  • filters (int) –

    Number of filters

  • kernel_size (int | tuple[int, int], default: 3 ) –

    Kernel size. Defaults to 3.

  • strides (int | tuple[int, int], default: 1 ) –

    Stride length. Defaults to 1.

  • padding (str, default: 'same' ) –

    Padding. Defaults to "same".

  • use_bias (bool, default: False ) –

    Add bias. Defaults to False.

  • groups (int, default: 1 ) –

    Number of groups. Defaults to 1.

  • dilation (int, default: 1 ) –

    Dilation rate. Defaults to 1.

  • name (str | None, default: None ) –

    Layer name. Defaults to None.

Returns:

  • Layer

    keras.Layer: Functional 2D conv layer

Source code in neuralspot_edge/layers/convolutional.py
def conv2d(
    filters: int,
    kernel_size: int | tuple[int, int] = 3,
    strides: int | tuple[int, int] = 1,
    padding: str = "same",
    use_bias: bool = False,
    groups: int = 1,
    dilation: int = 1,
    name: str | None = None,
) -> keras.Layer:
    """2D convolutional layer

    Args:
        filters (int): Number of filters
        kernel_size (int | tuple[int, int], optional): Kernel size. Defaults to 3.
        strides (int | tuple[int, int], optional): Stride length. Defaults to 1.
        padding (str, optional): Padding. Defaults to "same".
        use_bias (bool, optional): Add bias. Defaults to False.
        groups (int, optional): Number of groups. Defaults to 1.
        dilation (int, optional): Dilation rate. Defaults to 1.
        name (str | None, optional): Layer name. Defaults to None.

    Returns:
        keras.Layer: Functional 2D conv layer
    """
    name = name + ".conv" if name else None
    return keras.layers.Conv2D(
        filters,
        kernel_size=kernel_size,
        strides=strides,
        padding=padding,
        use_bias=use_bias,
        groups=groups,
        dilation_rate=dilation,
        kernel_initializer="he_normal",
        name=name,
    )

conv1d

conv1d(filters: int, kernel_size: int = 3, strides: int = 1, padding: str = 'same', use_bias: bool = False, name: str | None = None) -> keras.Layer

1D convolutional layer using 2D convolutional layer

Parameters:

  • filters (int) –

    Number of filters

  • kernel_size (int, default: 3 ) –

    Kernel size. Defaults to 3.

  • strides (int, default: 1 ) –

    Stride length. Defaults to 1.

  • padding (str, default: 'same' ) –

    Padding. Defaults to "same".

  • use_bias (bool, default: False ) –

    Add bias. Defaults to False.

  • name (str | None, default: None ) –

    Layer name. Defaults to None.

Returns:

  • Layer

    keras.Layer: Functional 1D conv layer

Source code in neuralspot_edge/layers/convolutional.py
def conv1d(
    filters: int,
    kernel_size: int = 3,
    strides: int = 1,
    padding: str = "same",
    use_bias: bool = False,
    name: str | None = None,
) -> keras.Layer:
    """1D convolutional layer using 2D convolutional layer

    Args:
        filters (int): Number of filters
        kernel_size (int, optional): Kernel size. Defaults to 3.
        strides (int, optional): Stride length. Defaults to 1.
        padding (str, optional): Padding. Defaults to "same".
        use_bias (bool, optional): Add bias. Defaults to False.
        name (str | None, optional): Layer name. Defaults to None.

    Returns:
        keras.Layer: Functional 1D conv layer
    """
    name = name + ".conv" if name else None
    return keras.layers.Conv2D(
        filters,
        kernel_size=(1, kernel_size),
        strides=(1, strides),
        padding=padding,
        use_bias=use_bias,
        kernel_initializer="he_normal",
        name=name,
    )