class_docstr: The class for implementing DRRG loss. This is partially adapted from
  https://github.com/GXYM/DRRG licensed under the MIT license.
  
  DRRG: `Deep Relational Reasoning Graph Network for Arbitrary Shape Text
  Detection <https://arxiv.org/abs/1908.05900>`_.
  
  Args:
      ohem_ratio (float): The negative/positive ratio in ohem. Defaults to
          3.0.
      downsample_ratio (float): Downsample ratio. Defaults to 1.0. TODO:
          remove it.
      orientation_thr (float): The threshold for distinguishing between
          head edge and tail edge among the horizontal and vertical edges
          of a quadrangle. Defaults to 2.0.
      resample_step (float): The step size for resampling the text center
          line. Defaults to 8.0.
      num_min_comps (int): The minimum number of text components, which
          should be larger than k_hop1 mentioned in paper. Defaults to 9.
      num_max_comps (int): The maximum number of text components. Defaults
          to 600.
      min_width (float): The minimum width of text components. Defaults to
          8.0.
      max_width (float): The maximum width of text components. Defaults to
          24.0.
      center_region_shrink_ratio (float): The shrink ratio of text center
          regions. Defaults to 0.3.
      comp_shrink_ratio (float): The shrink ratio of text components.
          Defaults to 1.0.
      comp_w_h_ratio (float): The width to height ratio of text components.
          Defaults to 0.3.
      min_rand_half_height(float): The minimum half-height of random text
          components. Defaults to 8.0.
      max_rand_half_height (float): The maximum half-height of random
          text components. Defaults to 24.0.
      jitter_level (float): The jitter level of text component geometric
          features. Defaults to 0.2.
      loss_text (dict): The loss config used to calculate the text loss.
          Defaults to ``dict(type='MaskedBalancedBCEWithLogitsLoss',
          fallback_negative_num=100, eps=1e-5)``.
      loss_center (dict): The loss config used to calculate the center loss.
          Defaults to ``dict(type='MaskedBCEWithLogitsLoss')``.
      loss_top (dict): The loss config used to calculate the top loss, which
          is a part of the height loss. Defaults to
          ``dict(type='SmoothL1Loss', reduction='none')``.
      loss_btm (dict): The loss config used to calculate the bottom loss,
          which is a part of the height loss. Defaults to
          ``dict(type='SmoothL1Loss', reduction='none')``.
      loss_sin (dict): The loss config used to calculate the sin loss.
          Defaults to ``dict(type='MaskedSmoothL1Loss')``.
      loss_cos (dict): The loss config used to calculate the cos loss.
          Defaults to ``dict(type='MaskedSmoothL1Loss')``.
      loss_gcn (dict): The loss config used to calculate the GCN loss.
          Defaults to ``dict(type='CrossEntropyLoss')``.
docstr: Generate text center region masks and geometric attribute maps.
  
  Args:
      img_size (tuple(int, int)): The image size (height, width).
      text_polys (list[ndarray]): The list of text polygons.
  
  Returns:
      tuple(center_lines, center_region_mask, top_height_map,
      bot_height_map,sin_map, cos_map):
  
      center_lines (list[ndarray]): The list of text center lines.
      center_region_mask (ndarray): The text center region mask.
      top_height_map (ndarray): The map on which the distance from points
          to top side lines will be drawn for each pixel in text center
          regions.
      bot_height_map (ndarray): The map on which the distance from points
          to bottom side lines will be drawn for each pixel in text
          center regions.
      sin_map (ndarray): The sin(theta) map where theta is the angle
          between vector (top point - bottom point) and vector (1, 0).
      cos_map (ndarray): The cos(theta) map where theta is the angle
          between vector (top point - bottom point) and vector (1, 0).
