class_docstr: A PyTorch implementation of `SVTR: Scene Text Recognition with a Single
  Visual Model <https://arxiv.org/abs/2205.00159>`_
  
  Code is partially modified from https://github.com/PaddlePaddle/PaddleOCR.
  
  Args:
      img_size (Tuple[int, int], optional): The expected input image shape.
          Defaults to [32, 100].
      in_channels (int, optional): The num of input channels. Defaults to 3.
      embed_dims (Tuple[int, int, int], optional): Number of input channels.
          Defaults to [64, 128, 256].
      depth (Tuple[int, int, int], optional):
          The number of MixingBlock at each stage. Defaults to [3, 6, 3].
      num_heads (Tuple[int, int, int], optional): Number of attention heads.
          Defaults to [2, 4, 8].
      mixer_types (Tuple[str], optional): Mixing type in a MixingBlock.
          Defaults to ['Local']*6+['Global']*6.
      window_size (Tuple[Tuple[int, int]], optional):
          The height and width of the window at eeach stage.
          Defaults to [[7, 11], [7, 11], [7, 11]].
      merging_types (str, optional): The way of downsample in MergingBlock.
          Defaults to 'Conv'.
      mlp_ratio (int, optional): Ratio of hidden features to input in MLP.
          Defaults to 4.
      qkv_bias (bool, optional):
          Whether to add bias for qkv in attention modules. Defaults to True.
      qk_scale (float, optional): A scaling factor. Defaults to None.
      drop_rate (float, optional): Probability of an element to be zeroed.
          Defaults to 0.0.
      last_drop (float, optional): cfg of dropout at last stage.
          Defaults to 0.1.
      attn_drop_rate (float, optional): _description_. Defaults to 0..
      drop_path_rate (float, optional): stochastic depth rate.
          Defaults to 0.1.
      out_channels (int, optional): The num of output channels in backone.
          Defaults to 192.
      max_seq_len (int, optional): Maximum output sequence length :math:`T`.
          Defaults to 25.
      num_layers (int, optional): The num of conv in PatchEmbedding.
          Defaults to 2.
      prenorm (bool, optional): Whether to place the MixingBlock before norm.
          Defaults to True.
      init_cfg (dict or list[dict], optional): Initialization configs.
          Defaults to None.
