class_docstr: Encoder Network.
  
  Args:
      input_size (tuple[int, int]): Size of input image
      latent_vec_size (int): Size of latent vector z
      num_input_channels (int): Number of input channels in the image
      n_features (int): Number of features per convolution layer
      extra_layers (int): Number of extra layers since the network uses only a single encoder layer by default.
          Defaults to 0.
class_docstr_tok: ["Encoder","Network",".","Args",":","input_size","(","tuple","[","int",",","int","]",")",":","Size","of","input","image","latent_vec_size","(","int",")",":","Size","of","latent","vector","z","num_input_channels","(","int",")",":","Number","of","input","channels","in","the","image","n_features","(","int",")",":","Number","of","features","per","convolution","layer","extra_layers","(","int",")",":","Number","of","extra","layers","since","the","network","uses","only","a","single","encoder","layer","by","default",".","Defaults","to","0","."]
code: def __init__(
      self,
      input_size: tuple[int, int],
      latent_vec_size: int,
      num_input_channels: int,
      n_features: int,
      extra_layers: int = 0,
      add_final_conv_layer: bool = True,
  ) -> None:
      super().__init__()
  
      self.input_layers = nn.Sequential()
      self.input_layers.add_module(
          f"initial-conv-{num_input_channels}-{n_features}",
          nn.Conv2d(
              num_input_channels,
              n_features,
              kernel_size=4,
              stride=2,
              padding=4,
              bias=False,
          ),
      )
      self.input_layers.add_module(
          f"initial-relu-{n_features}", nn.LeakyReLU(0.2, inplace=True)
      )
  
      # Extra Layers
      self.extra_layers = nn.Sequential()
  
      for layer in range(extra_layers):
          self.extra_layers.add_module(
              f"extra-layers-{layer}-{n_features}-conv",
              nn.Conv2d(
                  n_features,
                  n_features,
                  kernel_size=3,
                  stride=1,
                  padding=1,
                  bias=False,
              ),
          )
          self.extra_layers.add_module(
              f"extra-layers-{layer}-{n_features}-batchnorm",
              nn.BatchNorm2d(n_features),
          )
          self.extra_layers.add_module(
              f"extra-layers-{layer}-{n_features}-relu",
              nn.LeakyReLU(0.2, inplace=True),
          )
  
      # Create pyramid features to reach latent vector
      self.pyramid_features = nn.Sequential()
      pyramid_dim = (
          min(*input_size) // 2
      )  # Use the smaller dimension to create pyramid.
      while pyramid_dim > 4:
          in_features = n_features
          out_features = n_features * 2
          self.pyramid_features.add_module(
              f"pyramid-{in_features}-{out_features}-conv",
              nn.Conv2d(
                  in_features,
                  out_features,
                  kernel_size=4,
                  stride=2,
                  padding=1,
                  bias=False,
              ),
          )
          self.pyramid_features.add_module(
              f"pyramid-{out_features}-batchnorm",
              nn.BatchNorm2d(out_features),
          )
          self.pyramid_features.add_module(
              f"pyramid-{out_features}-relu",
              nn.LeakyReLU(0.2, inplace=True),
          )
          n_features = out_features
          pyramid_dim = pyramid_dim // 2
  
      # Final conv
      if add_final_conv_layer:
          self.final_conv_layer = nn.Conv2d(
              n_features,
              latent_vec_size,
              kernel_size=4,
              stride=1,
              padding=0,
              bias=False,
          )
  
imports: from __future__ import annotations
  import math
  import torch
  from torch import Tensor, nn
  from anomalib.data.utils.image import pad_nextpow2
label_desc: Use image node_id 1 to create a new Encoder object from inherited base classes: nn with example: obj = Encoder(input_size, latent_vec_size, num_input_channels, n_features, extra_layers, add_final_conv_layer)