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: Convert Instance datas from MMDet into MMOCR's format.
  
  Args:
      data: (list[DetDataSample]): Detection results of the
          input images. Each DetDataSample usually contain
          'pred_instances'. And the ``pred_instances`` usually
          contains following keys.
          - scores (Tensor): Classification scores, has a shape
              (num_instance, )
          - labels (Tensor): Labels of bboxes, has a shape
              (num_instances, ).
          - bboxes (Tensor): Has a shape (num_instances, 4),
              the last dimension 4 arrange as (x1, y1, x2, y2).
          - masks (Tensor, Optional): Has a shape (num_instances, H, W).
      data_samples (list[:obj:`TextDetDataSample`]): The annotation data
          of every samples.
  
  Returns:
      list[TextDetDataSample]: A list of N datasamples containing ground
          truth and prediction results.
          The polygon results are saved in
          ``TextDetDataSample.pred_instances.polygons``
          The confidence scores are saved in
          ``TextDetDataSample.pred_instances.scores``.
docstr_tok: ["Convert","Instance","datas","from","MMDet","into","MMOCR","'s","format",".","Args",":","data",":","(","list","[","DetDataSample","]",")",":","Detection","results","of","the","input","images",".","Each","DetDataSample","usually","contain","'pred_instances","'",".","And","the","``","pred_instances","``","usually","contains","following","keys",".","-","scores","(","Tensor",")",":","Classification","scores",",","has","a","shape","(","num_instance",",",")","-","labels","(","Tensor",")",":","Labels","of","bboxes",",","has","a","shape","(","num_instances",",",")",".","-","bboxes","(","Tensor",")",":","Has","a","shape","(","num_instances",",","4",")",",","the","last","dimension","4","arrange","as","(","x1",",","y1",",","x2",",","y2",")",".","-","masks","(","Tensor",",","Optional",")",":","Has","a","shape","(","num_instances",",","H",",","W",")",".","data_samples","(","list","[",":","obj",":","`","TextDetDataSample","`","]",")",":","The","annotation","data","of","every","samples",".","Returns",":","list","[","TextDetDataSample","]",":","A","list","of","N","datasamples","containing","ground","truth","and","prediction","results",".","The","polygon","results","are","saved","in","``","TextDetDataSample.pred_instances.polygons","``","The","confidence","scores","are","saved","in","``","TextDetDataSample.pred_instances.scores","``","."]
code: def adapt_predictions(
      self, data: MMDET_SampleList, data_samples: DetSampleList
  ) -> DetSampleList:
      """Convert Instance datas from MMDet into MMOCR's format.
  
      Args:
          data: (list[DetDataSample]): Detection results of the
              input images. Each DetDataSample usually contain
              'pred_instances'. And the ``pred_instances`` usually
              contains following keys.
              - scores (Tensor): Classification scores, has a shape
                  (num_instance, )
              - labels (Tensor): Labels of bboxes, has a shape
                  (num_instances, ).
              - bboxes (Tensor): Has a shape (num_instances, 4),
                  the last dimension 4 arrange as (x1, y1, x2, y2).
              - masks (Tensor, Optional): Has a shape (num_instances, H, W).
          data_samples (list[:obj:`TextDetDataSample`]): The annotation data
              of every samples.
  
      Returns:
          list[TextDetDataSample]: A list of N datasamples containing ground
              truth and prediction results.
              The polygon results are saved in
              ``TextDetDataSample.pred_instances.polygons``
              The confidence scores are saved in
              ``TextDetDataSample.pred_instances.scores``.
      """
      for i, det_data_sample in enumerate(data):
          data_samples[i].pred_instances = InstanceData()
          # convert mask to polygons if mask exists
          if "masks" in det_data_sample.pred_instances.keys():
              masks = det_data_sample.pred_instances.masks.cpu().numpy()
              polygons = []
              scores = []
              for mask_idx, mask in enumerate(masks):
                  contours, _ = bitmap_to_polygon(mask)
                  polygons += [
                      contour.reshape(-1) for contour in contours
                  ]
                  scores += [
                      det_data_sample.pred_instances.scores[
                          mask_idx
                      ].cpu()
                  ] * len(contours)
              # filter invalid polygons
              filterd_polygons = []
              keep_idx = []
              for poly_idx, polygon in enumerate(polygons):
                  if len(polygon) < 6:
                      continue
                  filterd_polygons.append(polygon)
                  keep_idx.append(poly_idx)
              # convert by text_repr_type
              if self.text_repr_type == "quad":
                  for j, poly in enumerate(filterd_polygons):
                      poly = poly.reshape(-1, 2)
                      rect = cv2.minAreaRect(poly)
                      vertices = cv2.boxPoints(rect)
                      poly = vertices.flatten()
                      filterd_polygons[j] = poly
  
              data_samples[i].pred_instances.polygons = filterd_polygons
              data_samples[i].pred_instances.scores = torch.FloatTensor(
                  scores
              )[keep_idx]
          else:
              bboxes = (
                  det_data_sample.pred_instances.bboxes.cpu().numpy()
              )
              polygons = [bbox2poly(bbox) for bbox in bboxes]
              data_samples[i].pred_instances.polygons = polygons
              data_samples[i].pred_instances.scores = torch.FloatTensor(
                  det_data_sample.pred_instances.scores.cpu()
              )
  
      return data_samples
  
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 3 for calling the MMDetWrapper obj's underlying member method code with example usage: obj.adapt_predictions(data, data_samples) and returns: data_samples