peal.architectures.module_blocks.ResnetBlock¶
- class peal.architectures.module_blocks.ResnetBlock[source]¶
Bases:
SequentialBasic residual block with two 3x3 convolutions and a skip connection.
The residual branch is conv-(bn)-act-conv-(bn). When
stride > 1the identity path is replaced byAvgPool2d(2)followed by a 1x1 convolution so that shapes match; the sum is followed by a final activation.- Parameters:
input_channels (
int) – Number of input channels.activation (
typeofnn.Module) – Activation class, instantiated without arguments.stride (
int) – Stride of the first convolution (2 downsamples).conv (
typeofnn.Module) – Convolution class (nn.Conv1d/Conv2d/Conv3d).batchnorm (
typeofnn.Module) – Batchnorm class matchingconv; used ifconfig.use_batchnorm.config (
ResnetConfig) – Providesnum_neurons(output channels) anduse_batchnorm.
Notes
The downsampling path always uses
nn.AvgPool2dregardless oftensor_dim.Methods
- __init__(input_channels, activation, stride, conv, batchnorm, config)[source]¶
The __init__ method initializes the ResnetBlock class. :param input_channels: The number of input channels. :param activation: The activation function class. :param stride: The stride of the convolution. :param conv: The convolution class. :param batchnorm: The batchnorm class. :param config: The config of the block.
- Parameters:
input_channels (pydantic.types.PositiveInt)
activation (Type[torch.nn.Module])
stride (pydantic.types.PositiveInt)
conv (Type[torch.nn.Module])
batchnorm (Type[torch.nn.Module])
config (ResnetConfig)