class_docstr: The implementation of the paper: Spatial Dual-Modality Graph Reasoning
  for Key Information Extraction. https://arxiv.org/abs/2103.14470.
  
  Args:
      backbone (dict, optional): Config of backbone. If None, None will be
          passed to kie_head during training and testing. Defaults to None.
      roi_extractor (dict, optional): Config of roi extractor. Only
          applicable when backbone is not None. Defaults to None.
      neck (dict, optional): Config of neck. Defaults to None.
      kie_head (dict): Config of KIE head. Defaults to None.
      dictionary (dict, optional): Config of dictionary. Defaults to None.
      data_preprocessor (dict or ConfigDict, optional): The pre-process
          config of :class:`BaseDataPreprocessor`.  it usually includes,
          ``pad_size_divisor``, ``pad_value``, ``mean`` and ``std``. It has
          to be None when working in non-visual mode. Defaults to None.
      init_cfg (dict or list[dict], optional): Initialization configs.
          Defaults to None.
docstr: Calculate losses from a batch of inputs and data samples.
  
  Args:
      inputs (torch.Tensor): Input images of shape (N, C, H, W).
          Typically these should be mean centered and std scaled.
      data_samples (list[KIEDataSample]): A list of N datasamples,
          containing meta information and gold annotations for each of
          the images.
  Returns:
      dict[str, Tensor]: A dictionary of loss components.
docstr_tok: ["Calculate","losses","from","a","batch","of","inputs","and","data","samples",".","Args",":","inputs","(","torch.Tensor",")",":","Input","images","of","shape","(","N",",","C",",","H",",","W",")",".","Typically","these","should","be","mean","centered","and","std","scaled",".","data_samples","(","list","[","KIEDataSample","]",")",":","A","list","of","N","datasamples",",","containing","meta","information","and","gold","annotations","for","each","of","the","images",".","Returns",":","dict","[","str",",","Tensor","]",":","A","dictionary","of","loss","components","."]
code: def loss(
      self,
      inputs: torch.Tensor,
      data_samples: Sequence[KIEDataSample],
      **kwargs,
  ) -> dict:
      """Calculate losses from a batch of inputs and data samples.
  
      Args:
          inputs (torch.Tensor): Input images of shape (N, C, H, W).
              Typically these should be mean centered and std scaled.
          data_samples (list[KIEDataSample]): A list of N datasamples,
              containing meta information and gold annotations for each of
              the images.
      Returns:
          dict[str, Tensor]: A dictionary of loss components.
      """
      x = self.extract_feat(
          inputs,
          [
              data_sample.gt_instances.bboxes
              for data_sample in data_samples
          ],
      )
      return self.kie_head.loss(x, data_samples)
  
file_path: mmocr/mmocr/models/kie/extractors/sdmgr.py
imports: import warnings
  from typing import Dict, List, Optional, Sequence, Tuple
  import torch
  from mmdet.structures.bbox import bbox2roi
  from mmengine.model import BaseModel
  from torch import nn
  from mmocr.registry import MODELS, TASK_UTILS
  from mmocr.structures import KIEDataSample
label_desc: Use image node_id 4 for calling the SDMGR obj's underlying member method code with example usage: obj.loss(inputs, data_samples) and returns: self