class_docstr: The class for implementing DBNet loss.
  
  This is partially adapted from https://github.com/MhLiao/DB.
  
  Args:
      loss_prob (dict): The loss config for probability map. Defaults to
          dict(type='MaskedBalancedBCEWithLogitsLoss').
      loss_thr (dict): The loss config for threshold map. Defaults to
          dict(type='MaskedSmoothL1Loss', beta=0).
      loss_db (dict): The loss config for binary map. Defaults to
          dict(type='MaskedDiceLoss').
      weight_prob (float): The weight of probability map loss.
          Denoted as :math:`\alpha` in paper. Defaults to 5.
      weight_thr (float): The weight of threshold map loss.
          Denoted as :math:`\beta` in paper. Defaults to 10.
      shrink_ratio (float): The ratio of shrunk text region. Defaults to 0.4.
      thr_min (float): The minimum threshold map value. Defaults to 0.3.
      thr_max (float): The maximum threshold map value. Defaults to 0.7.
      min_sidelength (int or float): The minimum sidelength of the
          minimum rotated rectangle around any text region. Defaults to 8.
docstr: Generate threshold map for one polygon.
  
  Args:
      polygon (np.ndarray): The polygon.
      canvas (np.ndarray): The generated threshold map.
      mask (np.ndarray): The generated threshold mask.
docstr_tok: ["Generate","threshold","map","for","one","polygon",".","Args",":","polygon","(","np.ndarray",")",":","The","polygon",".","canvas","(","np.ndarray",")",":","The","generated","threshold","map",".","mask","(","np.ndarray",")",":","The","generated","threshold","mask","."]
code: def _draw_border_map(
      self, polygon: np.ndarray, canvas: np.ndarray, mask: np.ndarray
  ) -> None:
      """Generate threshold map for one polygon.
  
      Args:
          polygon (np.ndarray): The polygon.
          canvas (np.ndarray): The generated threshold map.
          mask (np.ndarray): The generated threshold mask.
      """
  
      polygon = polygon.reshape(-1, 2)
      polygon_obj = Polygon(polygon)
      distance = (
          polygon_obj.area
          * (1 - np.power(self.shrink_ratio, 2))
          / polygon_obj.length
      )
      expanded_polygon = offset_polygon(polygon, distance)
      if len(expanded_polygon) == 0:
          print(
              f"Padding {polygon} with {distance} gets {expanded_polygon}"
          )
          expanded_polygon = polygon.copy().astype(np.int32)
      else:
          expanded_polygon = expanded_polygon.reshape(-1, 2).astype(
              np.int32
          )
  
      x_min = expanded_polygon[:, 0].min()
      x_max = expanded_polygon[:, 0].max()
      y_min = expanded_polygon[:, 1].min()
      y_max = expanded_polygon[:, 1].max()
  
      width = x_max - x_min + 1
      height = y_max - y_min + 1
  
      polygon[:, 0] = polygon[:, 0] - x_min
      polygon[:, 1] = polygon[:, 1] - y_min
  
      xs = np.broadcast_to(
          np.linspace(0, width - 1, num=width).reshape(1, width),
          (height, width),
      )
      ys = np.broadcast_to(
          np.linspace(0, height - 1, num=height).reshape(height, 1),
          (height, width),
      )
  
      distance_map = np.zeros(
          (polygon.shape[0], height, width), dtype=np.float32
      )
      for i in range(polygon.shape[0]):
          j = (i + 1) % polygon.shape[0]
          absolute_distance = self._dist_points2line(
              xs, ys, polygon[i], polygon[j]
          )
          distance_map[i] = np.clip(absolute_distance / distance, 0, 1)
      distance_map = distance_map.min(axis=0)
  
      x_min_valid = min(max(0, x_min), canvas.shape[1] - 1)
      x_max_valid = min(max(0, x_max), canvas.shape[1] - 1)
      y_min_valid = min(max(0, y_min), canvas.shape[0] - 1)
      y_max_valid = min(max(0, y_max), canvas.shape[0] - 1)
  
      if x_min_valid - x_min >= width or y_min_valid - y_min >= height:
          return
  
      cv2.fillPoly(mask, [expanded_polygon.astype(np.int32)], 1.0)
      canvas[
          y_min_valid : y_max_valid + 1, x_min_valid : x_max_valid + 1
      ] = np.fmax(
          1
          - distance_map[
              y_min_valid - y_min : y_max_valid - y_max + height,
              x_min_valid - x_min : x_max_valid - x_max + width,
          ],
          canvas[
              y_min_valid : y_max_valid + 1,
              x_min_valid : x_max_valid + 1,
          ],
      )
  
imports: from typing import Dict, List, Sequence, Tuple, Union
  import cv2
  import numpy
  import torch
  from mmdet.models.utils import multi_apply
  from shapely.geometry import Polygon
  from torch import Tensor
  from mmocr.registry import MODELS
  from mmocr.structures import TextDetDataSample
  from mmocr.utils import offset_polygon
  from mmocr.utils.typing_utils import ArrayLike
  from .seg_based_module_loss import SegBasedModuleLoss
label_desc: Use image node_id 5 for calling the DBModuleLoss obj's underlying member method code with example usage: obj._draw_border_map(polygon, canvas, mask) without return types