From 1f82ad23a0a409e01e3f7362442aeb35121a0179 Mon Sep 17 00:00:00 2001 From: Guanghua Yu <742925032@qq.com> Date: Thu, 11 Feb 2021 15:12:21 +0800 Subject: [PATCH] fix solov2 with_background & from_config (#2211) --- .../configs/solov2/_base_/solov2_r50_fpn.yml | 6 ----- .../ppdet/data/transform/batch_operator.py | 2 +- .../ppdet/modeling/architectures/solov2.py | 24 +++++++++++++++---- dygraph/ppdet/modeling/heads/solov2_head.py | 2 +- dygraph/ppdet/py_op/post_process.py | 2 +- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/dygraph/configs/solov2/_base_/solov2_r50_fpn.yml b/dygraph/configs/solov2/_base_/solov2_r50_fpn.yml index e67a6e1b6..92ebe213e 100644 --- a/dygraph/configs/solov2/_base_/solov2_r50_fpn.yml +++ b/dygraph/configs/solov2/_base_/solov2_r50_fpn.yml @@ -9,7 +9,6 @@ SOLOv2: mask_head: SOLOv2MaskHead ResNet: - # index 0 stands for res2 depth: 50 norm_type: bn freeze_at: 0 @@ -17,11 +16,7 @@ ResNet: num_stages: 4 FPN: - in_channels: [256, 512, 1024, 2048] out_channel: 256 - min_level: 0 - max_level: 4 - spatial_scale: [0.25, 0.125, 0.0625, 0.03125] SOLOv2Head: seg_feat_channels: 512 @@ -32,7 +27,6 @@ SOLOv2Head: mask_nms: MaskMatrixNMS SOLOv2MaskHead: - in_channels: 256 mid_channels: 128 out_channels: 256 start_level: 0 diff --git a/dygraph/ppdet/data/transform/batch_operator.py b/dygraph/ppdet/data/transform/batch_operator.py index aabd0cf5d..1e876c754 100644 --- a/dygraph/ppdet/data/transform/batch_operator.py +++ b/dygraph/ppdet/data/transform/batch_operator.py @@ -644,7 +644,7 @@ class Gt2Solov2TargetOp(BaseOperator): max_ins_num = [0] * len(self.num_grids) for sample in samples: gt_bboxes_raw = sample['gt_bbox'] - gt_labels_raw = sample['gt_class'] + gt_labels_raw = sample['gt_class'] + 1 im_c, im_h, im_w = sample['image'].shape[:] gt_masks_raw = sample['gt_segm'].astype(np.uint8) mask_feat_size = [ diff --git a/dygraph/ppdet/modeling/architectures/solov2.py b/dygraph/ppdet/modeling/architectures/solov2.py index d7a34c0d2..4e5fc2118 100644 --- a/dygraph/ppdet/modeling/architectures/solov2.py +++ b/dygraph/ppdet/modeling/architectures/solov2.py @@ -18,7 +18,7 @@ from __future__ import print_function import paddle -from ppdet.core.workspace import register +from ppdet.core.workspace import register, create from .meta_arch import BaseArch __all__ = ['SOLOv2'] @@ -37,7 +37,6 @@ class SOLOv2(BaseArch): """ __category__ = 'architecture' - __inject__ = ['backbone', 'neck', 'solov2_head', 'mask_head'] def __init__(self, backbone, solov2_head, mask_head, neck=None): super(SOLOv2, self).__init__() @@ -46,11 +45,28 @@ class SOLOv2(BaseArch): self.solov2_head = solov2_head self.mask_head = mask_head + @classmethod + def from_config(cls, cfg, *args, **kwargs): + backbone = create(cfg['backbone']) + + kwargs = {'input_shape': backbone.out_shape} + neck = create(cfg['neck'], **kwargs) + + kwargs = {'input_shape': neck.out_shape} + solov2_head = create(cfg['solov2_head'], **kwargs) + mask_head = create(cfg['mask_head'], **kwargs) + + return { + 'backbone': backbone, + 'neck': neck, + 'solov2_head': solov2_head, + 'mask_head': mask_head, + } + def model_arch(self): body_feats = self.backbone(self.inputs) - if self.neck is not None: - body_feats, spatial_scale = self.neck(body_feats) + body_feats = self.neck(body_feats) self.seg_pred = self.mask_head(body_feats) diff --git a/dygraph/ppdet/modeling/heads/solov2_head.py b/dygraph/ppdet/modeling/heads/solov2_head.py index f43271a86..d24b0b029 100644 --- a/dygraph/ppdet/modeling/heads/solov2_head.py +++ b/dygraph/ppdet/modeling/heads/solov2_head.py @@ -190,7 +190,7 @@ class SOLOv2Head(nn.Layer): self.num_classes = num_classes self.in_channels = in_channels self.seg_num_grids = num_grids - self.cate_out_channels = self.num_classes - 1 + self.cate_out_channels = self.num_classes self.seg_feat_channels = seg_feat_channels self.stacked_convs = stacked_convs self.kernel_out_channels = kernel_out_channels diff --git a/dygraph/ppdet/py_op/post_process.py b/dygraph/ppdet/py_op/post_process.py index 04fabaa31..0c02cdba3 100755 --- a/dygraph/ppdet/py_op/post_process.py +++ b/dygraph/ppdet/py_op/post_process.py @@ -87,7 +87,7 @@ def get_solov2_segm_res(results, image_id, num_id_to_cat_id_map): return None # for each sample for i in range(lengths - 1): - clsid = int(clsid_labels[i]) + 1 + clsid = int(clsid_labels[i]) catid = num_id_to_cat_id_map[clsid] score = float(clsid_scores[i]) mask = segms[i] -- GitLab