class_docstr: The class for implementing FCENet loss.
  
  FCENet(CVPR2021): `Fourier Contour Embedding for Arbitrary-shaped Text
  Detection <https://arxiv.org/abs/2104.10442>`_
  
  Args:
      fourier_degree (int) : The maximum Fourier transform degree k.
      num_sample (int) : The sampling points number of regression
          loss. If it is too small, fcenet tends to be overfitting.
      negative_ratio (float or int): Maximum ratio of negative
          samples to positive ones in OHEM. Defaults to 3.
      resample_step (float): The step size for resampling the text center
          line (TCL). It's better not to exceed half of the minimum width.
      center_region_shrink_ratio (float): The shrink ratio of text center
          region.
      level_size_divisors (tuple(int)): The downsample ratio on each level.
      level_proportion_range (tuple(tuple(int))): The range of text sizes
          assigned to each level.
      loss_tr (dict) : The loss config used to calculate the text region
          loss. Defaults to dict(type='MaskedBalancedBCELoss').
      loss_tcl (dict) : The loss config used to calculate the text center
          line loss. Defaults to dict(type='MaskedBCELoss').
      loss_reg_x (dict) : The loss config used to calculate the regression
          loss on x axis. Defaults to dict(type='MaskedSmoothL1Loss').
      loss_reg_y (dict) : The loss config used to calculate the regression
          loss on y axis. Defaults to dict(type='MaskedSmoothL1Loss').
class_docstr_tok: ["The","class","for","implementing","FCENet","loss",".","FCENet","(","CVPR2021",")",":","`","Fourier","Contour","Embedding","for","Arbitrary-shaped","Text","Detection","<","https",":","\/\/arxiv.org\/abs\/2104.10442",">","`","_","Args",":","fourier_degree","(","int",")",":","The","maximum","Fourier","transform","degree","k.","num_sample","(","int",")",":","The","sampling","points","number","of","regression","loss",".","If","it","is","too","small",",","fcenet","tends","to","be","overfitting",".","negative_ratio","(","float","or","int",")",":","Maximum","ratio","of","negative","samples","to","positive","ones","in","OHEM",".","Defaults","to","3.","resample_step","(","float",")",":","The","step","size","for","resampling","the","text","center","line","(","TCL",")",".","It","'s","better","not","to","exceed","half","of","the","minimum","width",".","center_region_shrink_ratio","(","float",")",":","The","shrink","ratio","of","text","center","region",".","level_size_divisors","(","tuple","(","int",")",")",":","The","downsample","ratio","on","each","level",".","level_proportion_range","(","tuple","(","tuple","(","int",")",")",")",":","The","range","of","text","sizes","assigned","to","each","level",".","loss_tr","(","dict",")",":","The","loss","config","used","to","calculate","the","text","region","loss",".","Defaults","to","dict","(","type='MaskedBalancedBCELoss","'",")",".","loss_tcl","(","dict",")",":","The","loss","config","used","to","calculate","the","text","center","line","loss",".","Defaults","to","dict","(","type='MaskedBCELoss","'",")",".","loss_reg_x","(","dict",")",":","The","loss","config","used","to","calculate","the","regression","loss","on","x","axis",".","Defaults","to","dict","(","type='MaskedSmoothL1Loss","'",")",".","loss_reg_y","(","dict",")",":","The","loss","config","used","to","calculate","the","regression","loss","on","y","axis",".","Defaults","to","dict","(","type='MaskedSmoothL1Loss","'",")","."]
docstr: Generate targets for one feature level.
  
  Args:
      img_size (tuple(int, int)): The image size of (height, width).
      text_polys (List[ndarray]): 2D array of text polygons.
      ignore_flags (torch.BoolTensor, optional): Indicate whether the
          corresponding text polygon is ignored. Defaults to None.
  
  Returns:
      tuple[Tensor]: A tuple of three tensors from one feature level
      as the targets.
