Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapter new type promotion rule for Paddle 2.6 #8856

Open
wants to merge 1 commit into
base: release/2.7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion ppdet/modeling/assigners/atss_assigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions ppdet/modeling/assigners/fcosr_assigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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
return assigned_labels, assigned_rboxes, assigned_scores
2 changes: 1 addition & 1 deletion ppdet/modeling/assigners/rotated_task_aligned_assigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ppdet/modeling/assigners/task_aligned_assigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion ppdet/modeling/assigners/task_aligned_assigner_cr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion ppdet/modeling/heads/ttf_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion ppdet/modeling/losses/gfocal_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ppdet/modeling/losses/iou_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ppdet/modeling/losses/ssd_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
8 changes: 4 additions & 4 deletions ppdet/modeling/proposal_generator/anchor_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down