class_docstr: Implements a SAR architecture as described in `"Show, Attend and Read:A Simple and Strong Baseline for
  Irregular Text Recognition" <https://arxiv.org/pdf/1811.00751.pdf>`_.
  
  Args:
  ----
      feature_extractor: the backbone serving as feature extractor
      vocab: vocabulary used for encoding
      rnn_units: number of hidden units in both encoder and decoder LSTM
      embedding_units: number of embedding units
      attention_units: number of hidden units in attention module
      max_length: maximum word length handled by the model
      dropout_prob: dropout probability of the encoder LSTM
      exportable: onnx exportable returns only logits
      cfg: dictionary containing information about the model
class_docstr_tok: ["Implements","a","SAR","architecture","as","described","in","`","``","Show",",","Attend","and","Read",":","A","Simple","and","Strong","Baseline","for","Irregular","Text","Recognition","''","<","https",":","\/\/arxiv.org\/pdf\/1811.00751.pdf",">","`","_",".","Args",":","--","--","feature_extractor",":","the","backbone","serving","as","feature","extractor","vocab",":","vocabulary","used","for","encoding","rnn_units",":","number","of","hidden","units","in","both","encoder","and","decoder","LSTM","embedding_units",":","number","of","embedding","units","attention_units",":","number","of","hidden","units","in","attention","module","max_length",":","maximum","word","length","handled","by","the","model","dropout_prob",":","dropout","probability","of","the","encoder","LSTM","exportable",":","onnx","exportable","returns","only","logits","cfg",":","dictionary","containing","information","about","the","model"]
code: def forward(
      self,
      x: torch.Tensor,
      target: Optional[List[str]] = None,
      return_model_output: bool = False,
      return_preds: bool = False,
  ) -> Dict[str, Any]:
      features = self.feat_extractor(x)["features"]
      # NOTE: use max instead of functional max_pool2d which leads to ONNX incompatibility (kernel_size)
      # Vertical max pooling (N, C, H, W) --> (N, C, W)
      pooled_features = features.max(dim=-2).values
      # (N, W, C)
      pooled_features = pooled_features.permute(0, 2, 1).contiguous()
      # (N, C)
      encoded = self.encoder(pooled_features)
      if target is not None:
          _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)
  
      if self.training and target is None:
          raise ValueError(
              "Need to provide labels during training for teacher forcing"
          )
  
      decoded_features = _bf16_to_float32(
          self.decoder(
              features, encoded, gt=None if target is None else gt
          )
      )
  
      out: Dict[str, Any] = {}
      if self.exportable:
          out["logits"] = decoded_features
          return out
  
      if return_model_output:
          out["out_map"] = decoded_features
  
      if target is None or return_preds:
          # Post-process boxes
          out["preds"] = self.postprocessor(decoded_features)
  
      if target is not None:
          out["loss"] = self.compute_loss(decoded_features, gt, seq_len)
  
      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 ...classification import resnet31
  from ...utils.pytorch import _bf16_to_float32, load_pretrained_params
  from ..core import RecognitionModel, RecognitionPostProcessor
label_desc: Use image node_id 2 for calling the SAR obj's underlying member method code with example usage: obj.forward(x, target, return_model_output, return_preds) and returns: out, out