class_docstr: Implement Adaptive 2D positional encoder for SATRN, see `SATRN.
  
  <https://arxiv.org/abs/1910.04396>`_ Modified from
  https://github.com/Media-Smart/vedastr Licensed under the Apache License,
  Version 2.0 (the "License");
  
  Args:
      d_hid (int): Dimensions of hidden layer. Defaults to 512.
      n_height (int): Max height of the 2D feature output. Defaults to 100.
      n_width (int): Max width of the 2D feature output. Defaults to 100.
      dropout (float): Dropout rate. Defaults to 0.1.
      init_cfg (dict or list[dict], optional): Initialization configs.
          Defaults to [dict(type='Xavier', layer='Conv2d')]
code: def __init__(
      self,
      d_hid: int = 512,
      n_height: int = 100,
      n_width: int = 100,
      dropout: float = 0.1,
      init_cfg: Optional[Union[Dict, List[Dict]]] = [
          dict(type="Xavier", layer="Conv2d")
      ],
  ) -> None:
      super().__init__(init_cfg=init_cfg)
  
      h_position_encoder = self._get_sinusoid_encoding_table(
          n_height, d_hid
      )
      h_position_encoder = h_position_encoder.transpose(0, 1)
      h_position_encoder = h_position_encoder.view(
          1, d_hid, n_height, 1
      )
  
      w_position_encoder = self._get_sinusoid_encoding_table(
          n_width, d_hid
      )
      w_position_encoder = w_position_encoder.transpose(0, 1)
      w_position_encoder = w_position_encoder.view(1, d_hid, 1, n_width)
  
      self.register_buffer("h_position_encoder", h_position_encoder)
      self.register_buffer("w_position_encoder", w_position_encoder)
  
      self.h_scale = self._scale_factor_generate(d_hid)
      self.w_scale = self._scale_factor_generate(d_hid)
      self.pool = nn.AdaptiveAvgPool2d(1)
      self.dropout = nn.Dropout(p=dropout)
  
imports: from typing import Dict, List, Optional, Union
  import numpy
  import torch
  import torch.nn
  from mmcv.cnn import ConvModule
  from mmengine.model import BaseModule
  from torch import Tensor
  from mmocr.models.common import MultiHeadAttention
label_desc: Use image node_id 1 to create a new Adaptive2DPositionalEncoding object from inherited base classes: BaseModule with example: obj = Adaptive2DPositionalEncoding(d_hid, n_height, n_width, dropout, init_cfg)