diff --git a/ppdet/modeling/assigners/atss_assigner.py b/ppdet/modeling/assigners/atss_assigner.py index f1aae2bebc8..00103005f62 100644 --- a/ppdet/modeling/assigners/atss_assigner.py +++ b/ppdet/modeling/assigners/atss_assigner.py @@ -192,7 +192,7 @@ def forward(self, # assigned target batch_ind = paddle.arange( end=batch_size, dtype=gt_labels.dtype).unsqueeze(-1) - assigned_gt_index = assigned_gt_index + batch_ind * num_max_boxes + assigned_gt_index = assigned_gt_index + (batch_ind * num_max_boxes).astype(assigned_gt_index.dtype) assigned_labels = paddle.gather( gt_labels.flatten(), assigned_gt_index.flatten(), axis=0) assigned_labels = assigned_labels.reshape([batch_size, num_anchors]) diff --git a/ppdet/modeling/assigners/fcosr_assigner.py b/ppdet/modeling/assigners/fcosr_assigner.py index 46b743e601a..1402488555c 100644 --- a/ppdet/modeling/assigners/fcosr_assigner.py +++ b/ppdet/modeling/assigners/fcosr_assigner.py @@ -193,7 +193,7 @@ def forward(self, # assigned target batch_ind = paddle.arange( end=batch_size, dtype=gt_labels.dtype).unsqueeze(-1) - assigned_gt_index = assigned_gt_index + batch_ind * num_max_boxes + assigned_gt_index = assigned_gt_index + (batch_ind * num_max_boxes).astype(assigned_gt_index.dtype) assigned_labels = paddle.gather( gt_labels.flatten(), assigned_gt_index.flatten(), axis=0) assigned_labels = assigned_labels.reshape([batch_size, num_anchors]) @@ -224,4 +224,4 @@ def forward(self, (-1, 5))).reshape((b, l, 1)) assigned_scores = assigned_scores * iou_score - return assigned_labels, assigned_rboxes, assigned_scores \ No newline at end of file + return assigned_labels, assigned_rboxes, assigned_scores diff --git a/ppdet/modeling/assigners/rotated_task_aligned_assigner.py b/ppdet/modeling/assigners/rotated_task_aligned_assigner.py index eeb9a68b670..fa810e5e18f 100644 --- a/ppdet/modeling/assigners/rotated_task_aligned_assigner.py +++ b/ppdet/modeling/assigners/rotated_task_aligned_assigner.py @@ -113,7 +113,7 @@ def forward(self, # select topk largest alignment metrics pred bbox as candidates # for each gt, [B, n, L] is_in_topk = gather_topk_anchors( - alignment_metrics * is_in_gts, self.topk, topk_mask=pad_gt_mask) + alignment_metrics * is_in_gts.astype(alignment_metrics.dtype), self.topk, topk_mask=pad_gt_mask) # select positive sample, [B, n, L] mask_positive = is_in_topk * is_in_gts * pad_gt_mask diff --git a/ppdet/modeling/assigners/task_aligned_assigner.py b/ppdet/modeling/assigners/task_aligned_assigner.py index 23af79439ae..48c9439535a 100644 --- a/ppdet/modeling/assigners/task_aligned_assigner.py +++ b/ppdet/modeling/assigners/task_aligned_assigner.py @@ -163,7 +163,7 @@ def forward(self, assigned_gt_index = mask_positive.argmax(axis=-2) # assigned target - assigned_gt_index = assigned_gt_index + batch_ind * num_max_boxes + assigned_gt_index = assigned_gt_index + (batch_ind * num_max_boxes).astype(assigned_gt_index.dtype) assigned_labels = paddle.gather( gt_labels.flatten(), assigned_gt_index.flatten(), axis=0) assigned_labels = assigned_labels.reshape([batch_size, num_anchors]) diff --git a/ppdet/modeling/assigners/task_aligned_assigner_cr.py b/ppdet/modeling/assigners/task_aligned_assigner_cr.py index 5c5097604d5..0d054e06a7f 100644 --- a/ppdet/modeling/assigners/task_aligned_assigner_cr.py +++ b/ppdet/modeling/assigners/task_aligned_assigner_cr.py @@ -151,7 +151,7 @@ def forward(self, assigned_gt_index = mask_positive.argmax(axis=-2) # assigned target - assigned_gt_index = assigned_gt_index + batch_ind * num_max_boxes + assigned_gt_index = assigned_gt_index + (batch_ind * num_max_boxes).astype(assigned_gt_index.dtype) assigned_labels = paddle.gather( gt_labels.flatten(), assigned_gt_index.flatten(), axis=0) assigned_labels = assigned_labels.reshape([batch_size, num_anchors]) diff --git a/ppdet/modeling/heads/ttf_head.py b/ppdet/modeling/heads/ttf_head.py index dfe97bdb715..f5f464a81ff 100644 --- a/ppdet/modeling/heads/ttf_head.py +++ b/ppdet/modeling/heads/ttf_head.py @@ -281,7 +281,7 @@ def get_loss(self, pred_hm, pred_wh, target_hm, box_target, target_weight): base_loc.stop_gradient = True pred_boxes = paddle.concat( - [0 - pred_wh[:, 0:2, :, :] + base_loc, pred_wh[:, 2:4] + base_loc], + [0 - pred_wh[:, 0:2, :, :] + base_loc.astype(pred_wh.dtype), pred_wh[:, 2:4] + base_loc.astype(pred_wh.dtype)], axis=1) pred_boxes = paddle.transpose(pred_boxes, [0, 2, 3, 1]) boxes = paddle.transpose(box_target, [0, 2, 3, 1]) diff --git a/ppdet/modeling/losses/gfocal_loss.py b/ppdet/modeling/losses/gfocal_loss.py index 37e27f084e6..e5ec23b4fbf 100644 --- a/ppdet/modeling/losses/gfocal_loss.py +++ b/ppdet/modeling/losses/gfocal_loss.py @@ -75,7 +75,7 @@ def quality_focal_loss(pred, target, beta=2.0, use_sigmoid=True): loss_pos = func( pred, score, reduction='none') * scale_factor_new.abs().pow(beta) - loss = loss * paddle.logical_not(pos_mask) + loss_pos * pos_mask + loss = loss * paddle.logical_not(pos_mask).astype(loss.dtype) + loss_pos * pos_mask loss = loss.sum(axis=1) return loss diff --git a/ppdet/modeling/losses/iou_loss.py b/ppdet/modeling/losses/iou_loss.py index b5cac22e342..3c315da18d8 100644 --- a/ppdet/modeling/losses/iou_loss.py +++ b/ppdet/modeling/losses/iou_loss.py @@ -184,7 +184,7 @@ def __call__(self, pbox, gbox, iou_weight=1.): intsctk = (xkis2 - xkis1) * (ykis2 - ykis1) intsctk = intsctk * paddle.greater_than( - xkis2, xkis1) * paddle.greater_than(ykis2, ykis1) + xkis2, xkis1).astype(intsctk.dtype) * paddle.greater_than(ykis2, ykis1).astype(intsctk.dtype) unionk = (x2 - x1) * (y2 - y1) + (x2g - x1g) * (y2g - y1g ) - intsctk + self.eps iouk = intsctk / unionk diff --git a/ppdet/modeling/losses/ssd_loss.py b/ppdet/modeling/losses/ssd_loss.py index 2ab94f2b5bb..a6cecbd40ce 100644 --- a/ppdet/modeling/losses/ssd_loss.py +++ b/ppdet/modeling/losses/ssd_loss.py @@ -124,7 +124,7 @@ def _mine_hard_example(self, [pos.shape[1] * mine_neg_ratio]) num_negs.append(num_neg) num_negs = paddle.stack(num_negs).expand_as(idx_rank) - neg_mask = (idx_rank < num_negs).astype(conf_loss.dtype) + neg_mask = (idx_rank.astype(num_negs.dtype) < num_negs).astype(conf_loss.dtype) return (neg_mask + pos).astype('bool') diff --git a/ppdet/modeling/proposal_generator/anchor_generator.py b/ppdet/modeling/proposal_generator/anchor_generator.py index 9a8e24ea363..f5008d00def 100644 --- a/ppdet/modeling/proposal_generator/anchor_generator.py +++ b/ppdet/modeling/proposal_generator/anchor_generator.py @@ -187,11 +187,11 @@ def gen_base_anchors(self): h_ratios = paddle.sqrt(self.ratios) w_ratios = 1 / h_ratios if self.scale_major: - ws = (w * w_ratios[:] * self.scales[:]).reshape([-1]) - hs = (h * h_ratios[:] * self.scales[:]).reshape([-1]) + ws = (w * w_ratios[:] * self.scales[:].astype(w_ratios.dtype)).reshape([-1]) + hs = (h * h_ratios[:] * self.scales[:].astype(h_ratios.dtype)).reshape([-1]) else: - ws = (w * self.scales[:] * w_ratios[:]).reshape([-1]) - hs = (h * self.scales[:] * h_ratios[:]).reshape([-1]) + ws = (w * self.scales[:].astype(w_ratios.dtype) * w_ratios[:]).reshape([-1]) + hs = (h * self.scales[:].astype(h_ratios.dtype) * h_ratios[:]).reshape([-1]) base_anchors = paddle.stack( [