Residual layer#

class ResidualBlock(input_dim, output_dim, hidden_dim, spectral_norm=False, activation=ReLU())[source]#

Bases: Module

Residual block base class. Implementation of a residual block.

See also

Original reference: He, Kaiming, et al. Deep residual learning for image recognition. Proceedings of the IEEE conference on computer vision and pattern recognition. 2016.. DOI: https://arxiv.org/pdf/1512.03385.pdf.

Initializes the ResidualBlock module.

Parameters:
  • input_dim (int) – Dimension of the input to pass to the feedforward linear layer.

  • output_dim (int) – Dimension of the output from the residual layer.

  • hidden_dim (int) – Hidden dimension for mapping the input (first block).

  • spectral_norm (bool) – Apply spectral normalization to feedforward layers, defaults to False.

  • activation (torch.nn.Module) – Cctivation function after first block.

forward(x)[source]#

Forward pass for residual block layer.

Parameters:

x (torch.Tensor) – Input tensor for the residual layer.

Returns:

Output tensor for the residual layer.

Return type:

torch.Tensor