docstr_tok: ["Generate","targets","for","one","feature","level",".","Args",":","img_size","(","tuple","(","int",",","int",")",")",":","The","image","size","of","(","height",",","width",")",".","text_polys","(","List","[","ndarray","]",")",":","2D","array","of","text","polygons",".","ignore_flags","(","torch.BoolTensor",",","optional",")",":","Indicate","whether","the","corresponding","text","polygon","is","ignored",".","Defaults","to","None",".","Returns",":","tuple","[","Tensor","]",":","A","tuple","of","three","tensors","from","one","feature","level","as","the","targets","."]
code: def _generate_level_targets(
      self,
      img_size: Tuple[int, int],
      text_polys: List[ArrayLike],
      ignore_flags: Optional[torch.BoolTensor] = None,
  ) -> Tuple[torch.Tensor]:
      """Generate targets for one feature level.
  
      Args:
          img_size (tuple(int, int)): The image size of (height, width).
          text_polys (List[ndarray]): 2D array of text polygons.
          ignore_flags (torch.BoolTensor, optional): Indicate whether the
              corresponding text polygon is ignored. Defaults to None.
  
      Returns:
          tuple[Tensor]: A tuple of three tensors from one feature level
          as the targets.
      """
      h, w = img_size
      lv_size_divs = self.level_size_divisors
      lv_proportion_range = self.level_proportion_range
  
      lv_size_divs = self.level_size_divisors
      lv_proportion_range = self.level_proportion_range
      lv_text_polys = [[] for i in range(len(lv_size_divs))]
      lv_ignore_polys = [[] for i in range(len(lv_size_divs))]
      level_maps = []
  
      for poly_ind, poly in enumerate(text_polys):
          poly = np.array(poly, dtype=np.int_).reshape((1, -1, 2))
          _, _, box_w, box_h = cv2.boundingRect(poly)
          proportion = max(box_h, box_w) / (h + 1e-8)
  
          for ind, proportion_range in enumerate(lv_proportion_range):
              if proportion_range[0] < proportion < proportion_range[1]:
                  if (
                      ignore_flags is not None
                      and ignore_flags[poly_ind]
                  ):
                      lv_ignore_polys[ind].append(
                          poly[0] / lv_size_divs[ind]
                      )
                  else:
                      lv_text_polys[ind].append(
                          poly[0] / lv_size_divs[ind]
                      )
  
      for ind, size_divisor in enumerate(lv_size_divs):
          current_level_maps = []
          level_img_size = (h // size_divisor, w // size_divisor)
  
          text_region = self._generate_text_region_mask(
              level_img_size, lv_text_polys[ind]
          )[None]
          current_level_maps.append(text_region)
  
          center_region = self._generate_center_region_mask(
              level_img_size, lv_text_polys[ind]
          )[None]
          current_level_maps.append(center_region)
  
          effective_mask = self._generate_effective_mask(
              level_img_size, lv_ignore_polys[ind]
          )[None]
          current_level_maps.append(effective_mask)
  
          (
              fourier_real_map,
              fourier_image_maps,
          ) = self._generate_fourier_maps(
              level_img_size, lv_text_polys[ind]
          )
          current_level_maps.append(fourier_real_map)
          current_level_maps.append(fourier_image_maps)
  
          level_maps.append(np.concatenate(current_level_maps))
  
      return level_maps
  
imports: from typing import Dict, List, Optional, Sequence, Tuple, Union
  import cv2
  import numpy
  import torch
  from mmdet.models.utils import multi_apply
  from numpy.fft import fft
  from numpy.linalg import norm
  from mmocr.registry import MODELS
  from mmocr.structures import TextDetDataSample
  from mmocr.utils.typing_utils import ArrayLike
  from .textsnake_module_loss import TextSnakeModuleLoss
label_desc: Use image node_id 6 for calling the FCEModuleLoss obj's underlying member method code with example usage: obj._generate_level_targets(img_size, text_polys, ignore_flags) and returns: level_maps