diff --git a/dygraph/configs/dcn/README.md b/dygraph/configs/dcn/README.md new file mode 100644 index 0000000000000000000000000000000000000000..dd863bc522ace56eddb882fd4c55ea4f9db27163 --- /dev/null +++ b/dygraph/configs/dcn/README.md @@ -0,0 +1,33 @@ +### Deformable ConvNets v2 + +| 骨架网络 | 网络类型 | 卷积 | 每张GPU图片个数 | 学习率策略 |推理时间(fps)| Box AP | Mask AP | 下载 | 配置文件 | +| :------------------- | :------------- | :-----: |:--------: | :-----: | :-----------: |:----: | :-----: | :----------------------------------------------------------: | :----: | +| ResNet50-FPN | Faster | c3-c5 | 2 | 1x | - | 41.3 | - | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/dygraph/faster_rcnn_dcn_r50_fpn_1x_coco.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/master/dygraph/configs/dcn/faster_rcnn_dcn_r50_fpn_1x_coco.yml) | +| ResNet50-vd-FPN | Faster | c3-c5 | 2 | 2x | - | 42.4 | - | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/dygraph/faster_rcnn_dcn_r50_vd_fpn_2x.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/master/dygraph/configs/dcn/faster_rcnn_dcn_r50_vd_fpn_2x.yml) | +| ResNet101-vd-FPN | Faster | c3-c5 | 2 | 1x | - | 44.1 | - | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/dygraph/faster_rcnn_dcn_r101_vd_fpn_1x.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/master/dygraph/configs/dcn/faster_rcnn_dcn_r101_vd_fpn_1x.yml) | +| ResNeXt101-vd-FPN | Faster | c3-c5 | 1 | 1x | - | 45.2 | - | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/dygraph/faster_rcnn_dcn_x101_vd_64x4d_fpn_1x.pdparams) |[配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/master/dygraph/configs/dcn/faster_rcnn_dcn_x101_vd_64x4d_fpn_1x.yml) | +| ResNet50-FPN | Mask | c3-c5 | 1 | 1x | - | 41.9 | 37.3 | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/dygraph/mask_rcnn_dcn_r50_fpn_1x.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/master/dygraph/configs/dcn/mask_rcnn_dcn_r50_fpn_1x.yml) | +| ResNet50-vd-FPN | Mask | c3-c5 | 1 | 2x | - | 42.9 | 38.0 | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/dygraph/mask_rcnn_dcn_r50_vd_fpn_2x.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/master/dygraph/configs/dcn/mask_rcnn_dcn_r50_vd_fpn_2x.yml) | +| ResNet101-vd-FPN | Mask | c3-c5 | 1 | 1x | - | 44.6 | 39.2 | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/dygraph/mask_rcnn_dcn_r101_vd_fpn_1x.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/master/dygraph/configs/dcn/mask_rcnn_dcn_r101_vd_fpn_1x.yml) | +| ResNeXt101-vd-FPN | Mask | c3-c5 | 1 | 1x | - | 46.2 | 40.4 | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/dygraph/mask_rcnn_dcn_x101_vd_64x4d_fpn_1x.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/master/dygraph/configs/dcn/mask_rcnn_dcn_x101_vd_64x4d_fpn_1x.yml) | + +**注意事项:** + +- Deformable卷积网络v2(dcn_v2)参考自论文[Deformable ConvNets v2](https://arxiv.org/abs/1811.11168). +- `c3-c5`意思是在resnet模块的3到5阶段增加`dcn`. + +## Citations +``` +@inproceedings{dai2017deformable, + title={Deformable Convolutional Networks}, + author={Dai, Jifeng and Qi, Haozhi and Xiong, Yuwen and Li, Yi and Zhang, Guodong and Hu, Han and Wei, Yichen}, + booktitle={Proceedings of the IEEE international conference on computer vision}, + year={2017} +} +@article{zhu2018deformable, + title={Deformable ConvNets v2: More Deformable, Better Results}, + author={Zhu, Xizhou and Hu, Han and Lin, Stephen and Dai, Jifeng}, + journal={arXiv preprint arXiv:1811.11168}, + year={2018} +} +``` diff --git a/dygraph/configs/dcn/faster_rcnn_dcn_r101_vd_fpn_1x_coco.yml b/dygraph/configs/dcn/faster_rcnn_dcn_r101_vd_fpn_1x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..9d97b0468884c3db2e01161c9a8a42030a98001b --- /dev/null +++ b/dygraph/configs/dcn/faster_rcnn_dcn_r101_vd_fpn_1x_coco.yml @@ -0,0 +1,29 @@ +_BASE_: [ + 'faster_rcnn_dcn_r50_fpn_1x_coco.yml', +] +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_pretrained.tar +weights: output/faster_rcnn_dcn_r101_fpn_1x_coco/model_final + +ResNet: + # index 0 stands for res2 + depth: 101 + variant: d + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + dcn_v2_stages: [1,2,3] + +epoch: 12 +LearningRate: + base_lr: 0.02 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [8, 11] + - !LinearWarmup + start_factor: 0.1 + steps: 1000 + +TrainReader: + batch_size: 2 diff --git a/dygraph/configs/dcn/faster_rcnn_dcn_r50_fpn_1x_coco.yml b/dygraph/configs/dcn/faster_rcnn_dcn_r50_fpn_1x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..4540f51f719e800df7eddbe2c3be64dc6f3fbe41 --- /dev/null +++ b/dygraph/configs/dcn/faster_rcnn_dcn_r50_fpn_1x_coco.yml @@ -0,0 +1,30 @@ +_BASE_: [ + '../datasets/coco_detection.yml', + '../runtime.yml', + '../faster_rcnn/_base_/optimizer_1x.yml', + '../faster_rcnn/_base_/faster_rcnn_r50_fpn.yml', + '../faster_rcnn/_base_/faster_fpn_reader.yml', +] +weights: output/faster_rcnn_dcn_r50_fpn_1x_coco/model_final + +ResNet: + depth: 50 + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + dcn_v2_stages: [1,2,3] + +epoch: 12 +LearningRate: + base_lr: 0.02 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [8, 11] + - !LinearWarmup + start_factor: 0.1 + steps: 1000 + +TrainReader: + batch_size: 2 diff --git a/dygraph/configs/dcn/faster_rcnn_dcn_r50_vd_fpn_2x_coco.yml b/dygraph/configs/dcn/faster_rcnn_dcn_r50_vd_fpn_2x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..9269df4ad83a13817f4437f94360a37a0c744ce3 --- /dev/null +++ b/dygraph/configs/dcn/faster_rcnn_dcn_r50_vd_fpn_2x_coco.yml @@ -0,0 +1,29 @@ +_BASE_: [ + 'faster_rcnn_dcn_r50_fpn_1x_coco.yml', +] +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_vd_pretrained.tar +weights: output/faster_rcnn_dcn_r50_vd_fpn_2x_coco/model_final + +ResNet: + # index 0 stands for res2 + depth: 50 + variant: d + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + dcn_v2_stages: [1,2,3] + +epoch: 24 +LearningRate: + base_lr: 0.02 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [16, 22] + - !LinearWarmup + start_factor: 0.1 + steps: 1000 + +TrainReader: + batch_size: 2 diff --git a/dygraph/configs/dcn/faster_rcnn_dcn_x101_vd_64x4d_fpn_1x_coco.yml b/dygraph/configs/dcn/faster_rcnn_dcn_x101_vd_64x4d_fpn_1x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..4148ab88f8637b73cfeb70fbcec865d73b28fd60 --- /dev/null +++ b/dygraph/configs/dcn/faster_rcnn_dcn_x101_vd_64x4d_fpn_1x_coco.yml @@ -0,0 +1,29 @@ +_BASE_: [ + 'faster_rcnn_dcn_r50_fpn_1x_coco.yml', +] +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNeXt101_vd_64x4d_pretrained.tar +weights: output/faster_rcnn_dcn_x101_vd_64x4d_fpn_1x_coco/model_final.pdparams + +ResNet: + # for ResNeXt: groups, base_width, base_channels + depth: 101 + groups: 64 + base_width: 4 + base_channels: 64 + variant: d + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + dcn_v2_stages: [1,2,3] + +epoch: 12 +LearningRate: + base_lr: 0.01 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [8, 11] + - !LinearWarmup + start_factor: 0.1 + steps: 1000 diff --git a/dygraph/configs/dcn/mask_rcnn_dcn_r101_vd_fpn_1x_coco.yml b/dygraph/configs/dcn/mask_rcnn_dcn_r101_vd_fpn_1x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..722a95ff72efcf9aeeaedb0dd02d4973c1ac81af --- /dev/null +++ b/dygraph/configs/dcn/mask_rcnn_dcn_r101_vd_fpn_1x_coco.yml @@ -0,0 +1,26 @@ +_BASE_: [ + 'mask_rcnn_dcn_r50_fpn_1x_coco.yml', +] +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_pretrained.tar +weights: output/mask_rcnn_dcn_r101_fpn_1x_coco/model_final.pdparams + +ResNet: + # index 0 stands for res2 + depth: 101 + variant: d + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + dcn_v2_stages: [1,2,3] + +epoch: 12 +LearningRate: + base_lr: 0.01 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [8, 11] + - !LinearWarmup + start_factor: 0.1 + steps: 1000 diff --git a/dygraph/configs/dcn/mask_rcnn_dcn_r50_fpn_1x_coco.yml b/dygraph/configs/dcn/mask_rcnn_dcn_r50_fpn_1x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..d7db95dc0e2a64aa5eca21bd5e50f3326a1d60d6 --- /dev/null +++ b/dygraph/configs/dcn/mask_rcnn_dcn_r50_fpn_1x_coco.yml @@ -0,0 +1,27 @@ +_BASE_: [ + '../datasets/coco_instance.yml', + '../runtime.yml', + '../mask_rcnn/_base_/optimizer_1x.yml', + '../mask_rcnn/_base_/mask_rcnn_r50_fpn.yml', + '../mask_rcnn/_base_/mask_fpn_reader.yml', +] +weights: output/mask_rcnn_dcn_r50_fpn_1x_coco/model_final + +ResNet: + depth: 50 + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + dcn_v2_stages: [1,2,3] + +epoch: 12 +LearningRate: + base_lr: 0.01 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [8, 11] + - !LinearWarmup + start_factor: 0.1 + steps: 1000 diff --git a/dygraph/configs/dcn/mask_rcnn_dcn_r50_vd_fpn_2x_coco.yml b/dygraph/configs/dcn/mask_rcnn_dcn_r50_vd_fpn_2x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..4793dfd06b3c2e93fb4130b3f227d437d834ec35 --- /dev/null +++ b/dygraph/configs/dcn/mask_rcnn_dcn_r50_vd_fpn_2x_coco.yml @@ -0,0 +1,26 @@ +_BASE_: [ + 'mask_rcnn_dcn_r50_fpn_1x_coco.yml', +] +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_vd_pretrained.tar +weights: output/mask_rcnn_dcn_r50_vd_fpn_2x_coco/model_final + +ResNet: + # index 0 stands for res2 + depth: 50 + variant: d + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + dcn_v2_stages: [1,2,3] + +epoch: 24 +LearningRate: + base_lr: 0.01 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [16, 22] + - !LinearWarmup + start_factor: 0.1 + steps: 1000 diff --git a/dygraph/configs/dcn/mask_rcnn_dcn_x101_vd_64x4d_fpn_1x_coco.yml b/dygraph/configs/dcn/mask_rcnn_dcn_x101_vd_64x4d_fpn_1x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..2d52e5e90dd83f4a67edca3ae0d7c8301d97a4aa --- /dev/null +++ b/dygraph/configs/dcn/mask_rcnn_dcn_x101_vd_64x4d_fpn_1x_coco.yml @@ -0,0 +1,29 @@ +_BASE_: [ + 'mask_rcnn_dcn_r50_fpn_1x_coco.yml', +] +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNeXt101_vd_64x4d_pretrained.tar +weights: output/mask_rcnn_dcn_x101_vd_64x4d_fpn_1x_coco/model_final.pdparams + +ResNet: + # for ResNeXt: groups, base_width, base_channels + depth: 101 + variant: d + groups: 64 + base_width: 4 + base_channels: 64 + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + dcn_v2_stages: [1,2,3] + +epoch: 12 +LearningRate: + base_lr: 0.01 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [8, 11] + - !LinearWarmup + start_factor: 0.1 + steps: 1000 diff --git a/dygraph/configs/faster_rcnn/README.md b/dygraph/configs/faster_rcnn/README.md index d4120b32561b35f66e41cac045a4d41d137943a3..b9def62ebb1d6e975293799fb08111a090f3352e 100644 --- a/dygraph/configs/faster_rcnn/README.md +++ b/dygraph/configs/faster_rcnn/README.md @@ -4,8 +4,11 @@ | 骨架网络 | 网络类型 | 每张GPU图片个数 | 学习率策略 |推理时间(fps) | Box AP | Mask AP | 下载 | 配置文件 | | :------------------- | :------------- | :-----: | :-----: | :------------: | :-----: | :-----: | :-----------------------------------------------------: | :-----: | -| ResNet50 | Faster | 1 | 1x | ---- | 35.1 | - | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/dygraph/faster_rcnn_r50_1x_coco.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/dygraph/configs/faster_rcnn_r50_1x_coco.yml) | -| ResNet50-FPN | Faster | 1 | 1x | ---- | 37.0 | - | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/dygraph/faster_rcnn_r50_fpn_1x_coco.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/dygraph/configs/faster_rcnn_r50_fpn_1x_coco.yml) | +| ResNet50 | Faster | 1 | 1x | ---- | 35.1 | - | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/dygraph/faster_rcnn_r50_1x_coco.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/dygraph/configs/faster_rcnn/faster_rcnn_r50_1x_coco.yml) | +| ResNet50-FPN | Faster | 1 | 1x | ---- | 37.0 | - | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/dygraph/faster_rcnn_r50_fpn_1x_coco.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/dygraph/configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.yml) | +| ResNet34-FPN | Faster | 2 | 1x | ---- | 36.7 | - | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/dygraph/faster_rcnn_r34_fpn_1x_coco.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/dygraph/configs/faster_rcnn/faster_rcnn_r34_fpn_1x_coco.yml) | +| ResNet101 | Faster | 1 | 1x | ---- | 38.3 | - | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/dygraph/faster_rcnn_r101_1x_coco.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/dygraph/configs/faster_rcnn/faster_rcnn_r101_1x_coco.yml) | +| ResNet101-FPN | Faster | 1 | 1x | ---- | 38.7 | - | [下载链接](https://paddlemodels.bj.bcebos.com/object_detection/dygraph/faster_rcnn_r101_fpn_1x_coco.pdparams) | [配置文件](https://github.com/PaddlePaddle/PaddleDetection/tree/dygraph/configs/faster_rcnn/faster_rcnn_r101_fpn_1x_coco.yml) | ## Citations ``` diff --git a/dygraph/configs/faster_rcnn/faster_rcnn_r101_1x_coco.yml b/dygraph/configs/faster_rcnn/faster_rcnn_r101_1x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..f286c35c14255c43dca7f66d2ed2dfd30984201a --- /dev/null +++ b/dygraph/configs/faster_rcnn/faster_rcnn_r101_1x_coco.yml @@ -0,0 +1,14 @@ +_BASE_: [ + 'faster_rcnn_r50_1x_coco.yml', +] + +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_pretrained.tar +weights: output/faster_rcnn_r101_1x_coco/model_final + +ResNet: + # index 0 stands for res2 + depth: 101 + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 diff --git a/dygraph/configs/faster_rcnn/faster_rcnn_r101_fpn_1x_coco.yml b/dygraph/configs/faster_rcnn/faster_rcnn_r101_fpn_1x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..94166c695fcad85393c9233645c7e48dbcd59f17 --- /dev/null +++ b/dygraph/configs/faster_rcnn/faster_rcnn_r101_fpn_1x_coco.yml @@ -0,0 +1,14 @@ +_BASE_: [ + 'faster_rcnn_r50_fpn_1x_coco.yml', +] + +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_pretrained.tar +weights: output/faster_rcnn_r101_fpn_1x_coco/model_final + +ResNet: + # index 0 stands for res2 + depth: 101 + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 diff --git a/dygraph/configs/faster_rcnn/faster_rcnn_r101_fpn_2x_coco.yml b/dygraph/configs/faster_rcnn/faster_rcnn_r101_fpn_2x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..2ebbd04174e3110c7658ea56cb0b8016012798eb --- /dev/null +++ b/dygraph/configs/faster_rcnn/faster_rcnn_r101_fpn_2x_coco.yml @@ -0,0 +1,25 @@ +_BASE_: [ + 'faster_rcnn_r50_fpn_1x_coco.yml', +] + +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_pretrained.tar +weights: output/faster_rcnn_r101_fpn_2x_coco/model_final + +ResNet: + # index 0 stands for res2 + depth: 101 + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + +epoch: 24 +LearningRate: + base_lr: 0.01 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [16, 22] + - !LinearWarmup + start_factor: 0.3333333333333333 + steps: 500 diff --git a/dygraph/configs/faster_rcnn/faster_rcnn_r101_vd_1x_coco.yml b/dygraph/configs/faster_rcnn/faster_rcnn_r101_vd_1x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..4998728e374a0f1685b03b56ad2ee21413d6e393 --- /dev/null +++ b/dygraph/configs/faster_rcnn/faster_rcnn_r101_vd_1x_coco.yml @@ -0,0 +1,26 @@ +_BASE_: [ + 'faster_rcnn_r50_1x_coco.yml', +] + +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_vd_pretrained.tar +weights: output/faster_rcnn_r101_vd_1x_coco/model_final + +ResNet: + # index 0 stands for res2 + depth: 101 + variant: d + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + +epoch: 12 +LearningRate: + base_lr: 0.01 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [8, 11] + - !LinearWarmup + start_factor: 0.3333333333333333 + steps: 1000 diff --git a/dygraph/configs/faster_rcnn/faster_rcnn_r101_vd_fpn_1x_coco.yml b/dygraph/configs/faster_rcnn/faster_rcnn_r101_vd_fpn_1x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..c1ac42b0881bdc283aaac90ef03c16aaa26706bf --- /dev/null +++ b/dygraph/configs/faster_rcnn/faster_rcnn_r101_vd_fpn_1x_coco.yml @@ -0,0 +1,25 @@ +_BASE_: [ + 'faster_rcnn_r50_fpn_1x_coco.yml', +] +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_vd_pretrained.tar +weights: output/faster_rcnn_r101_vd_fpn_1x_coco/model_final.pdparams + +ResNet: + # index 0 stands for res2 + depth: 101 + variant: d + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + +epoch: 12 +LearningRate: + base_lr: 0.01 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [8, 11] + - !LinearWarmup + start_factor: 0.3333333333333333 + steps: 1000 diff --git a/dygraph/configs/faster_rcnn/faster_rcnn_r34_fpn_1x_coco.yml b/dygraph/configs/faster_rcnn/faster_rcnn_r34_fpn_1x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..84d4d3b90db8c6e53a1d5be6990b92edad118554 --- /dev/null +++ b/dygraph/configs/faster_rcnn/faster_rcnn_r34_fpn_1x_coco.yml @@ -0,0 +1,34 @@ +_BASE_: [ + 'faster_rcnn_r50_fpn_1x_coco.yml', +] + +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet34_pretrained.tar +weights: output/faster_rcnn_r34_fpn_1x_coco/model_final + +ResNet: + # index 0 stands for res2 + depth: 34 + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + +FPN: + in_channels: [64, 128, 256, 512] + out_channel: 256 + min_level: 0 + max_level: 4 + spatial_scale: [0.25, 0.125, 0.0625, 0.03125] + +LearningRate: + base_lr: 0.02 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [8, 11] + - !LinearWarmup + start_factor: 0.1 + steps: 1000 + +TrainReader: + batch_size: 2 diff --git a/dygraph/configs/faster_rcnn/faster_rcnn_r34_vd_fpn_1x_coco.yml b/dygraph/configs/faster_rcnn/faster_rcnn_r34_vd_fpn_1x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..bc24e1c92becbae41dc3a0e3450b4589bcf408d0 --- /dev/null +++ b/dygraph/configs/faster_rcnn/faster_rcnn_r34_vd_fpn_1x_coco.yml @@ -0,0 +1,35 @@ +_BASE_: [ + 'faster_rcnn_r50_fpn_1x_coco.yml', +] + +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet34_vd_pretrained.tar +weights: output/faster_rcnn_r34_vd_fpn_1x_coco/model_final + +ResNet: + # index 0 stands for res2 + depth: 34 + variant: d + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + +FPN: + in_channels: [64, 128, 256, 512] + out_channel: 256 + min_level: 0 + max_level: 4 + spatial_scale: [0.25, 0.125, 0.0625, 0.03125] + +LearningRate: + base_lr: 0.02 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [8, 11] + - !LinearWarmup + start_factor: 0.1 + steps: 1000 + +TrainReader: + batch_size: 2 diff --git a/dygraph/configs/faster_rcnn/faster_rcnn_r50_2x_coco.yml b/dygraph/configs/faster_rcnn/faster_rcnn_r50_2x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..0ce3a69b4abd1a7d85990ddeddce26ecd8548a72 --- /dev/null +++ b/dygraph/configs/faster_rcnn/faster_rcnn_r50_2x_coco.yml @@ -0,0 +1,15 @@ +_BASE_: [ + 'faster_rcnn_r50_1x_coco.yml', +] +weights: output/faster_rcnn_r50_2x_coco/model_final + +epoch: 24 +LearningRate: + base_lr: 0.01 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [16, 22] + - !LinearWarmup + start_factor: 0.3333333333333333 + steps: 500 diff --git a/dygraph/configs/faster_rcnn/faster_rcnn_r50_fpn_2x_coco.yml b/dygraph/configs/faster_rcnn/faster_rcnn_r50_fpn_2x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..f931515d3ab7ecc36741982e221d878d8988cc47 --- /dev/null +++ b/dygraph/configs/faster_rcnn/faster_rcnn_r50_fpn_2x_coco.yml @@ -0,0 +1,18 @@ +_BASE_: [ + 'faster_rcnn_r50_fpn_1x_coco.yml', +] +weights: output/faster_rcnn_r50_fpn_2x_coco/model_final + +epoch: 24 +LearningRate: + base_lr: 0.02 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [16, 22] + - !LinearWarmup + start_factor: 0.3333333333333333 + steps: 500 + +TrainReader: + batch_size: 2 diff --git a/dygraph/configs/faster_rcnn/faster_rcnn_r50_vd_fpn_2x_coco.yml b/dygraph/configs/faster_rcnn/faster_rcnn_r50_vd_fpn_2x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..200ec47c23a1a4705953bbe92960f93dca807afc --- /dev/null +++ b/dygraph/configs/faster_rcnn/faster_rcnn_r50_vd_fpn_2x_coco.yml @@ -0,0 +1,28 @@ +_BASE_: [ + 'faster_rcnn_r50_fpn_1x_coco.yml', +] +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_vd_pretrained.tar +weights: output/faster_rcnn_r50_vd_fpn_2x_coco/model_final + +ResNet: + # index 0 stands for res2 + depth: 50 + variant: d + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + +epoch: 24 +LearningRate: + base_lr: 0.02 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [16, 22] + - !LinearWarmup + start_factor: 0.3333333333333333 + steps: 500 + +TrainReader: + batch_size: 2 diff --git a/dygraph/configs/faster_rcnn/faster_rcnn_x101_vd_64x4d_fpn_1x_coco.yml b/dygraph/configs/faster_rcnn/faster_rcnn_x101_vd_64x4d_fpn_1x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..4f890f07547abd2e650e1cedc574c2d311dfac53 --- /dev/null +++ b/dygraph/configs/faster_rcnn/faster_rcnn_x101_vd_64x4d_fpn_1x_coco.yml @@ -0,0 +1,29 @@ +_BASE_: [ + 'faster_rcnn_r50_fpn_1x_coco.yml', +] + +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNeXt101_vd_64x4d_pretrained.tar +weights: output/faster_rcnn_x101_vd_64x4d_fpn_1x_coco/model_final.pdparams + +ResNet: + # for ResNeXt: groups, base_width, base_channels + depth: 101 + groups: 64 + base_width: 4 + base_channels: 64 + variant: d + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + +epoch: 12 +LearningRate: + base_lr: 0.01 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [8, 11] + - !LinearWarmup + start_factor: 0.1 + steps: 1000 diff --git a/dygraph/configs/faster_rcnn/faster_rcnn_x101_vd_64x4d_fpn_2x_coco.yml b/dygraph/configs/faster_rcnn/faster_rcnn_x101_vd_64x4d_fpn_2x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..99283a81a26aaeeb8de4661c08a637ce79286afa --- /dev/null +++ b/dygraph/configs/faster_rcnn/faster_rcnn_x101_vd_64x4d_fpn_2x_coco.yml @@ -0,0 +1,29 @@ +_BASE_: [ + 'faster_rcnn_r50_fpn_1x_coco.yml', +] + +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNeXt101_vd_64x4d_pretrained.tar +weights: output/faster_rcnn_x101_vd_64x4d_fpn_2x_coco/model_final.pdparams + +ResNet: + # for ResNeXt: groups, base_width, base_channels + depth: 101 + groups: 64 + base_width: 4 + base_channels: 64 + variant: d + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + +epoch: 24 +LearningRate: + base_lr: 0.01 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [16, 22] + - !LinearWarmup + start_factor: 0.1 + steps: 1000 diff --git a/dygraph/configs/mask_rcnn/mask_rcnn_r101_fpn_1x_coco.yml b/dygraph/configs/mask_rcnn/mask_rcnn_r101_fpn_1x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..71a3fcf759ef9b0b2c91f67984d6ef831eaf42cd --- /dev/null +++ b/dygraph/configs/mask_rcnn/mask_rcnn_r101_fpn_1x_coco.yml @@ -0,0 +1,13 @@ +_BASE_: [ + 'mask_rcnn_r50_fpn_1x_coco.yml', +] +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_pretrained.tar +weights: output/mask_rcnn_r101_fpn_1x_coco/model_final.pdparams + +ResNet: + # index 0 stands for res2 + depth: 101 + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 diff --git a/dygraph/configs/mask_rcnn/mask_rcnn_r50_2x_coco.yml b/dygraph/configs/mask_rcnn/mask_rcnn_r50_2x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..f1e6b669bd7a941608c785593314c6e7feff0b59 --- /dev/null +++ b/dygraph/configs/mask_rcnn/mask_rcnn_r50_2x_coco.yml @@ -0,0 +1,15 @@ +_BASE_: [ + 'mask_rcnn_r50_1x_coco.yml', +] +weights: output/mask_rcnn_r50_2x_coco/model_final + +epoch: 24 +LearningRate: + base_lr: 0.01 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [16, 22] + - !LinearWarmup + start_factor: 0.3333333333333333 + steps: 500 diff --git a/dygraph/configs/mask_rcnn/mask_rcnn_r50_fpn_2x_coco.yml b/dygraph/configs/mask_rcnn/mask_rcnn_r50_fpn_2x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..f687fd69b1e0521a825da658f2ad14a33ef4b581 --- /dev/null +++ b/dygraph/configs/mask_rcnn/mask_rcnn_r50_fpn_2x_coco.yml @@ -0,0 +1,15 @@ +_BASE_: [ + 'mask_rcnn_r50_fpn_1x_coco.yml', +] +weights: output/mask_rcnn_r50_fpn_2x_coco/model_final + +epoch: 24 +LearningRate: + base_lr: 0.01 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [16, 22] + - !LinearWarmup + start_factor: 0.3333333333333333 + steps: 500 diff --git a/dygraph/configs/mask_rcnn/mask_rcnn_r50_vd_fpn_2x_coco.yml b/dygraph/configs/mask_rcnn/mask_rcnn_r50_vd_fpn_2x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..618fe5dc6e9d98e50548b2483de4268238fbbfc3 --- /dev/null +++ b/dygraph/configs/mask_rcnn/mask_rcnn_r50_vd_fpn_2x_coco.yml @@ -0,0 +1,26 @@ +_BASE_: [ + 'mask_rcnn_r50_fpn_1x_coco.yml', +] + +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_vd_pretrained.tar +weights: output/mask_rcnn_r50_vd_fpn_2x_coco/model_final + +ResNet: + # index 0 stands for res2 + depth: 50 + variant: d + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + +epoch: 24 +LearningRate: + base_lr: 0.01 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [16, 22] + - !LinearWarmup + start_factor: 0.3333333333333333 + steps: 500 diff --git a/dygraph/configs/mask_rcnn/mask_rcnn_x101_vd_64x4d_fpn_1x_coco.yml b/dygraph/configs/mask_rcnn/mask_rcnn_x101_vd_64x4d_fpn_1x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..4c1f8ce3f550c971846485453788a690491b2c5f --- /dev/null +++ b/dygraph/configs/mask_rcnn/mask_rcnn_x101_vd_64x4d_fpn_1x_coco.yml @@ -0,0 +1,29 @@ +_BASE_: [ + 'mask_rcnn_r50_fpn_1x_coco.yml', +] + +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNeXt101_vd_64x4d_pretrained.tar +weights: output/mask_rcnn_x101_vd_64x4d_fpn_1x_coco/model_final.pdparams + +ResNet: + # for ResNeXt: groups, base_width, base_channels + depth: 101 + variant: d + groups: 64 + base_width: 4 + base_channels: 64 + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + +epoch: 12 +LearningRate: + base_lr: 0.01 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [8, 11] + - !LinearWarmup + start_factor: 0.1 + steps: 1000 diff --git a/dygraph/configs/mask_rcnn/mask_rcnn_x101_vd_64x4d_fpn_2x_coco.yml b/dygraph/configs/mask_rcnn/mask_rcnn_x101_vd_64x4d_fpn_2x_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..b21db19e392f9c79abab604fe75bb0894eb916a0 --- /dev/null +++ b/dygraph/configs/mask_rcnn/mask_rcnn_x101_vd_64x4d_fpn_2x_coco.yml @@ -0,0 +1,29 @@ +_BASE_: [ + 'mask_rcnn_r50_fpn_1x_coco.yml', +] + +pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNeXt101_vd_64x4d_pretrained.tar +weights: output/mask_rcnn_x101_vd_64x4d_fpn_2x_coco/model_final.pdparams + +ResNet: + # for ResNeXt: groups, base_width, base_channels + depth: 101 + variant: d + groups: 64 + base_width: 4 + base_channels: 64 + norm_type: bn + freeze_at: 0 + return_idx: [0,1,2,3] + num_stages: 4 + +epoch: 24 +LearningRate: + base_lr: 0.01 + schedulers: + - !PiecewiseDecay + gamma: 0.1 + milestones: [16, 22] + - !LinearWarmup + start_factor: 0.1 + steps: 1000 diff --git a/dygraph/ppdet/modeling/backbones/name_adapter.py b/dygraph/ppdet/modeling/backbones/name_adapter.py index 3f5ea945126f03e45570aa1e76a0e68ed0591314..4afbb9b189e5091dc048194ca5f3a5cbaea061d3 100644 --- a/dygraph/ppdet/modeling/backbones/name_adapter.py +++ b/dygraph/ppdet/modeling/backbones/name_adapter.py @@ -41,6 +41,17 @@ class NameAdapter(object): shortcut_name = name + "_branch1" return conv_name1, conv_name2, conv_name3, shortcut_name + def fix_basicblock_name(self, name): + if self.model_type == 'SEResNeXt': + conv_name1 = 'conv' + name + '_x1' + conv_name2 = 'conv' + name + '_x2' + shortcut_name = name + else: + conv_name1 = name + "_branch2a" + conv_name2 = name + "_branch2b" + shortcut_name = name + "_branch1" + return conv_name1, conv_name2, shortcut_name + def fix_layer_warp_name(self, stage_num, count, i): name = 'res' + str(stage_num) if count > 10 and stage_num == 4: diff --git a/dygraph/ppdet/modeling/backbones/resnet.py b/dygraph/ppdet/modeling/backbones/resnet.py index a7976369b2508cd2fa89e23be5ddaadd535bdaad..93f0e69ed146fae98c9326ca79de70a781701e84 100755 --- a/dygraph/ppdet/modeling/backbones/resnet.py +++ b/dygraph/ppdet/modeling/backbones/resnet.py @@ -12,16 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import numpy as np -from paddle import ParamAttr +import math import paddle import paddle.nn as nn import paddle.nn.functional as F -from paddle.nn import Conv2D, BatchNorm -from paddle.nn import MaxPool2D - +from paddle import ParamAttr from ppdet.core.workspace import register, serializable - from paddle.regularizer import L2Decay from .name_adapter import NameAdapter from numbers import Integral @@ -29,6 +25,14 @@ from ppdet.modeling.layers import DeformableConvV2 __all__ = ['ResNet', 'Res5Head'] +ResNet_cfg = { + 18: [2, 2, 2, 2], + 34: [3, 4, 6, 3], + 50: [3, 4, 6, 3], + 101: [3, 4, 23, 3], + 152: [3, 8, 36, 3], +} + class ConvNormLayer(nn.Layer): def __init__(self, @@ -37,6 +41,7 @@ class ConvNormLayer(nn.Layer): filter_size, stride, name_adapter, + groups=1, act=None, norm_type='bn', norm_decay=0., @@ -50,13 +55,13 @@ class ConvNormLayer(nn.Layer): self.act = act if not dcn_v2: - self.conv = Conv2D( + self.conv = nn.Conv2D( in_channels=ch_in, out_channels=ch_out, kernel_size=filter_size, stride=stride, padding=(filter_size - 1) // 2, - groups=1, + groups=groups, weight_attr=ParamAttr( learning_rate=lr, name=name + "_weights"), bias_attr=False) @@ -67,7 +72,7 @@ class ConvNormLayer(nn.Layer): kernel_size=filter_size, stride=stride, padding=(filter_size - 1) // 2, - groups=1, + groups=groups, weight_attr=ParamAttr( learning_rate=lr, name=name + '_weights'), bias_attr=False, @@ -87,14 +92,18 @@ class ConvNormLayer(nn.Layer): trainable=False if freeze_norm else True) global_stats = True if freeze_norm else False - self.norm = BatchNorm( - ch_out, - act=act, - param_attr=param_attr, - bias_attr=bias_attr, - use_global_stats=global_stats, - moving_mean_name=bn_name + '_mean', - moving_variance_name=bn_name + '_variance') + if norm_type == 'sync_bn': + self.norm = nn.SyncBatchNorm( + ch_out, weight_attr=param_attr, bias_attr=bias_attr) + else: + self.norm = nn.BatchNorm( + ch_out, + act=None, + param_attr=param_attr, + bias_attr=bias_attr, + use_global_stats=global_stats, + moving_mean_name=bn_name + '_mean', + moving_variance_name=bn_name + '_variance') norm_params = self.norm.parameters() if freeze_norm: @@ -103,8 +112,104 @@ class ConvNormLayer(nn.Layer): def forward(self, inputs): out = self.conv(inputs) - if self.norm_type == 'bn': + if self.norm_type in ['bn', 'sync_bn']: out = self.norm(out) + if self.act: + out = getattr(F, self.act)(out) + return out + + +class BasicBlock(nn.Layer): + def __init__(self, + ch_in, + ch_out, + stride, + shortcut, + name_adapter, + name, + variant='b', + lr=1.0, + norm_type='bn', + norm_decay=0., + freeze_norm=True, + dcn_v2=False): + super(BasicBlock, self).__init__() + assert dcn_v2 is False, "Not implemented yet." + conv_name1, conv_name2, shortcut_name = name_adapter.fix_basicblock_name( + name) + + self.shortcut = shortcut + if not shortcut: + if variant == 'd' and stride == 2: + self.short = nn.Sequential() + self.short.add_sublayer( + 'pool', + nn.AvgPool2D( + kernel_size=2, stride=2, padding=0, ceil_mode=True)) + self.short.add_sublayer( + 'conv', + ConvNormLayer( + ch_in=ch_in, + ch_out=ch_out, + filter_size=1, + stride=1, + name_adapter=name_adapter, + norm_type=norm_type, + norm_decay=norm_decay, + freeze_norm=freeze_norm, + lr=lr, + name=shortcut_name)) + else: + self.short = ConvNormLayer( + ch_in=ch_in, + ch_out=ch_out, + filter_size=1, + stride=stride, + name_adapter=name_adapter, + norm_type=norm_type, + norm_decay=norm_decay, + freeze_norm=freeze_norm, + lr=lr, + name=shortcut_name) + + self.branch2a = ConvNormLayer( + ch_in=ch_in, + ch_out=ch_out, + filter_size=3, + stride=stride, + name_adapter=name_adapter, + act='relu', + norm_type=norm_type, + norm_decay=norm_decay, + freeze_norm=freeze_norm, + lr=lr, + name=conv_name1) + + self.branch2b = ConvNormLayer( + ch_in=ch_out, + ch_out=ch_out, + filter_size=3, + stride=1, + name_adapter=name_adapter, + act=None, + norm_type=norm_type, + norm_decay=norm_decay, + freeze_norm=freeze_norm, + lr=lr, + name=conv_name2) + + def forward(self, inputs): + out = self.branch2a(inputs) + out = self.branch2b(out) + + if self.shortcut: + short = inputs + else: + short = self.short(inputs) + + out = paddle.add(x=out, y=short) + out = F.relu(out) + return out @@ -117,6 +222,9 @@ class BottleNeck(nn.Layer): name_adapter, name, variant='b', + groups=1, + base_width=4, + base_channels=64, lr=1.0, norm_type='bn', norm_decay=0., @@ -128,29 +236,58 @@ class BottleNeck(nn.Layer): else: stride1, stride2 = 1, stride + # ResNeXt + if groups == 1: + width = ch_out + else: + width = int( + math.floor(ch_out * (base_width * 1.0 / base_channels)) * + groups) + conv_name1, conv_name2, conv_name3, \ shortcut_name = name_adapter.fix_bottleneck_name(name) self.shortcut = shortcut if not shortcut: - self.short = ConvNormLayer( - ch_in=ch_in, - ch_out=ch_out * 4, - filter_size=1, - stride=stride, - name_adapter=name_adapter, - norm_type=norm_type, - norm_decay=norm_decay, - freeze_norm=freeze_norm, - lr=lr, - name=shortcut_name) + if variant == 'd' and stride == 2: + self.short = nn.Sequential() + self.short.add_sublayer( + 'pool', + nn.AvgPool2D( + kernel_size=2, stride=2, padding=0, ceil_mode=True)) + self.short.add_sublayer( + 'conv', + ConvNormLayer( + ch_in=ch_in, + ch_out=ch_out * 4, + filter_size=1, + stride=1, + name_adapter=name_adapter, + norm_type=norm_type, + norm_decay=norm_decay, + freeze_norm=freeze_norm, + lr=lr, + name=shortcut_name)) + else: + self.short = ConvNormLayer( + ch_in=ch_in, + ch_out=ch_out * 4, + filter_size=1, + stride=stride, + name_adapter=name_adapter, + norm_type=norm_type, + norm_decay=norm_decay, + freeze_norm=freeze_norm, + lr=lr, + name=shortcut_name) self.branch2a = ConvNormLayer( ch_in=ch_in, - ch_out=ch_out, + ch_out=width, filter_size=1, stride=stride1, name_adapter=name_adapter, + groups=1, act='relu', norm_type=norm_type, norm_decay=norm_decay, @@ -159,11 +296,12 @@ class BottleNeck(nn.Layer): name=conv_name1) self.branch2b = ConvNormLayer( - ch_in=ch_out, - ch_out=ch_out, + ch_in=width, + ch_out=width, filter_size=3, stride=stride2, name_adapter=name_adapter, + groups=groups, act='relu', norm_type=norm_type, norm_decay=norm_decay, @@ -173,11 +311,12 @@ class BottleNeck(nn.Layer): name=conv_name2) self.branch2c = ConvNormLayer( - ch_in=ch_out, + ch_in=width, ch_out=ch_out * 4, filter_size=1, stride=1, name_adapter=name_adapter, + groups=1, norm_type=norm_type, norm_decay=norm_decay, freeze_norm=freeze_norm, @@ -202,11 +341,16 @@ class BottleNeck(nn.Layer): class Blocks(nn.Layer): def __init__(self, + depth, ch_in, ch_out, count, name_adapter, stage_num, + variant='b', + groups=1, + base_width=-1, + base_channels=-1, lr=1.0, norm_type='bn', norm_decay=0., @@ -217,22 +361,42 @@ class Blocks(nn.Layer): self.blocks = [] for i in range(count): conv_name = name_adapter.fix_layer_warp_name(stage_num, count, i) - - block = self.add_sublayer( - conv_name, - BottleNeck( - ch_in=ch_in if i == 0 else ch_out * 4, - ch_out=ch_out, - stride=2 if i == 0 and stage_num != 2 else 1, - shortcut=False if i == 0 else True, - name_adapter=name_adapter, - name=conv_name, - variant=name_adapter.variant, - lr=lr, - norm_type=norm_type, - norm_decay=norm_decay, - freeze_norm=freeze_norm, - dcn_v2=dcn_v2)) + if depth >= 50: + block = self.add_sublayer( + conv_name, + BottleNeck( + ch_in=ch_in if i == 0 else ch_out * 4, + ch_out=ch_out, + stride=2 if i == 0 and stage_num != 2 else 1, + shortcut=False if i == 0 else True, + name_adapter=name_adapter, + name=conv_name, + variant=variant, + groups=groups, + base_width=base_width, + base_channels=base_channels, + lr=lr, + norm_type=norm_type, + norm_decay=norm_decay, + freeze_norm=freeze_norm, + dcn_v2=dcn_v2)) + else: + ch_in = ch_in // 4 if i > 0 else ch_in + block = self.add_sublayer( + conv_name, + BasicBlock( + ch_in=ch_in if i == 0 else ch_out, + ch_out=ch_out, + stride=2 if i == 0 and stage_num != 2 else 1, + shortcut=False if i == 0 else True, + name_adapter=name_adapter, + name=conv_name, + variant=variant, + lr=lr, + norm_type=norm_type, + norm_decay=norm_decay, + freeze_norm=freeze_norm, + dcn_v2=dcn_v2)) self.blocks.append(block) def forward(self, inputs): @@ -242,16 +406,18 @@ class Blocks(nn.Layer): return block_out -ResNet_cfg = {50: [3, 4, 6, 3], 101: [3, 4, 23, 3], 152: [3, 8, 36, 3]} - - @register @serializable class ResNet(nn.Layer): + __shared__ = ['norm_type'] + def __init__(self, depth=50, variant='b', - lr_mult=1., + lr_mult_list=[1.0, 1.0, 1.0, 1.0], + groups=1, + base_width=-1, + base_channels=-1, norm_type='bn', norm_decay=0, freeze_norm=True, @@ -260,6 +426,8 @@ class ResNet(nn.Layer): dcn_v2_stages=[-1], num_stages=4): super(ResNet, self).__init__() + self._model_type = 'ResNet' if groups == 1 else 'ResNeXt' + assert num_stages >= 1 and num_stages <= 4 self.depth = depth self.variant = variant self.norm_type = norm_type @@ -274,6 +442,11 @@ class ResNet(nn.Layer): 'is {}'.format(max(return_idx), num_stages) self.return_idx = return_idx self.num_stages = num_stages + assert len(lr_mult_list) == 4, \ + "lr_mult_list length must be 4 but got {}".format(len(lr_mult_list)) + if isinstance(dcn_v2_stages, Integral): + dcn_v2_stages = [dcn_v2_stages] + assert max(dcn_v2_stages) < num_stages if isinstance(dcn_v2_stages, Integral): dcn_v2_stages = [dcn_v2_stages] @@ -302,30 +475,38 @@ class ResNet(nn.Layer): filter_size=k, stride=s, name_adapter=na, + groups=1, act='relu', norm_type=norm_type, norm_decay=norm_decay, freeze_norm=freeze_norm, - lr=lr_mult, + lr=1.0, name=_name)) - self.pool = MaxPool2D(kernel_size=3, stride=2, padding=1) + self.pool = nn.MaxPool2D(kernel_size=3, stride=2, padding=1) ch_in_list = [64, 256, 512, 1024] ch_out_list = [64, 128, 256, 512] self.res_layers = [] for i in range(num_stages): + lr_mult = lr_mult_list[i] stage_num = i + 2 res_name = "res{}".format(stage_num) res_layer = self.add_sublayer( res_name, Blocks( - ch_in_list[i], + depth, + ch_in_list[i] // 4 + if i > 0 and depth < 50 else ch_in_list[i], ch_out_list[i], count=block_nums[i], name_adapter=na, stage_num=stage_num, + variant=variant, + groups=groups, + base_width=base_width, + base_channels=base_channels, lr=lr_mult, norm_type=norm_type, norm_decay=norm_decay,