class_docstr: Convert scores to quadrangles via post processing in PANet. This is
  partially adapted from https://github.com/WenmuZhou/PAN.pytorch.
  
  Args:
      text_repr_type (str): The boundary encoding type 'poly' or 'quad'.
          Defaults to 'poly'.
      score_threshold (float): The minimal text score.
          Defaults to 0.3.
      rescale_fields (list[str]): The bbox/polygon field names to
          be rescaled. If None, no rescaling will be performed. Defaults to
          ['polygons'].
      min_text_confidence (float): The minimal text confidence.
          Defaults to 0.5.
      min_kernel_confidence (float): The minimal kernel confidence.
          Defaults to 0.5.
      distance_threshold (float): The minimal distance between the point to
          mean of text kernel. Defaults to 3.0.
      min_text_area (int): The minimal text instance region area.
          Defaults to 16.
      downsample_ratio (float): Downsample ratio. Defaults to 0.25.
docstr: Get text instance predictions of one image.
  
  Args:
      pred_result (torch.Tensor): Prediction results of an image which
          is a tensor of shape :math:`(N, H, W)`.
      data_sample (TextDetDataSample): Datasample of an image.
  
  Returns:
      TextDetDataSample: A new DataSample with predictions filled in.
      Polygons and results are saved in
      ``TextDetDataSample.pred_instances.polygons``. The confidence
      scores are saved in ``TextDetDataSample.pred_instances.scores``.
docstr_tok: ["Get","text","instance","predictions","of","one","image",".","Args",":","pred_result","(","torch.Tensor",")",":","Prediction","results","of","an","image","which","is","a","tensor","of","shape",":","math",":","`","(","N",",","H",",","W",")","`",".","data_sample","(","TextDetDataSample",")",":","Datasample","of","an","image",".","Returns",":","TextDetDataSample",":","A","new","DataSample","with","predictions","filled","in",".","Polygons","and","results","are","saved","in","``","TextDetDataSample.pred_instances.polygons","``",".","The","confidence","scores","are","saved","in","``","TextDetDataSample.pred_instances.scores","``","."]
code: def get_text_instances(
      self,
      pred_results: torch.Tensor,
      data_sample: TextDetDataSample,
      **kwargs,
  ) -> TextDetDataSample:
      """Get text instance predictions of one image.
  
      Args:
          pred_result (torch.Tensor): Prediction results of an image which
              is a tensor of shape :math:`(N, H, W)`.
          data_sample (TextDetDataSample): Datasample of an image.
  
      Returns:
          TextDetDataSample: A new DataSample with predictions filled in.
          Polygons and results are saved in
          ``TextDetDataSample.pred_instances.polygons``. The confidence
          scores are saved in ``TextDetDataSample.pred_instances.scores``.
      """
      assert pred_results.dim() == 3
  
      pred_results[:2, :, :] = torch.sigmoid(pred_results[:2, :, :])
      pred_results = pred_results.detach().cpu().numpy()
  
      text_score = pred_results[0].astype(np.float32)
      text = pred_results[0] > self.min_text_confidence
      kernel = (pred_results[1] > self.min_kernel_confidence) * text
      embeddings = pred_results[2:] * text.astype(np.float32)
      embeddings = embeddings.transpose((1, 2, 0))  # (h, w, 4)
  
      region_num, labels = cv2.connectedComponents(
          kernel.astype(np.uint8), connectivity=4
      )
      contours, _ = cv2.findContours(
          (kernel * 255).astype(np.uint8),
          cv2.RETR_LIST,
          cv2.CHAIN_APPROX_NONE,
      )
      kernel_contours = np.zeros(text.shape, dtype="uint8")
      cv2.drawContours(kernel_contours, contours, -1, 255)
      text_points = pixel_group(
          text_score,
          text,
          embeddings,
          labels,
          kernel_contours,
          region_num,
          self.distance_threshold,
      )
  
      polygons = []
      scores = []
      for text_point in text_points:
          text_confidence = text_point[0]
          text_point = text_point[2:]
          text_point = np.array(text_point, dtype=int).reshape(-1, 2)
          area = text_point.shape[0]
          if (
              area < self.min_text_area
              or text_confidence <= self.score_threshold
          ):
              continue
  
          polygon = self._points2boundary(text_point)
          if len(polygon) > 0:
              polygons.append(polygon)
              scores.append(text_confidence)
      pred_instances = InstanceData()
      pred_instances.polygons = polygons
      pred_instances.scores = torch.FloatTensor(scores)
      data_sample.pred_instances = pred_instances
      scale_factor = data_sample.scale_factor
      scale_factor = tuple(
          factor * self.downsample_ratio for factor in scale_factor
      )
      data_sample.set_metainfo(dict(scale_factor=scale_factor))
      return data_sample
  
file_path: mmocr/mmocr/models/textdet/postprocessors/pan_postprocessor.py
imports: from typing import List, Sequence
  import cv2
  import numpy
  import torch
  from mmcv.ops import pixel_group
  from mmengine.structures import InstanceData
  from mmocr.registry import MODELS
  from mmocr.structures import TextDetDataSample
  from .base import BaseTextDetPostProcessor
label_desc: Use image node_id 2 for calling the PANPostprocessor obj's underlying member method code with example usage: obj.get_text_instances(pred_results, data_sample) and returns: data_sample