From ace7a7819401434c5516a2311b398cecc7392325 Mon Sep 17 00:00:00 2001 From: Jaeguk Hyun Date: Tue, 12 Jul 2022 09:47:36 +0900 Subject: [PATCH] [MPA] Enable SSD and YOLOX model template (#1156) * Changes for SC integration for detection tasks * Add SSD, YOLOX to mpa, and SC integration * Change submodules for YOLOX enable * Change default task op as REPLACE * Change default temlates in mmdetection * Bug fifor YOLOX enable both mpa and ote * Change hyperparams for training small dataset * Rebuildsubmodule * Rebuild submodule * Change learning schedules * Change ote_sdk requirements.txt * Remove template.yaml * Unification of recipe * Change mpa submodule * Modification for flake8 test * Change mpa submodule * Add VfNet * Commit for changed mpa submodule * Change mpa submodule and remove remark --- .../data_pipeline.py | 74 +++++++++++++++++++ .../cspdarknet_yolox_cls_incr/hpo_config.yaml | 16 ++++ .../cspdarknet_yolox_cls_incr/model.py | 3 + .../template_experimental.yaml | 51 +++++++++++++ .../template_experimental.yaml | 4 +- .../mobilenetv2_ssd_cls_incr/hpo_config.yaml | 16 ++++ .../mobilenetv2_ssd_cls_incr/model.py | 8 ++ .../template_experimental.yaml | 51 +++++++++++++ ote_sdk/requirements.txt | 2 +- 9 files changed, 222 insertions(+), 3 deletions(-) create mode 100644 external/model-preparation-algorithm/configs/detection/cspdarknet_yolox_cls_incr/data_pipeline.py create mode 100644 external/model-preparation-algorithm/configs/detection/cspdarknet_yolox_cls_incr/hpo_config.yaml create mode 100644 external/model-preparation-algorithm/configs/detection/cspdarknet_yolox_cls_incr/model.py create mode 100644 external/model-preparation-algorithm/configs/detection/cspdarknet_yolox_cls_incr/template_experimental.yaml create mode 100644 external/model-preparation-algorithm/configs/detection/mobilenetv2_ssd_cls_incr/hpo_config.yaml create mode 100644 external/model-preparation-algorithm/configs/detection/mobilenetv2_ssd_cls_incr/model.py create mode 100644 external/model-preparation-algorithm/configs/detection/mobilenetv2_ssd_cls_incr/template_experimental.yaml diff --git a/external/model-preparation-algorithm/configs/detection/cspdarknet_yolox_cls_incr/data_pipeline.py b/external/model-preparation-algorithm/configs/detection/cspdarknet_yolox_cls_incr/data_pipeline.py new file mode 100644 index 00000000000..028d05ba84b --- /dev/null +++ b/external/model-preparation-algorithm/configs/detection/cspdarknet_yolox_cls_incr/data_pipeline.py @@ -0,0 +1,74 @@ +dataset_type = 'CocoDataset' +data_root = 'data/coco/' +samples_per_gpu = 2 +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) +img_scale = (640, 640) + +train_pipeline = [ + dict(type='Mosaic', img_scale=img_scale, pad_val=114.0), + dict( + type='RandomAffine', + scaling_ratio_range=(0.5, 1.5), + border=(-img_scale[0] // 2, -img_scale[1] // 2)), + dict( + type='PhotoMetricDistortion', + brightness_delta=32, + contrast_range=(0.5, 1.5), + saturation_range=(0.5, 1.5), + hue_delta=18), + dict(type='RandomFlip', flip_ratio=0.5), + dict(type='Resize', keep_ratio=True), + dict(type='Pad', pad_to_square=True, pad_val=114.0), + dict(type='Normalize', **img_norm_cfg), + dict(type='DefaultFormatBundle'), + dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels']) +] + +test_pipeline = [ + dict(type='LoadImageFromFile'), + dict( + type='MultiScaleFlipAug', + img_scale=(416, 416), + flip=False, + transforms=[ + dict(type='Resize', keep_ratio=False), + dict(type='RandomFlip'), + dict(type='Pad', size=(416, 416), pad_val=114.0), + dict(type='Normalize', **img_norm_cfg), + dict(type='DefaultFormatBundle'), + dict(type='Collect', keys=['img']) + ]) +] + +data = dict( + samples_per_gpu=samples_per_gpu, + workers_per_gpu=4, + num_classes=2, + train=dict( + type='MultiImageMixDataset', + dataset=dict( + type=dataset_type, + ann_file=data_root + 'annotations/instances_train2017.json', + img_prefix=data_root + 'train2017/', + pipeline=[ + dict(type='LoadImageFromFile', to_float32=True), + dict(type='LoadAnnotations', with_bbox=True) + ], + ), + pipeline=train_pipeline, + dynamic_scale=img_scale, + ), + val=dict( + type=dataset_type, + ann_file=data_root + 'annotations/instances_val2017.json', + img_prefix=data_root + 'val2017/', + test_mode=True, + pipeline=test_pipeline), + test=dict( + type=dataset_type, + ann_file=data_root + 'annotations/instances_val2017.json', + img_prefix=data_root + 'val2017/', + test_mode=True, + pipeline=test_pipeline) +) diff --git a/external/model-preparation-algorithm/configs/detection/cspdarknet_yolox_cls_incr/hpo_config.yaml b/external/model-preparation-algorithm/configs/detection/cspdarknet_yolox_cls_incr/hpo_config.yaml new file mode 100644 index 00000000000..05a66a73905 --- /dev/null +++ b/external/model-preparation-algorithm/configs/detection/cspdarknet_yolox_cls_incr/hpo_config.yaml @@ -0,0 +1,16 @@ +metric: mAP +search_algorithm: smbo +early_stop: None +hp_space: + learning_parameters.learning_rate: + param_type: quniform + range: + - 0.001 + - 0.1 + - 0.001 + learning_parameters.batch_size: + param_type: qloguniform + range: + - 4 + - 8 + - 2 diff --git a/external/model-preparation-algorithm/configs/detection/cspdarknet_yolox_cls_incr/model.py b/external/model-preparation-algorithm/configs/detection/cspdarknet_yolox_cls_incr/model.py new file mode 100644 index 00000000000..51f2d44cda9 --- /dev/null +++ b/external/model-preparation-algorithm/configs/detection/cspdarknet_yolox_cls_incr/model.py @@ -0,0 +1,3 @@ +_base_ = [ + '../../../submodule/recipes/stages/_base_/models/detectors/yolox.custom.py' +] diff --git a/external/model-preparation-algorithm/configs/detection/cspdarknet_yolox_cls_incr/template_experimental.yaml b/external/model-preparation-algorithm/configs/detection/cspdarknet_yolox_cls_incr/template_experimental.yaml new file mode 100644 index 00000000000..b98942e0210 --- /dev/null +++ b/external/model-preparation-algorithm/configs/detection/cspdarknet_yolox_cls_incr/template_experimental.yaml @@ -0,0 +1,51 @@ +# Description. +model_template_id: ClassIncremental_Object_Detection_YOLOX +name: YOLOX-ClsIncr +task_type: DETECTION +task_family: VISION +instantiation: "CLASS" +summary: Class-Incremental Object Detection for YOLOX +application: ~ + +# Algo backend. +framework: MPA v1.1.0 + +# Task implementations. +entrypoints: + base: mpa_tasks.apis.detection.DetectionTrainTask + openvino: detection_tasks.apis.detection.OpenVINODetectionTask + +# Capabilities. +capabilities: [] + +# Hyperparameters. +hyper_parameters: + base_path: ../configuration.yaml + parameter_overrides: + learning_parameters: + batch_size: + default_value: 16 + learning_rate: + default_value: 0.0025 + learning_rate_warmup_iters: + default_value: 500 + num_iters: + default_value: 300 + algo_backend: + train_type: + default_value: Incremental + +# Training resources. +max_nodes: 1 +training_targets: + - GPU + - CPU + +# Stats. +gigaflops: 20.6 +size: 9.1 +# # Inference options. Defined by OpenVINO capabilities, not Algo Backend or Platform. +# inference_targets: +# - CPU +# - GPU +# - VPU diff --git a/external/model-preparation-algorithm/configs/detection/mobilenetv2_atss_cls_incr/template_experimental.yaml b/external/model-preparation-algorithm/configs/detection/mobilenetv2_atss_cls_incr/template_experimental.yaml index 2330284c4b1..c091e64ae40 100644 --- a/external/model-preparation-algorithm/configs/detection/mobilenetv2_atss_cls_incr/template_experimental.yaml +++ b/external/model-preparation-algorithm/configs/detection/mobilenetv2_atss_cls_incr/template_experimental.yaml @@ -28,9 +28,9 @@ hyper_parameters: learning_rate: default_value: 0.001 learning_rate_warmup_iters: - default_value: 200 + default_value: 10 num_iters: - default_value: 30 + default_value: 100 algo_backend: train_type: default_value: Incremental diff --git a/external/model-preparation-algorithm/configs/detection/mobilenetv2_ssd_cls_incr/hpo_config.yaml b/external/model-preparation-algorithm/configs/detection/mobilenetv2_ssd_cls_incr/hpo_config.yaml new file mode 100644 index 00000000000..05a66a73905 --- /dev/null +++ b/external/model-preparation-algorithm/configs/detection/mobilenetv2_ssd_cls_incr/hpo_config.yaml @@ -0,0 +1,16 @@ +metric: mAP +search_algorithm: smbo +early_stop: None +hp_space: + learning_parameters.learning_rate: + param_type: quniform + range: + - 0.001 + - 0.1 + - 0.001 + learning_parameters.batch_size: + param_type: qloguniform + range: + - 4 + - 8 + - 2 diff --git a/external/model-preparation-algorithm/configs/detection/mobilenetv2_ssd_cls_incr/model.py b/external/model-preparation-algorithm/configs/detection/mobilenetv2_ssd_cls_incr/model.py new file mode 100644 index 00000000000..909742b76ba --- /dev/null +++ b/external/model-preparation-algorithm/configs/detection/mobilenetv2_ssd_cls_incr/model.py @@ -0,0 +1,8 @@ +_base_ = [ + '../../../submodule/samples/cfgs/models/backbones/ote_mobilenet_v2_w1.yaml', + '../../../submodule/recipes/stages/_base_/models/detectors/ssd.custom.py' +] + +model = dict( + backbone=dict(out_indices=(4, 5,)) +) diff --git a/external/model-preparation-algorithm/configs/detection/mobilenetv2_ssd_cls_incr/template_experimental.yaml b/external/model-preparation-algorithm/configs/detection/mobilenetv2_ssd_cls_incr/template_experimental.yaml new file mode 100644 index 00000000000..81f498f4128 --- /dev/null +++ b/external/model-preparation-algorithm/configs/detection/mobilenetv2_ssd_cls_incr/template_experimental.yaml @@ -0,0 +1,51 @@ +# Description. +model_template_id: ClassIncremental_Object_Detection_Gen3_SSD +name: SSD-ClsIncr +task_type: DETECTION +task_family: VISION +instantiation: "CLASS" +summary: Class-Incremental Object Detection for SSD +application: ~ + +# Algo backend. +framework: MPA v1.1.0 + +# Task implementations. +entrypoints: + base: mpa_tasks.apis.detection.DetectionTrainTask + openvino: detection_tasks.apis.detection.OpenVINODetectionTask + +# Capabilities. +capabilities: [] + +# Hyperparameters. +hyper_parameters: + base_path: ../configuration.yaml + parameter_overrides: + learning_parameters: + batch_size: + default_value: 4 + learning_rate: + default_value: 0.001 + learning_rate_warmup_iters: + default_value: 200 + num_iters: + default_value: 30 + algo_backend: + train_type: + default_value: Incremental + +# Training resources. +max_nodes: 1 +training_targets: + - GPU + - CPU + +# Stats. +gigaflops: 20.6 +size: 9.1 +# # Inference options. Defined by OpenVINO capabilities, not Algo Backend or Platform. +# inference_targets: +# - CPU +# - GPU +# - VPU diff --git a/ote_sdk/requirements.txt b/ote_sdk/requirements.txt index 5a641fbd2ba..dfe3a621aed 100644 --- a/ote_sdk/requirements.txt +++ b/ote_sdk/requirements.txt @@ -2,7 +2,7 @@ numpy>=1.16.4 scikit-learn==0.24.* Shapely>=1.7.1,<=1.8.0 networkx>=2.5,<2.8.1rc1 -opencv-python==4.5.5.* +opencv-python==4.5.* pymongo==3.12.0 omegaconf==2.1.* natsort>=6.0.0