code: def _calc_obj_loss(
      output,
      obj,
      tobj,
      gt_box,
      batch_size,
      anchors,
      num_classes,
      downsample,
      ignore_thresh,
      scale_x_y,
  ):
      # A prediction bbox overlap any gt_bbox over ignore_thresh,
      # objectness loss will be ignored, process as follows:
      # 1. get pred bbox, which is same with YOLOv3 infer mode, use yolo_box here
      # NOTE: img_size is set as 1.0 to get noramlized pred bbox
      bbox, prob = paddle.vision.ops.yolo_box(
          x=output,
          img_size=paddle.ones(shape=[batch_size, 2], dtype="int32"),
          anchors=anchors,
          class_num=num_classes,
          conf_thresh=0.0,
          downsample_ratio=downsample,
          clip_bbox=False,
          scale_x_y=scale_x_y,
      )
      # 2. split pred bbox and gt bbox by sample, calculate IoU between pred bbox
      #    and gt bbox in each sample
      if batch_size > 1:
          preds = paddle.split(bbox, batch_size, axis=0)
          gts = paddle.split(gt_box, batch_size, axis=0)
      else:
          preds = [bbox]
          gts = [gt_box]
          probs = [prob]
      ious = []
      for pred, gt in zip(preds, gts):
  
          def box_xywh2xyxy(box):
              x = box[:, 0]
              y = box[:, 1]
              w = box[:, 2]
              h = box[:, 3]
              return paddle.stack(
                  [
                      x - w / 2.0,
                      y - h / 2.0,
                      x + w / 2.0,
                      y + h / 2.0,
                  ],
                  axis=1,
              )
  
          pred = paddle.squeeze(pred, axis=[0])
          gt = box_xywh2xyxy(paddle.squeeze(gt, axis=[0]))
          ious.append(iou_similarity(pred, gt))
      iou = paddle.stack(ious, axis=0)
      # 3. Get iou_mask by IoU between gt bbox and prediction bbox,
      #    Get obj_mask by tobj(holds gt_score), calculate objectness loss
      max_iou = paddle.max(iou, axis=-1)
      iou_mask = paddle.cast(max_iou <= ignore_thresh, dtype="float32")
      output_shape = paddle.shape(output)
      an_num = len(anchors) // 2
      iou_mask = paddle.reshape(
          iou_mask, (-1, an_num, output_shape[2], output_shape[3])
      )
      iou_mask.stop_gradient = True
      # NOTE: tobj holds gt_score, obj_mask holds object existence mask
      obj_mask = paddle.cast(tobj > 0.0, dtype="float32")
      obj_mask.stop_gradient = True
      # For positive objectness grids, objectness loss should be calculated
      # For negative objectness grids, objectness loss is calculated only iou_mask == 1.0
      obj_sigmoid = F.sigmoid(obj)
      loss_obj = F.binary_cross_entropy(
          obj_sigmoid, obj_mask, reduction="none"
      )
      loss_obj_pos = paddle.sum(loss_obj * tobj, axis=[1, 2, 3])
      loss_obj_neg = paddle.sum(
          loss_obj * (1.0 - obj_mask) * iou_mask, axis=[1, 2, 3]
      )
      return loss_obj_pos, loss_obj_neg
  
imports: from __future__ import division
  import unittest
  import paddle
  import paddle.nn.functional
  import os
  import sys
  from ppdet.modeling.losses import YOLOv3Loss
  from ppdet.data.transform.op_helper import jaccard_overlap
  from ppdet.modeling.bbox_utils import iou_similarity
  import numpy
label_desc: Use image node_id 3 for calling a global function with example usage: _calc_obj_loss(output, obj, tobj, gt_box, batch_size, anchors, num_classes, downsample, ignore_thresh, scale_x_y) and returns: loss_obj_pos,  loss_obj_neg, paddle