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.
      ohem_ratio (float): the negative/positive ratio in OHEM.
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",".","ohem_ratio","(","float",")",":","the","negative\/positive","ratio","in","OHEM","."]
code: def forward_single(self, pred, gt):
      cls_pred = paddle.transpose(pred[0], (0, 2, 3, 1))
      reg_pred = paddle.transpose(pred[1], (0, 2, 3, 1))
      gt = paddle.transpose(gt, (0, 2, 3, 1))
  
      k = 2 * self.fourier_degree + 1
      tr_pred = paddle.reshape(cls_pred[:, :, :, :2], (-1, 2))
      tcl_pred = paddle.reshape(cls_pred[:, :, :, 2:], (-1, 2))
      x_pred = paddle.reshape(reg_pred[:, :, :, 0:k], (-1, k))
      y_pred = paddle.reshape(reg_pred[:, :, :, k : 2 * k], (-1, k))
  
      tr_mask = gt[:, :, :, :1].reshape([-1])
      tcl_mask = gt[:, :, :, 1:2].reshape([-1])
      train_mask = gt[:, :, :, 2:3].reshape([-1])
      x_map = paddle.reshape(gt[:, :, :, 3 : 3 + k], (-1, k))
      y_map = paddle.reshape(gt[:, :, :, 3 + k :], (-1, k))
  
      tr_train_mask = (train_mask * tr_mask).astype("bool")
      tr_train_mask2 = paddle.concat(
          [tr_train_mask.unsqueeze(1), tr_train_mask.unsqueeze(1)],
          axis=1,
      )
      # tr loss
      loss_tr = self.ohem(tr_pred, tr_mask, train_mask)
      # tcl loss
      loss_tcl = paddle.to_tensor(0.0).astype("float32")
      tr_neg_mask = tr_train_mask.logical_not()
      tr_neg_mask2 = paddle.concat(
          [tr_neg_mask.unsqueeze(1), tr_neg_mask.unsqueeze(1)], axis=1
      )
      if tr_train_mask.sum().item() > 0:
          loss_tcl_pos = F.cross_entropy(
              tcl_pred.masked_select(tr_train_mask2).reshape([-1, 2]),
              tcl_mask.masked_select(tr_train_mask).astype("int64"),
          )
          loss_tcl_neg = F.cross_entropy(
              tcl_pred.masked_select(tr_neg_mask2).reshape([-1, 2]),
              tcl_mask.masked_select(tr_neg_mask).astype("int64"),
          )
          loss_tcl = loss_tcl_pos + 0.5 * loss_tcl_neg
  
      # regression loss
      loss_reg_x = paddle.to_tensor(0.0).astype("float32")
      loss_reg_y = paddle.to_tensor(0.0).astype("float32")
      if tr_train_mask.sum().item() > 0:
          weight = (
              tr_mask.masked_select(
                  tr_train_mask.astype("bool")
              ).astype("float32")
              + tcl_mask.masked_select(
                  tr_train_mask.astype("bool")
              ).astype("float32")
          ) / 2
          weight = weight.reshape([-1, 1])
  
          ft_x, ft_y = self.fourier2poly(x_map, y_map)
          ft_x_pre, ft_y_pre = self.fourier2poly(x_pred, y_pred)
  
          dim = ft_x.shape[1]
  
          tr_train_mask3 = paddle.concat(
              [tr_train_mask.unsqueeze(1) for i in range(dim)], axis=1
          )
  
          loss_reg_x = paddle.mean(
              weight
              * F.smooth_l1_loss(
                  ft_x_pre.masked_select(tr_train_mask3).reshape(
                      [-1, dim]
                  ),
                  ft_x.masked_select(tr_train_mask3).reshape([-1, dim]),
                  reduction="none",
              )
          )
          loss_reg_y = paddle.mean(
              weight
              * F.smooth_l1_loss(
                  ft_y_pre.masked_select(tr_train_mask3).reshape(
                      [-1, dim]
                  ),
                  ft_y.masked_select(tr_train_mask3).reshape([-1, dim]),
                  reduction="none",
              )
          )
  
      return loss_tr, loss_tcl, loss_reg_x, loss_reg_y
  
file_path: PaddleOCR/ppocr/losses/det_fce_loss.py
imports: import numpy
  from paddle import nn
  import paddle
  import paddle.nn.functional
  from functools import partial
label_desc: Use image node_id 3 for calling the FCELoss 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