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: Compute loss for one feature level.
  
  Args:
      pred (dict): A dict with keys ``cls_res`` and ``reg_res``
          corresponds to the classification result and regression result
          from one feature level.
      gt (Tensor): Ground truth for one feature level. Cls and reg
          targets are concatenated along the channel dimension.
  
  Returns:
      list[Tensor]: A list of losses for each feature level.
docstr_tok: ["Compute","loss","for","one","feature","level",".","Args",":","pred","(","dict",")",":","A","dict","with","keys","``","cls_res","``","and","``","reg_res","``","corresponds","to","the","classification","result","and","regression","result","from","one","feature","level",".","gt","(","Tensor",")",":","Ground","truth","for","one","feature","level",".","Cls","and","reg","targets","are","concatenated","along","the","channel","dimension",".","Returns",":","list","[","Tensor","]",":","A","list","of","losses","for","each","feature","level","."]
code: def forward_single(
      self, pred: torch.Tensor, gt: torch.Tensor
  ) -> Sequence[torch.Tensor]:
      """Compute loss for one feature level.
  
      Args:
          pred (dict): A dict with keys ``cls_res`` and ``reg_res``
              corresponds to the classification result and regression result
              from one feature level.
          gt (Tensor): Ground truth for one feature level. Cls and reg
              targets are concatenated along the channel dimension.
  
      Returns:
          list[Tensor]: A list of losses for each feature level.
      """
      assert isinstance(pred, dict) and isinstance(gt, torch.Tensor)
      cls_pred = pred["cls_res"].permute(0, 2, 3, 1).contiguous()
      reg_pred = pred["reg_res"].permute(0, 2, 3, 1).contiguous()
  
      gt = gt.permute(0, 2, 3, 1).contiguous()
  
      k = 2 * self.fourier_degree + 1
      tr_pred = cls_pred[:, :, :, :2].view(-1, 2)
      tcl_pred = cls_pred[:, :, :, 2:].view(-1, 2)
      x_pred = reg_pred[:, :, :, 0:k].view(-1, k)
      y_pred = reg_pred[:, :, :, k : 2 * k].view(-1, k)
  
      tr_mask = gt[:, :, :, :1].view(-1)
      tcl_mask = gt[:, :, :, 1:2].view(-1)
      train_mask = gt[:, :, :, 2:3].view(-1)
      x_map = gt[:, :, :, 3 : 3 + k].view(-1, k)
      y_map = gt[:, :, :, 3 + k :].view(-1, k)
  
      tr_train_mask = (train_mask * tr_mask).float()
      # text region loss
      loss_tr = self.loss_tr(
          tr_pred.softmax(-1)[:, 1], tr_mask, train_mask
      )
  
      # text center line loss
      tr_neg_mask = 1 - tr_train_mask
      loss_tcl_positive = self.loss_center(
          tcl_pred.softmax(-1)[:, 1], tcl_mask, tr_train_mask
      )
      loss_tcl_negative = self.loss_center(
          tcl_pred.softmax(-1)[:, 1], tcl_mask, tr_neg_mask
      )
      loss_tcl = loss_tcl_positive + 0.5 * loss_tcl_negative
  
      # regression loss
      loss_reg_x = torch.tensor(0.0).float().to(x_pred.device)
      loss_reg_y = torch.tensor(0.0).float().to(x_pred.device)
      if tr_train_mask.sum().item() > 0:
          weight = (
              tr_mask[tr_train_mask.bool()].float()
              + tcl_mask[tr_train_mask.bool()].float()
          ) / 2
          weight = weight.contiguous().view(-1, 1)
  
          ft_x, ft_y = self._fourier2poly(x_map, y_map)
          ft_x_pre, ft_y_pre = self._fourier2poly(x_pred, y_pred)
  
          loss_reg_x = torch.mean(
              weight
              * self.loss_reg_x(
                  ft_x_pre[tr_train_mask.bool()],
                  ft_x[tr_train_mask.bool()],
              )
          )
          loss_reg_y = torch.mean(
              weight
              * self.loss_reg_x(
                  ft_y_pre[tr_train_mask.bool()],
                  ft_y[tr_train_mask.bool()],
              )
          )
  
      return loss_tr, loss_tcl, loss_reg_x, loss_reg_y
  
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 3 for calling the FCEModuleLoss obj's underlying member method code with example usage: obj.forward_single(pred, gt) and returns: loss_tr,  loss_tcl,  loss_reg_x,  loss_reg_y