From 60a0e7791e809ab215f7c4ce2d7e5cb1fd6b3c2f Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Wed, 26 Jun 2019 10:43:06 +0800 Subject: [PATCH] Fix `norm_decay` in config files (#2539) * Fix `norm_decay` in config files should be float value now * Clean up a bit mostly max line length related --- .../configs/faster_rcnn_r50_fpn_1x.yml | 2 +- .../configs/faster_rcnn_r50_fpn_2x.yml | 2 +- .../configs/mask_rcnn_r50_2x.yml | 2 +- .../ppdet/modeling/architectures/mask_rcnn.py | 16 ++++++++++------ .../ppdet/modeling/backbones/resnet.py | 9 +++++---- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/PaddleCV/object_detection/configs/faster_rcnn_r50_fpn_1x.yml b/PaddleCV/object_detection/configs/faster_rcnn_r50_fpn_1x.yml index cc0dea95..594bd0d6 100644 --- a/PaddleCV/object_detection/configs/faster_rcnn_r50_fpn_1x.yml +++ b/PaddleCV/object_detection/configs/faster_rcnn_r50_fpn_1x.yml @@ -21,7 +21,7 @@ FasterRCNN: ResNet: norm_type: affine_channel - norm_decay: true + norm_decay: 0. depth: 50 feature_maps: [2, 3, 4, 5] freeze_at: 2 diff --git a/PaddleCV/object_detection/configs/faster_rcnn_r50_fpn_2x.yml b/PaddleCV/object_detection/configs/faster_rcnn_r50_fpn_2x.yml index e4ba3ce1..895442e0 100644 --- a/PaddleCV/object_detection/configs/faster_rcnn_r50_fpn_2x.yml +++ b/PaddleCV/object_detection/configs/faster_rcnn_r50_fpn_2x.yml @@ -21,7 +21,7 @@ FasterRCNN: ResNet: norm_type: affine_channel - norm_decay: true + norm_decay: 0. depth: 50 feature_maps: [2, 3, 4, 5] freeze_at: 2 diff --git a/PaddleCV/object_detection/configs/mask_rcnn_r50_2x.yml b/PaddleCV/object_detection/configs/mask_rcnn_r50_2x.yml index 1c67e59a..fb08e174 100644 --- a/PaddleCV/object_detection/configs/mask_rcnn_r50_2x.yml +++ b/PaddleCV/object_detection/configs/mask_rcnn_r50_2x.yml @@ -23,7 +23,7 @@ MaskRCNN: ResNet: norm_type: affine_channel - norm_decay: true + norm_decay: 0. depth: 50 feature_maps: 4 freeze_at: 2 diff --git a/PaddleCV/object_detection/ppdet/modeling/architectures/mask_rcnn.py b/PaddleCV/object_detection/ppdet/modeling/architectures/mask_rcnn.py index 15ef6c7f..116e0eaa 100644 --- a/PaddleCV/object_detection/ppdet/modeling/architectures/mask_rcnn.py +++ b/PaddleCV/object_detection/ppdet/modeling/architectures/mask_rcnn.py @@ -64,13 +64,16 @@ class MaskRCNN(object): def build(self, feed_vars, mode='train'): im = feed_vars['image'] - assert mode in ['train', 'test'], "only support 'train' and 'test' mode" + assert mode in ['train', 'test'], \ + "only 'train' and 'test' mode is supported" if mode == 'train': - required_fields = ['gt_label', 'gt_box', 'gt_mask', 'is_crowd', 'im_info'] + required_fields = ['gt_label', 'gt_box', 'gt_mask', + 'is_crowd', 'im_info'] else: required_fields = ['im_shape', 'im_info'] for var in required_fields: - assert var in feed_vars, "{} has no {} field".format(feed_vars, var) + assert var in feed_vars, \ + "{} has no {} field".format(feed_vars, var) im_info = feed_vars['im_info'] body_feats = self.backbone(im) @@ -144,7 +147,8 @@ class MaskRCNN(object): with switch.case(cond): fluid.layers.assign(input=bbox_pred, output=mask_pred) with switch.default(): - bbox = fluid.layers.slice(bbox_pred, [1], starts=[2], ends=[6]) + bbox = fluid.layers.slice(bbox_pred, [1], + starts=[2], ends=[6]) im_scale = fluid.layers.slice( im_info, [1], starts=[2], ends=[3]) @@ -155,8 +159,8 @@ class MaskRCNN(object): mask_feat = self.roi_extractor(last_feat, mask_rois) mask_feat = self.bbox_head.get_head_feat(mask_feat) else: - mask_feat = self.roi_extractor(body_feats, mask_rois, - spatial_scale, is_mask=True) + mask_feat = self.roi_extractor( + body_feats, mask_rois, spatial_scale, is_mask=True) mask_out = self.mask_head.get_prediction(mask_feat, bbox) fluid.layers.assign(input=mask_out, output=mask_pred) diff --git a/PaddleCV/object_detection/ppdet/modeling/backbones/resnet.py b/PaddleCV/object_detection/ppdet/modeling/backbones/resnet.py index 7d879ba7..3d36bfa2 100644 --- a/PaddleCV/object_detection/ppdet/modeling/backbones/resnet.py +++ b/PaddleCV/object_detection/ppdet/modeling/backbones/resnet.py @@ -39,11 +39,11 @@ class ResNet(object): Args: depth (int): ResNet depth, should be 18, 34, 50, 101, 152. freeze_at (int): freeze the backbone at which stage - norm_type (str): normalization type, 'bn', 'sync_bn' or 'affine_channel' + norm_type (str): normalization type, 'bn'/'sync_bn'/'affine_channel' freeze_norm (bool): freeze normalization layers norm_decay (float): weight decay for normalization layer weights variant (str): ResNet variant, supports 'a', 'b', 'c', 'd' currently - feature_maps (list): index of the stages whose feature maps are returned + feature_maps (list): index of stages whose feature maps are returned """ def __init__(self, @@ -330,6 +330,7 @@ class ResNetC5(ResNet): norm_decay=0., variant='b', feature_maps=[5]): - super(ResNetC5, self).__init__(depth, freeze_at, norm_type, freeze_norm, - norm_decay, variant, feature_maps) + super(ResNetC5, self).__init__( + depth, freeze_at, norm_type, freeze_norm, norm_decay, + variant, feature_maps) self.severed_head = True -- GitLab