class_docstr: ## ResNet Model
  
  This is a the base of the resnet model without
  the final linear layer and softmax for classification.
  
  The resnet is made of stacked [residual blocks](#residual_block) or
  [bottleneck residual blocks](#bottleneck_residual_block).
  The feature map size is halved after a few blocks with a block of stride length $2$.
  The number of channels is increased when the feature map size is reduced.
  Finally the feature map is average pooled to get a vector representation.
class_docstr_tok: ["#","#","ResNet","Model","This","is","a","the","base","of","the","resnet","model","without","the","final","linear","layer","and","softmax","for","classification",".","The","resnet","is","made","of","stacked","[","residual","blocks","]","(","#","residual_block",")","or","[","bottleneck","residual","blocks","]","(","#","bottleneck_residual_block",")",".","The","feature","map","size","is","halved","after","a","few","blocks","with","a","block","of","stride","length","$","2","$",".","The","number","of","channels","is","increased","when","the","feature","map","size","is","reduced",".","Finally","the","feature","map","is","average","pooled","to","get","a","vector","representation","."]
docstr: * `x` has shape `[batch_size, img_channels, height, width]`
docstr_tok: ["*","`","x","`","has","shape","`","[","batch_size",",","img_channels",",","height",",","width","]","`"]
code: def forward(self, x: torch.Tensor):
      """
      * `x` has shape `[batch_size, img_channels, height, width]`
      """
  
      # Initial convolution and batch normalization
      x = self.bn(self.conv(x))
      # Residual (or bottleneck) blocks
      x = self.blocks(x)
      # Change `x` from shape `[batch_size, channels, h, w]` to `[batch_size, channels, h * w]`
      x = x.view(x.shape[0], x.shape[1], -1)
      # Global average pooling
      return x.mean(dim=-1)
  
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 ResNetBase obj's underlying member method code with example usage: obj.forward(x) and returns: x