Skip to content

Commit

Permalink
[WIP]Features/add yolo 20230301 (alibaba#297)
Browse files Browse the repository at this point in the history
add fcos and yolox pai_config
  • Loading branch information
liaogulou authored Mar 6, 2023
1 parent 5c33d9e commit d8f59a2
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 19 deletions.
13 changes: 8 additions & 5 deletions configs/detection/fcos/coco_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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=[
Expand All @@ -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=[
Expand Down
4 changes: 1 addition & 3 deletions configs/detection/fcos/fcos_r50_torch_1x_coco.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
114 changes: 114 additions & 0 deletions configs/detection/fcos/fcos_r50_torch_1x_pai.py
Original file line number Diff line number Diff line change
@@ -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),
],
)
]
20 changes: 9 additions & 11 deletions configs/detection/yolox/yolox_s_8xb16_300e_coco_pai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -90,7 +88,7 @@
eval_pipelines = [
dict(
mode='test',
data=data['val'],
data=val_dataset,
evaluators=[dict(type='CocoDetectionEvaluator', classes=CLASSES)],
)
]
5 changes: 5 additions & 0 deletions easycv/utils/config_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit d8f59a2

Please sign in to comment.