提交 2953d108 编写于 作者: Y Yang Zhang 提交者: GitHub

Provide a way to avoid duplicated config keys, e.g., `num_classes` (#2764)

* Clean up a bit

* Add `__shared__` annotation for shared variables between modules

* Dedup `num_classes` configurations

* Document `__shared__` usage

* Remove some unused variable

* Improve docstring and add comments for `__shared__`
上级 a653012d
...@@ -10,6 +10,7 @@ save_dir: output ...@@ -10,6 +10,7 @@ save_dir: output
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar
weights: output/cascade_rcnn_r50_fpn_1x/model_final weights: output/cascade_rcnn_r50_fpn_1x/model_final
metric: COCO metric: COCO
num_classes: 81
CascadeRCNN: CascadeRCNN:
backbone: ResNet backbone: ResNet
...@@ -74,7 +75,6 @@ CascadeBBoxAssigner: ...@@ -74,7 +75,6 @@ CascadeBBoxAssigner:
bg_thresh_hi: [0.5, 0.6, 0.7] bg_thresh_hi: [0.5, 0.6, 0.7]
fg_thresh: [0.5, 0.6, 0.7] fg_thresh: [0.5, 0.6, 0.7]
fg_fraction: 0.25 fg_fraction: 0.25
num_classes: 81
CascadeBBoxHead: CascadeBBoxHead:
head: FC6FC7Head head: FC6FC7Head
...@@ -82,7 +82,6 @@ CascadeBBoxHead: ...@@ -82,7 +82,6 @@ CascadeBBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
FC6FC7Head: FC6FC7Head:
num_chan: 1024 num_chan: 1024
......
...@@ -10,6 +10,7 @@ snapshot_iter: 10000 ...@@ -10,6 +10,7 @@ snapshot_iter: 10000
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_pretrained.tar
metric: COCO metric: COCO
weights: output/faster_rcnn_r101_1x/model_final weights: output/faster_rcnn_r101_1x/model_final
num_classes: 81
FasterRCNN: FasterRCNN:
backbone: ResNet backbone: ResNet
...@@ -64,7 +65,6 @@ BBoxAssigner: ...@@ -64,7 +65,6 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
BBoxHead: BBoxHead:
head: ResNetC5 head: ResNetC5
...@@ -72,7 +72,6 @@ BBoxHead: ...@@ -72,7 +72,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
LearningRate: LearningRate:
base_lr: 0.01 base_lr: 0.01
......
...@@ -10,6 +10,7 @@ save_dir: output ...@@ -10,6 +10,7 @@ save_dir: output
pretrain_weights: http://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_pretrained.tar pretrain_weights: http://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_pretrained.tar
weights: output/faster_rcnn_r101_fpn_1x/model_final weights: output/faster_rcnn_r101_fpn_1x/model_final
metric: COCO metric: COCO
num_classes: 81
FasterRCNN: FasterRCNN:
backbone: ResNet backbone: ResNet
...@@ -73,7 +74,6 @@ BBoxAssigner: ...@@ -73,7 +74,6 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
BBoxHead: BBoxHead:
head: TwoFCHead head: TwoFCHead
...@@ -81,7 +81,6 @@ BBoxHead: ...@@ -81,7 +81,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
TwoFCHead: TwoFCHead:
num_chan: 1024 num_chan: 1024
......
...@@ -10,6 +10,7 @@ save_dir: output ...@@ -10,6 +10,7 @@ save_dir: output
pretrain_weights: http://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_pretrained.tar pretrain_weights: http://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_pretrained.tar
weights: output/faster_rcnn_r101_fpn_2x/model_final weights: output/faster_rcnn_r101_fpn_2x/model_final
metric: COCO metric: COCO
num_classes: 81
FasterRCNN: FasterRCNN:
backbone: ResNet backbone: ResNet
...@@ -73,7 +74,6 @@ BBoxAssigner: ...@@ -73,7 +74,6 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
BBoxHead: BBoxHead:
head: TwoFCHead head: TwoFCHead
...@@ -81,7 +81,6 @@ BBoxHead: ...@@ -81,7 +81,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
TwoFCHead: TwoFCHead:
num_chan: 1024 num_chan: 1024
......
...@@ -10,6 +10,7 @@ save_dir: output ...@@ -10,6 +10,7 @@ save_dir: output
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_vd_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_vd_pretrained.tar
weights: output/faster_rcnn_r101_vd_fpn_1x/model_final weights: output/faster_rcnn_r101_vd_fpn_1x/model_final
metric: COCO metric: COCO
num_classes: 81
FasterRCNN: FasterRCNN:
backbone: ResNet backbone: ResNet
...@@ -74,7 +75,6 @@ BBoxAssigner: ...@@ -74,7 +75,6 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
BBoxHead: BBoxHead:
head: TwoFCHead head: TwoFCHead
...@@ -82,7 +82,6 @@ BBoxHead: ...@@ -82,7 +82,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
TwoFCHead: TwoFCHead:
num_chan: 1024 num_chan: 1024
......
...@@ -10,6 +10,7 @@ save_dir: output ...@@ -10,6 +10,7 @@ save_dir: output
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_vd_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_vd_pretrained.tar
weights: output/faster_rcnn_r101_vd_fpn_2x/model_final weights: output/faster_rcnn_r101_vd_fpn_2x/model_final
metric: COCO metric: COCO
num_classes: 81
FasterRCNN: FasterRCNN:
backbone: ResNet backbone: ResNet
...@@ -74,7 +75,6 @@ BBoxAssigner: ...@@ -74,7 +75,6 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
BBoxHead: BBoxHead:
head: TwoFCHead head: TwoFCHead
...@@ -82,7 +82,6 @@ BBoxHead: ...@@ -82,7 +82,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
TwoFCHead: TwoFCHead:
num_chan: 1024 num_chan: 1024
......
...@@ -10,6 +10,7 @@ snapshot_iter: 10000 ...@@ -10,6 +10,7 @@ snapshot_iter: 10000
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar
metric: COCO metric: COCO
weights: output/faster_rcnn_r50_1x/model_final weights: output/faster_rcnn_r50_1x/model_final
num_classes: 81
FasterRCNN: FasterRCNN:
backbone: ResNet backbone: ResNet
...@@ -64,7 +65,6 @@ BBoxAssigner: ...@@ -64,7 +65,6 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
BBoxHead: BBoxHead:
head: ResNetC5 head: ResNetC5
...@@ -72,7 +72,6 @@ BBoxHead: ...@@ -72,7 +72,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
LearningRate: LearningRate:
base_lr: 0.01 base_lr: 0.01
......
...@@ -10,6 +10,7 @@ snapshot_iter: 10000 ...@@ -10,6 +10,7 @@ snapshot_iter: 10000
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar
metric: COCO metric: COCO
weights: output/faster_rcnn_r50_2x/model_final weights: output/faster_rcnn_r50_2x/model_final
num_classes: 81
FasterRCNN: FasterRCNN:
backbone: ResNet backbone: ResNet
...@@ -64,7 +65,6 @@ BBoxAssigner: ...@@ -64,7 +65,6 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
BBoxHead: BBoxHead:
head: ResNetC5 head: ResNetC5
...@@ -72,7 +72,6 @@ BBoxHead: ...@@ -72,7 +72,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
LearningRate: LearningRate:
base_lr: 0.01 base_lr: 0.01
......
...@@ -10,6 +10,7 @@ save_dir: output ...@@ -10,6 +10,7 @@ save_dir: output
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar
metric: COCO metric: COCO
weights: output/fpn/faster_rcnn_r50_fpn_1x/model_final weights: output/fpn/faster_rcnn_r50_fpn_1x/model_final
num_classes: 81
FasterRCNN: FasterRCNN:
backbone: ResNet backbone: ResNet
...@@ -74,7 +75,6 @@ BBoxAssigner: ...@@ -74,7 +75,6 @@ BBoxAssigner:
bg_thresh_hi: 0.5 bg_thresh_hi: 0.5
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
BBoxHead: BBoxHead:
head: TwoFCHead head: TwoFCHead
...@@ -82,7 +82,6 @@ BBoxHead: ...@@ -82,7 +82,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
TwoFCHead: TwoFCHead:
num_chan: 1024 num_chan: 1024
......
...@@ -10,6 +10,7 @@ save_dir: output ...@@ -10,6 +10,7 @@ save_dir: output
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar
metric: COCO metric: COCO
weights: output/faster_rcnn_r50_fpn_2x/model_final weights: output/faster_rcnn_r50_fpn_2x/model_final
num_classes: 81
FasterRCNN: FasterRCNN:
backbone: ResNet backbone: ResNet
...@@ -74,7 +75,6 @@ BBoxAssigner: ...@@ -74,7 +75,6 @@ BBoxAssigner:
bg_thresh_hi: 0.5 bg_thresh_hi: 0.5
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
BBoxHead: BBoxHead:
head: TwoFCHead head: TwoFCHead
...@@ -82,7 +82,6 @@ BBoxHead: ...@@ -82,7 +82,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
TwoFCHead: TwoFCHead:
num_chan: 1024 num_chan: 1024
......
...@@ -10,6 +10,7 @@ snapshot_iter: 10000 ...@@ -10,6 +10,7 @@ snapshot_iter: 10000
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_vd_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_vd_pretrained.tar
metric: COCO metric: COCO
weights: output/faster_rcnn_r50_vd_1x/model_final weights: output/faster_rcnn_r50_vd_1x/model_final
num_classes: 81
FasterRCNN: FasterRCNN:
backbone: ResNet backbone: ResNet
...@@ -66,7 +67,6 @@ BBoxAssigner: ...@@ -66,7 +67,6 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
BBoxHead: BBoxHead:
head: ResNetC5 head: ResNetC5
...@@ -74,7 +74,6 @@ BBoxHead: ...@@ -74,7 +74,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
LearningRate: LearningRate:
base_lr: 0.01 base_lr: 0.01
......
...@@ -10,6 +10,7 @@ save_dir: output ...@@ -10,6 +10,7 @@ save_dir: output
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_vd_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_vd_pretrained.tar
weights: output/faster_rcnn_r50_vd_fpn_2x/model_final weights: output/faster_rcnn_r50_vd_fpn_2x/model_final
metric: COCO metric: COCO
num_classes: 81
FasterRCNN: FasterRCNN:
backbone: ResNet backbone: ResNet
...@@ -74,7 +75,6 @@ BBoxAssigner: ...@@ -74,7 +75,6 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
BBoxHead: BBoxHead:
head: TwoFCHead head: TwoFCHead
...@@ -82,7 +82,6 @@ BBoxHead: ...@@ -82,7 +82,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
TwoFCHead: TwoFCHead:
num_chan: 1024 num_chan: 1024
......
...@@ -10,6 +10,7 @@ save_dir: output ...@@ -10,6 +10,7 @@ save_dir: output
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/SE154_vd_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/SE154_vd_pretrained.tar
weights: output/faster_rcnn_se154_vd_fpn_s1x/model_final weights: output/faster_rcnn_se154_vd_fpn_s1x/model_final
metric: COCO metric: COCO
num_classes: 81
FasterRCNN: FasterRCNN:
backbone: SENet backbone: SENet
...@@ -76,7 +77,6 @@ BBoxAssigner: ...@@ -76,7 +77,6 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
BBoxHead: BBoxHead:
head: TwoFCHead head: TwoFCHead
...@@ -84,7 +84,6 @@ BBoxHead: ...@@ -84,7 +84,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
TwoFCHead: TwoFCHead:
num_chan: 1024 num_chan: 1024
......
...@@ -10,6 +10,7 @@ save_dir: output ...@@ -10,6 +10,7 @@ save_dir: output
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNeXt101_vd_64x4d_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNeXt101_vd_64x4d_pretrained.tar
weights: output/faster_rcnn_x101_vd_64x4d_fpn_1x/model_final weights: output/faster_rcnn_x101_vd_64x4d_fpn_1x/model_final
metric: COCO metric: COCO
num_classes: 81
FasterRCNN: FasterRCNN:
backbone: ResNeXt backbone: ResNeXt
...@@ -76,7 +77,6 @@ BBoxAssigner: ...@@ -76,7 +77,6 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
BBoxHead: BBoxHead:
head: TwoFCHead head: TwoFCHead
...@@ -84,7 +84,6 @@ BBoxHead: ...@@ -84,7 +84,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
TwoFCHead: TwoFCHead:
num_chan: 1024 num_chan: 1024
......
...@@ -10,6 +10,7 @@ save_dir: output ...@@ -10,6 +10,7 @@ save_dir: output
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet101_pretrained.tar
metric: COCO metric: COCO
weights: output/mask_rcnn_r101_fpn_1x/model_final/ weights: output/mask_rcnn_r101_fpn_1x/model_final/
num_classes: 81
MaskRCNN: MaskRCNN:
backbone: ResNet backbone: ResNet
...@@ -68,7 +69,6 @@ FPNRoIAlign: ...@@ -68,7 +69,6 @@ FPNRoIAlign:
MaskHead: MaskHead:
dilation: 1 dilation: 1
num_chan_reduced: 256 num_chan_reduced: 256
num_classes: 81
num_convs: 4 num_convs: 4
resolution: 28 resolution: 28
...@@ -79,7 +79,6 @@ BBoxAssigner: ...@@ -79,7 +79,6 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
MaskAssigner: MaskAssigner:
resolution: 28 resolution: 28
...@@ -90,7 +89,6 @@ BBoxHead: ...@@ -90,7 +89,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
TwoFCHead: TwoFCHead:
num_chan: 1024 num_chan: 1024
......
...@@ -10,6 +10,7 @@ save_dir: output ...@@ -10,6 +10,7 @@ save_dir: output
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar
metric: COCO metric: COCO
weights: output/mask_rcnn_r50_1x/model_final weights: output/mask_rcnn_r50_1x/model_final
num_classes: 81
MaskRCNN: MaskRCNN:
backbone: ResNet backbone: ResNet
...@@ -66,12 +67,10 @@ BBoxHead: ...@@ -66,12 +67,10 @@ BBoxHead:
nms_threshold: 0.5 nms_threshold: 0.5
normalized: false normalized: false
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
MaskHead: MaskHead:
dilation: 1 dilation: 1
num_chan_reduced: 256 num_chan_reduced: 256
num_classes: 81
resolution: 14 resolution: 14
BBoxAssigner: BBoxAssigner:
...@@ -81,10 +80,8 @@ BBoxAssigner: ...@@ -81,10 +80,8 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
MaskAssigner: MaskAssigner:
num_classes: 81
resolution: 14 resolution: 14
LearningRate: LearningRate:
......
...@@ -10,6 +10,7 @@ save_dir: output ...@@ -10,6 +10,7 @@ save_dir: output
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar
metric: COCO metric: COCO
weights: output/mask_rcnn_r50_2x/model_final/ weights: output/mask_rcnn_r50_2x/model_final/
num_classes: 81
MaskRCNN: MaskRCNN:
backbone: ResNet backbone: ResNet
...@@ -67,12 +68,10 @@ BBoxHead: ...@@ -67,12 +68,10 @@ BBoxHead:
nms_threshold: 0.5 nms_threshold: 0.5
normalized: false normalized: false
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
MaskHead: MaskHead:
dilation: 1 dilation: 1
num_chan_reduced: 256 num_chan_reduced: 256
num_classes: 81
resolution: 14 resolution: 14
BBoxAssigner: BBoxAssigner:
...@@ -82,10 +81,8 @@ BBoxAssigner: ...@@ -82,10 +81,8 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
MaskAssigner: MaskAssigner:
num_classes: 81
resolution: 14 resolution: 14
LearningRate: LearningRate:
......
...@@ -10,6 +10,7 @@ save_dir: output ...@@ -10,6 +10,7 @@ save_dir: output
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar
metric: COCO metric: COCO
weights: output/mask_rcnn_r50_fpn_1x/model_final/ weights: output/mask_rcnn_r50_fpn_1x/model_final/
num_classes: 81
MaskRCNN: MaskRCNN:
backbone: ResNet backbone: ResNet
...@@ -68,7 +69,6 @@ FPNRoIAlign: ...@@ -68,7 +69,6 @@ FPNRoIAlign:
MaskHead: MaskHead:
dilation: 1 dilation: 1
num_chan_reduced: 256 num_chan_reduced: 256
num_classes: 81
num_convs: 4 num_convs: 4
resolution: 28 resolution: 28
...@@ -79,7 +79,6 @@ BBoxAssigner: ...@@ -79,7 +79,6 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
MaskAssigner: MaskAssigner:
resolution: 28 resolution: 28
...@@ -90,7 +89,6 @@ BBoxHead: ...@@ -90,7 +89,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
TwoFCHead: TwoFCHead:
num_chan: 1024 num_chan: 1024
......
...@@ -10,6 +10,7 @@ save_dir: output ...@@ -10,6 +10,7 @@ save_dir: output
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_cos_pretrained.tar
weights: output/mask_rcnn_r50_fpn_2x/model_final/ weights: output/mask_rcnn_r50_fpn_2x/model_final/
metric: COCO metric: COCO
num_classes: 81
MaskRCNN: MaskRCNN:
backbone: ResNet backbone: ResNet
...@@ -68,7 +69,6 @@ FPNRoIAlign: ...@@ -68,7 +69,6 @@ FPNRoIAlign:
MaskHead: MaskHead:
dilation: 1 dilation: 1
num_chan_reduced: 256 num_chan_reduced: 256
num_classes: 81
num_convs: 4 num_convs: 4
resolution: 28 resolution: 28
...@@ -79,7 +79,6 @@ BBoxAssigner: ...@@ -79,7 +79,6 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
MaskAssigner: MaskAssigner:
resolution: 28 resolution: 28
...@@ -90,7 +89,6 @@ BBoxHead: ...@@ -90,7 +89,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
TwoFCHead: TwoFCHead:
num_chan: 1024 num_chan: 1024
...@@ -116,7 +114,7 @@ OptimizerBuilder: ...@@ -116,7 +114,7 @@ OptimizerBuilder:
MaskRCNNTrainFeed: MaskRCNNTrainFeed:
batch_size: 1 batch_size: 1
dataset: dataset:
dataset_dir: dataset/coco dataset_dir: dataset/coco
annotation: annotations/instances_train2017.json annotation: annotations/instances_train2017.json
image_dir: train2017 image_dir: train2017
batch_transforms: batch_transforms:
...@@ -127,7 +125,7 @@ MaskRCNNTrainFeed: ...@@ -127,7 +125,7 @@ MaskRCNNTrainFeed:
MaskRCNNEvalFeed: MaskRCNNEvalFeed:
batch_size: 1 batch_size: 1
dataset: dataset:
dataset_dir: dataset/coco dataset_dir: dataset/coco
annotation: annotations/instances_val2017.json annotation: annotations/instances_val2017.json
image_dir: val2017 image_dir: val2017
batch_transforms: batch_transforms:
......
...@@ -10,6 +10,7 @@ save_dir: output ...@@ -10,6 +10,7 @@ save_dir: output
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_vd_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/ResNet50_vd_pretrained.tar
metric: COCO metric: COCO
weights: output/mask_rcnn_r50_vd_fpn_2x/model_final/ weights: output/mask_rcnn_r50_vd_fpn_2x/model_final/
num_classes: 81
MaskRCNN: MaskRCNN:
backbone: ResNet backbone: ResNet
...@@ -69,7 +70,6 @@ FPNRoIAlign: ...@@ -69,7 +70,6 @@ FPNRoIAlign:
MaskHead: MaskHead:
dilation: 1 dilation: 1
num_chan_reduced: 256 num_chan_reduced: 256
num_classes: 81
num_convs: 4 num_convs: 4
resolution: 28 resolution: 28
...@@ -80,7 +80,6 @@ BBoxAssigner: ...@@ -80,7 +80,6 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
MaskAssigner: MaskAssigner:
resolution: 28 resolution: 28
...@@ -91,7 +90,6 @@ BBoxHead: ...@@ -91,7 +90,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
TwoFCHead: TwoFCHead:
num_chan: 1024 num_chan: 1024
......
...@@ -10,6 +10,7 @@ save_dir: output ...@@ -10,6 +10,7 @@ save_dir: output
pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/SE154_vd_pretrained.tar pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/SE154_vd_pretrained.tar
weights: output/mask_rcnn_se154_vd_fpn_s1x/model_final/ weights: output/mask_rcnn_se154_vd_fpn_s1x/model_final/
metric: COCO metric: COCO
num_classes: 81
MaskRCNN: MaskRCNN:
backbone: SENet backbone: SENet
...@@ -71,7 +72,6 @@ FPNRoIAlign: ...@@ -71,7 +72,6 @@ FPNRoIAlign:
MaskHead: MaskHead:
dilation: 1 dilation: 1
num_chan_reduced: 256 num_chan_reduced: 256
num_classes: 81
num_convs: 4 num_convs: 4
resolution: 28 resolution: 28
...@@ -82,7 +82,6 @@ BBoxAssigner: ...@@ -82,7 +82,6 @@ BBoxAssigner:
bg_thresh_lo: 0.0 bg_thresh_lo: 0.0
fg_fraction: 0.25 fg_fraction: 0.25
fg_thresh: 0.5 fg_thresh: 0.5
num_classes: 81
MaskAssigner: MaskAssigner:
resolution: 28 resolution: 28
...@@ -93,7 +92,6 @@ BBoxHead: ...@@ -93,7 +92,6 @@ BBoxHead:
keep_top_k: 100 keep_top_k: 100
nms_threshold: 0.5 nms_threshold: 0.5
score_threshold: 0.05 score_threshold: 0.05
num_classes: 81
TwoFCHead: TwoFCHead:
num_chan: 1024 num_chan: 1024
...@@ -120,7 +118,7 @@ MaskRCNNTrainFeed: ...@@ -120,7 +118,7 @@ MaskRCNNTrainFeed:
# batch size per device # batch size per device
batch_size: 1 batch_size: 1
dataset: dataset:
dataset_dir: dataset/coco dataset_dir: dataset/coco
image_dir: train2017 image_dir: train2017
annotation: annotations/instances_train2017.json annotation: annotations/instances_train2017.json
batch_transforms: batch_transforms:
......
...@@ -188,3 +188,14 @@ A small utility (`tools/configure.py`) is included to simplify the configuration ...@@ -188,3 +188,14 @@ A small utility (`tools/configure.py`) is included to simplify the configuration
```shell ```shell
python tools/configure.py --minimal generate FasterRCNN BBoxHead python tools/configure.py --minimal generate FasterRCNN BBoxHead
``` ```
# FAQ
**Q:** There are some configuration options that are used by multiple modules (e.g., `num_classes`), how do I avoid duplication in config files?
**A:** We provided a `__shared__` annotation for exactly this purpose, simply annotate like this `__shared__ = ['num_classes']`. It works as follows:
1. if `num_classes` is configured for a module in config file, it takes precedence.
2. if `num_classes` is not configured for a module but is present in the config file as a global key, its value will be used.
3. otherwise, the default value (`81`) will be used.
...@@ -180,3 +180,14 @@ pip install typeguard http://github.com/willthefrog/docstring_parser/tarball/mas ...@@ -180,3 +180,14 @@ pip install typeguard http://github.com/willthefrog/docstring_parser/tarball/mas
```shell ```shell
python tools/configure.py --minimal generate FasterRCNN BBoxHead python tools/configure.py --minimal generate FasterRCNN BBoxHead
``` ```
# FAQ
**Q:** 某些配置项会在多个模块中用到(如 `num_classes`),如何避免在配置文件中多次重复设置?
**A:** 框架提供了 `__shared__` 标记来实现配置的共享,用户可以标记参数,如 `__shared__ = ['num_classes']` ,配置数值作用规则如下:
1. 如果模块配置中提供了 `num_classes` ,会优先使用其数值。
2. 如果模块配置中未提供 `num_classes` ,但配置文件中存在全局键值,那么会使用全局键值。
3. 两者均为配置的情况下,将使用默认值(`81`)。
...@@ -43,13 +43,14 @@ except Exception: ...@@ -43,13 +43,14 @@ except Exception:
if not check_type.__warning_sent__: if not check_type.__warning_sent__:
from ppdet.utils.cli import ColorTTY from ppdet.utils.cli import ColorTTY
color_tty = ColorTTY() color_tty = ColorTTY()
message = "typeguard is not installed, type checking is not available" message = "typeguard is not installed," \
+ "type checking is not available"
print(color_tty.yellow(message)) print(color_tty.yellow(message))
check_type.__warning_sent__ = True check_type.__warning_sent__ = True
check_type.__warning_sent__ = False check_type.__warning_sent__ = False
__all__ = ['SchemaValue', 'SchemaDict', 'extract_schema'] __all__ = ['SchemaValue', 'SchemaDict', 'SharedConfig', 'extract_schema']
class SchemaValue(object): class SchemaValue(object):
...@@ -160,6 +161,27 @@ class SchemaDict(dict): ...@@ -160,6 +161,27 @@ class SchemaDict(dict):
self.name, ", ".join(mismatch_keys))) self.name, ", ".join(mismatch_keys)))
class SharedConfig(object):
"""
Representation class for `__shared__` annotations, which work as follows:
- if `key` is set for the module in config file, its value will take
precedence
- if `key` is not set for the module but present in the config file, its
value will be used
- otherwise, use the provided `default_value` as fallback
Args:
key: config[key] will be injected
default_value: fallback value
"""
def __init__(self, key, default_value=None):
super(SharedConfig, self).__init__()
self.key = key
self.default_value = default_value
def extract_schema(cls): def extract_schema(cls):
""" """
Extract schema from a given class Extract schema from a given class
...@@ -216,6 +238,7 @@ def extract_schema(cls): ...@@ -216,6 +238,7 @@ def extract_schema(cls):
schema.strict = not has_kwargs schema.strict = not has_kwargs
schema.pymodule = importlib.import_module(cls.__module__) schema.pymodule = importlib.import_module(cls.__module__)
schema.inject = getattr(cls, '__inject__', []) schema.inject = getattr(cls, '__inject__', [])
schema.shared = getattr(cls, '__shared__', [])
for idx, name in enumerate(names): for idx, name in enumerate(names):
comment = name in comments and comments[name] or name comment = name in comments and comments[name] or name
if name in schema.inject: if name in schema.inject:
...@@ -223,8 +246,13 @@ def extract_schema(cls): ...@@ -223,8 +246,13 @@ def extract_schema(cls):
else: else:
type_ = name in annotations and annotations[name] or None type_ = name in annotations and annotations[name] or None
value_schema = SchemaValue(name, comment, type_) value_schema = SchemaValue(name, comment, type_)
if idx >= num_required: if name in schema.shared:
value_schema.set_default(defaults[idx - num_required]) assert idx >= num_required, "shared config must have default value"
default = defaults[idx - num_required]
value_schema.set_default(SharedConfig(name, default))
elif idx >= num_required:
default = defaults[idx - num_required]
value_schema.set_default(default)
schema.set_schema(name, value_schema) schema.set_schema(name, value_schema)
return schema return schema
...@@ -16,6 +16,7 @@ import importlib ...@@ -16,6 +16,7 @@ import importlib
import inspect import inspect
import yaml import yaml
from .schema import SharedConfig
__all__ = ['serializable', 'Callable'] __all__ = ['serializable', 'Callable']
...@@ -59,7 +60,8 @@ def _make_python_representer(cls): ...@@ -59,7 +60,8 @@ def _make_python_representer(cls):
def serializable(cls): def serializable(cls):
""" """
Add loader and dumper for given class, which must be "trivially serializable" Add loader and dumper for given class, which must be
"trivially serializable"
Args: Args:
cls: class to be serialized cls: class to be serialized
...@@ -72,6 +74,10 @@ def serializable(cls): ...@@ -72,6 +74,10 @@ def serializable(cls):
return cls return cls
yaml.add_representer(SharedConfig,
lambda d, o: d.represent_data(o.default_value))
@serializable @serializable
class Callable(object): class Callable(object):
""" """
......
...@@ -23,7 +23,7 @@ import sys ...@@ -23,7 +23,7 @@ import sys
import yaml import yaml
import copy import copy
from .config.schema import SchemaDict, extract_schema from .config.schema import SchemaDict, SharedConfig, extract_schema
from .config.yaml_helpers import serializable from .config.yaml_helpers import serializable
__all__ = [ __all__ = [
...@@ -136,7 +136,8 @@ def create(cls_or_name, **kwargs): ...@@ -136,7 +136,8 @@ def create(cls_or_name, **kwargs):
assert type(cls_or_name) in [type, str assert type(cls_or_name) in [type, str
], "should be a class or name of a class" ], "should be a class or name of a class"
name = type(cls_or_name) == str and cls_or_name or cls_or_name.__name__ name = type(cls_or_name) == str and cls_or_name or cls_or_name.__name__
assert name in global_config and isinstance(global_config[name], SchemaDict), \ assert name in global_config and \
isinstance(global_config[name], SchemaDict), \
"the module {} is not registered".format(name) "the module {} is not registered".format(name)
config = global_config[name] config = global_config[name]
config.update(kwargs) config.update(kwargs)
...@@ -145,9 +146,26 @@ def create(cls_or_name, **kwargs): ...@@ -145,9 +146,26 @@ def create(cls_or_name, **kwargs):
kwargs = {} kwargs = {}
kwargs.update(global_config[name]) kwargs.update(global_config[name])
# parse `shared` annoation of registered modules
if getattr(config, 'shared', None):
for k in config.shared:
target_key = config[k]
shared_conf = config.schema[k].default
assert isinstance(shared_conf, SharedConfig)
if target_key is not None and not isinstance(
target_key, SharedConfig):
continue # value is given for the module
elif shared_conf.key in global_config:
# `key` is present in config
kwargs[k] = global_config[shared_conf.key]
else:
kwargs[k] = shared_conf.default_value
# parse `inject` annoation of registered modules
if getattr(config, 'inject', None): if getattr(config, 'inject', None):
for k in config.inject: for k in config.inject:
target_key = global_config[name][k] target_key = config[k]
# optional dependency # optional dependency
if target_key is None: if target_key is None:
continue continue
......
...@@ -181,7 +181,6 @@ class DataSet(object): ...@@ -181,7 +181,6 @@ class DataSet(object):
Args: Args:
annotation (str): annotation file path annotation (str): annotation file path
image_dir (str): directory where image files are stored image_dir (str): directory where image files are stored
num_classes (int): number of classes
shuffle (bool): shuffle samples shuffle (bool): shuffle samples
""" """
__source__ = 'RoiDbSource' __source__ = 'RoiDbSource'
......
...@@ -25,7 +25,7 @@ from paddle.fluid.regularizer import L2Decay ...@@ -25,7 +25,7 @@ from paddle.fluid.regularizer import L2Decay
from ppdet.modeling.ops import (AnchorGenerator, RetinaTargetAssign, from ppdet.modeling.ops import (AnchorGenerator, RetinaTargetAssign,
RetinaOutputDecoder) RetinaOutputDecoder)
from ppdet.core.workspace import register, serializable from ppdet.core.workspace import register
__all__ = ['RetinaHead'] __all__ = ['RetinaHead']
...@@ -52,6 +52,7 @@ class RetinaHead(object): ...@@ -52,6 +52,7 @@ class RetinaHead(object):
sigma (float): The parameter in smooth l1 loss sigma (float): The parameter in smooth l1 loss
""" """
__inject__ = ['anchor_generator', 'target_assign', 'output_decoder'] __inject__ = ['anchor_generator', 'target_assign', 'output_decoder']
__shared__ = ['num_classes']
def __init__(self, def __init__(self,
anchor_generator=AnchorGenerator().__dict__, anchor_generator=AnchorGenerator().__dict__,
...@@ -333,7 +334,6 @@ class RetinaHead(object): ...@@ -333,7 +334,6 @@ class RetinaHead(object):
cls_pred_reshape_list = output['cls_pred'] cls_pred_reshape_list = output['cls_pred']
bbox_pred_reshape_list = output['bbox_pred'] bbox_pred_reshape_list = output['bbox_pred']
anchor_reshape_list = output['anchor'] anchor_reshape_list = output['anchor']
anchor_var_reshape_list = output['anchor_var']
for i in range(self.max_level - self.min_level + 1): for i in range(self.max_level - self.min_level + 1):
cls_pred_reshape_list[i] = fluid.layers.sigmoid( cls_pred_reshape_list[i] = fluid.layers.sigmoid(
cls_pred_reshape_list[i]) cls_pred_reshape_list[i])
......
...@@ -88,6 +88,7 @@ class GenerateProposals(object): ...@@ -88,6 +88,7 @@ class GenerateProposals(object):
class MaskAssigner(object): class MaskAssigner(object):
__op__ = fluid.layers.generate_mask_labels __op__ = fluid.layers.generate_mask_labels
__append_doc__ = True __append_doc__ = True
__shared__ = ['num_classes']
def __init__(self, num_classes=81, resolution=14): def __init__(self, num_classes=81, resolution=14):
super(MaskAssigner, self).__init__() super(MaskAssigner, self).__init__()
...@@ -123,6 +124,7 @@ class MultiClassNMS(object): ...@@ -123,6 +124,7 @@ class MultiClassNMS(object):
class BBoxAssigner(object): class BBoxAssigner(object):
__op__ = fluid.layers.generate_proposal_labels __op__ = fluid.layers.generate_proposal_labels
__append_doc__ = True __append_doc__ = True
__shared__ = ['num_classes']
def __init__(self, def __init__(self,
batch_size_per_im=512, batch_size_per_im=512,
......
...@@ -92,12 +92,13 @@ class BBoxHead(object): ...@@ -92,12 +92,13 @@ class BBoxHead(object):
RCNN bbox head RCNN bbox head
Args: Args:
head (object): the head module instance, e.g., `ResNetC5` or `TwoFCHead` head (object): the head module instance, e.g., `ResNetC5`, `TwoFCHead`
box_coder (object): `BoxCoder` instance box_coder (object): `BoxCoder` instance
nms (object): `MultiClassNMS` instance nms (object): `MultiClassNMS` instance
num_classes: number of output classes num_classes: number of output classes
""" """
__inject__ = ['head', 'box_coder', 'nms'] __inject__ = ['head', 'box_coder', 'nms']
__shared__ = ['num_classes']
def __init__(self, def __init__(self,
head, head,
......
...@@ -37,6 +37,7 @@ class CascadeBBoxHead(object): ...@@ -37,6 +37,7 @@ class CascadeBBoxHead(object):
num_classes: number of output classes num_classes: number of output classes
""" """
__inject__ = ['head', 'nms'] __inject__ = ['head', 'nms']
__shared__ = ['num_classes']
def __init__(self, head, nms=MultiClassNMS().__dict__, num_classes=81): def __init__(self, head, nms=MultiClassNMS().__dict__, num_classes=81):
super(CascadeBBoxHead, self).__init__() super(CascadeBBoxHead, self).__init__()
......
...@@ -38,6 +38,8 @@ class MaskHead(object): ...@@ -38,6 +38,8 @@ class MaskHead(object):
num_classes (int): number of output classes num_classes (int): number of output classes
""" """
__shared__ = ['num_classes']
def __init__(self, def __init__(self,
num_convs=0, num_convs=0,
num_chan_reduced=256, num_chan_reduced=256,
......
...@@ -26,6 +26,8 @@ __all__ = ['BBoxAssigner', 'MaskAssigner', 'CascadeBBoxAssigner'] ...@@ -26,6 +26,8 @@ __all__ = ['BBoxAssigner', 'MaskAssigner', 'CascadeBBoxAssigner']
@register @register
class CascadeBBoxAssigner(object): class CascadeBBoxAssigner(object):
__shared__ = ['num_classes']
def __init__(self, def __init__(self,
batch_size_per_im=512, batch_size_per_im=512,
fg_fraction=.25, fg_fraction=.25,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册