From 7b6758b42366ee49a038a846dd47b112c9550094 Mon Sep 17 00:00:00 2001 From: wanghuancoder Date: Wed, 2 Aug 2023 14:08:49 +0800 Subject: [PATCH] support stride and speed up (#8489) * support stride and speed up * refine --- ppdet/modeling/assigners/simota_assigner.py | 4 ++-- ppdet/modeling/transformers/matchers.py | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ppdet/modeling/assigners/simota_assigner.py b/ppdet/modeling/assigners/simota_assigner.py index abc055d29..4ec87cbcf 100644 --- a/ppdet/modeling/assigners/simota_assigner.py +++ b/ppdet/modeling/assigners/simota_assigner.py @@ -241,8 +241,8 @@ class SimOTAAssigner(object): pos_inds, neg_inds, pos_gt_bboxes, pos_assigned_gt_inds \ = self.get_sample(assigned_gt_inds, gt_bboxes.numpy()) - bbox_target = np.zeros_like(flatten_bboxes) - bbox_weight = np.zeros_like(flatten_bboxes) + bbox_target = np.zeros(flatten_bboxes.shape, paddle.common_ops_import.convert_dtype(flatten_bboxes.dtype)) + bbox_weight = np.zeros_like(bbox_target) label = np.ones([num_bboxes], dtype=np.int64) * self.num_classes label_weight = np.zeros([num_bboxes], dtype=np.float32) diff --git a/ppdet/modeling/transformers/matchers.py b/ppdet/modeling/transformers/matchers.py index 72459a3f9..8082c0e62 100644 --- a/ppdet/modeling/transformers/matchers.py +++ b/ppdet/modeling/transformers/matchers.py @@ -175,10 +175,16 @@ class HungarianMatcher(nn.Layer): C = C.reshape([bs, num_queries, -1]) C = [a.squeeze(0) for a in C.chunk(bs)] sizes = [a.shape[0] for a in gt_bbox] - indices = [ - linear_sum_assignment(c.split(sizes, -1)[i].numpy()) - for i, c in enumerate(C) - ] + if hasattr(paddle.Tensor, "contiguous"): + indices = [ + linear_sum_assignment(c.split(sizes, -1)[i].contiguous().numpy()) + for i, c in enumerate(C) + ] + else: + indices = [ + linear_sum_assignment(c.split(sizes, -1)[i].numpy()) + for i, c in enumerate(C) + ] return [(paddle.to_tensor( i, dtype=paddle.int64), paddle.to_tensor( j, dtype=paddle.int64)) for i, j in indices] -- GitLab