diff --git a/ppdet/modeling/losses/pisa_utils.py b/ppdet/modeling/losses/pisa_utils.py index 6d6345037eeaa740caeddc1cd3b1ea2bf0c1ca88..431eaf99d515d1dcf4cac174f702102f4383661d 100644 --- a/ppdet/modeling/losses/pisa_utils.py +++ b/ppdet/modeling/losses/pisa_utils.py @@ -59,7 +59,7 @@ def get_isr_p_func(pos_iou_thresh=0.25, bias=0, k=2): weight_factor = np.clip(max_l_num - l_max_iou_rank, 0., None) / max_l_num weight_factor = np.power(bias + (1 - bias) * weight_factor, k) - pos_weights[l_inds] *= weight_factor * 1.2 + pos_weights[l_inds] *= weight_factor pos_weights = pos_weights / np.mean(pos_weights) all_pos_weights[pos_mask] = pos_weights diff --git a/ppdet/modeling/losses/yolo_loss.py b/ppdet/modeling/losses/yolo_loss.py index 5f31a498d617af3722bfcac6a4cc18c45c4b954c..b2f0191e2a5d35c38b7efa6b741971b9d5ad1625 100644 --- a/ppdet/modeling/losses/yolo_loss.py +++ b/ppdet/modeling/losses/yolo_loss.py @@ -142,21 +142,24 @@ class YOLOv3Loss(object): iou = self._calc_iou(output, target, gt_box, anchors, batch_size, num_classes, downsample, scale_x_y) - # sorted_iou, sorted_gt_inds = fluid.layers.argsort(iou, axis=-1, descending=True) - # max_iou = sorted_iou[:, :, 0:1] - # gt_inds = fluid.layers.cast(sorted_gt_inds[:, :, 0:1], dtype='float32') - # pred_cls = fluid.layers.argmax(cls, axis=-1) - # pred_cls = fluid.layers.reshape(pred_cls, [batch_size, -1, 1]) - # pred_cls = fluid.layers.cast(pred_cls, dtype='float32') - # isr_p_input = fluid.layers.concat([max_iou, gt_inds, pred_cls], axis=-1) - # isr_p = get_isr_p_func() - # pos_weights = fluid.layers.zeros_like(max_iou) - # fluid.layers.py_func(isr_p, isr_p_input, pos_weights) - # - # tobj_shape = fluid.layers.shape(tobj) - # pos_weights = fluid.layers.reshape(pos_weights, (-1, an_num, tobj_shape[2], - # tobj_shape[3])) - # tobj = tobj * pos_weights + sorted_iou, sorted_gt_inds = fluid.layers.argsort( + iou, axis=-1, descending=True) + max_iou = sorted_iou[:, :, 0:1] + gt_inds = fluid.layers.cast( + sorted_gt_inds[:, :, 0:1], dtype='float32') + pred_cls = fluid.layers.argmax(cls, axis=-1) + pred_cls = fluid.layers.reshape(pred_cls, [batch_size, -1, 1]) + pred_cls = fluid.layers.cast(pred_cls, dtype='float32') + isr_p_input = fluid.layers.concat( + [max_iou, gt_inds, pred_cls], axis=-1) + isr_p = get_isr_p_func() + pos_weights = fluid.layers.zeros_like(max_iou) + fluid.layers.py_func(isr_p, isr_p_input, pos_weights) + + tobj_shape = fluid.layers.shape(tobj) + pos_weights = fluid.layers.reshape(pos_weights, ( + -1, an_num, tobj_shape[2], tobj_shape[3])) + tobj = tobj * pos_weights # isr_tobj = tobj * pos_weights # loss_cls = fluid.layers.sigmoid_cross_entropy_with_logits(cls, tcls)