class_docstr: Base class for the module loss of segmentation-based text detection
  algorithms with some handy utilities.
class_docstr_tok: ["Base","class","for","the","module","loss","of","segmentation-based","text","detection","algorithms","with","some","handy","utilities","."]
docstr: Generate text instance kernels according to a shrink ratio.
  
  Args:
      img_size (tuple(int, int)): The image size of (height, width).
      text_polys (Sequence[np.ndarray]): 2D array of text polygons.
      shrink_ratio (float or int): The shrink ratio of kernel.
      max_shrink_dist (float or int): The maximum shrinking distance.
      ignore_flags (torch.BoolTensor, optional): Indicate whether the
          corresponding text polygon is ignored. Defaults to None.
  
  Returns:
      tuple(ndarray, ndarray): The text instance kernels of shape
          (height, width) and updated ignorance flags.
docstr_tok: ["Generate","text","instance","kernels","according","to","a","shrink","ratio",".","Args",":","img_size","(","tuple","(","int",",","int",")",")",":","The","image","size","of","(","height",",","width",")",".","text_polys","(","Sequence","[","np.ndarray","]",")",":","2D","array","of","text","polygons",".","shrink_ratio","(","float","or","int",")",":","The","shrink","ratio","of","kernel",".","max_shrink_dist","(","float","or","int",")",":","The","maximum","shrinking","distance",".","ignore_flags","(","torch.BoolTensor",",","optional",")",":","Indicate","whether","the","corresponding","text","polygon","is","ignored",".","Defaults","to","None",".","Returns",":","tuple","(","ndarray",",","ndarray",")",":","The","text","instance","kernels","of","shape","(","height",",","width",")","and","updated","ignorance","flags","."]
code: def _generate_kernels(
      self,
      img_size: Tuple[int, int],
      text_polys: Sequence[np.ndarray],
      shrink_ratio: float,
      max_shrink_dist: Union[float, int] = sys.maxsize,
      ignore_flags: Optional[torch.Tensor] = None,
  ) -> Tuple[np.ndarray, np.ndarray]:
      """Generate text instance kernels according to a shrink ratio.
  
      Args:
          img_size (tuple(int, int)): The image size of (height, width).
          text_polys (Sequence[np.ndarray]): 2D array of text polygons.
          shrink_ratio (float or int): The shrink ratio of kernel.
          max_shrink_dist (float or int): The maximum shrinking distance.
          ignore_flags (torch.BoolTensor, optional): Indicate whether the
              corresponding text polygon is ignored. Defaults to None.
  
      Returns:
          tuple(ndarray, ndarray): The text instance kernels of shape
              (height, width) and updated ignorance flags.
      """
      assert isinstance(img_size, tuple)
      assert isinstance(shrink_ratio, (float, int))
  
      logger: MMLogger = MMLogger.get_current_instance()
  
      h, w = img_size
      text_kernel = np.zeros((h, w), dtype=np.float32)
  
      for text_ind, poly in enumerate(text_polys):
          if ignore_flags is not None and ignore_flags[text_ind]:
              continue
          poly = poly.reshape(-1, 2).astype(np.int32)
          poly_obj = Polygon(poly)
          area = poly_obj.area
          peri = poly_obj.length
          distance = min(
              int(
                  area
                  * (1 - shrink_ratio * shrink_ratio)
                  / (peri + 0.001)
                  + 0.5
              ),
              max_shrink_dist,
          )
          shrunk_poly = offset_polygon(poly, -distance)
  
          if len(shrunk_poly) == 0:
              if ignore_flags is not None:
                  ignore_flags[text_ind] = True
              continue
  
          try:
              shrunk_poly = shrunk_poly.reshape(-1, 2)
          except Exception as e:
              logger.info(f"{shrunk_poly} with error {e}")
              if ignore_flags is not None:
                  ignore_flags[text_ind] = True
              continue
  
          cv2.fillPoly(
              text_kernel, [shrunk_poly.astype(np.int32)], text_ind + 1
          )
  
      return text_kernel, ignore_flags
  
file_path: mmocr/mmocr/models/textdet/module_losses/seg_based_module_loss.py
imports: import sys
  from typing import Optional, Sequence, Tuple, Union
  import cv2
  import numpy
  import torch
  from mmengine.logging import MMLogger
  from shapely.geometry import Polygon
  from mmocr.utils.polygon_utils import offset_polygon
  from .base import BaseTextDetModuleLoss
label_desc: Use image node_id 1 for calling the SegBasedModuleLoss obj's underlying member method code with example usage: obj._generate_kernels(img_size, text_polys, shrink_ratio, max_shrink_dist, ignore_flags) and returns: text_kernel,  ignore_flags