class_docstr_tok: ["A","PyTorch","implementation","of","`","SVTR",":","Scene","Text","Recognition","with","a","Single","Visual","Model","<","https",":","\/\/arxiv.org\/abs\/2205.00159",">","`","_","Code","is","partially","modified","from","https",":","\/\/github.com\/PaddlePaddle\/PaddleOCR",".","Args",":","img_size","(","Tuple","[","int",",","int","]",",","optional",")",":","The","expected","input","image","shape",".","Defaults","to","[","32",",","100","]",".","in_channels","(","int",",","optional",")",":","The","num","of","input","channels",".","Defaults","to","3.","embed_dims","(","Tuple","[","int",",","int",",","int","]",",","optional",")",":","Number","of","input","channels",".","Defaults","to","[","64",",","128",",","256","]",".","depth","(","Tuple","[","int",",","int",",","int","]",",","optional",")",":","The","number","of","MixingBlock","at","each","stage",".","Defaults","to","[","3",",","6",",","3","]",".","num_heads","(","Tuple","[","int",",","int",",","int","]",",","optional",")",":","Number","of","attention","heads",".","Defaults","to","[","2",",","4",",","8","]",".","mixer_types","(","Tuple","[","str","]",",","optional",")",":","Mixing","type","in","a","MixingBlock",".","Defaults","to","[","'Local","'","]","*","6+","[","'Global","'","]","*","6.","window_size","(","Tuple","[","Tuple","[","int",",","int","]","]",",","optional",")",":","The","height","and","width","of","the","window","at","eeach","stage",".","Defaults","to","[","[","7",",","11","]",",","[","7",",","11","]",",","[","7",",","11","]","]",".","merging_types","(","str",",","optional",")",":","The","way","of","downsample","in","MergingBlock",".","Defaults","to","'Conv","'",".","mlp_ratio","(","int",",","optional",")",":","Ratio","of","hidden","features","to","input","in","MLP",".","Defaults","to","4.","qkv_bias","(","bool",",","optional",")",":","Whether","to","add","bias","for","qkv","in","attention","modules",".","Defaults","to","True",".","qk_scale","(","float",",","optional",")",":","A","scaling","factor",".","Defaults","to","None",".","drop_rate","(","float",",","optional",")",":","Probability","of","an","element","to","be","zeroed",".","Defaults","to","0.0.","last_drop","(","float",",","optional",")",":","cfg","of","dropout","at","last","stage",".","Defaults","to","0.1.","attn_drop_rate","(","float",",","optional",")",":","_description_",".","Defaults","to","0","..","drop_path_rate","(","float",",","optional",")",":","stochastic","depth","rate",".","Defaults","to","0.1.","out_channels","(","int",",","optional",")",":","The","num","of","output","channels","in","backone",".","Defaults","to","192.","max_seq_len","(","int",",","optional",")",":","Maximum","output","sequence","length",":","math",":","`","T","`",".","Defaults","to","25.","num_layers","(","int",",","optional",")",":","The","num","of","conv","in","PatchEmbedding",".","Defaults","to","2.","prenorm","(","bool",",","optional",")",":","Whether","to","place","the","MixingBlock","before","norm",".","Defaults","to","True",".","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","configs",".","Defaults","to","None","."]
code: def __init__(
      self,
      img_size: Tuple[int, int] = [32, 100],
      in_channels: int = 3,
      embed_dims: Tuple[int, int, int] = [64, 128, 256],
      depth: Tuple[int, int, int] = [3, 6, 3],
      num_heads: Tuple[int, int, int] = [2, 4, 8],
      mixer_types: Tuple[str] = ["Local"] * 6 + ["Global"] * 6,
      window_size: Tuple[Tuple[int, int]] = [[7, 11], [7, 11], [7, 11]],
      merging_types: str = "Conv",
      mlp_ratio: int = 4,
      qkv_bias: bool = True,
      qk_scale: float = None,
      drop_rate: float = 0.0,
      last_drop: float = 0.1,
      attn_drop_rate: float = 0.0,
      drop_path_rate: float = 0.1,
      out_channels: int = 192,
      max_seq_len: int = 25,
      num_layers: int = 2,
      prenorm: bool = True,
      init_cfg: Optional[Union[Dict, List[Dict]]] = None,
  ):
      super().__init__(init_cfg)
      self.img_size = img_size
      self.embed_dims = embed_dims
      self.out_channels = out_channels
      self.prenorm = prenorm
      self.patch_embed = OverlapPatchEmbed(
          in_channels=in_channels,
          embed_dims=embed_dims[0],
          num_layers=num_layers,
      )
      num_patches = (img_size[1] // (2**num_layers)) * (
          img_size[0] // (2**num_layers)
      )
      self.input_shape = [
          img_size[0] // (2**num_layers),
          img_size[1] // (2**num_layers),
      ]
      self.absolute_pos_embed = nn.Parameter(
          torch.zeros(
              [1, num_patches, embed_dims[0]], dtype=torch.float32
          ),
          requires_grad=True,
      )
      self.pos_drop = nn.Dropout(drop_rate)
      dpr = np.linspace(0, drop_path_rate, sum(depth))
  
      self.blocks1 = nn.ModuleList(
          [
              MixingBlock(
                  embed_dims=embed_dims[0],
                  num_heads=num_heads[0],
                  mixer=mixer_types[0 : depth[0]][i],
                  window_size=window_size[0],
                  input_shape=self.input_shape,
                  mlp_ratio=mlp_ratio,
                  qkv_bias=qkv_bias,
                  qk_scale=qk_scale,
                  drop=drop_rate,
                  attn_drop=attn_drop_rate,
                  drop_path=dpr[0 : depth[0]][i],
                  prenorm=prenorm,
              )
              for i in range(depth[0])
          ]
      )
      self.downsample1 = MerigingBlock(
          in_channels=embed_dims[0],
          out_channels=embed_dims[1],
          types=merging_types,
          stride=[2, 1],
      )
      input_shape = [self.input_shape[0] // 2, self.input_shape[1]]
      self.merging_types = merging_types
  
      self.blocks2 = nn.ModuleList(
          [
              MixingBlock(
                  embed_dims=embed_dims[1],
                  num_heads=num_heads[1],
                  mixer=mixer_types[depth[0] : depth[0] + depth[1]][i],
                  window_size=window_size[1],
                  input_shape=input_shape,
                  mlp_ratio=mlp_ratio,
                  qkv_bias=qkv_bias,
                  qk_scale=qk_scale,
                  drop=drop_rate,
                  attn_drop=attn_drop_rate,
                  drop_path=dpr[depth[0] : depth[0] + depth[1]][i],
                  prenorm=prenorm,
              )
              for i in range(depth[1])
          ]
      )
      self.downsample2 = MerigingBlock(
          in_channels=embed_dims[1],
          out_channels=embed_dims[2],
          types=merging_types,
          stride=[2, 1],
      )
      input_shape = [self.input_shape[0] // 4, self.input_shape[1]]
  
      self.blocks3 = nn.ModuleList(
          [
              MixingBlock(
                  embed_dims=embed_dims[2],
                  num_heads=num_heads[2],
                  mixer=mixer_types[depth[0] + depth[1] :][i],
                  window_size=window_size[2],
                  input_shape=input_shape,
                  mlp_ratio=mlp_ratio,
                  qkv_bias=qkv_bias,
                  qk_scale=qk_scale,
                  drop=drop_rate,
                  attn_drop=attn_drop_rate,
                  drop_path=dpr[depth[0] + depth[1] :][i],
                  prenorm=prenorm,
              )
              for i in range(depth[2])
          ]
      )
      self.layer_norm = nn.LayerNorm(self.embed_dims[-1], eps=1e-6)
      self.avgpool = nn.AdaptiveAvgPool2d([1, max_seq_len])
      self.last_conv = nn.Conv2d(
          in_channels=embed_dims[2],
          out_channels=self.out_channels,
          kernel_size=1,
          bias=False,
          stride=1,
          padding=0,
      )
      self.hardwish = nn.Hardswish()
      self.dropout = nn.Dropout(p=last_drop)
  
      trunc_normal_init(self.absolute_pos_embed, mean=0, std=0.02)
      self.apply(self._init_weights)
  
imports: from typing import Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule
  from mmcv.cnn.bricks import DropPath
  from mmengine.model import BaseModule
  from mmengine.model.weight_init import trunc_normal_init
  from mmocr.registry import MODELS
  from mmocr.structures import TextRecogDataSample
label_desc: Use image node_id 1 to create a new SVTREncoder object from inherited base classes: BaseModule with example: obj = SVTREncoder(img_size, in_channels, embed_dims, depth, num_heads, mixer_types, window_size, merging_types, mlp_ratio, qkv_bias, qk_scale, drop_rate, last_drop, attn_drop_rate, drop_path_rate, out_channels, max_seq_len, num_layers, prenorm, init_cfg)