class_docstr: Implements MASTER as described in paper: <https://arxiv.org/pdf/1910.02562.pdf>`_.
  Implementation based on the official Pytorch implementation: <https://github.com/wenwenyu/MASTER-pytorch>`_.
  
  Args:
  ----
      feature_extractor: the backbone serving as feature extractor
      vocab: vocabulary, (without EOS, SOS, PAD)
      d_model: d parameter for the transformer decoder
      dff: depth of the pointwise feed-forward layer
      num_heads: number of heads for the mutli-head attention module
      num_layers: number of decoder layers to stack
      max_length: maximum length of character sequence handled by the model
      dropout: dropout probability of the decoder
      input_shape: size of the image inputs
      exportable: onnx exportable returns only logits
      cfg: dictionary containing information about the model
class_docstr_tok: ["Implements","MASTER","as","described","in","paper",":","<","https",":","\/\/arxiv.org\/pdf\/1910.02562.pdf",">","`","_",".","Implementation","based","on","the","official","Pytorch","implementation",":","<","https",":","\/\/github.com\/wenwenyu\/MASTER-pytorch",">","`","_",".","Args",":","--","--","feature_extractor",":","the","backbone","serving","as","feature","extractor","vocab",":","vocabulary",",","(","without","EOS",",","SOS",",","PAD",")","d_model",":","d","parameter","for","the","transformer","decoder","dff",":","depth","of","the","pointwise","feed-forward","layer","num_heads",":","number","of","heads","for","the","mutli-head","attention","module","num_layers",":","number","of","decoder","layers","to","stack","max_length",":","maximum","length","of","character","sequence","handled","by","the","model","dropout",":","dropout","probability","of","the","decoder","input_shape",":","size","of","the","image","inputs","exportable",":","onnx","exportable","returns","only","logits","cfg",":","dictionary","containing","information","about","the","model"]
code: def __init__(
      self,
      feature_extractor: nn.Module,
      vocab: str,
      d_model: int = 512,
      dff: int = 2048,
      num_heads: int = 8,  # number of heads in the transformer decoder
      num_layers: int = 3,
      max_length: int = 50,
      dropout: float = 0.2,
      input_shape: Tuple[int, int, int] = (
          3,
          32,
          128,
      ),  # different from the paper
      exportable: bool = False,
      cfg: Optional[Dict[str, Any]] = None,
  ) -> None:
      super().__init__()
  
      self.exportable = exportable
      self.max_length = max_length
      self.d_model = d_model
      self.vocab = vocab
      self.cfg = cfg
      self.vocab_size = len(vocab)
  
      self.feat_extractor = feature_extractor
      self.positional_encoding = PositionalEncoding(
          self.d_model, dropout, max_len=input_shape[1] * input_shape[2]
      )
  
      self.decoder = Decoder(
          num_layers=num_layers,
          d_model=self.d_model,
          num_heads=num_heads,
          vocab_size=self.vocab_size + 3,  # EOS, SOS, PAD
          dff=dff,
          dropout=dropout,
          maximum_position_encoding=self.max_length,
      )
  
      self.linear = nn.Linear(self.d_model, self.vocab_size + 3)
      self.postprocessor = MASTERPostProcessor(vocab=self.vocab)
  
      for n, m in self.named_modules():
          # Don't override the initialization of the backbone
          if n.startswith("feat_extractor."):
              continue
          if isinstance(m, nn.Conv2d):
              nn.init.kaiming_normal_(
                  m.weight, mode="fan_out", nonlinearity="relu"
              )
          elif isinstance(m, (nn.BatchNorm2d, nn.GroupNorm)):
              nn.init.constant_(m.weight, 1)
              nn.init.constant_(m.bias, 0)
  
imports: from copy import deepcopy
  from typing import Any, Callable, Dict, List, Optional, Tuple
  import torch
  from torch import nn
  from torch.nn import functional
  from torchvision.models._utils import IntermediateLayerGetter
  from doctr.datasets import VOCABS
  from doctr.models.classification import magc_resnet31
  from doctr.models.modules.transformer import Decoder, PositionalEncoding
  from ...utils.pytorch import _bf16_to_float32, load_pretrained_params
  from .base import _MASTER, _MASTERPostProcessor
label_desc: Use image node_id 1 to create a new MASTER object from inherited base classes: _MASTER, nn with example: obj = MASTER(feature_extractor, vocab, d_model, dff, num_heads, num_layers, max_length, dropout, input_shape, exportable, cfg)