一文了解mmdetection中的–cfg-options
--cfg-options
是用于在命令行中设置mmdetection配置文件的选项。它允许您以键值对的形式覆盖配置文件中的选项。
以下是使用--cfg-options
的示例:
python tools/train.py ${CONFIG_FILE} --cfg-options \
optimizer.lr=0.02 \
optimizer.weight_decay=0.0001 \
runtime.total_epochs=12
此命令将使用给定的${CONFIG_FILE}
作为基础配置,并覆盖三个选项:optimizer.lr
,optimizer.weight_decay
和runtime.total_epochs
。
其中,optimizer.lr
和optimizer.weight_decay
是优化器的超参数,runtime.total_epochs
是训练总轮数。
您可以将任意数量的选项传递给--cfg-options
,每个选项之间使用空格分隔。如果选项值包含空格,则应使用双引号将其括起来。
请注意,这些设置将优先于配置文件中的设置。因此,在覆盖选项时,最好了解配置文件中定义的默认值。
优化器修改
配置文件:
optim_wrapper = dict(type=‘OptimWrapper’,
optimizer=dict(type=‘Adam’,
lr=0.0003,
weight_decay=0.0001))
将优化器使用命令行修改配置文件
python tools/train.py configs/my_config.py
--cfg-options optim_wrapper.optimizer.type=‘Adam’
optim_wrapper.optimizer.lr=0.0003
学习率策略修改
配置文件:
param_scheduler = [
dict(type='LinearLR',
start_factor=0.001,
by_epoch=False,
begin=0,
end=500),
dict(type='MultiStepLR',
begin=0,
end=24,
by_epoch=True,
milestones=[16, 22],
gamma=0.1)
]
将学习率策略使用命令行修改配置文件
python tools/train.py configs/my_config.py
–cfg-options param_scheduler.0.start_factor=0.01
param_scheduler.1.milestones="[12, 18]"
设置训练轮数
配置文件:
train_cfg = dict(type='EpochBasedTrainLoop', max_epochs=24, val_interval=1)
将训练轮数使用命令行修改配置文件
python tools/train.py configs/my_config.py
–cfg-options train_cfg.max_epochs=100