class_docstr: The class for implementing TextSnake loss. This is partially adapted
  from https://github.com/princewang1994/TextSnake.pytorch.
  
  TextSnake: `A Flexible Representation for Detecting Text of Arbitrary
  Shapes <https://arxiv.org/abs/1807.01544>`_.
  
  Args:
      ohem_ratio (float): The negative/positive ratio in ohem.
      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.
      resample_step (float): The step of resampling.
      center_region_shrink_ratio (float): The shrink ratio of text center.
      loss_text (dict): The loss config used to calculate the text loss.
      loss_center (dict): The loss config used to calculate the center loss.
      loss_radius (dict): The loss config used to calculate the radius loss.
      loss_sin (dict): The loss config used to calculate the sin loss.
      loss_cos (dict): The loss config used to calculate the cos loss.
docstr: Generate text center region mask and geometric attribute maps.
  
  Args:
      img_size (tuple(int, int)): The image size of (height, width).
      text_polys (list[ndarray]): The list of text polygons.
  
  Returns:
      Tuple(center_region_mask, radius_map, sin_map, cos_map):
  
      - center_region_mask (ndarray): The text center region mask.
      - radius_map (ndarray): The distance map from each pixel in text
        center region to top sideline.
      - 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","mask","and","geometric","attribute","maps",".","Args",":","img_size","(","tuple","(","int",",","int",")",")",":","The","image","size","of","(","height",",","width",")",".","text_polys","(","list","[","ndarray","]",")",":","The","list","of","text","polygons",".","Returns",":","Tuple","(","center_region_mask",",","radius_map",",","sin_map",",","cos_map",")",":","-","center_region_mask","(","ndarray",")",":","The","text","center","region","mask",".","-","radius_map","(","ndarray",")",":","The","distance","map","from","each","pixel","in","text","center","region","to","top","sideline",".","-","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[ndarray, ndarray, ndarray, ndarray]:
      """Generate text center region mask and geometric attribute maps.
  
      Args:
          img_size (tuple(int, int)): The image size of (height, width).
          text_polys (list[ndarray]): The list of text polygons.
  
      Returns:
          Tuple(center_region_mask, radius_map, sin_map, cos_map):
  
          - center_region_mask (ndarray): The text center region mask.
          - radius_map (ndarray): The distance map from each pixel in text
            center region to top sideline.
          - 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)
  
      center_region_mask = np.zeros(img_size, np.uint8)
      radius_map = np.zeros(img_size, dtype=np.float32)
      sin_map = np.zeros(img_size, dtype=np.float32)
      cos_map = np.zeros(img_size, dtype=np.float32)
  
      for poly in text_polys:
          polygon_points = np.array(poly).reshape(-1, 2)
  
          n = len(polygon_points)
          keep_inds = []
          for i in range(n):
              if (
                  norm(polygon_points[i] - polygon_points[(i + 1) % n])
                  > 1e-5
              ):
                  keep_inds.append(i)
          polygon_points = polygon_points[keep_inds]
  
          _, _, 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]) > 0.9:
              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 = (
              norm(resampled_top_line[0] - resampled_bot_line[0]) / 4.0
          )
          line_tail_shrink_len = (
              norm(resampled_top_line[-1] - resampled_bot_line[-1])
              / 4.0
          )
          head_shrink_num = int(
              line_head_shrink_len // self.resample_step
          )
          tail_shrink_num = int(
              line_tail_shrink_len // self.resample_step
          )
  
          if len(center_line) > head_shrink_num + tail_shrink_num + 2:
              center_line = center_line[
                  head_shrink_num : len(center_line) - tail_shrink_num
              ]
              resampled_top_line = resampled_top_line[
                  head_shrink_num : len(resampled_top_line)
                  - tail_shrink_num
              ]
              resampled_bot_line = resampled_bot_line[
                  head_shrink_num : len(resampled_bot_line)
                  - tail_shrink_num
              ]
  
          self._draw_center_region_maps(
              resampled_top_line,
              resampled_bot_line,
              center_line,
              center_region_mask,
              radius_map,
              sin_map,
              cos_map,
              self.center_region_shrink_ratio,
          )
  
      return center_region_mask, radius_map, sin_map, cos_map
  
imports: from typing import Dict, List, Sequence, Tuple
  import cv2
  import numpy
  import torch
  from mmcv.image import impad, 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 .seg_based_module_loss import SegBasedModuleLoss
label_desc: Use image node_id 7 for calling the TextSnakeModuleLoss obj's underlying member method code with example usage: obj._generate_center_mask_attrib_maps(img_size, text_polys) and returns: center_region_mask,  radius_map,  sin_map,  cos_map