class_docstr: The correlation block.
  
  Creates a correlation pyramid with ``num_levels`` levels from the outputs of the feature encoder,
  and then indexes from this pyramid to create correlation features.
  The "indexing" of a given centroid pixel x' is done by concatenating its surrounding neighbors that
  are within a ``radius``, according to the infinity norm (see paper section 3.2).
  Note: typo in the paper, it should be infinity norm, not 1-norm.
class_docstr_tok: ["The","correlation","block",".","Creates","a","correlation","pyramid","with","``","num_levels","``","levels","from","the","outputs","of","the","feature","encoder",",","and","then","indexes","from","this","pyramid","to","create","correlation","features",".","The","``","indexing","''","of","a","given","centroid","pixel","x","'","is","done","by","concatenating","its","surrounding","neighbors","that","are","within","a","``","radius","``",",","according","to","the","infinity","norm","(","see","paper","section","3.2",")",".","Note",":","typo","in","the","paper",",","it","should","be","infinity","norm",",","not","1-norm","."]
docstr: Build the correlation pyramid from two feature maps.
  
  The correlation volume is first computed as the dot product of each pair (pixel_in_fmap1, pixel_in_fmap2)
  The last 2 dimensions of the correlation volume are then pooled num_levels times at different resolutions
  to build the correlation pyramid.
docstr_tok: ["Build","the","correlation","pyramid","from","two","feature","maps",".","The","correlation","volume","is","first","computed","as","the","dot","product","of","each","pair","(","pixel_in_fmap1",",","pixel_in_fmap2",")","The","last","2","dimensions","of","the","correlation","volume","are","then","pooled","num_levels","times","at","different","resolutions","to","build","the","correlation","pyramid","."]
code: def build_pyramid(self, fmap1, fmap2):
      """Build the correlation pyramid from two feature maps.
  
      The correlation volume is first computed as the dot product of each pair (pixel_in_fmap1, pixel_in_fmap2)
      The last 2 dimensions of the correlation volume are then pooled num_levels times at different resolutions
      to build the correlation pyramid.
      """
  
      if fmap1.shape != fmap2.shape:
          raise ValueError(
              f"Input feature maps should have the same shape, instead got {fmap1.shape} (fmap1.shape) != {fmap2.shape} (fmap2.shape)"
          )
  
      # Explaining min_fmap_size below: the fmaps are down-sampled (num_levels - 1) times by a factor of 2.
      # The last corr_volume most have at least 2 values (hence the 2* factor), otherwise grid_sample() would
      # produce nans in its output.
      min_fmap_size = 2 * (2 ** (self.num_levels - 1))
      if any(
          fmap_size < min_fmap_size for fmap_size in fmap1.shape[-2:]
      ):
          raise ValueError(
              "Feature maps are too small to be down-sampled by the correlation pyramid. "
              f"H and W of feature maps should be at least {min_fmap_size}; got: {fmap1.shape[-2:]}. "
              "Remember that input images to the model are downsampled by 8, so that means their "
              f"dimensions should be at least 8 * {min_fmap_size} = {8 * min_fmap_size}."
          )
  
      corr_volume = self._compute_corr_volume(fmap1, fmap2)
  
      (
          batch_size,
          h,
          w,
          num_channels,
          _,
          _,
      ) = corr_volume.shape  # _, _ = h, w
      corr_volume = corr_volume.reshape(
          batch_size * h * w, num_channels, h, w
      )
      self.corr_pyramid = [corr_volume]
      for _ in range(self.num_levels - 1):
          corr_volume = F.avg_pool2d(
              corr_volume, kernel_size=2, stride=2
          )
          self.corr_pyramid.append(corr_volume)
  
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 2 for calling the CorrBlock obj's underlying member method code with example usage: obj.build_pyramid(fmap1, fmap2) without return types