code: def get_loss(self, head_outs, gt_meta):
      (
          pred_scores,
          pred_distri,
          pred_contrast_encoder,
          anchors,
          anchor_points,
          num_anchors_list,
          stride_tensor,
      ) = head_outs
  
      anchor_points_s = anchor_points / stride_tensor
      pred_bboxes = self._bbox_decode(anchor_points_s, pred_distri)
  
      gt_labels = gt_meta["gt_class"]
      gt_bboxes = gt_meta["gt_bbox"]
      pad_gt_mask = gt_meta["pad_gt_mask"]
      # 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,
              pred_bboxes=pred_bboxes.detach() * stride_tensor,
          )
          alpha_l = 0.25
      else:
          if self.sm_use:
              (
                  assigned_labels,
                  assigned_bboxes,
                  assigned_scores,
              ) = self.assigner(
                  pred_scores.detach(),
                  pred_bboxes.detach() * stride_tensor,
                  anchor_points,
                  stride_tensor,
                  gt_labels,
                  gt_bboxes,
                  pad_gt_mask,
                  bg_index=self.num_classes,
              )
          else:
              (
                  assigned_labels,
                  assigned_bboxes,
                  assigned_scores,
              ) = self.assigner(
                  pred_scores.detach(),
                  pred_bboxes.detach() * stride_tensor,
                  anchor_points,
                  num_anchors_list,
                  gt_labels,
                  gt_bboxes,
                  pad_gt_mask,
                  bg_index=self.num_classes,
              )
          alpha_l = -1
      # rescale bbox
      assigned_bboxes /= stride_tensor
      # cls loss
      if self.use_varifocal_loss:
          one_hot_label = F.one_hot(
              assigned_labels, self.num_classes + 1
          )[..., :-1]
          loss_cls = self._varifocal_loss(
              pred_scores, assigned_scores, one_hot_label
          )
      else:
          loss_cls = self._focal_loss(
              pred_scores, assigned_scores, alpha_l
          )
  
      assigned_scores_sum = assigned_scores.sum()
      if paddle.distributed.get_world_size() > 1:
          paddle.distributed.all_reduce(assigned_scores_sum)
          assigned_scores_sum /= paddle.distributed.get_world_size()
      assigned_scores_sum = paddle.clip(assigned_scores_sum, min=1.0)
      loss_cls /= assigned_scores_sum
  
      loss_l1, loss_iou, loss_dfl = self._bbox_loss(
          pred_distri,
          pred_bboxes,
          anchor_points_s,
          assigned_labels,
          assigned_bboxes,
          assigned_scores,
          assigned_scores_sum,
      )
      # contrast loss
      loss_contrast = self.contrast_loss(
          pred_contrast_encoder.reshape(
              [-1, pred_contrast_encoder.shape[-1]]
          ),
          assigned_labels.reshape([-1]),
          assigned_scores.max(-1).reshape([-1]),
      )
  
      loss = (
          self.loss_weight["class"] * loss_cls
          + self.loss_weight["iou"] * loss_iou
          + self.loss_weight["dfl"] * loss_dfl
          + self.loss_weight["contrast"] * loss_contrast
      )
  
      out_dict = {
          "loss": loss,
          "loss_cls": loss_cls,
          "loss_iou": loss_iou,
          "loss_dfl": loss_dfl,
          "loss_l1": loss_l1,
          "loss_contrast": loss_contrast,
      }
      return out_dict
  
file_path: PaddleDetection/ppdet/modeling/heads/ppyoloe_contrast_head.py
imports: import paddle
  import paddle.nn
  import paddle.nn.functional
  from ppdet.core.workspace import register
  from ..initializer import bias_init_with_prob, constant_
  from ..assigners.utils import generate_anchors_for_grid_cell
  from ppdet.modeling.heads.ppyoloe_head import PPYOLOEHead
label_desc: Use image node_id 4 for calling the PPYOLOEContrastHead obj's underlying member method code with example usage: obj.get_loss(head_outs, gt_meta) and returns: out_dict