class_docstr: LoFTR transformer module from: https://arxiv.org/pdf/2104.00680.pdf
  Canonical implementations at: https://github.com/zju3dv/LoFTR/blob/master/src/loftr/loftr_module/transformer.py
class_docstr_tok: ["LoFTR","transformer","module","from",":","https",":","\/\/arxiv.org\/pdf\/2104.00680.pdf","Canonical","implementations","at",":","https",":","\/\/github.com\/zju3dv\/LoFTR\/blob\/master\/src\/loftr\/loftr_module\/transformer.py"]
code: def __init__(
      self,
      *,
      dim_model: int,
      num_heads: int,
      attention_module: Callable[..., nn.Module] = LinearAttention,
  ) -> None:
      super().__init__()
  
      self.attention_op = attention_module()
  
      if not isinstance(
          self.attention_op, (LinearAttention, SoftmaxAttention)
      ):
          raise ValueError(
              f"attention_module must be an instance of LinearAttention or SoftmaxAttention. Got {type(self.attention_op)}"
          )
  
      self.dim_head = dim_model // num_heads
      self.num_heads = num_heads
  
      # multi-head attention
      self.query_proj = nn.Linear(dim_model, dim_model, bias=False)
      self.key_proj = nn.Linear(dim_model, dim_model, bias=False)
      self.value_proj = nn.Linear(dim_model, dim_model, bias=False)
      self.merge = nn.Linear(dim_model, dim_model, bias=False)
  
      # feed forward network
      self.ffn = nn.Sequential(
          nn.Linear(dim_model * 2, dim_model * 2, bias=False),
          nn.ReLU(),
          nn.Linear(dim_model * 2, dim_model, bias=False),
      )
  
      # norm layers
      self.attention_norm = nn.LayerNorm(dim_model)
      self.ffn_norm = nn.LayerNorm(dim_model)
  
imports: import math
  from functools import partial
  from typing import Callable, Dict, Iterable, List, Optional, Tuple
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torchvision.models.optical_flow.raft
  from torch import Tensor
  from torchvision.models._api import register_model, Weights, WeightsEnum
  from torchvision.models._utils import handle_legacy_interface
  from torchvision.models.optical_flow._utils import grid_sample, make_coords_grid, upsample_flow
  from torchvision.ops import Conv2dNormActivation
  from torchvision.prototype.transforms._presets import StereoMatching
label_desc: Use image node_id 1 to create a new LocalFeatureEncoderLayer object from inherited base classes: nn with example: obj = LocalFeatureEncoderLayer()