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_directions: List[str],
      attention_module: Callable[..., nn.Module] = LinearAttention,
  ) -> None:
      super(LocalFeatureTransformer, self).__init__()
  
      self.attention_module = attention_module
      self.attention_directions = attention_directions
      for direction in attention_directions:
          if direction not in ["self", "cross"]:
              raise ValueError(
                  f"Attention direction {direction} unsupported. LocalFeatureTransformer accepts only ``attention_type`` in ``[self, cross]``."
              )
  
      self.layers = nn.ModuleList(
          [
              LocalFeatureEncoderLayer(
                  dim_model=dim_model,
                  num_heads=num_heads,
                  attention_module=attention_module,
              )
              for _ in attention_directions
          ]
      )
  
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 LocalFeatureTransformer object from inherited base classes: nn with example: obj = LocalFeatureTransformer()