class_docstr: A wrapper of MMDet's model.
  
  Args:
      cfg (dict): The config of the model.
      text_repr_type (str): The boundary encoding type 'poly' or 'quad'.
          Defaults to 'poly'.
docstr: The unified entry for a forward process in both training and test.
  
  The method works in three modes: "tensor", "predict" and "loss":
  
  - "tensor": Forward the whole network and return tensor or tuple of
  tensor without any post-processing, same as a common nn.Module.
  - "predict": Forward and return the predictions, which are fully
  processed to a list of :obj:`DetDataSample`.
  - "loss": Forward and return a dict of losses according to the given
  inputs and data samples.
  
  Note that this method doesn't handle either back propagation or
  parameter update, which are supposed to be done in :meth:`train_step`.
  
  Args:
      inputs (torch.Tensor): The input tensor with shape
          (N, C, ...) in general.
      data_samples (list[:obj:`DetDataSample`] or
          list[:obj:`TextDetDataSample`]): The annotation data of every
          sample. When in "predict" mode, it should be a list of
          :obj:`TextDetDataSample`. Otherwise they are
          :obj:`DetDataSample`s. Defaults to None.
      mode (str): Running mode. Defaults to 'tensor'.
  
  Returns:
      The return type depends on ``mode``.
  
      - If ``mode="tensor"``, return a tensor or a tuple of tensor.
      - If ``mode="predict"``, return a list of :obj:`TextDetDataSample`.
      - If ``mode="loss"``, return a dict of tensor.
docstr_tok: ["The","unified","entry","for","a","forward","process","in","both","training","and","test",".","The","method","works","in","three","modes",":","``","tensor","''",",","``","predict","''","and","``","loss","''",":","-","``","tensor","''",":","Forward","the","whole","network","and","return","tensor","or","tuple","of","tensor","without","any","post-processing",",","same","as","a","common","nn.Module",".","-","``","predict","''",":","Forward","and","return","the","predictions",",","which","are","fully","processed","to","a","list","of",":","obj",":","`","DetDataSample","`",".","-","``","loss","''",":","Forward","and","return","a","dict","of","losses","according","to","the","given","inputs","and","data","samples",".","Note","that","this","method","does","n't","handle","either","back","propagation","or","parameter","update",",","which","are","supposed","to","be","done","in",":","meth",":","`","train_step","`",".","Args",":","inputs","(","torch.Tensor",")",":","The","input","tensor","with","shape","(","N",",","C",",","...",")","in","general",".","data_samples","(","list","[",":","obj",":","`","DetDataSample","`","]","or","list","[",":","obj",":","`","TextDetDataSample","`","]",")",":","The","annotation","data","of","every","sample",".","When","in","``","predict","''","mode",",","it","should","be","a","list","of",":","obj",":","`","TextDetDataSample","`",".","Otherwise","they","are",":","obj",":","`","DetDataSample","`","s",".","Defaults","to","None",".","mode","(","str",")",":","Running","mode",".","Defaults","to","'tensor","'",".","Returns",":","The","return","type","depends","on","``","mode","``",".","-","If","``","mode=","''","tensor","''","``",",","return","a","tensor","or","a","tuple","of","tensor",".","-","If","``","mode=","''","predict","''","``",",","return","a","list","of",":","obj",":","`","TextDetDataSample","`",".","-","If","``","mode=","''","loss","''","``",",","return","a","dict","of","tensor","."]
code: def forward(
      self,
      inputs: torch.Tensor,
      data_samples: Optional[
          Union[DetSampleList, MMDET_SampleList]
      ] = None,
      mode: str = "tensor",
      **kwargs,
  ) -> ForwardResults:
      """The unified entry for a forward process in both training and test.
  
      The method works in three modes: "tensor", "predict" and "loss":
  
      - "tensor": Forward the whole network and return tensor or tuple of
      tensor without any post-processing, same as a common nn.Module.
      - "predict": Forward and return the predictions, which are fully
      processed to a list of :obj:`DetDataSample`.
      - "loss": Forward and return a dict of losses according to the given
      inputs and data samples.
  
      Note that this method doesn't handle either back propagation or
      parameter update, which are supposed to be done in :meth:`train_step`.
  
      Args:
          inputs (torch.Tensor): The input tensor with shape
              (N, C, ...) in general.
          data_samples (list[:obj:`DetDataSample`] or
              list[:obj:`TextDetDataSample`]): The annotation data of every
              sample. When in "predict" mode, it should be a list of
              :obj:`TextDetDataSample`. Otherwise they are
              :obj:`DetDataSample`s. Defaults to None.
          mode (str): Running mode. Defaults to 'tensor'.
  
      Returns:
          The return type depends on ``mode``.
  
          - If ``mode="tensor"``, return a tensor or a tuple of tensor.
          - If ``mode="predict"``, return a list of :obj:`TextDetDataSample`.
          - If ``mode="loss"``, return a dict of tensor.
      """
      if mode == "predict":
          ocr_data_samples = data_samples
          data_samples = []
          for i in range(len(ocr_data_samples)):
              data_samples.append(
                  DetDataSample(metainfo=ocr_data_samples[i].metainfo)
              )
  
      results = self.wrapped_model.forward(
          inputs, data_samples, mode, **kwargs
      )
  
      if mode == "predict":
          results = self.adapt_predictions(results, ocr_data_samples)
  
      return results
  
file_path: mmocr/mmocr/models/textdet/detectors/mmdet_wrapper.py
imports: from typing import Dict, List, Optional, Tuple, Union
  import cv2
  import torch
  from mmdet.structures import DetDataSample
  from mmdet.structures import SampleList
  from mmdet.structures.mask import bitmap_to_polygon
  from mmengine.model import BaseModel
  from mmengine.structures import InstanceData
  from mmocr.registry import MODELS
  from mmocr.utils.bbox_utils import bbox2poly
  from mmocr.utils.typing_utils import DetSampleList
label_desc: Use image node_id 2 for calling the MMDetWrapper obj's underlying member method code with example usage: obj.forward(inputs, data_samples, mode) and returns: results