diff --git a/configs/ppyoloe/_base_/optimizer_80e.yml b/configs/ppyoloe/_base_/optimizer_80e.yml new file mode 100644 index 0000000000000000000000000000000000000000..7a8773df15aa103f3194f56634604d84a2a084eb --- /dev/null +++ b/configs/ppyoloe/_base_/optimizer_80e.yml @@ -0,0 +1,18 @@ +epoch: 80 + +LearningRate: + base_lr: 0.001 + schedulers: + - !CosineDecay + max_epochs: 96 + - !LinearWarmup + start_factor: 0. + epochs: 5 + +OptimizerBuilder: + optimizer: + momentum: 0.9 + type: Momentum + regularizer: + factor: 0.0005 + type: L2 diff --git a/configs/ppyoloe/_base_/ppyoloe_plus_crn.yml b/configs/ppyoloe/_base_/ppyoloe_plus_crn.yml new file mode 100644 index 0000000000000000000000000000000000000000..664bbfa1a774a0c9859dcb4a6f395f916bae7c89 --- /dev/null +++ b/configs/ppyoloe/_base_/ppyoloe_plus_crn.yml @@ -0,0 +1,46 @@ +architecture: YOLOv3 +norm_type: sync_bn +use_ema: true +ema_decay: 0.9998 + +YOLOv3: + backbone: CSPResNet + neck: CustomCSPPAN + yolo_head: PPYOLOEHead + post_process: ~ + +CSPResNet: + layers: [3, 6, 6, 3] + channels: [64, 128, 256, 512, 1024] + return_idx: [1, 2, 3] + use_large_stem: True + use_alpha: True + +CustomCSPPAN: + out_channels: [768, 384, 192] + stage_num: 1 + block_num: 3 + act: 'swish' + spp: true + +PPYOLOEHead: + fpn_strides: [32, 16, 8] + grid_cell_scale: 5.0 + grid_cell_offset: 0.5 + static_assigner_epoch: 30 + use_varifocal_loss: True + loss_weight: {class: 1.0, iou: 2.5, dfl: 0.5} + static_assigner: + name: ATSSAssigner + topk: 9 + assigner: + name: TaskAlignedAssigner + topk: 13 + alpha: 1.0 + beta: 6.0 + nms: + name: MultiClassNMS + nms_top_k: 1000 + keep_top_k: 300 + score_threshold: 0.01 + nms_threshold: 0.7 diff --git a/configs/ppyoloe/_base_/ppyoloe_plus_reader.yml b/configs/ppyoloe/_base_/ppyoloe_plus_reader.yml new file mode 100644 index 0000000000000000000000000000000000000000..cd9cdeff8b9d46e41a4e6fb518339168dfd4b154 --- /dev/null +++ b/configs/ppyoloe/_base_/ppyoloe_plus_reader.yml @@ -0,0 +1,40 @@ +worker_num: 4 +eval_height: &eval_height 640 +eval_width: &eval_width 640 +eval_size: &eval_size [*eval_height, *eval_width] + +TrainReader: + sample_transforms: + - Decode: {} + - RandomDistort: {} + - RandomExpand: {fill_value: [123.675, 116.28, 103.53]} + - RandomCrop: {} + - RandomFlip: {} + batch_transforms: + - BatchRandomResize: {target_size: [320, 352, 384, 416, 448, 480, 512, 544, 576, 608, 640, 672, 704, 736, 768], random_size: True, random_interp: True, keep_ratio: False} + - NormalizeImage: {mean: [0., 0., 0.], std: [1., 1., 1.], norm_type: none} + - Permute: {} + - PadGT: {} + batch_size: 8 + shuffle: true + drop_last: true + use_shared_memory: true + collate_batch: true + +EvalReader: + sample_transforms: + - Decode: {} + - Resize: {target_size: *eval_size, keep_ratio: False, interp: 2} + - NormalizeImage: {mean: [0., 0., 0.], std: [1., 1., 1.], norm_type: none} + - Permute: {} + batch_size: 2 + +TestReader: + inputs_def: + image_shape: [3, *eval_height, *eval_width] + sample_transforms: + - Decode: {} + - Resize: {target_size: *eval_size, keep_ratio: False, interp: 2} + - NormalizeImage: {mean: [0., 0., 0.], std: [1., 1., 1.], norm_type: none} + - Permute: {} + batch_size: 1 diff --git a/configs/ppyoloe/legacy_model/README.md b/configs/ppyoloe/legacy_model/README.md new file mode 100644 index 0000000000000000000000000000000000000000..3daab44766fe8a07adf9a93fd30c9cf47aa38fac --- /dev/null +++ b/configs/ppyoloe/legacy_model/README.md @@ -0,0 +1,39 @@ +# PP-YOLOE Legacy Model Zoo (2022.03) + +## Legacy Model Zoo +| Model | Epoch | GPU number | images/GPU | backbone | input shape | Box APval
0.5:0.95 | Box APtest
0.5:0.95 | Params(M) | FLOPs(G) | V100 FP32(FPS) | V100 TensorRT FP16(FPS) | download | config | +|:------------------------:|:-------:|:-------:|:--------:|:----------:| :-------:| :------------------: | :-------------------: |:---------:|:--------:|:---------------:| :---------------------: | :------: | :------: | +| PP-YOLOE-s | 400 | 8 | 32 | cspresnet-s | 640 | 43.4 | 43.6 | 7.93 | 17.36 | 208.3 | 333.3 | [model](https://paddledet.bj.bcebos.com/models/ppyoloe_crn_s_400e_coco.pdparams) | [config](./ppyoloe_crn_s_400e_coco.yml) | +| PP-YOLOE-s | 300 | 8 | 32 | cspresnet-s | 640 | 43.0 | 43.2 | 7.93 | 17.36 | 208.3 | 333.3 | [model](https://paddledet.bj.bcebos.com/models/ppyoloe_crn_s_300e_coco.pdparams) | [config](./ppyoloe_crn_s_300e_coco.yml) | +| PP-YOLOE-m | 300 | 8 | 28 | cspresnet-m | 640 | 49.0 | 49.1 | 23.43 | 49.91 | 123.4 | 208.3 | [model](https://paddledet.bj.bcebos.com/models/ppyoloe_crn_m_300e_coco.pdparams) | [config](./ppyoloe_crn_m_300e_coco.yml) | +| PP-YOLOE-l | 300 | 8 | 20 | cspresnet-l | 640 | 51.4 | 51.6 | 52.20 | 110.07 | 78.1 | 149.2 | [model](https://paddledet.bj.bcebos.com/models/ppyoloe_crn_l_300e_coco.pdparams) | [config](./ppyoloe_crn_l_300e_coco.yml) | +| PP-YOLOE-x | 300 | 8 | 16 | cspresnet-x | 640 | 52.3 | 52.4 | 98.42 | 206.59 | 45.0 | 95.2 | [model](https://paddledet.bj.bcebos.com/models/ppyoloe_crn_x_300e_coco.pdparams) | [config](./ppyoloe_crn_x_300e_coco.yml) | + +### Comprehensive Metrics +| Model | Epoch | AP0.5:0.95 | AP0.5 | AP0.75 | APsmall | APmedium | APlarge | ARsmall | ARmedium | ARlarge | download | config | +|:----------------------:|:-----:|:---------------:|:----------:|:-------------:| :------------:| :-----------: | :----------: |:------------:|:-------------:|:------------:| :-----: | :-----: | +| PP-YOLOE-s | 400 | 43.4 | 60.0 | 47.5 | 25.7 | 47.8 | 59.2 | 43.9 | 70.8 | 81.9 | [model](https://paddledet.bj.bcebos.com/models/ppyoloe_crn_s_400e_coco.pdparams) | [config](./ppyoloe_crn_s_400e_coco.yml)| +| PP-YOLOE-s | 300 | 43.0 | 59.6 | 47.2 | 26.0 | 47.4 | 58.7 | 45.1 | 70.6 | 81.4 | [model](https://paddledet.bj.bcebos.com/models/ppyoloe_crn_s_300e_coco.pdparams) | [config](./ppyoloe_crn_s_300e_coco.yml)| +| PP-YOLOE-m | 300 | 49.0 | 65.9 | 53.8 | 30.9 | 53.5 | 65.3 | 50.9 | 74.4 | 84.7 | [model](https://paddledet.bj.bcebos.com/models/ppyoloe_crn_m_300e_coco.pdparams) | [config](./ppyoloe_crn_m_300e_coco.yml)| +| PP-YOLOE-l | 300 | 51.4 | 68.6 | 56.2 | 34.8 | 56.1 | 68.0 | 53.1 | 76.8 | 85.6 | [model](https://paddledet.bj.bcebos.com/models/ppyoloe_crn_l_300e_coco.pdparams) | [config](./ppyoloe_crn_l_300e_coco.yml)| +| PP-YOLOE-x | 300 | 52.3 | 69.5 | 56.8 | 35.1 | 57.0 | 68.6 | 55.5 | 76.9 | 85.7 | [model](https://paddledet.bj.bcebos.com/models/ppyoloe_crn_x_300e_coco.pdparams) | [config](./ppyoloe_crn_x_300e_coco.yml)| + + +**Notes:** + +- PP-YOLOE is trained on COCO train2017 dataset and evaluated on val2017 & test-dev2017 dataset. +- The model weights in the table of Comprehensive Metrics are **the same as** that in the original Model Zoo, and evaluated on **val2017**. +- PP-YOLOE used 8 GPUs for training, if **GPU number** or **mini-batch size** is changed, **learning rate** should be adjusted according to the formula **lrnew = lrdefault * (batch_sizenew * GPU_numbernew) / (batch_sizedefault * GPU_numberdefault)**. +- PP-YOLOE inference speed is tesed on single Tesla V100 with batch size as 1, **CUDA 10.2**, **CUDNN 7.6.5**, **TensorRT 6.0.1.8** in TensorRT mode. + +## Appendix + +Ablation experiments of PP-YOLOE. + +| NO. | Model | Box APval | Params(M) | FLOPs(G) | V100 FP32 FPS | +| :--: | :---------------------------: | :------------------: | :-------: | :------: | :-----------: | +| A | PP-YOLOv2 | 49.1 | 54.58 | 115.77 | 68.9 | +| B | A + Anchor-free | 48.8 | 54.27 | 114.78 | 69.8 | +| C | B + CSPRepResNet | 49.5 | 47.42 | 101.87 | 85.5 | +| D | C + TAL | 50.4 | 48.32 | 104.75 | 84.0 | +| E | D + ET-Head | 50.9 | 52.20 | 110.07 | 78.1 | diff --git a/configs/ppyoloe/_base_/optimizer_300e.yml b/configs/ppyoloe/legacy_model/_base_/optimizer_300e.yml similarity index 93% rename from configs/ppyoloe/_base_/optimizer_300e.yml rename to configs/ppyoloe/legacy_model/_base_/optimizer_300e.yml index b2ce356539c149f494c6a9f9d0ad683c78df602d..ab94c9c3ea313e3290117c1134132d92f3dd761f 100644 --- a/configs/ppyoloe/_base_/optimizer_300e.yml +++ b/configs/ppyoloe/legacy_model/_base_/optimizer_300e.yml @@ -1,7 +1,7 @@ epoch: 300 LearningRate: - base_lr: 0.025 + base_lr: 0.01 schedulers: - !CosineDecay max_epochs: 360 diff --git a/configs/ppyoloe/_base_/optimizer_36e_xpu.yml b/configs/ppyoloe/legacy_model/_base_/optimizer_36e_xpu.yml similarity index 100% rename from configs/ppyoloe/_base_/optimizer_36e_xpu.yml rename to configs/ppyoloe/legacy_model/_base_/optimizer_36e_xpu.yml diff --git a/configs/ppyoloe/legacy_model/_base_/optimizer_400e.yml b/configs/ppyoloe/legacy_model/_base_/optimizer_400e.yml new file mode 100644 index 0000000000000000000000000000000000000000..de33fb749509bd2a3bbd6727aa698827ab634d12 --- /dev/null +++ b/configs/ppyoloe/legacy_model/_base_/optimizer_400e.yml @@ -0,0 +1,18 @@ +epoch: 400 + +LearningRate: + base_lr: 0.01 + schedulers: + - !CosineDecay + max_epochs: 480 + - !LinearWarmup + start_factor: 0. + epochs: 5 + +OptimizerBuilder: + optimizer: + momentum: 0.9 + type: Momentum + regularizer: + factor: 0.0005 + type: L2 diff --git a/configs/ppyoloe/_base_/ppyoloe_crn.yml b/configs/ppyoloe/legacy_model/_base_/ppyoloe_crn.yml similarity index 100% rename from configs/ppyoloe/_base_/ppyoloe_crn.yml rename to configs/ppyoloe/legacy_model/_base_/ppyoloe_crn.yml diff --git a/configs/ppyoloe/_base_/ppyoloe_reader.yml b/configs/ppyoloe/legacy_model/_base_/ppyoloe_reader.yml similarity index 98% rename from configs/ppyoloe/_base_/ppyoloe_reader.yml rename to configs/ppyoloe/legacy_model/_base_/ppyoloe_reader.yml index 058b4ee478d05fea850d7970e1e6a61d81352e78..9f99713e5c106321025842db1f61361a82364e77 100644 --- a/configs/ppyoloe/_base_/ppyoloe_reader.yml +++ b/configs/ppyoloe/legacy_model/_base_/ppyoloe_reader.yml @@ -15,7 +15,7 @@ TrainReader: - NormalizeImage: {mean: [0.485, 0.456, 0.406], std: [0.229, 0.224, 0.225], is_scale: True} - Permute: {} - PadGT: {} - batch_size: 20 + batch_size: 8 shuffle: true drop_last: true use_shared_memory: true diff --git a/configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml b/configs/ppyoloe/legacy_model/ppyoloe_crn_l_300e_coco.yml similarity index 84% rename from configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml rename to configs/ppyoloe/legacy_model/ppyoloe_crn_l_300e_coco.yml index ef3422815b4376fdd921516e235ec59af28681f7..724d854533de708fc0f26f785816441c1cf5fb3d 100644 --- a/configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml +++ b/configs/ppyoloe/legacy_model/ppyoloe_crn_l_300e_coco.yml @@ -1,6 +1,6 @@ _BASE_: [ - '../datasets/coco_detection.yml', - '../runtime.yml', + '../../datasets/coco_detection.yml', + '../../runtime.yml', './_base_/optimizer_300e.yml', './_base_/ppyoloe_crn.yml', './_base_/ppyoloe_reader.yml', diff --git a/configs/ppyoloe/ppyoloe_crn_l_36e_coco_xpu.yml b/configs/ppyoloe/legacy_model/ppyoloe_crn_l_36e_coco_xpu.yml similarity index 95% rename from configs/ppyoloe/ppyoloe_crn_l_36e_coco_xpu.yml rename to configs/ppyoloe/legacy_model/ppyoloe_crn_l_36e_coco_xpu.yml index 3797288864c978f7872c9b994af2477bb6c31acd..c8efcae522b7f39f4bf1caf8008ef02183bbb12f 100644 --- a/configs/ppyoloe/ppyoloe_crn_l_36e_coco_xpu.yml +++ b/configs/ppyoloe/legacy_model/ppyoloe_crn_l_36e_coco_xpu.yml @@ -1,6 +1,6 @@ _BASE_: [ - '../datasets/coco_detection.yml', - '../runtime.yml', + '../../datasets/coco_detection.yml', + '../../runtime.yml', './_base_/optimizer_36e_xpu.yml', './_base_/ppyoloe_reader.yml', ] diff --git a/configs/ppyoloe/ppyoloe_crn_m_300e_coco.yml b/configs/ppyoloe/legacy_model/ppyoloe_crn_m_300e_coco.yml similarity index 73% rename from configs/ppyoloe/ppyoloe_crn_m_300e_coco.yml rename to configs/ppyoloe/legacy_model/ppyoloe_crn_m_300e_coco.yml index 26b606a54e00699ee78f3a087ba675b817da072d..de684208c3b2e81f8a1f405562e376fc37bb43d0 100644 --- a/configs/ppyoloe/ppyoloe_crn_m_300e_coco.yml +++ b/configs/ppyoloe/legacy_model/ppyoloe_crn_m_300e_coco.yml @@ -1,6 +1,6 @@ _BASE_: [ - '../datasets/coco_detection.yml', - '../runtime.yml', + '../../datasets/coco_detection.yml', + '../../runtime.yml', './_base_/optimizer_300e.yml', './_base_/ppyoloe_crn.yml', './_base_/ppyoloe_reader.yml', @@ -13,9 +13,3 @@ weights: output/ppyoloe_crn_m_300e_coco/model_final pretrain_weights: https://paddledet.bj.bcebos.com/models/pretrained/CSPResNetb_m_pretrained.pdparams depth_mult: 0.67 width_mult: 0.75 - -TrainReader: - batch_size: 28 - -LearningRate: - base_lr: 0.035 diff --git a/configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml b/configs/ppyoloe/legacy_model/ppyoloe_crn_s_300e_coco.yml similarity index 73% rename from configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml rename to configs/ppyoloe/legacy_model/ppyoloe_crn_s_300e_coco.yml index 4cd3e68da6b5f1e672e67b416155f3d0fa8ab3e2..f0cf05df049c065d287bef3d0add25671fa9a98d 100644 --- a/configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml +++ b/configs/ppyoloe/legacy_model/ppyoloe_crn_s_300e_coco.yml @@ -1,6 +1,6 @@ _BASE_: [ - '../datasets/coco_detection.yml', - '../runtime.yml', + '../../datasets/coco_detection.yml', + '../../runtime.yml', './_base_/optimizer_300e.yml', './_base_/ppyoloe_crn.yml', './_base_/ppyoloe_reader.yml', @@ -13,9 +13,3 @@ weights: output/ppyoloe_crn_s_300e_coco/model_final pretrain_weights: https://paddledet.bj.bcebos.com/models/pretrained/CSPResNetb_s_pretrained.pdparams depth_mult: 0.33 width_mult: 0.50 - -TrainReader: - batch_size: 32 - -LearningRate: - base_lr: 0.04 diff --git a/configs/ppyoloe/legacy_model/ppyoloe_crn_s_400e_coco.yml b/configs/ppyoloe/legacy_model/ppyoloe_crn_s_400e_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..7c06afe47f33e7a16f3d2dbf329261f84faf739a --- /dev/null +++ b/configs/ppyoloe/legacy_model/ppyoloe_crn_s_400e_coco.yml @@ -0,0 +1,18 @@ +_BASE_: [ + '../../datasets/coco_detection.yml', + '../../runtime.yml', + './_base_/optimizer_400e.yml', + './_base_/ppyoloe_crn.yml', + './_base_/ppyoloe_reader.yml', +] + +log_iter: 100 +snapshot_epoch: 10 +weights: output/ppyoloe_crn_s_400e_coco/model_final + +pretrain_weights: https://paddledet.bj.bcebos.com/models/pretrained/CSPResNetb_s_pretrained.pdparams +depth_mult: 0.33 +width_mult: 0.50 + +PPYOLOEHead: + static_assigner_epoch: 133 diff --git a/configs/ppyoloe/ppyoloe_crn_x_300e_coco.yml b/configs/ppyoloe/legacy_model/ppyoloe_crn_x_300e_coco.yml similarity index 73% rename from configs/ppyoloe/ppyoloe_crn_x_300e_coco.yml rename to configs/ppyoloe/legacy_model/ppyoloe_crn_x_300e_coco.yml index d2b4407df3f479f047f101bd345f8eea26ed117c..4f1ef2e18a0ab94fa54c95f40adac4234e6b0405 100644 --- a/configs/ppyoloe/ppyoloe_crn_x_300e_coco.yml +++ b/configs/ppyoloe/legacy_model/ppyoloe_crn_x_300e_coco.yml @@ -1,6 +1,6 @@ _BASE_: [ - '../datasets/coco_detection.yml', - '../runtime.yml', + '../../datasets/coco_detection.yml', + '../../runtime.yml', './_base_/optimizer_300e.yml', './_base_/ppyoloe_crn.yml', './_base_/ppyoloe_reader.yml', @@ -13,9 +13,3 @@ weights: output/ppyoloe_crn_x_300e_coco/model_final pretrain_weights: https://paddledet.bj.bcebos.com/models/pretrained/CSPResNetb_x_pretrained.pdparams depth_mult: 1.33 width_mult: 1.25 - -TrainReader: - batch_size: 16 - -LearningRate: - base_lr: 0.02 diff --git a/configs/ppyoloe/ppyoloe_crn_s_400e_coco.yml b/configs/ppyoloe/ppyoloe_crn_s_400e_coco.yml deleted file mode 100644 index c3cddf48bb75d733aaf15bfbd148b8e480d48493..0000000000000000000000000000000000000000 --- a/configs/ppyoloe/ppyoloe_crn_s_400e_coco.yml +++ /dev/null @@ -1,46 +0,0 @@ -_BASE_: [ - '../datasets/coco_detection.yml', - '../runtime.yml', - './_base_/optimizer_300e.yml', - './_base_/ppyoloe_crn.yml', - './_base_/ppyoloe_reader.yml', -] - -log_iter: 100 -snapshot_epoch: 10 -weights: output/ppyoloe_crn_s_400e_coco/model_final - -pretrain_weights: https://paddledet.bj.bcebos.com/models/pretrained/CSPResNetb_s_pretrained.pdparams -depth_mult: 0.33 -width_mult: 0.50 - -TrainReader: - batch_size: 32 - -epoch: 400 -LearningRate: - base_lr: 0.04 - schedulers: - - !CosineDecay - max_epochs: 480 - - !LinearWarmup - start_factor: 0. - epochs: 5 - -OptimizerBuilder: - optimizer: - momentum: 0.9 - type: Momentum - regularizer: - factor: 0.0005 - type: L2 - - -PPYOLOEHead: - static_assigner_epoch: 133 - nms: - name: MultiClassNMS - nms_top_k: 1000 - keep_top_k: 300 - score_threshold: 0.01 - nms_threshold: 0.7 diff --git a/configs/ppyoloe/ppyoloe_plus_crn_l_80e_coco.yml b/configs/ppyoloe/ppyoloe_plus_crn_l_80e_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..626cc2810510a908cb361bf63e4c1ae087adcba7 --- /dev/null +++ b/configs/ppyoloe/ppyoloe_plus_crn_l_80e_coco.yml @@ -0,0 +1,15 @@ +_BASE_: [ + '../datasets/coco_detection.yml', + '../runtime.yml', + './_base_/optimizer_80e.yml', + './_base_/ppyoloe_plus_crn.yml', + './_base_/ppyoloe_plus_reader.yml', +] + +log_iter: 100 +snapshot_epoch: 5 +weights: output/ppyoloe_plus_crn_l_80e_coco/model_final + +pretrain_weights: https://bj.bcebos.com/v1/paddledet/models/pretrained/ppyoloe_crn_l_obj365_pretrained.pdparams +depth_mult: 1.0 +width_mult: 1.0 diff --git a/configs/ppyoloe/ppyoloe_plus_crn_m_80e_coco.yml b/configs/ppyoloe/ppyoloe_plus_crn_m_80e_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..3209bef6b91c03c12b09bb8038adc82b7d1de8e0 --- /dev/null +++ b/configs/ppyoloe/ppyoloe_plus_crn_m_80e_coco.yml @@ -0,0 +1,15 @@ +_BASE_: [ + '../datasets/coco_detection.yml', + '../runtime.yml', + './_base_/optimizer_80e.yml', + './_base_/ppyoloe_plus_crn.yml', + './_base_/ppyoloe_plus_reader.yml', +] + +log_iter: 100 +snapshot_epoch: 5 +weights: output/ppyoloe_plus_crn_m_80e_coco/model_final + +pretrain_weights: https://bj.bcebos.com/v1/paddledet/models/pretrained/ppyoloe_crn_m_obj365_pretrained.pdparams +depth_mult: 0.67 +width_mult: 0.75 diff --git a/configs/ppyoloe/ppyoloe_plus_crn_s_80e_coco.yml b/configs/ppyoloe/ppyoloe_plus_crn_s_80e_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..862f322c48ec6fd7f7bc669f4be8b436746046e7 --- /dev/null +++ b/configs/ppyoloe/ppyoloe_plus_crn_s_80e_coco.yml @@ -0,0 +1,15 @@ +_BASE_: [ + '../datasets/coco_detection.yml', + '../runtime.yml', + './_base_/optimizer_80e.yml', + './_base_/ppyoloe_plus_crn.yml', + './_base_/ppyoloe_plus_reader.yml', +] + +log_iter: 100 +snapshot_epoch: 5 +weights: output/ppyoloe_plus_crn_s_80e_coco/model_final + +pretrain_weights: https://bj.bcebos.com/v1/paddledet/models/pretrained/ppyoloe_crn_s_obj365_pretrained.pdparams +depth_mult: 0.33 +width_mult: 0.50 diff --git a/configs/ppyoloe/ppyoloe_plus_crn_x_80e_coco.yml b/configs/ppyoloe/ppyoloe_plus_crn_x_80e_coco.yml new file mode 100644 index 0000000000000000000000000000000000000000..cd41814f972cff4b1193c0c7813d22764b1f565d --- /dev/null +++ b/configs/ppyoloe/ppyoloe_plus_crn_x_80e_coco.yml @@ -0,0 +1,15 @@ +_BASE_: [ + '../datasets/coco_detection.yml', + '../runtime.yml', + './_base_/optimizer_80e.yml', + './_base_/ppyoloe_plus_crn.yml', + './_base_/ppyoloe_plus_reader.yml', +] + +log_iter: 100 +snapshot_epoch: 5 +weights: output/ppyoloe_plus_crn_x_80e_coco/model_final + +pretrain_weights: https://bj.bcebos.com/v1/paddledet/models/pretrained/ppyoloe_crn_x_obj365_pretrained.pdparams +depth_mult: 1.33 +width_mult: 1.25 diff --git a/deploy/cpp/include/preprocess_op.h b/deploy/cpp/include/preprocess_op.h index a54bc2afb8aacbc55241b866ba41acc00491e4f3..e3d4a99bb15f2860a7ce4c7bb17b332565de2da1 100644 --- a/deploy/cpp/include/preprocess_op.h +++ b/deploy/cpp/include/preprocess_op.h @@ -65,7 +65,8 @@ class NormalizeImage : public PreprocessOp { virtual void Init(const YAML::Node& item) { mean_ = item["mean"].as>(); scale_ = item["std"].as>(); - is_scale_ = item["is_scale"].as(); + if (item["is_scale"]) is_scale_ = item["is_scale"].as(); + if (item["norm_type"]) norm_type_ = item["norm_type"].as(); } virtual void Run(cv::Mat* im, ImageBlob* data); @@ -75,6 +76,7 @@ class NormalizeImage : public PreprocessOp { std::vector mean_; std::vector scale_; bool is_scale_ = true; + std::string norm_type_ = "mean_std"; }; class Permute : public PreprocessOp { diff --git a/deploy/cpp/src/preprocess_op.cc b/deploy/cpp/src/preprocess_op.cc index 6147555be57a2739fcd4a773eb281aaa966763b0..e1cbfe4f15a49930ac9759e8d1b71232f167ad04 100644 --- a/deploy/cpp/src/preprocess_op.cc +++ b/deploy/cpp/src/preprocess_op.cc @@ -34,14 +34,16 @@ void NormalizeImage::Run(cv::Mat* im, ImageBlob* data) { e /= 255.0; } (*im).convertTo(*im, CV_32FC3, e); - for (int h = 0; h < im->rows; h++) { - for (int w = 0; w < im->cols; w++) { - im->at(h, w)[0] = - (im->at(h, w)[0] - mean_[0]) / scale_[0]; - im->at(h, w)[1] = - (im->at(h, w)[1] - mean_[1]) / scale_[1]; - im->at(h, w)[2] = - (im->at(h, w)[2] - mean_[2]) / scale_[2]; + if (norm_type_ == "mean_std"){ + for (int h = 0; h < im->rows; h++) { + for (int w = 0; w < im->cols; w++) { + im->at(h, w)[0] = + (im->at(h, w)[0] - mean_[0]) / scale_[0]; + im->at(h, w)[1] = + (im->at(h, w)[1] - mean_[1]) / scale_[1]; + im->at(h, w)[2] = + (im->at(h, w)[2] - mean_[2]) / scale_[2]; + } } } } diff --git a/deploy/python/preprocess.py b/deploy/python/preprocess.py index 4fc80d1a33521f9b0b2a48c8e965fc3fb643110d..51033aebc818a6e53c0528e202db272bfc5dd9bc 100644 --- a/deploy/python/preprocess.py +++ b/deploy/python/preprocess.py @@ -275,13 +275,14 @@ class NormalizeImage(object): mean (list): im - mean std (list): im / std is_scale (bool): whether need im / 255 - is_channel_first (bool): if True: image shape is CHW, else: HWC + norm_type (str): type in ['mean_std', 'none'] """ - def __init__(self, mean, std, is_scale=True): + def __init__(self, mean, std, is_scale=True, norm_type='mean_std'): self.mean = mean self.std = std self.is_scale = is_scale + self.norm_type = norm_type def __call__(self, im, im_info): """ @@ -293,13 +294,15 @@ class NormalizeImage(object): im_info (dict): info of processed image """ im = im.astype(np.float32, copy=False) - mean = np.array(self.mean)[np.newaxis, np.newaxis, :] - std = np.array(self.std)[np.newaxis, np.newaxis, :] - if self.is_scale: - im = im / 255.0 - im -= mean - im /= std + scale = 1.0 / 255.0 + im *= scale + + if self.norm_type == 'mean_std': + mean = np.array(self.mean)[np.newaxis, np.newaxis, :] + std = np.array(self.std)[np.newaxis, np.newaxis, :] + im -= mean + im /= std return im, im_info diff --git a/deploy/serving/python/preprocess_ops.py b/deploy/serving/python/preprocess_ops.py index 0a419688b1db243179082487d1c19b2a9a4e3d4b..15f76159818a159f3967c7778eda7dc53a8a40a4 100644 --- a/deploy/serving/python/preprocess_ops.py +++ b/deploy/serving/python/preprocess_ops.py @@ -87,13 +87,14 @@ class NormalizeImage(object): mean (list): im - mean std (list): im / std is_scale (bool): whether need im / 255 - is_channel_first (bool): if True: image shape is CHW, else: HWC + norm_type (str): type in ['mean_std', 'none'] """ - def __init__(self, mean, std, is_scale=True): + def __init__(self, mean, std, is_scale=True, norm_type='mean_std'): self.mean = mean self.std = std self.is_scale = is_scale + self.norm_type = norm_type def __call__(self, im, im_info): """ @@ -105,13 +106,15 @@ class NormalizeImage(object): im_info (dict): info of processed image """ im = im.astype(np.float32, copy=False) - mean = np.array(self.mean)[np.newaxis, np.newaxis, :] - std = np.array(self.std)[np.newaxis, np.newaxis, :] - if self.is_scale: - im = im / 255.0 - im -= mean - im /= std + scale = 1.0 / 255.0 + im *= scale + + if self.norm_type == 'mean_std': + mean = np.array(self.mean)[np.newaxis, np.newaxis, :] + std = np.array(self.std)[np.newaxis, np.newaxis, :] + im -= mean + im /= std return im, im_info diff --git a/deploy/third_engine/onnx/preprocess.py b/deploy/third_engine/onnx/preprocess.py index 7ed422c53c2301a63fafd6f5c8019ed51d857865..3554b7f81250bdffbbd78d1ec4905bcf722943e6 100644 --- a/deploy/third_engine/onnx/preprocess.py +++ b/deploy/third_engine/onnx/preprocess.py @@ -91,13 +91,14 @@ class NormalizeImage(object): mean (list): im - mean std (list): im / std is_scale (bool): whether need im / 255 - is_channel_first (bool): if True: image shape is CHW, else: HWC + norm_type (str): type in ['mean_std', 'none'] """ - def __init__(self, mean, std, is_scale=True): + def __init__(self, mean, std, is_scale=True, norm_type='mean_std'): self.mean = mean self.std = std self.is_scale = is_scale + self.norm_type = norm_type def __call__(self, im, im_info): """ @@ -109,13 +110,15 @@ class NormalizeImage(object): im_info (dict): info of processed image """ im = im.astype(np.float32, copy=False) - mean = np.array(self.mean)[np.newaxis, np.newaxis, :] - std = np.array(self.std)[np.newaxis, np.newaxis, :] - if self.is_scale: - im = im / 255.0 - im -= mean - im /= std + scale = 1.0 / 255.0 + im *= scale + + if self.norm_type == 'mean_std': + mean = np.array(self.mean)[np.newaxis, np.newaxis, :] + std = np.array(self.std)[np.newaxis, np.newaxis, :] + im -= mean + im /= std return im, im_info diff --git a/ppdet/data/transform/operators.py b/ppdet/data/transform/operators.py index ad0bfdf2ad72035291d9111c4be2ba18b0615621..01af29ffc4f481e4e044979542ca1d4387c56374 100644 --- a/ppdet/data/transform/operators.py +++ b/ppdet/data/transform/operators.py @@ -359,19 +359,26 @@ class RandomErasingImage(BaseOperator): @register_op class NormalizeImage(BaseOperator): - def __init__(self, mean=[0.485, 0.456, 0.406], std=[1, 1, 1], - is_scale=True): + def __init__(self, + mean=[0.485, 0.456, 0.406], + std=[0.229, 0.224, 0.225], + is_scale=True, + norm_type='mean_std'): """ Args: mean (list): the pixel mean std (list): the pixel variance + is_scale (bool): scale the pixel to [0,1] + norm_type (str): type in ['mean_std', 'none'] """ super(NormalizeImage, self).__init__() self.mean = mean self.std = std self.is_scale = is_scale + self.norm_type = norm_type if not (isinstance(self.mean, list) and isinstance(self.std, list) and - isinstance(self.is_scale, bool)): + isinstance(self.is_scale, bool) and + self.norm_type in ['mean_std', 'none']): raise TypeError("{}: input type is invalid.".format(self)) from functools import reduce if reduce(lambda x, y: x * y, self.std) == 0: @@ -380,20 +387,20 @@ class NormalizeImage(BaseOperator): def apply(self, sample, context=None): """Normalize the image. Operators: - 1.(optional) Scale the image to [0,1] - 2. Each pixel minus mean and is divided by std + 1.(optional) Scale the pixel to [0,1] + 2.(optional) Each pixel minus mean and is divided by std """ im = sample['image'] im = im.astype(np.float32, copy=False) - mean = np.array(self.mean)[np.newaxis, np.newaxis, :] - std = np.array(self.std)[np.newaxis, np.newaxis, :] - if self.is_scale: - im = im / 255.0 - - im -= mean - im /= std - + scale = 1.0 / 255.0 + im *= scale + + if self.norm_type == 'mean_std': + mean = np.array(self.mean)[np.newaxis, np.newaxis, :] + std = np.array(self.std)[np.newaxis, np.newaxis, :] + im -= mean + im /= std sample['image'] = im return sample