def get_odm_loss(self, odm_target, s2anet_head_out, reg_loss_type='gwd'):
    (labels, label_weights, bbox_targets, bbox_weights, bbox_gt_bboxes, pos_inds, neg_inds) = odm_target
    (fam_cls_branch_list, fam_reg_branch_list, odm_cls_branch_list, odm_reg_branch_list) = s2anet_head_out
    odm_cls_losses = []
    odm_bbox_losses = []
    st_idx = 0
    num_total_samples = ((len(pos_inds) + len(neg_inds)) if self.sampling else len(pos_inds))
    num_total_samples = max(1, num_total_samples)
    for (idx, feat_size) in enumerate(self.featmap_sizes_list):
        feat_anchor_num = (feat_size[0] * feat_size[1])
        feat_labels = labels[st_idx:(st_idx + feat_anchor_num)]
        feat_label_weights = label_weights[st_idx:(st_idx + feat_anchor_num)]
        feat_bbox_targets = bbox_targets[st_idx:(st_idx + feat_anchor_num), :]
        feat_bbox_weights = bbox_weights[st_idx:(st_idx + feat_anchor_num), :]
        feat_labels = feat_labels.reshape((- 1))
        feat_label_weights = feat_label_weights.reshape((- 1))
        odm_cls_score = odm_cls_branch_list[idx]
        odm_cls_score = paddle.squeeze(odm_cls_score, axis=0)
        odm_cls_score1 = odm_cls_score
        feat_labels = paddle.to_tensor(feat_labels)
        feat_labels_one_hot = paddle.nn.functional.one_hot(feat_labels, (self.cls_out_channels + 1))
        feat_labels_one_hot = feat_labels_one_hot[:, 1:]
        feat_labels_one_hot.stop_gradient = True
        num_total_samples = paddle.to_tensor(num_total_samples, dtype='float32', stop_gradient=True)
        odm_cls = F.sigmoid_focal_loss(odm_cls_score1, feat_labels_one_hot, normalizer=num_total_samples, reduction='none')
        feat_label_weights = feat_label_weights.reshape(feat_label_weights.shape[0], 1)
        feat_label_weights = np.repeat(feat_label_weights, self.cls_out_channels, axis=1)
        feat_label_weights = paddle.to_tensor(feat_label_weights)
        feat_label_weights.stop_gradient = True
        odm_cls = (odm_cls * feat_label_weights)
        odm_cls_total = paddle.sum(odm_cls)
        odm_cls_losses.append(odm_cls_total)
        feat_bbox_targets = paddle.to_tensor(feat_bbox_targets, dtype='float32')
        feat_bbox_targets = paddle.reshape(feat_bbox_targets, [(- 1), 5])
        feat_bbox_targets.stop_gradient = True
        odm_bbox_pred = odm_reg_branch_list[idx]
        odm_bbox_pred = paddle.squeeze(odm_bbox_pred, axis=0)
        odm_bbox_pred = paddle.reshape(odm_bbox_pred, [(- 1), 5])
        odm_bbox = self.smooth_l1_loss(odm_bbox_pred, feat_bbox_targets)
        loss_weight = paddle.to_tensor(self.reg_loss_weight, dtype='float32', stop_gradient=True)
        odm_bbox = paddle.multiply(odm_bbox, loss_weight)
        feat_bbox_weights = paddle.to_tensor(feat_bbox_weights, stop_gradient=True)
        if (reg_loss_type == 'l1'):
            odm_bbox = (odm_bbox * feat_bbox_weights)
            odm_bbox_total = (paddle.sum(odm_bbox) / num_total_samples)
        elif ((reg_loss_type == 'iou') or (reg_loss_type == 'gwd')):
            odm_bbox = paddle.sum(odm_bbox, axis=(- 1))
            feat_bbox_weights = paddle.sum(feat_bbox_weights, axis=(- 1))
            try:
                from rbox_iou_ops import rbox_iou
            except Exception as e:
                print('import custom_ops error, try install rbox_iou_ops following ppdet/ext_op/README.md', e)
                sys.stdout.flush()
                sys.exit((- 1))
            odm_bbox_decode = self.delta2rbox(self.refine_anchor_list[idx], odm_bbox_pred)
            bbox_gt_bboxes = paddle.to_tensor(bbox_gt_bboxes, dtype=odm_bbox_decode.dtype, place=odm_bbox_decode.place)
            bbox_gt_bboxes.stop_gradient = True
            iou = rbox_iou(odm_bbox_decode, bbox_gt_bboxes)
            iou = paddle.diag(iou)
            if (reg_loss_type == 'gwd'):
                bbox_gt_bboxes_level = bbox_gt_bboxes[st_idx:(st_idx + feat_anchor_num), :]
                odm_bbox_total = self.gwd_loss(odm_bbox_decode, bbox_gt_bboxes_level)
                odm_bbox_total = (odm_bbox_total * feat_bbox_weights)
                odm_bbox_total = (paddle.sum(odm_bbox_total) / num_total_samples)
        odm_bbox_losses.append(odm_bbox_total)
        st_idx += feat_anchor_num
    odm_cls_loss = paddle.add_n(odm_cls_losses)
    odm_cls_loss_weight = paddle.to_tensor(self.cls_loss_weight[1], dtype='float32', stop_gradient=True)
    odm_cls_loss = (odm_cls_loss * odm_cls_loss_weight)
    odm_reg_loss = paddle.add_n(odm_bbox_losses)
    return (odm_cls_loss, odm_reg_loss)
