qumphy.models.xresnet1d module

File: qumphy/models/xresnet1d.py Project: 22HLT01 QUMPHY Contact: oskar.pfeffer@ptb.de Gitlab: https://gitlab.com/qumphy Description: One-dimensional XResNet and XBotNet model architectures.

qumphy.models.xresnet1d.BatchNorm(nf, norm_type=NormType.Batch, **kwargs)[source]

Create a batch normalization layer.

Parameters:
  • nf (int) – Number of input features.

  • norm_type (NormType) – Type of batch normalization initialization.

  • **kwargs – Additional keyword arguments passed to the batch normalization layer.

Returns:

Initialized batch normalization layer.

Return type:

nn.Module

class qumphy.models.xresnet1d.ConvLayer(*args: Any, **kwargs: Any)[source]

Bases: Sequential

One-dimensional convolutional layer with optional activation and normalization.

class qumphy.models.xresnet1d.MHSA1d(*args: Any, **kwargs: Any)[source]

Bases: Module

Multi-head self-attention block for one-dimensional inputs.

forward(x)[source]

Run a forward pass through the attention block.

Parameters:

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

Returns:

Output tensor with the same shape as the input.

Return type:

torch.Tensor

class qumphy.models.xresnet1d.NormType(value)

Bases: Enum

An enumeration.

Batch = 1
BatchZero = 2
class qumphy.models.xresnet1d.ResBlock(*args: Any, **kwargs: Any)[source]

Bases: Module

Residual block for one-dimensional XResNet models.

forward(x)[source]

Run a forward pass through the residual block.

Parameters:

x (torch.Tensor) – Input tensor.

Returns:

Output tensor after the residual connection and activation.

Return type:

torch.Tensor

class qumphy.models.xresnet1d.ResBlock_dropout(*args: Any, **kwargs: Any)[source]

Bases: Module

Residual block with Monte Carlo dropout for one-dimensional XResNet models.

forward(x)[source]

Run a forward pass through the dropout residual block.

Parameters:

x (torch.Tensor) – Input tensor.

Returns:

Output tensor after the residual connection and activation.

Return type:

torch.Tensor

class qumphy.models.xresnet1d.XResNet1d(*args: Any, **kwargs: Any)[source]

Bases: Sequential

Configurable one-dimensional XResNet model.

get_layer_groups()[source]

Get layer groups of the model.

Returns:

Tuple containing selected feature layers and the model head.

Return type:

tuple

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.xresnet1d.XResNet1d101(*args: Any, **kwargs: Any)[source]

Bases: XResNet1d

XResNet1d-101 model.

class qumphy.models.xresnet1d.XResNet1d50(*args: Any, **kwargs: Any)[source]

Bases: XResNet1d

XResNet1d-50 model.

qumphy.models.xresnet1d.init_cnn(m)[source]

Initialize CNN module weights recursively.

Parameters:

m (nn.Module) – Module whose children should be initialized.

Returns:

The function modifies the module weights in place.

Return type:

None

qumphy.models.xresnet1d.init_default(m, func=torch.nn.init.kaiming_normal_)[source]

Initialize module weights and bias.

Parameters:
  • m (nn.Module) – Module whose weights and bias should be initialized.

  • func (callable) – Initialization function applied to the module weights.

Returns:

Initialized module.

Return type:

nn.Module

qumphy.models.xresnet1d.xbotnet1d101(**kwargs)[source]

Create an XBotNet1d-101 model with multi-head self-attention.

Parameters:

**kwargs – Additional keyword arguments passed to XResNet1d.

Returns:

Initialized XBotNet1d-101 model.

Return type:

XResNet1d

qumphy.models.xresnet1d.xbotnet1d152(**kwargs)[source]

Create an XBotNet1d-152 model with multi-head self-attention.

Parameters:

**kwargs – Additional keyword arguments passed to XResNet1d.

Returns:

Initialized XBotNet1d-152 model.

