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"]
docstr: Call function for training
  
  Args:
  ----
      x: images
      target: list of str labels
      return_model_output: if True, return logits
      return_preds: if True, decode logits
  
  Returns:
  -------
      A dictionnary containing eventually loss, logits and predictions.
docstr_tok: ["Call","function","for","training","Args",":","--","--","x",":","images","target",":","list","of","str","labels","return_model_output",":","if","True",",","return","logits","return_preds",":","if","True",",","decode","logits","Returns",":","--","--","--","-","A","dictionnary","containing","eventually","loss",",","logits","and","predictions","."]
code: def forward(
      self,
      x: torch.Tensor,
      target: Optional[List[str]] = None,
      return_model_output: bool = False,
      return_preds: bool = False,
  ) -> Dict[str, Any]:
      """Call function for training
  
      Args:
      ----
          x: images
          target: list of str labels
          return_model_output: if True, return logits
          return_preds: if True, decode logits
  
      Returns:
      -------
          A dictionnary containing eventually loss, logits and predictions.
      """
      # Encode
      features = self.feat_extractor(x)["features"]
      b, c, h, w = features.shape
      # (N, C, H, W) --> (N, H * W, C)
      features = features.view(b, c, h * w).permute((0, 2, 1))
      # add positional encoding to features
      encoded = self.positional_encoding(features)
  
      out: Dict[str, Any] = {}
  
      if self.training and target is None:
          raise ValueError("Need to provide labels during training")
  
      if target is not None:
          # Compute target: tensor of gts and sequence lengths
          _gt, _seq_len = self.build_target(target)
          gt, seq_len = torch.from_numpy(_gt).to(
              dtype=torch.long
          ), torch.tensor(_seq_len)
          gt, seq_len = gt.to(x.device), seq_len.to(x.device)
  
          # Compute source mask and target mask
          source_mask, target_mask = self.make_source_and_target_mask(
              encoded, gt
          )
          output = self.decoder(gt, encoded, source_mask, target_mask)
          # Compute logits
          logits = self.linear(output)
      else:
          logits = self.decode(encoded)
  
      logits = _bf16_to_float32(logits)
  
      if self.exportable:
          out["logits"] = logits
          return out
  
      if target is not None:
          out["loss"] = self.compute_loss(logits, gt, seq_len)
  
      if return_model_output:
          out["out_map"] = logits
  
      if return_preds:
          out["preds"] = self.postprocessor(logits)
  
      return out
  
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 4 for calling the MASTER obj's underlying member method code with example usage: obj.forward(x, target, return_model_output, return_preds) and returns: out, out