docstr_tok: ["Generate","text","center","region","masks","and","geometric","attribute","maps",".","Args",":","img_size","(","tuple","(","int",",","int",")",")",":","The","image","size","(","height",",","width",")",".","text_polys","(","list","[","ndarray","]",")",":","The","list","of","text","polygons",".","Returns",":","tuple","(","center_lines",",","center_region_mask",",","top_height_map",",","bot_height_map",",","sin_map",",","cos_map",")",":","center_lines","(","list","[","ndarray","]",")",":","The","list","of","text","center","lines",".","center_region_mask","(","ndarray",")",":","The","text","center","region","mask",".","top_height_map","(","ndarray",")",":","The","map","on","which","the","distance","from","points","to","top","side","lines","will","be","drawn","for","each","pixel","in","text","center","regions",".","bot_height_map","(","ndarray",")",":","The","map","on","which","the","distance","from","points","to","bottom","side","lines","will","be","drawn","for","each","pixel","in","text","center","regions",".","sin_map","(","ndarray",")",":","The","sin","(","theta",")","map","where","theta","is","the","angle","between","vector","(","top","point","-","bottom","point",")","and","vector","(","1",",","0",")",".","cos_map","(","ndarray",")",":","The","cos","(","theta",")","map","where","theta","is","the","angle","between","vector","(","top","point","-","bottom","point",")","and","vector","(","1",",","0",")","."]
code: def _generate_center_mask_attrib_maps(
      self, img_size: Tuple[int, int], text_polys: List[ndarray]
  ) -> Tuple:
      """Generate text center region masks and geometric attribute maps.
  
      Args:
          img_size (tuple(int, int)): The image size (height, width).
          text_polys (list[ndarray]): The list of text polygons.
  
      Returns:
          tuple(center_lines, center_region_mask, top_height_map,
          bot_height_map,sin_map, cos_map):
  
          center_lines (list[ndarray]): The list of text center lines.
          center_region_mask (ndarray): The text center region mask.
          top_height_map (ndarray): The map on which the distance from points
              to top side lines will be drawn for each pixel in text center
              regions.
          bot_height_map (ndarray): The map on which the distance from points
              to bottom side lines will be drawn for each pixel in text
              center regions.
          sin_map (ndarray): The sin(theta) map where theta is the angle
              between vector (top point - bottom point) and vector (1, 0).
          cos_map (ndarray): The cos(theta) map where theta is the angle
              between vector (top point - bottom point) and vector (1, 0).
      """
  
      assert isinstance(img_size, tuple)
      assert check_argument.is_type_list(text_polys, ndarray)
  
      h, w = img_size
  
      center_lines = []
      center_region_mask = np.zeros((h, w), np.uint8)
      top_height_map = np.zeros((h, w), dtype=np.float32)
      bot_height_map = np.zeros((h, w), dtype=np.float32)
      sin_map = np.zeros((h, w), dtype=np.float32)
      cos_map = np.zeros((h, w), dtype=np.float32)
  
      for poly in text_polys:
          polygon_points = poly.reshape(-1, 2)
          _, _, top_line, bot_line = self._reorder_poly_edge(
              polygon_points
          )
          (
              resampled_top_line,
              resampled_bot_line,
          ) = self._resample_sidelines(
              top_line, bot_line, self.resample_step
          )
          resampled_bot_line = resampled_bot_line[::-1]
          center_line = (resampled_top_line + resampled_bot_line) / 2
  
          if self.vector_slope(center_line[-1] - center_line[0]) > 2:
              if (center_line[-1] - center_line[0])[1] < 0:
                  center_line = center_line[::-1]
                  resampled_top_line = resampled_top_line[::-1]
                  resampled_bot_line = resampled_bot_line[::-1]
          else:
              if (center_line[-1] - center_line[0])[0] < 0:
                  center_line = center_line[::-1]
                  resampled_top_line = resampled_top_line[::-1]
                  resampled_bot_line = resampled_bot_line[::-1]
  
          line_head_shrink_len = (
              np.clip(
                  (
                      norm(top_line[0] - bot_line[0])
                      * self.comp_w_h_ratio
                  ),
                  self.min_width,
                  self.max_width,
              )
              / 2
          )
          line_tail_shrink_len = (
              np.clip(
                  (
                      norm(top_line[-1] - bot_line[-1])
                      * self.comp_w_h_ratio
                  ),
                  self.min_width,
                  self.max_width,
              )
              / 2
          )
          num_head_shrink = int(
              line_head_shrink_len // self.resample_step
          )
          num_tail_shrink = int(
              line_tail_shrink_len // self.resample_step
          )
          if len(center_line) > num_head_shrink + num_tail_shrink + 2:
              center_line = center_line[
                  num_head_shrink : len(center_line) - num_tail_shrink
              ]
              resampled_top_line = resampled_top_line[
                  num_head_shrink : len(resampled_top_line)
                  - num_tail_shrink
              ]
              resampled_bot_line = resampled_bot_line[
                  num_head_shrink : len(resampled_bot_line)
                  - num_tail_shrink
              ]
          center_lines.append(center_line.astype(np.int32))
  
          self._draw_center_region_maps(
              resampled_top_line,
              resampled_bot_line,
              center_line,
              center_region_mask,
              top_height_map,
              bot_height_map,
              sin_map,
              cos_map,
              self.center_region_shrink_ratio,
          )
  
      return (
          center_lines,
          center_region_mask,
          top_height_map,
          bot_height_map,
          sin_map,
          cos_map,
      )
  
imports: from typing import Dict, List, Sequence, Tuple
  import cv2
  import numpy
  import torch
  from mmcv.image import imrescale
  from mmdet.models.utils import multi_apply
  from numpy import ndarray
  from numpy.linalg import norm
  from torch import Tensor
  from mmocr.registry import MODELS
  from mmocr.structures import TextDetDataSample
  from mmocr.utils import check_argument
  from .textsnake_module_loss import TextSnakeModuleLoss
label_desc: Use image node_id 5 for calling the DRRGModuleLoss obj's underlying member method code with example usage: obj._generate_center_mask_attrib_maps(img_size, text_polys) and returns: center_lines,  center_region_mask,  top_height_map,  bot_height_map,  sin_map,  cos_map