Closed kingbirdWc closed 3 years ago
训练报错 KeyError: 'YOLOX: \'cfg or default_args must contain the key "type", but got {\\'deepen_factor\\': 1.0, \\'widen_factor\\': 1.0}\nNone\''
cfg
default_args
我的配置文件如下: `base = ['../base/schedules/schedule_1x.py', '../base/default_runtime.py']
model = dict( type='YOLOX', backbone=dict(deepen_factor=1.0, widen_factor=1.0), neck=dict( in_channels=[256, 512, 1024], out_channels=256, num_csp_blocks=3), bbox_head=dict(in_channels=256, feat_channels=256), train_cfg=dict(assigner=dict(type='SimOTAAssigner', center_radius=2.5)),
# 0.01, and the threshold of the test phase is 0.001. test_cfg=dict(score_thr=0.01, nms=dict(type='nms', iou_threshold=0.65)))
data_root = '/home/wang/mycode/elec_coco/' dataset_type = 'CocoDataset'
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.1, 2), border=(-img_scale[0] // 2, -img_scale[1] // 2)), dict( type='MixUp', img_scale=img_scale, ratio_range=(0.8, 1.6), pad_val=114.0), 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']) ] classes = ("factory",) train_dataset = dict( type='MultiImageMixDataset', dataset=dict( type=dataset_type, classes = classes, ann_file=data_root + 'train.json', img_prefix=data_root + 'images/', pipeline=[ dict(type='LoadImageFromFile', to_float32=True), dict(type='LoadAnnotations', with_bbox=True) ], filter_empty_gt=False, ), pipeline=train_pipeline, dynamic_scale=img_scale)
test_pipeline = [ dict(type='LoadImageFromFile'), dict( type='MultiScaleFlipAug', img_scale=img_scale, flip=False, transforms=[ dict(type='Resize', keep_ratio=True), dict(type='RandomFlip'), dict(type='Pad', size=img_scale, pad_val=114.0), dict(type='Normalize', **img_norm_cfg), dict(type='DefaultFormatBundle'), dict(type='Collect', keys=['img']) ]) ]
data = dict( samples_per_gpu=4, workers_per_gpu=2, train=train_dataset, classes = classes, val=dict( type=dataset_type, ann_file=data_root + 'valid.json', img_prefix=data_root + 'images/', pipeline=test_pipeline), test=dict( type=dataset_type, ann_file=data_root + 'valid.json', img_prefix=data_root + 'images/', pipeline=test_pipeline))
optimizer = dict( type='SGD', lr=0.01, momentum=0.9, weight_decay=5e-4, nesterov=True, paramwise_cfg=dict(norm_decay_mult=0., bias_decay_mult=0.)) optimizer_config = dict(grad_clip=None)
lr_config = dict( delete=True, policy='YOLOX', warmup='exp', by_epoch=False, warmup_by_epoch=True, warmup_ratio=1, warmup_iters=5, # 5 epoch num_last_epochs=15, min_lr_ratio=0.005) runner = dict(type='EpochBasedRunner', max_epochs=300)
resume_from = None interval = 10
custom_hooks = [ dict(type='YOLOXModeSwitchHook', num_last_epochs=15, priority=48), dict( type='SyncRandomSizeHook', ratio_range=(14, 26), img_scale=img_scale, interval=interval, priority=48), dict( type='SyncNormHook', num_last_epochs=15, interval=interval, priority=48), dict(type='ExpMomentumEMAHook', resume_from=resume_from, priority=49) ] checkpoint_config = dict(interval=interval) evaluation = dict(interval=interval, metric='bbox') log_config = dict(interval=50) `
不好意思我改错了
我也遇到这个问题了 你咋解决的
训练报错 KeyError: 'YOLOX: \'
cfg
ordefault_args
must contain the key "type", but got {\\'deepen_factor\\': 1.0, \\'widen_factor\\': 1.0}\nNone\''我的配置文件如下: `base = ['../base/schedules/schedule_1x.py', '../base/default_runtime.py']
model settings
model = dict( type='YOLOX', backbone=dict(deepen_factor=1.0, widen_factor=1.0), neck=dict( in_channels=[256, 512, 1024], out_channels=256, num_csp_blocks=3), bbox_head=dict(in_channels=256, feat_channels=256), train_cfg=dict(assigner=dict(type='SimOTAAssigner', center_radius=2.5)),
In order to align the source code, the threshold of the val phase is
dataset settings
data_root = '/home/wang/mycode/elec_coco/' dataset_type = 'CocoDataset'
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.1, 2), border=(-img_scale[0] // 2, -img_scale[1] // 2)), dict( type='MixUp', img_scale=img_scale, ratio_range=(0.8, 1.6), pad_val=114.0), 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']) ] classes = ("factory",) train_dataset = dict( type='MultiImageMixDataset', dataset=dict( type=dataset_type, classes = classes, ann_file=data_root + 'train.json', img_prefix=data_root + 'images/', pipeline=[ dict(type='LoadImageFromFile', to_float32=True), dict(type='LoadAnnotations', with_bbox=True) ], filter_empty_gt=False, ), pipeline=train_pipeline, dynamic_scale=img_scale)
test_pipeline = [ dict(type='LoadImageFromFile'), dict( type='MultiScaleFlipAug', img_scale=img_scale, flip=False, transforms=[ dict(type='Resize', keep_ratio=True), dict(type='RandomFlip'), dict(type='Pad', size=img_scale, pad_val=114.0), dict(type='Normalize', **img_norm_cfg), dict(type='DefaultFormatBundle'), dict(type='Collect', keys=['img']) ]) ]
data = dict( samples_per_gpu=4, workers_per_gpu=2, train=train_dataset, classes = classes, val=dict( type=dataset_type, ann_file=data_root + 'valid.json', img_prefix=data_root + 'images/', pipeline=test_pipeline), test=dict( type=dataset_type, ann_file=data_root + 'valid.json', img_prefix=data_root + 'images/', pipeline=test_pipeline))
optimizer
default 8 gpu
optimizer = dict( type='SGD', lr=0.01, momentum=0.9, weight_decay=5e-4, nesterov=True, paramwise_cfg=dict(norm_decay_mult=0., bias_decay_mult=0.)) optimizer_config = dict(grad_clip=None)
learning policy
lr_config = dict( delete=True, policy='YOLOX', warmup='exp', by_epoch=False, warmup_by_epoch=True, warmup_ratio=1, warmup_iters=5, # 5 epoch num_last_epochs=15, min_lr_ratio=0.005) runner = dict(type='EpochBasedRunner', max_epochs=300)
resume_from = None interval = 10
custom_hooks = [ dict(type='YOLOXModeSwitchHook', num_last_epochs=15, priority=48), dict( type='SyncRandomSizeHook', ratio_range=(14, 26), img_scale=img_scale, interval=interval, priority=48), dict( type='SyncNormHook', num_last_epochs=15, interval=interval, priority=48), dict(type='ExpMomentumEMAHook', resume_from=resume_from, priority=49) ] checkpoint_config = dict(interval=interval) evaluation = dict(interval=interval, metric='bbox') log_config = dict(interval=50) `