From 0b3deb2e90e1db6bb779e6b495ba284ced7ef424 Mon Sep 17 00:00:00 2001 From: Nyakku Shigure Date: Mon, 17 Mar 2025 20:27:29 +0800 Subject: [PATCH 1/4] Add explicit assign to avoid inplace write a view tensor cause inconsistency between dygraph and static graph (#9331) --- ppdet/modeling/transformers/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ppdet/modeling/transformers/utils.py b/ppdet/modeling/transformers/utils.py index c5e69846c0..9d8f2e2265 100644 --- a/ppdet/modeling/transformers/utils.py +++ b/ppdet/modeling/transformers/utils.py @@ -248,8 +248,8 @@ def get_denoising_training_group(targets, num_denoising = int(max_gt_num * num_group) if label_noise_ratio > 0: - input_query_class = input_query_class.flatten() - pad_gt_mask = pad_gt_mask.flatten() + input_query_class = paddle.assign(input_query_class.flatten()) + pad_gt_mask = paddle.assign(pad_gt_mask.flatten()) # half of bbox prob, cast mask from bool to float bacause dtype promotaion # between bool and float is not supported in static mode. mask = paddle.cast( @@ -356,8 +356,8 @@ def get_contrastive_denoising_training_group(targets, num_denoising = int(max_gt_num * 2 * num_group) if label_noise_ratio > 0: - input_query_class = input_query_class.flatten() - pad_gt_mask = pad_gt_mask.flatten() + input_query_class = paddle.assign(input_query_class.flatten()) + pad_gt_mask = paddle.assign(pad_gt_mask.flatten()) # half of bbox prob mask = paddle.rand(input_query_class.shape) < (label_noise_ratio * 0.5) chosen_idx = paddle.nonzero(mask.cast(pad_gt_mask.dtype) * From b20369fd9bce0ad15f2f1d995bc4da3bb2373531 Mon Sep 17 00:00:00 2001 From: Jonathans575 <39874362+Jonathans575@users.noreply.github.com> Date: Fri, 28 Mar 2025 16:22:31 +0800 Subject: [PATCH 2/4] npu(bugfix): fix the ce problem for detr. (#9341) --- ppdet/modeling/losses/detr_loss.py | 14 ++++++++++---- ppdet/modeling/transformers/matchers.py | 3 +++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ppdet/modeling/losses/detr_loss.py b/ppdet/modeling/losses/detr_loss.py index 6712f928d5..2fc4d9dc2a 100644 --- a/ppdet/modeling/losses/detr_loss.py +++ b/ppdet/modeling/losses/detr_loss.py @@ -281,10 +281,16 @@ def _get_index_updates(self, num_query_objects, target, match_indices): ]) src_idx = paddle.concat([src for (src, _) in match_indices]) src_idx += (batch_idx * num_query_objects) - target_assign = paddle.concat([ - paddle.gather( - t, dst, axis=0) for t, (_, dst) in zip(target, match_indices) - ]) + if 'npu' in paddle.device.get_device(): + target_assign = paddle.concat([ + paddle.gather( + t.to(paddle.int32), dst.to(paddle.int32), axis=0) for t, (_, dst) in zip(target, match_indices) + ]) + else: + target_assign = paddle.concat([ + paddle.gather( + t, dst, axis=0) for t, (_, dst) in zip(target, match_indices) + ]) return src_idx, target_assign def _get_src_target_assign(self, src, target, match_indices): diff --git a/ppdet/modeling/transformers/matchers.py b/ppdet/modeling/transformers/matchers.py index d8f85fc55f..9e5fa378b0 100644 --- a/ppdet/modeling/transformers/matchers.py +++ b/ppdet/modeling/transformers/matchers.py @@ -103,6 +103,9 @@ def forward(self, out_bbox = boxes.detach().flatten(0, 1) # Also concat the target labels and boxes + if 'npu' in paddle.device.get_device(): + gt_class = [tensor.to(paddle.int32) for tensor in gt_class] + tgt_ids = paddle.concat(gt_class).flatten() tgt_bbox = paddle.concat(gt_bbox) From dbb9f5b2ccd99a68521527d63dcc3cc4bffc94c9 Mon Sep 17 00:00:00 2001 From: Nyakku Shigure Date: Wed, 16 Apr 2025 15:54:15 +0800 Subject: [PATCH 3/4] Use right dtype for 0 size `gt_class` and `is_crowd` (#9354) --- ppdet/data/transform/operators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ppdet/data/transform/operators.py b/ppdet/data/transform/operators.py index 692eefaa1a..6c50b75bd6 100644 --- a/ppdet/data/transform/operators.py +++ b/ppdet/data/transform/operators.py @@ -3165,7 +3165,7 @@ def crop(self, sample, region): [0, 4], dtype=np.float32) sample['gt_class'] = sample['gt_class'][keep_index] if len( keep_index) > 0 else np.zeros( - [0, 1], dtype=np.float32) + [0, 1], dtype=np.int32) if 'gt_score' in sample: sample['gt_score'] = sample['gt_score'][keep_index] if len( keep_index) > 0 else np.zeros( @@ -3173,7 +3173,7 @@ def crop(self, sample, region): if 'is_crowd' in sample: sample['is_crowd'] = sample['is_crowd'][keep_index] if len( keep_index) > 0 else np.zeros( - [0, 1], dtype=np.float32) + [0, 1], dtype=np.int32) if 'gt_areas' in sample: sample['gt_areas'] = np.take( sample['gt_areas'], keep_index, axis=0) From 07787471e9452bccb3d8aa6b8aa3fb93a4d1871a Mon Sep 17 00:00:00 2001 From: digital-nomad-cheng Date: Thu, 1 May 2025 21:06:38 +0200 Subject: [PATCH 4/4] Fix infer error when annotation is not needed. --- ppdet/data/source/dataset.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ppdet/data/source/dataset.py b/ppdet/data/source/dataset.py index cccf9570f2..4b4cb3a561 100644 --- a/ppdet/data/source/dataset.py +++ b/ppdet/data/source/dataset.py @@ -217,14 +217,14 @@ def _load_images(self, do_eval=False): images = self._parse() ct = 0 records = [] - anno_file = self.get_anno() - coco = COCO(anno_file) for image in images: assert image != '' and os.path.isfile(image), \ "Image {} not found".format(image) if self.sample_num > 0 and ct >= self.sample_num: break if do_eval: + anno_file = self.get_anno() + coco = COCO(anno_file) image_id = self.get_image_id(image, coco) ct = image_id rec = {'im_id': np.array([ct]), 'im_file': image}