class_docstr: PicoHeadV2
  Args:
      conv_feat (object): Instance of 'PicoFeat'
      num_classes (int): Number of classes
      fpn_stride (list): The stride of each FPN Layer
      prior_prob (float): Used to set the bias init for the class prediction layer
      loss_class (object): Instance of VariFocalLoss.
      loss_dfl (object): Instance of DistributionFocalLoss.
      loss_bbox (object): Instance of bbox loss.
      assigner (object): Instance of label assigner.
      reg_max: Max value of integral set :math: `{0, ..., reg_max}`
              n QFL setting. Default: 7.
class_docstr_tok: ["PicoHeadV2","Args",":","conv_feat","(","object",")",":","Instance","of","'PicoFeat'","num_classes","(","int",")",":","Number","of","classes","fpn_stride","(","list",")",":","The","stride","of","each","FPN","Layer","prior_prob","(","float",")",":","Used","to","set","the","bias","init","for","the","class","prediction","layer","loss_class","(","object",")",":","Instance","of","VariFocalLoss",".","loss_dfl","(","object",")",":","Instance","of","DistributionFocalLoss",".","loss_bbox","(","object",")",":","Instance","of","bbox","loss",".","assigner","(","object",")",":","Instance","of","label","assigner",".","reg_max",":","Max","value","of","integral","set",":","math",":","`","{","0",",","...",",","reg_max","}","`","n","QFL","setting",".","Default",":","7","."]
code: def get_loss(self, head_outs, gt_meta):
      pred_scores, pred_regs, pred_bboxes, fpn_feats = head_outs
      gt_labels = gt_meta["gt_class"]
      gt_bboxes = gt_meta["gt_bbox"]
      gt_scores = gt_meta["gt_score"] if "gt_score" in gt_meta else None
      num_imgs = gt_meta["im_id"].shape[0]
      pad_gt_mask = gt_meta["pad_gt_mask"]
  
      (
          anchors,
          _,
          num_anchors_list,
          stride_tensor_list,
      ) = generate_anchors_for_grid_cell(
          fpn_feats,
          self.fpn_stride,
          self.grid_cell_scale,
          self.cell_offset,
      )
  
      centers = bbox_center(anchors)
  
      # label assignment
      if gt_meta["epoch_id"] < self.static_assigner_epoch:
          (
              assigned_labels,
              assigned_bboxes,
              assigned_scores,
          ) = self.static_assigner(
              anchors,
              num_anchors_list,
              gt_labels,
              gt_bboxes,
              pad_gt_mask,
              bg_index=self.num_classes,
              gt_scores=gt_scores,
              pred_bboxes=pred_bboxes.detach() * stride_tensor_list,
          )
  
      else:
          (
              assigned_labels,
              assigned_bboxes,
              assigned_scores,
          ) = self.assigner(
              pred_scores.detach(),
              pred_bboxes.detach() * stride_tensor_list,
              centers,
              num_anchors_list,
              gt_labels,
              gt_bboxes,
              pad_gt_mask,
              bg_index=self.num_classes,
              gt_scores=gt_scores,
          )
  
      assigned_bboxes /= stride_tensor_list
  
      centers_shape = centers.shape
      flatten_centers = centers.expand(
          [num_imgs, centers_shape[0], centers_shape[1]]
      ).reshape([-1, 2])
      flatten_strides = stride_tensor_list.expand(
          [num_imgs, centers_shape[0], 1]
      ).reshape([-1, 1])
      flatten_cls_preds = pred_scores.reshape([-1, self.num_classes])
      flatten_regs = pred_regs.reshape([-1, 4 * (self.reg_max + 1)])
      flatten_bboxes = pred_bboxes.reshape([-1, 4])
      flatten_bbox_targets = assigned_bboxes.reshape([-1, 4])
      flatten_labels = assigned_labels.reshape([-1])
      flatten_assigned_scores = assigned_scores.reshape(
          [-1, self.num_classes]
      )
  
      pos_inds = paddle.nonzero(
          paddle.logical_and(
              (flatten_labels >= 0), (flatten_labels < self.num_classes)
          ),
          as_tuple=False,
      ).squeeze(1)
  
      num_total_pos = len(pos_inds)
  
      if num_total_pos > 0:
          pos_bbox_targets = paddle.gather(
              flatten_bbox_targets, pos_inds, axis=0
          )
          pos_decode_bbox_pred = paddle.gather(
              flatten_bboxes, pos_inds, axis=0
          )
          pos_reg = paddle.gather(flatten_regs, pos_inds, axis=0)
          pos_strides = paddle.gather(flatten_strides, pos_inds, axis=0)
          pos_centers = (
              paddle.gather(flatten_centers, pos_inds, axis=0)
              / pos_strides
          )
  
          weight_targets = flatten_assigned_scores.detach()
          weight_targets = paddle.gather(
              weight_targets.max(axis=1, keepdim=True), pos_inds, axis=0
          )
  
          pred_corners = pos_reg.reshape([-1, self.reg_max + 1])
          target_corners = bbox2distance(
              pos_centers, pos_bbox_targets, self.reg_max
          ).reshape([-1])
          # regression loss
          loss_bbox = paddle.sum(
              self.loss_bbox(pos_decode_bbox_pred, pos_bbox_targets)
              * weight_targets
          )
  
          # dfl loss
          loss_dfl = self.loss_dfl(
              pred_corners,
              target_corners,
              weight=weight_targets.expand([-1, 4]).reshape([-1]),
              avg_factor=4.0,
          )
      else:
          loss_bbox = paddle.zeros([1])
          loss_dfl = paddle.zeros([1])
  
      avg_factor = flatten_assigned_scores.sum()
      if paddle.distributed.get_world_size() > 1:
          paddle.distributed.all_reduce(avg_factor)
          avg_factor = paddle.clip(
              avg_factor / paddle.distributed.get_world_size(), min=1
          )
      loss_vfl = self.loss_vfl(
          flatten_cls_preds,
          flatten_assigned_scores,
          avg_factor=avg_factor,
      )
  
      loss_bbox = loss_bbox / avg_factor
      loss_dfl = loss_dfl / avg_factor
  
      loss_states = dict(
          loss_vfl=loss_vfl, loss_bbox=loss_bbox, loss_dfl=loss_dfl
      )
  
      return loss_states
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  import numpy
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddle import ParamAttr
  from paddle.nn.initializer import Normal, Constant
  from ppdet.modeling.ops import get_static_shape
  from ..initializer import normal_
  from ..assigners.utils import generate_anchors_for_grid_cell
  from ..bbox_utils import bbox_center, batch_distance2bbox, bbox2distance
  from ppdet.core.workspace import register
  from ppdet.modeling.layers import ConvNormLayer
  from .simota_head import OTAVFLHead
  from .gfl_head import Integral, GFLHead
  from ppdet.modeling.necks.csp_pan import DPModule
label_desc: Use image node_id 5 for calling the PicoHeadV2 obj's underlying member method code with example usage: obj.get_loss(head_outs, gt_meta) and returns: loss_states