class_docstr: Head block for SOLOv2 network
  
  Args:
      num_classes (int): Number of output classes.
      in_channels (int): Number of input channels.
      seg_feat_channels (int): Num_filters of kernel & categroy branch convolution operation.
      stacked_convs (int): Times of convolution operation.
      num_grids (list[int]): List of feature map grids size.
      kernel_out_channels (int): Number of output channels in kernel branch.
      dcn_v2_stages (list): Which stage use dcn v2 in tower. It is between [0, stacked_convs).
      segm_strides (list[int]): List of segmentation area stride.
      solov2_loss (object): SOLOv2Loss instance.
      score_threshold (float): Threshold of categroy score.
      mask_nms (object): MaskMatrixNMS instance.
class_docstr_tok: ["Head","block","for","SOLOv2","network","Args",":","num_classes","(","int",")",":","Number","of","output","classes",".","in_channels","(","int",")",":","Number","of","input","channels",".","seg_feat_channels","(","int",")",":","Num_filters","of","kernel","&","categroy","branch","convolution","operation",".","stacked_convs","(","int",")",":","Times","of","convolution","operation",".","num_grids","(","list","[","int","]",")",":","List","of","feature","map","grids","size",".","kernel_out_channels","(","int",")",":","Number","of","output","channels","in","kernel","branch",".","dcn_v2_stages","(","list",")",":","Which","stage","use","dcn","v2","in","tower",".","It","is","between","[","0",",","stacked_convs",")",".","segm_strides","(","list","[","int","]",")",":","List","of","segmentation","area","stride",".","solov2_loss","(","object",")",":","SOLOv2Loss","instance",".","score_threshold","(","float",")",":","Threshold","of","categroy","score",".","mask_nms","(","object",")",":","MaskMatrixNMS","instance","."]
docstr: Get loss of network of SOLOv2.
  
  Args:
      cate_preds (list): Tensor list of categroy branch output.
      kernel_preds (list): Tensor list of kernel branch output.
      ins_pred (list): Tensor list of instance branch output.
      ins_labels (list): List of instance labels pre batch.
      cate_labels (list): List of categroy labels pre batch.
      grid_order_list (list): List of index in pre grid.
      fg_num (int): Number of positive samples in a mini-batch.
  Returns:
      loss_ins (Tensor): The instance loss Tensor of SOLOv2 network.
      loss_cate (Tensor): The category loss Tensor of SOLOv2 network.
docstr_tok: ["Get","loss","of","network","of","SOLOv2",".","Args",":","cate_preds","(","list",")",":","Tensor","list","of","categroy","branch","output",".","kernel_preds","(","list",")",":","Tensor","list","of","kernel","branch","output",".","ins_pred","(","list",")",":","Tensor","list","of","instance","branch","output",".","ins_labels","(","list",")",":","List","of","instance","labels","pre","batch",".","cate_labels","(","list",")",":","List","of","categroy","labels","pre","batch",".","grid_order_list","(","list",")",":","List","of","index","in","pre","grid",".","fg_num","(","int",")",":","Number","of","positive","samples","in","a","mini-batch",".","Returns",":","loss_ins","(","Tensor",")",":","The","instance","loss","Tensor","of","SOLOv2","network",".","loss_cate","(","Tensor",")",":","The","category","loss","Tensor","of","SOLOv2","network","."]
code: def get_loss(
      self,
      cate_preds,
      kernel_preds,
      ins_pred,
      ins_labels,
      cate_labels,
      grid_order_list,
      fg_num,
  ):
      """
      Get loss of network of SOLOv2.
  
      Args:
          cate_preds (list): Tensor list of categroy branch output.
          kernel_preds (list): Tensor list of kernel branch output.
          ins_pred (list): Tensor list of instance branch output.
          ins_labels (list): List of instance labels pre batch.
          cate_labels (list): List of categroy labels pre batch.
          grid_order_list (list): List of index in pre grid.
          fg_num (int): Number of positive samples in a mini-batch.
      Returns:
          loss_ins (Tensor): The instance loss Tensor of SOLOv2 network.
          loss_cate (Tensor): The category loss Tensor of SOLOv2 network.
      """
      batch_size = paddle.shape(grid_order_list[0])[0]
      ins_pred_list = []
      for kernel_preds_level, grid_orders_level in zip(
          kernel_preds, grid_order_list
      ):
          if grid_orders_level.shape[1] == 0:
              ins_pred_list.append(None)
              continue
          grid_orders_level = paddle.reshape(grid_orders_level, [-1])
          reshape_pred = paddle.reshape(
              kernel_preds_level,
              shape=(
                  paddle.shape(kernel_preds_level)[0],
                  paddle.shape(kernel_preds_level)[1],
                  -1,
              ),
          )
          reshape_pred = paddle.transpose(reshape_pred, [0, 2, 1])
          reshape_pred = paddle.reshape(
              reshape_pred, shape=(-1, paddle.shape(reshape_pred)[2])
          )
          gathered_pred = paddle.gather(
              reshape_pred, index=grid_orders_level
          )
          gathered_pred = paddle.reshape(
              gathered_pred,
              shape=[batch_size, -1, paddle.shape(gathered_pred)[1]],
          )
          cur_ins_pred = ins_pred
          cur_ins_pred = paddle.reshape(
              cur_ins_pred,
              shape=(
                  paddle.shape(cur_ins_pred)[0],
                  paddle.shape(cur_ins_pred)[1],
                  -1,
              ),
          )
          ins_pred_conv = paddle.matmul(gathered_pred, cur_ins_pred)
          cur_ins_pred = paddle.reshape(
              ins_pred_conv,
              shape=(
                  -1,
                  paddle.shape(ins_pred)[-2],
                  paddle.shape(ins_pred)[-1],
              ),
          )
          ins_pred_list.append(cur_ins_pred)
  
      num_ins = paddle.sum(fg_num)
      cate_preds = [
          paddle.reshape(
              paddle.transpose(cate_pred, [0, 2, 3, 1]),
              shape=(-1, self.cate_out_channels),
          )
          for cate_pred in cate_preds
      ]
      flatten_cate_preds = paddle.concat(cate_preds)
      new_cate_labels = []
      for cate_label in cate_labels:
          new_cate_labels.append(paddle.reshape(cate_label, shape=[-1]))
      cate_labels = paddle.concat(new_cate_labels)
  
      loss_ins, loss_cate = self.solov2_loss(
          ins_pred_list,
          ins_labels,
          flatten_cate_preds,
          cate_labels,
          num_ins,
      )
  
      return {"loss_ins": loss_ins, "loss_cate": loss_cate}
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import paddle
  from paddle import ParamAttr
  import paddle.nn
  import paddle.nn.functional
  from paddle.nn.initializer import Normal, Constant
  from ppdet.modeling.layers import ConvNormLayer, MaskMatrixNMS, DropBlock
  from ppdet.core.workspace import register
  from six.moves import zip
  import numpy
label_desc: Use image node_id 6 for calling the SOLOv2Head obj's underlying member method code with example usage: obj.get_loss(cate_preds, kernel_preds, ins_pred, ins_labels, cate_labels, grid_order_list, fg_num) and returns: dict