class_docstr: The feature encoder, used both as the actual feature encoder, and as the context encoder.
  
  It must downsample its input by 8.
class_docstr_tok: ["The","feature","encoder",",","used","both","as","the","actual","feature","encoder",",","and","as","the","context","encoder",".","It","must","downsample","its","input","by","8","."]
code: def __init__(
      self,
      *,
      block=ResidualBlock,
      layers=(64, 64, 96, 128, 256),
      strides=(2, 1, 2, 2),
      norm_layer=nn.BatchNorm2d,
  ):
      super().__init__()
  
      if len(layers) != 5:
          raise ValueError(
              f"The expected number of layers is 5, instead got {len(layers)}"
          )
  
      # See note in ResidualBlock for the reason behind bias=True
      self.convnormrelu = Conv2dNormActivation(
          3,
          layers[0],
          norm_layer=norm_layer,
          kernel_size=7,
          stride=strides[0],
          bias=True,
      )
  
      self.layer1 = self._make_2_blocks(
          block,
          layers[0],
          layers[1],
          norm_layer=norm_layer,
          first_stride=strides[1],
      )
      self.layer2 = self._make_2_blocks(
          block,
          layers[1],
          layers[2],
          norm_layer=norm_layer,
          first_stride=strides[2],
      )
      self.layer3 = self._make_2_blocks(
          block,
          layers[2],
          layers[3],
          norm_layer=norm_layer,
          first_stride=strides[3],
      )
  
      self.conv = nn.Conv2d(layers[3], layers[4], kernel_size=1)
  
      for m in self.modules():
          if isinstance(m, nn.Conv2d):
              nn.init.kaiming_normal_(
                  m.weight, mode="fan_out", nonlinearity="relu"
              )
          elif isinstance(m, (nn.BatchNorm2d, nn.InstanceNorm2d)):
              if m.weight is not None:
                  nn.init.constant_(m.weight, 1)
              if m.bias is not None:
                  nn.init.constant_(m.bias, 0)
  
      num_downsamples = len(list(filter(lambda s: s == 2, strides)))
      self.output_dim = layers[-1]
      self.downsample_factor = 2**num_downsamples
  
imports: from typing import List, Optional
  import torch
  import torch.nn
  import torch.nn.functional
  from torch import Tensor
  from torch.nn.modules.batchnorm import BatchNorm2d
  from torch.nn.modules.instancenorm import InstanceNorm2d
  from torchvision.ops import Conv2dNormActivation
  from ...transforms._presets import OpticalFlow
  from ...utils import _log_api_usage_once
  from .._api import register_model, Weights, WeightsEnum
  from .._utils import handle_legacy_interface
  from ._utils import grid_sample, make_coords_grid, upsample_flow
label_desc: Use image node_id 1 to create a new FeatureEncoder object from inherited base classes: nn with example: obj = FeatureEncoder()