code: def forward(self, output, batch):
      predictions_lists = output["predictions_lists"]
      targets = batch["lane_line"].clone()
      cls_criterion = FocalLoss(alpha=0.25, gamma=2.0)
      cls_loss = paddle.to_tensor(0.0)
      reg_xytl_loss = paddle.to_tensor(0.0)
      iou_loss = paddle.to_tensor(0.0)
      cls_acc = []
      cls_acc_stage = []
      for stage in range(self.refine_layers):
          predictions_list = predictions_lists[stage]
          for predictions, target in zip(predictions_list, targets):
              target = target[target[:, 1] == 1]
  
              if len(target) == 0:
                  # If there are no targets, all predictions have to be negatives (i.e., 0 confidence)
                  cls_target = paddle.zeros(
                      [predictions.shape[0]], dtype="int64"
                  )
                  cls_pred = predictions[:, :2]
                  cls_loss = (
                      cls_loss
                      + cls_criterion(cls_pred, cls_target).sum()
                  )
                  continue
  
              with paddle.no_grad():
                  matched_row_inds, matched_col_inds = assign(
                      predictions, target, self.img_w, self.img_h
                  )
  
              # classification targets
              cls_target = paddle.zeros(
                  [predictions.shape[0]], dtype="int64"
              )
              cls_target[matched_row_inds] = 1
              cls_pred = predictions[:, :2]
  
              # regression targets -> [start_y, start_x, theta] (all transformed to absolute values), only on matched pairs
              reg_yxtl = predictions.index_select(matched_row_inds)[
                  ..., 2:6
              ]
  
              reg_yxtl[:, 0] *= self.n_strips
              reg_yxtl[:, 1] *= self.img_w - 1
              reg_yxtl[:, 2] *= 180
              reg_yxtl[:, 3] *= self.n_strips
  
              target_yxtl = target.index_select(matched_col_inds)[
                  ..., 2:6
              ].clone()
  
              # regression targets -> S coordinates (all transformed to absolute values)
              reg_pred = predictions.index_select(matched_row_inds)[
                  ..., 6:
              ]
              reg_pred *= self.img_w - 1
              reg_targets = target.index_select(matched_col_inds)[
                  ..., 6:
              ].clone()
  
              with paddle.no_grad():
                  predictions_starts = paddle.clip(
                      (
                          predictions.index_select(matched_row_inds)[
                              ..., 2
                          ]
                          * self.n_strips
                      )
                      .round()
                      .cast("int64"),
                      min=0,
                      max=self.n_strips,
                  )  # ensure the predictions starts is valid
  
                  target_starts = (
                      (
                          target.index_select(matched_col_inds)[..., 2]
                          * self.n_strips
                      )
                      .round()
                      .cast("int64")
                  )
                  target_yxtl[:, -1] -= (
                      predictions_starts - target_starts
                  )  # reg length
  
              # Loss calculation
              cls_loss = (
                  cls_loss
                  + cls_criterion(cls_pred, cls_target).sum()
                  / target.shape[0]
              )
  
              target_yxtl[:, 0] *= self.n_strips
              target_yxtl[:, 2] *= 180
  
              reg_xytl_loss = (
                  reg_xytl_loss
                  + F.smooth_l1_loss(
                      input=reg_yxtl,
                      label=target_yxtl,
                      reduction="none",
                  ).mean()
              )
  
              iou_loss = iou_loss + liou_loss(
                  reg_pred, reg_targets, self.img_w, length=15
              )
  
              cls_accuracy = accuracy(cls_pred, cls_target)
              cls_acc_stage.append(cls_accuracy)
  
          cls_acc.append(
              sum(cls_acc_stage) / (len(cls_acc_stage) + 1e-5)
          )
  
      # extra segmentation loss
      seg_loss = self.criterion(
          F.log_softmax(output["seg"], axis=1),
          batch["seg"].cast("int64"),
      )
  
      cls_loss /= len(targets) * self.refine_layers
      reg_xytl_loss /= len(targets) * self.refine_layers
      iou_loss /= len(targets) * self.refine_layers
  
      loss = (
          cls_loss * self.cls_loss_weight
          + reg_xytl_loss * self.xyt_loss_weight
          + seg_loss * self.seg_loss_weight
          + iou_loss * self.iou_loss_weight
      )
  
      return_value = {
          "loss": loss,
          "cls_loss": cls_loss * self.cls_loss_weight,
          "reg_xytl_loss": reg_xytl_loss * self.xyt_loss_weight,
          "seg_loss": seg_loss * self.seg_loss_weight,
          "iou_loss": iou_loss * self.iou_loss_weight,
      }
  
      for i in range(self.refine_layers):
          if not isinstance(cls_acc[i], paddle.Tensor):
              cls_acc[i] = paddle.to_tensor(cls_acc[i])
          return_value["stage_{}_acc".format(i)] = cls_acc[i]
  
      return return_value
  
file_path: PaddleDetection/ppdet/modeling/losses/clrnet_loss.py
imports: import paddle
  import paddle.nn
  import paddle.nn.functional
  from ppdet.core.workspace import register
  from ppdet.modeling.clrnet_utils import accuracy
  from ppdet.modeling.assigners.clrnet_assigner import assign
  from ppdet.modeling.losses.clrnet_line_iou_loss import liou_loss
label_desc: Use image node_id 2 for calling the CLRNetLoss obj's underlying member method code with example usage: obj.forward(output, batch) and returns: return_value