From b5c534c2cd123e5a83d8a4f49d8a681d2f4dad66 Mon Sep 17 00:00:00 2001 From: zhoujun Date: Sun, 21 Nov 2021 16:15:51 +0800 Subject: [PATCH] add Lightweight backbone of centernet (#4586) --- configs/centernet/README_cn.md | 6 +++- .../centernet_ghostnet_1_3x_140e_coco.yml | 20 +++++++++++ .../centernet_lcnet_1x_140e_coco.yml | 18 ++++++++++ .../centernet/centernet_mbv1_1x_140e_coco.yml | 21 ++++++++++++ .../centernet_mbv3_large_1x_140e_coco.yml | 22 +++++++++++++ .../centernet_shufflenetv2_1x_140e_coco.yml | 33 +++++++++++++++++++ deploy/python/keypoint_preprocess.py | 4 +-- ppdet/modeling/backbones/mobilenet_v1.py | 20 +++++------ ppdet/modeling/necks/centernet_fpn.py | 2 ++ 9 files changed, 133 insertions(+), 13 deletions(-) create mode 100644 configs/centernet/centernet_ghostnet_1_3x_140e_coco.yml create mode 100644 configs/centernet/centernet_lcnet_1x_140e_coco.yml create mode 100644 configs/centernet/centernet_mbv1_1x_140e_coco.yml create mode 100644 configs/centernet/centernet_mbv3_large_1x_140e_coco.yml create mode 100644 configs/centernet/centernet_shufflenetv2_1x_140e_coco.yml diff --git a/configs/centernet/README_cn.md b/configs/centernet/README_cn.md index 2f22fc5cd..c4158ecaa 100644 --- a/configs/centernet/README_cn.md +++ b/configs/centernet/README_cn.md @@ -20,7 +20,11 @@ | DLA-34(paper) | 512x512 | 37.4 | - | - | - | | DLA-34 | 512x512 | 37.6 | - | [下载链接](https://bj.bcebos.com/v1/paddledet/models/centernet_dla34_140e_coco.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/develop/configs/centernet/centernet_dla34_140e_coco.yml) | | ResNet50 + DLAUp | 512x512 | 38.9 | - | [下载链接](https://bj.bcebos.com/v1/paddledet/models/centernet_r50_140e_coco.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/develop/configs/centernet/centernet_r50_140e_coco.yml) | - +| GhostNet_x1_3 + DLAUp | 512x512 | 28.9 | - | [下载链接](https://paddledet.bj.bcebos.com/models/centernet_ghostnet_1_3x_140e_coco.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/develop/configs/centernet/centernet_ghostnet_1_3x_140e_coco.yml) | +| PP-LCNet_x1_0 + DLAUp | 512x512 | 26.9 | - | [下载链接](https://paddledet.bj.bcebos.com/models/centernet_lcnet_1x_140e_coco.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/develop/configs/centernet/centernet_lcnet_1x_140e_coco.yml) | +| MobileNetV1_1x + DLAUp | 512x512 | 28.2 | - | [下载链接](https://paddledet.bj.bcebos.com/models/centernet_mbv1_1x_140e_coco.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/develop/configs/centernet/centernet_mbv1_1x_140e_coco.yml) | +| MobileNetV3_large_x1_0 + DLAUp | 512x512 | 27.1 | - | [下载链接](https://paddledet.bj.bcebos.com/models/centernet_mbv3_large_1x_140e_coco.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/develop/configs/centernet/centernet_mbv3_large_1x_140e_coco.yml) | +| ShuffleNetV2_x1_0 + DLAUp | 512x512 | 23.8 | - | [下载链接](https://paddledet.bj.bcebos.com/models/centernet_shufflenetv2_1x_140e_coco.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/develop/configs/centernet/centernet_shufflenetv2_1x_140e_coco.yml) | ## 引用 ``` diff --git a/configs/centernet/centernet_ghostnet_1_3x_140e_coco.yml b/configs/centernet/centernet_ghostnet_1_3x_140e_coco.yml new file mode 100644 index 000000000..e8938f3b6 --- /dev/null +++ b/configs/centernet/centernet_ghostnet_1_3x_140e_coco.yml @@ -0,0 +1,20 @@ +_BASE_: [ + 'centernet_r50_140e_coco.yml' +] + +pretrain_weights: https://paddledet.bj.bcebos.com/models/pretrained/GhostNet_x1_3_ssld_pretrained.pdparams +weights: output/centernet_ghostnet_1_3x_140e_coco/model_final + +CenterNet: + backbone: GhostNet + neck: CenterNetDLAFPN + head: CenterNetHead + post_process: CenterNetPostProcess + +GhostNet: + scale: 1.3 + conv_decay: 0.00004 + feature_maps: [4, 6, 12, 17] + +TrainReader: + batch_size: 32 \ No newline at end of file diff --git a/configs/centernet/centernet_lcnet_1x_140e_coco.yml b/configs/centernet/centernet_lcnet_1x_140e_coco.yml new file mode 100644 index 000000000..8e223693f --- /dev/null +++ b/configs/centernet/centernet_lcnet_1x_140e_coco.yml @@ -0,0 +1,18 @@ +_BASE_: [ + 'centernet_r50_140e_coco.yml' +] +pretrain_weights: https://paddledet.bj.bcebos.com/models/pretrained/LCNet_x1_0_pretrained.pdparams +weights: output/centernet_lcnet_1x_140e_coco/model_final + +CenterNet: + backbone: LCNet + neck: CenterNetDLAFPN + head: CenterNetHead + post_process: CenterNetPostProcess + +LCNet: + scale: 1.0 + feature_maps: [2, 3, 4, 5] + +TrainReader: + batch_size: 32 \ No newline at end of file diff --git a/configs/centernet/centernet_mbv1_1x_140e_coco.yml b/configs/centernet/centernet_mbv1_1x_140e_coco.yml new file mode 100644 index 000000000..d58781067 --- /dev/null +++ b/configs/centernet/centernet_mbv1_1x_140e_coco.yml @@ -0,0 +1,21 @@ +_BASE_: [ + 'centernet_r50_140e_coco.yml' +] + +pretrain_weights: https://paddledet.bj.bcebos.com/models/pretrained/MobileNetV1_pretrained.pdparams +weights: output/centernet_mbv1_1x_140e_coco/model_final + +CenterNet: + backbone: MobileNet + neck: CenterNetDLAFPN + head: CenterNetHead + post_process: CenterNetPostProcess + +MobileNet: + scale: 1. + with_extra_blocks: false + extra_block_filters: [] + feature_maps: [3, 5, 11, 13] + +TrainReader: + batch_size: 32 \ No newline at end of file diff --git a/configs/centernet/centernet_mbv3_large_1x_140e_coco.yml b/configs/centernet/centernet_mbv3_large_1x_140e_coco.yml new file mode 100644 index 000000000..2852b6fb6 --- /dev/null +++ b/configs/centernet/centernet_mbv3_large_1x_140e_coco.yml @@ -0,0 +1,22 @@ +_BASE_: [ + 'centernet_r50_140e_coco.yml' +] + +pretrain_weights: https://paddledet.bj.bcebos.com/models/pretrained/MobileNetV3_large_x1_0_ssld_pretrained.pdparams +weights: output/centernet_mbv3_large_1x_140e_coco/model_final + +CenterNet: + backbone: MobileNetV3 + neck: CenterNetDLAFPN + head: CenterNetHead + post_process: CenterNetPostProcess + +MobileNetV3: + model_name: large + scale: 1. + with_extra_blocks: false + extra_block_filters: [] + feature_maps: [4, 7, 13, 16] + +TrainReader: + batch_size: 32 \ No newline at end of file diff --git a/configs/centernet/centernet_shufflenetv2_1x_140e_coco.yml b/configs/centernet/centernet_shufflenetv2_1x_140e_coco.yml new file mode 100644 index 000000000..9362ccdc4 --- /dev/null +++ b/configs/centernet/centernet_shufflenetv2_1x_140e_coco.yml @@ -0,0 +1,33 @@ +_BASE_: [ + 'centernet_r50_140e_coco.yml' +] + +pretrain_weights: https://paddledet.bj.bcebos.com/models/pretrained/ShuffleNetV2_x1_0_pretrained.pdparams +weights: output/centernet_shufflenetv2_1x_140e_coco/model_final + +CenterNet: + backbone: ShuffleNetV2 + neck: CenterNetDLAFPN + head: CenterNetHead + post_process: CenterNetPostProcess + +ShuffleNetV2: + scale: 1.0 + feature_maps: [5, 13, 17] + act: leaky_relu + +CenterNetDLAFPN: + first_level: 0 + last_level: 3 + down_ratio: 8 + dcn_v2: False + +TrainReader: + batch_size: 32 + +TestReader: + sample_transforms: + - Decode: {} + - WarpAffine: {keep_res: False, input_h: 512, input_w: 512} + - NormalizeImage: {mean: [0.40789655, 0.44719303, 0.47026116], std: [0.2886383 , 0.27408165, 0.27809834]} + - Permute: {} \ No newline at end of file diff --git a/deploy/python/keypoint_preprocess.py b/deploy/python/keypoint_preprocess.py index bf6a2aa1d..b4e50e887 100644 --- a/deploy/python/keypoint_preprocess.py +++ b/deploy/python/keypoint_preprocess.py @@ -77,10 +77,10 @@ def get_affine_transform(center, np.ndarray: The transform matrix. """ assert len(center) == 2 - assert len(input_size) == 2 assert len(output_size) == 2 assert len(shift) == 2 - + if not isinstance(input_size, (np.ndarray, list)): + input_size = np.array([input_size, input_size], dtype=np.float32) scale_tmp = input_size shift = np.array(shift) diff --git a/ppdet/modeling/backbones/mobilenet_v1.py b/ppdet/modeling/backbones/mobilenet_v1.py index 8cf602832..7b9fa80eb 100644 --- a/ppdet/modeling/backbones/mobilenet_v1.py +++ b/ppdet/modeling/backbones/mobilenet_v1.py @@ -226,7 +226,7 @@ class MobileNet(nn.Layer): norm_type=norm_type, name="conv2_1")) self.dwsl.append(dws21) - self._update_out_channels(64, len(self.dwsl), feature_maps) + self._update_out_channels(int(64 * scale), len(self.dwsl), feature_maps) dws22 = self.add_sublayer( "conv2_2", sublayer=DepthwiseSeparable( @@ -242,7 +242,7 @@ class MobileNet(nn.Layer): norm_type=norm_type, name="conv2_2")) self.dwsl.append(dws22) - self._update_out_channels(128, len(self.dwsl), feature_maps) + self._update_out_channels(int(128 * scale), len(self.dwsl), feature_maps) # 1/4 dws31 = self.add_sublayer( "conv3_1", @@ -259,7 +259,7 @@ class MobileNet(nn.Layer): norm_type=norm_type, name="conv3_1")) self.dwsl.append(dws31) - self._update_out_channels(128, len(self.dwsl), feature_maps) + self._update_out_channels(int(128 * scale), len(self.dwsl), feature_maps) dws32 = self.add_sublayer( "conv3_2", sublayer=DepthwiseSeparable( @@ -275,7 +275,7 @@ class MobileNet(nn.Layer): norm_type=norm_type, name="conv3_2")) self.dwsl.append(dws32) - self._update_out_channels(256, len(self.dwsl), feature_maps) + self._update_out_channels(int(256 * scale), len(self.dwsl), feature_maps) # 1/8 dws41 = self.add_sublayer( "conv4_1", @@ -292,7 +292,7 @@ class MobileNet(nn.Layer): norm_type=norm_type, name="conv4_1")) self.dwsl.append(dws41) - self._update_out_channels(256, len(self.dwsl), feature_maps) + self._update_out_channels(int(256 * scale), len(self.dwsl), feature_maps) dws42 = self.add_sublayer( "conv4_2", sublayer=DepthwiseSeparable( @@ -308,13 +308,13 @@ class MobileNet(nn.Layer): norm_type=norm_type, name="conv4_2")) self.dwsl.append(dws42) - self._update_out_channels(512, len(self.dwsl), feature_maps) + self._update_out_channels(int(512 * scale), len(self.dwsl), feature_maps) # 1/16 for i in range(5): tmp = self.add_sublayer( "conv5_" + str(i + 1), sublayer=DepthwiseSeparable( - in_channels=512, + in_channels=int(512 * scale), out_channels1=512, out_channels2=512, num_groups=512, @@ -326,7 +326,7 @@ class MobileNet(nn.Layer): norm_type=norm_type, name="conv5_" + str(i + 1))) self.dwsl.append(tmp) - self._update_out_channels(512, len(self.dwsl), feature_maps) + self._update_out_channels(int(512 * scale), len(self.dwsl), feature_maps) dws56 = self.add_sublayer( "conv5_6", sublayer=DepthwiseSeparable( @@ -342,7 +342,7 @@ class MobileNet(nn.Layer): norm_type=norm_type, name="conv5_6")) self.dwsl.append(dws56) - self._update_out_channels(1024, len(self.dwsl), feature_maps) + self._update_out_channels(int(1024 * scale), len(self.dwsl), feature_maps) # 1/32 dws6 = self.add_sublayer( "conv6", @@ -359,7 +359,7 @@ class MobileNet(nn.Layer): norm_type=norm_type, name="conv6")) self.dwsl.append(dws6) - self._update_out_channels(1024, len(self.dwsl), feature_maps) + self._update_out_channels(int(1024 * scale), len(self.dwsl), feature_maps) if self.with_extra_blocks: self.extra_blocks = [] diff --git a/ppdet/modeling/necks/centernet_fpn.py b/ppdet/modeling/necks/centernet_fpn.py index 1ca1a4b58..9f2bb04b8 100755 --- a/ppdet/modeling/necks/centernet_fpn.py +++ b/ppdet/modeling/necks/centernet_fpn.py @@ -270,6 +270,8 @@ class CenterNetDLAFPN(nn.Layer): feat = ida_up_feats[-1] if self.with_sge: feat = self.sge_attention(feat) + if self.down_ratio != 4: + feat = F.interpolate(feat, scale_factor=self.down_ratio // 4, mode="bilinear", align_corners=True) return feat @property -- GitLab