def get_odm_loss(self, odm_target, s2anet_head_out, reg_loss_type='gwd'):
    (labels, label_weights, bbox_targets, bbox_weights, bbox_gt_bboxes, pos_inds, neg_inds) = odm_target
    (fam_cls_branch_list, fam_reg_branch_list, odm_cls_branch_list, odm_reg_branch_list) = s2anet_head_out
    odm_cls_losses = []
    odm_bbox_losses = []
    st_idx = 0
    num_total_samples = ((len(pos_inds) + len(neg_inds)) if self.sampling else len(pos_inds))
    num_total_samples = max(1, num_total_samples)
    for (idx, feat_size) in enumerate(self.featmap_sizes_list):
        feat_anchor_num = (feat_size[0] * feat_size[1])
        feat_labels = labels[st_idx:(st_idx + feat_anchor_num)]
        feat_label_weights = label_weights[st_idx:(st_idx + feat_anchor_num)]
        feat_bbox_targets = bbox_targets[st_idx:(st_idx + feat_anchor_num), :]
        feat_bbox_weights = bbox_weights[st_idx:(st_idx + feat_anchor_num), :]
        feat_labels = feat_labels.reshape((- 1))
        feat_label_weights = feat_label_weights.reshape((- 1))
        odm_cls_score = odm_cls_branch_list[idx]
        odm_cls_score = paddle.squeeze(odm_cls_score, axis=0)
        odm_cls_score1 = odm_cls_score
        feat_labels = paddle.to_tensor(feat_labels)
        feat_labels_one_hot = paddle.nn.functional.one_hot(feat_labels, (self.cls_out_channels + 1))
        feat_labels_one_hot = feat_labels_one_hot[:, 1:]
        feat_labels_one_hot.stop_gradient = True
        num_total_samples = paddle.to_tensor(num_total_samples, dtype='float32', stop_gradient=True)
        odm_cls = F.sigmoid_focal_loss(odm_cls_score1, feat_labels_one_hot, normalizer=num_total_samples, reduction='none')
        feat_label_weights = feat_label_weights.reshape(feat_label_weights.shape[0], 1)
        feat_label_weights = np.repeat(feat_label_weights, self.cls_out_channels, axis=1)
        feat_label_weights = paddle.to_tensor(feat_label_weights)
        feat_label_weights.stop_gradient = True
        odm_cls = (odm_cls * feat_label_weights)
        odm_cls_total = paddle.sum(odm_cls)
        odm_cls_losses.append(odm_cls_total)
        feat_bbox_targets = paddle.to_tensor(feat_bbox_targets, dtype='float32')
        feat_bbox_targets = paddle.reshape(feat_bbox_targets, [(- 1), 5])
        feat_bbox_targets.stop_gradient = True
        odm_bbox_pred = odm_reg_branch_list[idx]
        odm_bbox_pred = paddle.squeeze(odm_bbox_pred, axis=0)
        odm_bbox_pred = paddle.reshape(odm_bbox_pred, [(- 1), 5])
        odm_bbox = self.smooth_l1_loss(odm_bbox_pred, feat_bbox_targets)
        loss_weight = paddle.to_tensor(self.reg_loss_weight, dtype='float32', stop_gradient=True)
        odm_bbox = paddle.multiply(odm_bbox, loss_weight)
        feat_bbox_weights = paddle.to_tensor(feat_bbox_weights, stop_gradient=True)
        if (reg_loss_type == 'l1'):
            odm_bbox = (odm_bbox * feat_bbox_weights)
            odm_bbox_total = (paddle.sum(odm_bbox) / num_total_samples)
        elif ((reg_loss_type == 'iou') or (reg_loss_type == 'gwd')):
            odm_bbox = paddle.sum(odm_bbox, axis=(- 1))
            feat_bbox_weights = paddle.sum(feat_bbox_weights, axis=(- 1))
            try:
                from rbox_iou_ops import rbox_iou
            except Exception as e:
                print('import custom_ops error, try install rbox_iou_ops following ppdet/ext_op/README.md', e)
                sys.stdout.flush()
                sys.exit((- 1))
            odm_bbox_decode = self.delta2rbox(self.refine_anchor_list[idx], odm_bbox_pred)
            bbox_gt_bboxes = paddle.to_tensor(bbox_gt_bboxes, dtype=odm_bbox_decode.dtype, place=odm_bbox_decode.place)
            bbox_gt_bboxes.stop_gradient = True
            iou = rbox_iou(odm_bbox_decode, bbox_gt_bboxes)
            iou = paddle.diag(iou)
            if (reg_loss_type == 'gwd'):
                bbox_gt_bboxes_level = bbox_gt_bboxes[st_idx:(st_idx + feat_anchor_num), :]
                odm_bbox_total = self.gwd_loss(odm_bbox_decode, bbox_gt_bboxes_level)
                odm_bbox_total = (odm_bbox_total * feat_bbox_weights)
                odm_bbox_total = (paddle.sum(odm_bbox_total) / num_total_samples)
        odm_bbox_losses.append(odm_bbox_total)
        st_idx += feat_anchor_num
    odm_cls_loss = paddle.add_n(odm_cls_losses)
    odm_cls_loss_weight = paddle.to_tensor(self.cls_loss_weight[1], dtype='float32', stop_gradient=True)
    odm_cls_loss = (odm_cls_loss * odm_cls_loss_weight)
    odm_reg_loss = paddle.add_n(odm_bbox_losses)
    return (odm_cls_loss, odm_reg_loss)