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: Transform Fourier coefficient maps to polygon maps.
  
  Args:
      real_maps (tensor): A map composed of the real parts of the
          Fourier coefficients, whose shape is (-1, 2k+1)
      imag_maps (tensor):A map composed of the imag parts of the
          Fourier coefficients, whose shape is (-1, 2k+1)
  
  Returns
      tuple(tensor, tensor):
  
      - x_maps (tensor): A map composed of the x value of the polygon
          represented by n sample points (xn, yn), whose shape is (-1, n)
      - y_maps (tensor): A map composed of the y value of the polygon
          represented by n sample points (xn, yn), whose shape is (-1, n)
docstr_tok: ["Transform","Fourier","coefficient","maps","to","polygon","maps",".","Args",":","real_maps","(","tensor",")",":","A","map","composed","of","the","real","parts","of","the","Fourier","coefficients",",","whose","shape","is","(","-1",",","2k+1",")","imag_maps","(","tensor",")",":","A","map","composed","of","the","imag","parts","of","the","Fourier","coefficients",",","whose","shape","is","(","-1",",","2k+1",")","Returns","tuple","(","tensor",",","tensor",")",":","-","x_maps","(","tensor",")",":","A","map","composed","of","the","x","value","of","the","polygon","represented","by","n","sample","points","(","xn",",","yn",")",",","whose","shape","is","(","-1",",","n",")","-","y_maps","(","tensor",")",":","A","map","composed","of","the","y","value","of","the","polygon","represented","by","n","sample","points","(","xn",",","yn",")",",","whose","shape","is","(","-1",",","n",")"]
code: def _fourier2poly(
      self, real_maps: torch.Tensor, imag_maps: torch.Tensor
  ) -> Sequence[torch.Tensor]:
      """Transform Fourier coefficient maps to polygon maps.
  
      Args:
          real_maps (tensor): A map composed of the real parts of the
              Fourier coefficients, whose shape is (-1, 2k+1)
          imag_maps (tensor):A map composed of the imag parts of the
              Fourier coefficients, whose shape is (-1, 2k+1)
  
      Returns
          tuple(tensor, tensor):
  
          - x_maps (tensor): A map composed of the x value of the polygon
              represented by n sample points (xn, yn), whose shape is (-1, n)
          - y_maps (tensor): A map composed of the y value of the polygon
              represented by n sample points (xn, yn), whose shape is (-1, n)
      """
  
      device = real_maps.device
  
      k_vect = torch.arange(
          -self.fourier_degree,
          self.fourier_degree + 1,
          dtype=torch.float,
          device=device,
      ).view(-1, 1)
      i_vect = torch.arange(
          0, self.num_sample, dtype=torch.float, device=device
      ).view(1, -1)
  
      transform_matrix = (
          2 * np.pi / self.num_sample * torch.mm(k_vect, i_vect)
      )
  
      x1 = torch.einsum(
          "ak, kn-> an", real_maps, torch.cos(transform_matrix)
      )
      x2 = torch.einsum(
          "ak, kn-> an", imag_maps, torch.sin(transform_matrix)
      )
      y1 = torch.einsum(
          "ak, kn-> an", real_maps, torch.sin(transform_matrix)
      )
      y2 = torch.einsum(
          "ak, kn-> an", imag_maps, torch.cos(transform_matrix)
      )
  
      x_maps = x1 - x2
      y_maps = y1 + y2
  
      return x_maps, y_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 14 for calling the FCEModuleLoss obj's underlying member method code with example usage: obj._fourier2poly(real_maps, imag_maps) and returns: x_maps,  y_maps