class_docstr: Implements a ViTSTR architecture as described in `"Vision Transformer for Fast and
  Efficient Scene Text Recognition" <https://arxiv.org/pdf/2105.08582.pdf>`_.
  
  Args:
  ----
      feature_extractor: the backbone serving as feature extractor
      vocab: vocabulary used for encoding
      embedding_units: number of embedding units
      max_length: maximum word length handled by the model
      dropout_prob: dropout probability of the encoder LSTM
      input_shape: input shape of the image
      exportable: onnx exportable returns only logits
      cfg: dictionary containing information about the model
class_docstr_tok: ["Implements","a","ViTSTR","architecture","as","described","in","`","``","Vision","Transformer","for","Fast","and","Efficient","Scene","Text","Recognition","''","<","https",":","\/\/arxiv.org\/pdf\/2105.08582.pdf",">","`","_",".","Args",":","--","--","feature_extractor",":","the","backbone","serving","as","feature","extractor","vocab",":","vocabulary","used","for","encoding","embedding_units",":","number","of","embedding","units","max_length",":","maximum","word","length","handled","by","the","model","dropout_prob",":","dropout","probability","of","the","encoder","LSTM","input_shape",":","input","shape","of","the","image","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"
      ]  # (batch_size, patches_seqlen, d_model)
  
      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")
  
      # borrowed from : https://github.com/baudm/parseq/blob/main/strhub/models/vitstr/model.py
      features = features[
          :, : self.max_length
      ]  # (batch_size, max_length, d_model)
      B, N, E = features.size()
      features = features.reshape(B * N, E)
      logits = self.head(features).view(
          B, N, len(self.vocab) + 1
      )  # (batch_size, max_length, vocab + 1)
      decoded_features = _bf16_to_float32(
          logits[:, 1:]
      )  # remove cls_token
  
      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 vit_b, vit_s
  from ...utils.pytorch import _bf16_to_float32, load_pretrained_params
  from .base import _ViTSTR, _ViTSTRPostProcessor
label_desc: Use image node_id 2 for calling the ViTSTR obj's underlying member method code with example usage: obj.forward(x, target, return_model_output, return_preds) and returns: out, out