qumphy.models.inception1d module

File: qumphy/models/inception1d.py Project: 22HLT01 QUMPHY Contact: oskar.pfeffer@ptb.de Gitlab: https://gitlab.com/qumphy Description: InceptionTime-based 1D convolutional neural network.

class qumphy.models.inception1d.Inception1d(*args: Any, **kwargs: Any)[source]

Bases: Module

inception time architecture

forward(x)[source]

Run a forward pass through the model.

Parameters:

x (torch.Tensor) – Input tensor of shape (batch_size, input_channels, sequence_length).

Returns:

Model output tensor of shape (batch_size, num_classes).

Return type:

torch.Tensor

get_layer_groups()[source]

Get grouped layers for model training.

Returns:

Layer groups containing part of the backbone and the model head. If the depth is less than or equal to 3, only the model head is returned.

Return type:

tuple or nn.Module

get_output_layer()[source]

Get the output layer of the model.

Returns:

Final output layer of the model head.

Return type:

nn.Module

set_output_layer(x)[source]

Set the output layer of the model.

Parameters:

x (nn.Module) – New output layer.

Returns:

The function modifies the output layer in place.

Return type:

None

class qumphy.models.inception1d.InceptionBackbone(*args: Any, **kwargs: Any)[source]

Bases: Module

Backbone of the 1D Inception architecture.

The backbone stacks multiple Inception blocks and optionally applies residual shortcut connections every three blocks.

forward(x)[source]

Run a forward pass through the Inception backbone.

Parameters:

x (torch.Tensor) – Input tensor of shape (batch_size, input_channels, sequence_length).

Returns:

Output features from the stacked Inception blocks.

Return type:

torch.Tensor

class qumphy.models.inception1d.InceptionBlock1d(*args: Any, **kwargs: Any)[source]

Bases: Module

One-dimensional Inception block.

The block applies several convolutions with different kernel sizes and concatenates their outputs with a max-pooling branch. :param ni: Number of input channels. :type ni: int :param nb_filters: Number of filters used in each convolution branch. :type nb_filters: int :param kss: List of kernel sizes used by the convolution branches. :type kss: list :param stride: Stride used in the bottleneck and pooling branches. :type stride: int :param act: Activation function name. This parameter is currently not used. :type act: str :param bottleneck_size: Number of filters used in the bottleneck convolution. If 0, no

bottleneck convolution is applied.

forward(x)[source]

Run a forward pass through the Inception block.

Parameters:

x (torch.Tensor) – Input tensor of shape (batch_size, channels, sequence_length).

Returns:

Output tensor after concatenation, batch normalization, and ReLU.

Return type:

torch.Tensor

class qumphy.models.inception1d.Shortcut1d(*args: Any, **kwargs: Any)[source]

Bases: Module

Residual shortcut connection for 1D convolutional features.

forward(inp, out)[source]

Apply the residual shortcut connection.

Parameters:
  • inp (torch.Tensor) – Input tensor used for the shortcut branch.

  • out (torch.Tensor) – Output tensor from the main branch.

Returns:

Result of adding the shortcut branch to the main branch and applying ReLU activation.

Return type:

torch.Tensor

qumphy.models.inception1d.conv(in_planes, out_planes, kernel_size=3, stride=1)[source]

Create a 1D convolutional layer with padding.

Parameters:
  • in_planes (int) – Number of input channels.

  • out_planes (int) – Number of output channels.

  • kernel_size (int) – Size of the convolution kernel.

  • stride (int) – Stride of the convolution.

Returns:

One-dimensional convolutional layer.

Return type:

nn.Conv1d

qumphy.models.inception1d.inception1d(**kwargs)[source]

Construct an Inception1d model.

Parameters:

**kwargs – Keyword arguments passed to Inception1d.

Returns:

Initialized Inception1d model.

Return type:

Inception1d

qumphy.models.inception1d.noop(x)[source]

Return the input unchanged.

Parameters:

x (torch.Tensor) – Input tensor.

Returns:

Same tensor as the input.

Return type:

torch.Tensor