From 31628f604b2b048eb08188fd6c9579b8fbd014ec Mon Sep 17 00:00:00 2001 From: wangguanzhong Date: Mon, 23 Nov 2020 10:36:52 +0800 Subject: [PATCH] fix train (#1743) --- configs/_base_/readers/mask_reader.yml | 2 +- ppdet/data/reader.py | 2 +- ppdet/data/source/coco.py | 5 ++--- ppdet/data/source/dataset.py | 3 ++- ppdet/modeling/architecture/meta_arch.py | 3 +-- tools/train.py | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/configs/_base_/readers/mask_reader.yml b/configs/_base_/readers/mask_reader.yml index c4908308f..07159041f 100644 --- a/configs/_base_/readers/mask_reader.yml +++ b/configs/_base_/readers/mask_reader.yml @@ -12,7 +12,7 @@ TrainReader: - PadBatch: {pad_to_stride: 32, use_padded_im_info: false, pad_gt: true} batch_size: 1 shuffle: true - drop_last: false + drop_last: true EvalReader: diff --git a/ppdet/data/reader.py b/ppdet/data/reader.py index 06e642acc..c279e5abd 100644 --- a/ppdet/data/reader.py +++ b/ppdet/data/reader.py @@ -135,7 +135,7 @@ class TrainReader(BaseDataLoader): batch_transforms=None, batch_size=1, shuffle=True, - drop_last=False, + drop_last=True, drop_empty=True, num_classes=81, with_background=True): diff --git a/ppdet/data/source/coco.py b/ppdet/data/source/coco.py index 49ac31025..69e383ac7 100644 --- a/ppdet/data/source/coco.py +++ b/ppdet/data/source/coco.py @@ -129,10 +129,9 @@ class COCODataSet(DetDataset): gt_bbox[i, :] = box['clean_bbox'] is_crowd[i][0] = box['iscrowd'] # check RLE format - if box['iscrowd'] == 1: + if 'segmentation' in box and box['iscrowd'] == 1: gt_poly[i] = [[0.0, 0.0], ] - continue - if 'segmentation' in box: + elif 'segmentation' in box: gt_poly[i] = box['segmentation'] if not any(gt_poly): diff --git a/ppdet/data/source/dataset.py b/ppdet/data/source/dataset.py index c8a2a9599..f5ef1aad5 100644 --- a/ppdet/data/source/dataset.py +++ b/ppdet/data/source/dataset.py @@ -22,6 +22,7 @@ except Exception: from paddle.io import Dataset from ppdet.core.workspace import register, serializable from ppdet.utils.download import get_dataset_path +import copy @serializable @@ -45,7 +46,7 @@ class DetDataset(Dataset): def __getitem__(self, idx): # data batch - roidb = self.roidbs[idx] + roidb = copy.deepcopy(self.roidbs[idx]) # data augment roidb = self.transform(roidb) # data item diff --git a/ppdet/modeling/architecture/meta_arch.py b/ppdet/modeling/architecture/meta_arch.py index ff6776269..51d185247 100644 --- a/ppdet/modeling/architecture/meta_arch.py +++ b/ppdet/modeling/architecture/meta_arch.py @@ -32,8 +32,7 @@ class BaseArch(nn.Layer): def build_inputs(self, data, input_def): inputs = {} for i, k in enumerate(input_def): - v = paddle.to_tensor(data[i]) - inputs[k] = v + inputs[k] = data[i] return inputs def model_arch(self): diff --git a/tools/train.py b/tools/train.py index 716b7b8a6..a59dd192d 100755 --- a/tools/train.py +++ b/tools/train.py @@ -126,7 +126,7 @@ def run(FLAGS, cfg, place): model = create(cfg.architecture) # Optimizer - lr = create('LearningRate')(step_per_epoch / int(ParallelEnv().nranks)) + lr = create('LearningRate')(step_per_epoch) optimizer = create('OptimizerBuilder')(lr, model.parameters()) # Init Model & Optimzer -- GitLab