class_docstr: <a id="residual_block"></a>
  
  ## Residual Block
  
  This implements the residual block described in the paper.
  It has two $3       imes 3$ convolution layers.
  
  ![Residual Block](residual_block.svg)
  
  The first convolution layer maps from `in_channels` to `out_channels`,
  where the `out_channels` is higher than `in_channels` when we reduce the
  feature map size with a stride length greater than $1$.
  
  The second convolution layer maps from `out_channels` to `out_channels` and
  always has a stride length of 1.
  
  Both convolution layers are followed by batch normalization.
class_docstr_tok: ["<","a","id=","''","residual_block","''",">","<","\/a",">","#","#","Residual","Block","This","implements","the","residual","block","described","in","the","paper",".","It","has","two","$","3","imes","3","$","convolution","layers",".","!","[","Residual","Block","]","(","residual_block.svg",")","The","first","convolution","layer","maps","from","`","in_channels","`","to","`","out_channels","`",",","where","the","`","out_channels","`","is","higher","than","`","in_channels","`","when","we","reduce","the","feature","map","size","with","a","stride","length","greater","than","$","1","$",".","The","second","convolution","layer","maps","from","`","out_channels","`","to","`","out_channels","`","and","always","has","a","stride","length","of","1",".","Both","convolution","layers","are","followed","by","batch","normalization","."]
docstr: * `x` is the input of shape `[batch_size, in_channels, height, width]`
docstr_tok: ["*","`","x","`","is","the","input","of","shape","`","[","batch_size",",","in_channels",",","height",",","width","]","`"]
code: def forward(self, x: torch.Tensor):
      """
      * `x` is the input of shape `[batch_size, in_channels, height, width]`
      """
      # Get the shortcut connection
      shortcut = self.shortcut(x)
      # First convolution and activation
      x = self.act1(self.bn1(self.conv1(x)))
      # Second convolution
      x = self.bn2(self.conv2(x))
      # Activation function after adding the shortcut
      return self.act2(x + shortcut)
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/resnet/__init__.py
imports: from typing import List, Optional
  import torch
  from torch import nn
  from labml_helpers.module import Module
label_desc: Use image node_id 2 for calling the ResidualBlock obj's underlying member method code with example usage: obj.forward(x) and returns: self