From d8f59a2e28e43f4090bf279ce750aecee2a6b1d7 Mon Sep 17 00:00:00 2001 From: gulou <113007768+gulou01517514@users.noreply.github.com> Date: Mon, 6 Mar 2023 11:35:20 +0800 Subject: [PATCH] [WIP]Features/add yolo 20230301 (#297) add fcos and yolox pai_config --- configs/detection/fcos/coco_detection.py | 13 +- .../detection/fcos/fcos_r50_torch_1x_coco.py | 4 +- .../detection/fcos/fcos_r50_torch_1x_pai.py | 114 ++++++++++++++++++ .../yolox/yolox_s_8xb16_300e_coco_pai.py | 20 ++- easycv/utils/config_tools.py | 5 + 5 files changed, 137 insertions(+), 19 deletions(-) create mode 100644 configs/detection/fcos/fcos_r50_torch_1x_pai.py diff --git a/configs/detection/fcos/coco_detection.py b/configs/detection/fcos/coco_detection.py index 902fca58..229711f7 100644 --- a/configs/detection/fcos/coco_detection.py +++ b/configs/detection/fcos/coco_detection.py @@ -20,12 +20,15 @@ train_img_prefix = data_root + 'train2017/' val_ann_file = data_root + 'annotations/instances_val2017.json' val_img_prefix = data_root + 'val2017/' +img_scale = (1333, 800) +data_type = 'DetSourceCoco' +test_batch_size = 1 img_norm_cfg = dict( mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) train_pipeline = [ - dict(type='MMResize', img_scale=(1333, 800), keep_ratio=True), + dict(type='MMResize', img_scale=img_scale, keep_ratio=True), dict(type='MMRandomFlip', flip_ratio=0.5), dict(type='MMNormalize', **img_norm_cfg), dict(type='MMPad', size_divisor=32), @@ -40,7 +43,7 @@ test_pipeline = [ dict( type='MMMultiScaleFlipAug', - img_scale=(1333, 800), + img_scale=img_scale, flip=False, transforms=[ dict(type='MMResize', keep_ratio=True), @@ -61,7 +64,7 @@ train_dataset = dict( type='DetDataset', data_source=dict( - type='DetSourceCoco', + type=data_type, ann_file=train_ann_file, img_prefix=train_img_prefix, pipeline=[ @@ -76,9 +79,9 @@ val_dataset = dict( type='DetDataset', - imgs_per_gpu=1, + imgs_per_gpu=test_batch_size, data_source=dict( - type='DetSourceCoco', + type=data_type, ann_file=val_ann_file, img_prefix=val_img_prefix, pipeline=[ diff --git a/configs/detection/fcos/fcos_r50_torch_1x_coco.py b/configs/detection/fcos/fcos_r50_torch_1x_coco.py index fc6dd4a7..b91da27d 100644 --- a/configs/detection/fcos/fcos_r50_torch_1x_coco.py +++ b/configs/detection/fcos/fcos_r50_torch_1x_coco.py @@ -1,10 +1,8 @@ _base_ = ['./fcos.py', './coco_detection.py', 'configs/base.py'] log_config = dict( - interval=50, - hooks=[ + interval=50, hooks=[ dict(type='TextLoggerHook'), - # dict(type='TensorboardLoggerHook') ]) checkpoint_config = dict(interval=10) diff --git a/configs/detection/fcos/fcos_r50_torch_1x_pai.py b/configs/detection/fcos/fcos_r50_torch_1x_pai.py new file mode 100644 index 00000000..50e8cd2b --- /dev/null +++ b/configs/detection/fcos/fcos_r50_torch_1x_pai.py @@ -0,0 +1,114 @@ +_base_ = ['./fcos.py', 'configs/base.py'] + +log_config = dict( + interval=50, hooks=[ + dict(type='TextLoggerHook'), + ]) + +checkpoint_config = dict(interval=10) +# optimizer +optimizer = dict( + type='SGD', + lr=0.01, + momentum=0.9, + weight_decay=0.0001, + paramwise_options=dict(bias_lr_mult=2., bias_decay_mult=0.)) +optimizer_config = dict(grad_clip=None) +# learning policy +lr_config = dict( + policy='step', + warmup='linear', + warmup_iters=500, + warmup_ratio=1.0 / 3, + warmup_by_epoch=False, + step=[8, 11]) + +total_epochs = 12 + +find_unused_parameters = False + +CLASSES = [ + 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', + 'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign', + 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', + 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', + 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', 'kite', + 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', + 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', + 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', + 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted plant', + 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', + 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', + 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', + 'hair drier', 'toothbrush' +] + +img_scale = (1333, 800) + +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) + +train_pipeline = [ + dict(type='MMResize', img_scale=img_scale, keep_ratio=True), + dict(type='MMRandomFlip', flip_ratio=0.5), + dict(type='MMNormalize', **img_norm_cfg), + dict(type='MMPad', size_divisor=32), + dict(type='DefaultFormatBundle'), + dict( + type='Collect', + keys=['img', 'gt_bboxes', 'gt_labels'], + meta_keys=('filename', 'ori_filename', 'ori_shape', 'ori_img_shape', + 'img_shape', 'pad_shape', 'scale_factor', 'flip', + 'flip_direction', 'img_norm_cfg')) +] +test_pipeline = [ + dict( + type='MMMultiScaleFlipAug', + img_scale=img_scale, + flip=False, + transforms=[ + dict(type='MMResize', keep_ratio=True), + dict(type='MMRandomFlip'), + dict(type='MMNormalize', **img_norm_cfg), + dict(type='MMPad', size_divisor=32), + dict(type='ImageToTensor', keys=['img']), + dict( + type='Collect', + keys=['img'], + meta_keys=('filename', 'ori_filename', 'ori_shape', + 'ori_img_shape', 'img_shape', 'pad_shape', + 'scale_factor', 'flip', 'flip_direction', + 'img_norm_cfg')) + ]) +] + +# dataset settings +data_type = 'DetSourcePAI' +train_path = 'data/coco/train2017.manifest' +val_path = 'data/coco/val2017.manifest' +test_batch_size = 1 + +train_dataset = dict( + type='DetDataset', + data_source=dict(type=data_type, path=train_path, classes=CLASSES), + pipeline=train_pipeline) + +val_dataset = dict( + type='DetDataset', + imgs_per_gpu=test_batch_size, + data_source=dict(type=data_type, path=val_path, classes=CLASSES), + pipeline=test_pipeline) + +data = dict( + imgs_per_gpu=2, workers_per_gpu=2, train=train_dataset, val=val_dataset) + +# evaluation +eval_config = dict(interval=1, gpu_collect=False) +eval_pipelines = [ + dict( + mode='test', + evaluators=[ + dict(type='CocoDetectionEvaluator', classes=CLASSES), + ], + ) +] diff --git a/configs/detection/yolox/yolox_s_8xb16_300e_coco_pai.py b/configs/detection/yolox/yolox_s_8xb16_300e_coco_pai.py index 1f509612..34f68ff0 100644 --- a/configs/detection/yolox/yolox_s_8xb16_300e_coco_pai.py +++ b/configs/detection/yolox/yolox_s_8xb16_300e_coco_pai.py @@ -62,24 +62,22 @@ dict(type='Collect', keys=['img']) ] +data_type = 'DetSourcePAI' +test_batch_size = 1 +train_path = 'data/coco/train2017.manifest' +val_path = 'data/coco/val2017.manifest' + # dataset settings -img_size = 640 train_dataset = dict( type='DetImagesMixDataset', - data_source=dict( - type='DetSourcePAI', - path='data/coco/train2017.manifest', - classes=CLASSES), + data_source=dict(type=data_type, path=train_path, classes=CLASSES), pipeline=train_pipeline, dynamic_scale=img_scale) val_dataset = dict( type='DetImagesMixDataset', - imgs_per_gpu=2, - data_source=dict( - type='DetSourcePAI', - path='data/coco/val2017.manifest', - classes=CLASSES), + imgs_per_gpu=test_batch_size, + data_source=dict(type=data_type, path=val_path, classes=CLASSES), pipeline=test_pipeline, dynamic_scale=None, label_padding=False) @@ -90,7 +88,7 @@ eval_pipelines = [ dict( mode='test', - data=data['val'], + data=val_dataset, evaluators=[dict(type='CocoDetectionEvaluator', classes=CLASSES)], ) ] diff --git a/easycv/utils/config_tools.py b/easycv/utils/config_tools.py index d0678e3b..b4a1bca2 100644 --- a/easycv/utils/config_tools.py +++ b/easycv/utils/config_tools.py @@ -525,6 +525,11 @@ def validate_export_config(cfg): # detection 'YOLOX': 'configs/config_templates/yolox.py', 'YOLOX_ITAG': 'configs/config_templates/yolox_itag.py', + 'YOLOX_ITAG_EASY': + 'configs/detection/yolox/yolox_s_8xb16_300e_coco_pai.py', + 'YOLOX_COCO_EASY': 'configs/detection/yolox/yolox_s_8xb16_300e_coco.py', + 'FCOS_ITAG_EASY': 'configs/detection/fcos/fcos_r50_torch_1x_pai.py', + 'FCOS_COCO_EASY': 'configs/detection/fcos/fcos_r50_torch_1x_coco.py', # ssl 'MOCO_R50_TFRECORD': 'configs/config_templates/moco_r50_tfrecord.py',