Return type:

XResNet1d

qumphy.models.xresnet1d.xbotnet1d50(**kwargs)[source]

Create an XBotNet1d-50 model with multi-head self-attention.

Parameters:

**kwargs – Additional keyword arguments passed to XResNet1d.

Returns:

Initialized XBotNet1d-50 model.

Return type:

XResNet1d

qumphy.models.xresnet1d.xresnet1d101(**kwargs)[source]

Create an XResNet1d-101 model.

Parameters:

**kwargs – Additional keyword arguments passed to XResNet1d.

Returns:

Initialized XResNet1d-101 model.

Return type:

XResNet1d

qumphy.models.xresnet1d.xresnet1d152(**kwargs)[source]

Create an XResNet1d-152 model.

Parameters:

**kwargs – Additional keyword arguments passed to XResNet1d.

Returns:

Initialized XResNet1d-152 model.

Return type:

XResNet1d

qumphy.models.xresnet1d.xresnet1d18(**kwargs)[source]

Create an XResNet1d-18 model.

Parameters:

**kwargs – Additional keyword arguments passed to XResNet1d.

Returns:

Initialized XResNet1d-18 model.

Return type:

XResNet1d

qumphy.models.xresnet1d.xresnet1d18_deep(**kwargs)[source]

Create a deep XResNet1d-18 model.

Parameters:

**kwargs – Additional keyword arguments passed to XResNet1d.

Returns:

Initialized deep XResNet1d-18 model.

Return type:

XResNet1d

qumphy.models.xresnet1d.xresnet1d18_deeper(**kwargs)[source]

Create a deeper XResNet1d-18 model.

Parameters:

**kwargs – Additional keyword arguments passed to XResNet1d.

Returns:

Initialized deeper XResNet1d-18 model.

Return type:

XResNet1d

qumphy.models.xresnet1d.xresnet1d34(**kwargs)[source]

Create an XResNet1d-34 model.

Parameters:

**kwargs – Additional keyword arguments passed to XResNet1d.

Returns:

Initialized XResNet1d-34 model.

Return type:

XResNet1d

qumphy.models.xresnet1d.xresnet1d34_deep(**kwargs)[source]

Create a deep XResNet1d-34 model.

Parameters:

**kwargs – Additional keyword arguments passed to XResNet1d.

Returns:

Initialized deep XResNet1d-34 model.

Return type:

XResNet1d

qumphy.models.xresnet1d.xresnet1d34_deeper(**kwargs)[source]

Create a deeper XResNet1d-34 model.

Parameters:

**kwargs – Additional keyword arguments passed to XResNet1d.

Returns:

Initialized deeper XResNet1d-34 model.

Return type:

XResNet1d

qumphy.models.xresnet1d.xresnet1d50(**kwargs)[source]

Create an XResNet1d-50 model.

Parameters:

**kwargs – Additional keyword arguments passed to XResNet1d.

Returns:

Initialized XResNet1d-50 model.

Return type:

XResNet1d

qumphy.models.xresnet1d.xresnet1d50_MCD(**kwargs)[source]

Create an XResNet1d-50 model with Monte Carlo dropout.

Parameters:

**kwargs – Additional keyword arguments passed to XResNet1d.

Returns:

Initialized XResNet1d-50 model with Monte Carlo dropout.

Return type:

XResNet1d

qumphy.models.xresnet1d.xresnet1d50_deep(**kwargs)[source]

Create a deep XResNet1d-50 model.

Parameters:

**kwargs – Additional keyword arguments passed to XResNet1d.

Returns:

Initialized deep XResNet1d-50 model.

Return type:

XResNet1d

qumphy.models.xresnet1d.xresnet1d50_deeper(**kwargs)[source]

Create a deeper XResNet1d-50 model.

Parameters:

**kwargs – Additional keyword arguments passed to XResNet1d.

Returns:

Initialized deeper XResNet1d-50 model.

Return type:

XResNet1d