mmdetection的一些使用记录

mmdetection 训练自己的模型

COCO数据集格式:

mmdetection
├── mmdet
├── tools
├── configs
├── data
│   ├── coco
│   │   ├── annotations
│   │   ├── train2017
│   │   ├── val2017
│   │   ├── test2017

修改类别数:(以一个类别为例)

  1. 修改CLASSES
需要修改的地方在mmdetection/mmdet/datasets/coco.py。把CLASSES的那个tuple改为自己数据集对应的种类tuple。
  1. 修改coco_classes
在mmdetection/mmdet/core/evaluation/class_names.py修改coco_classes数据集类别,这个关系到后面test的时候结果图中显示的类别名称
  1. 修改num_classes(以fcos为例)
model = dict(
    bbox_head=dict(
    num_classes=1
    )
)

修改batch_size、learning rate(以batch_size16为例)

'''lr=0.005 for 2 GPUs * 2 imgs/gpu (batch size = 2*2 = 4)
lr=0.01 for 4 GPUs * 2 imgs/gpu (batch size = 4*2 = 8)
lr=0.02 for 8 GPUs and 2 img/gpu (batch size = 8*2 = 16)
lr=0.08 for 16 GPUs * 4 imgs/gpu (batch size = 16*4 = 64)
....
lr = 0.0125*batch_size'''
# 1.修改batch_size
	# (1)mmdetection-master/configs/_base_/datasets/coco_instance.py
	samples_per_gpu=8, # 单个 GPU 测试时的 Batch size
    workers_per_gpu=8, # 单个 GPU 分配的数据加载线程数
	# (2)mmdetection-master/configs/fcos/fcos_x101_64x4d_fpn_gn-head_mstrain_640-800_2x_coco.py
	samples_per_gpu=8, # 单个 GPU 测试时的 Batch size
    workers_per_gpu=8, # 单个 GPU 分配的数据加载线程数
# 2.修改学习率
	# (1) mmdetection-master/configs/_base_/schedules/schedule_1x.py
	optimizer = dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001)
	# (2)mmdetection-master/configs/fcos/fcos_x101_64x4d_fpn_gn-head_mstrain_640-800_2x_coco.py
	runner = dict(type='EpochBasedRunner', max_epochs=33)

修改epoch

1. 修改mmdetection-master/configs/_base_/schedules/schedule_1x.py中的max_epochs
2. 修改mmdetection-master/configs/fcos/fcos_x101_64x4d_fpn_gn-head_mstrain_640-800_2x_coco.py中的max_epochs

以fcos为例:

python tools/train.py configs/fcos/fcos_x101_64x4d_fpn_gn-head_mstrain_640-800_2x_coco.py --work-dir logs/fcos

若需指定使用某张显卡再在以上命令前添加:

CUDA_VISIBLE_DEVICES=卡的id

若需边训练边输出验证结果:

--no-validate False

mmdetection 中断训练后继续训练

以fcos为例:

python tools/train.py configs/fcos/fcos_x101_64x4d_fpn_gn-head_mstrain_640-800_2x_coco.py --work-dir logs/fcos--resume-from logs/fcos/latest.pth

mmdetection测试自己的模型

代码中没有FPS计算的部分,若需要得到FPS,可做以下修改:

# 将mmdetection-master/mmdet/apis/test.py中的result = model(return_loss=False, rescale=True, **data)修改为:
torch.cuda.synchronize()
start = time.time()
result = model(return_loss=False, rescale=True, **data)
torch.cuda.synchronize()
end = time.time()
total_time = total_time+(end - start)
print("   inference: ",end - start, "s")

多张图片

python tools/test.py configs/fcos/fcos_x101_64x4d_fpn_gn-head_mstrain_640-800_2x_coco.py logs/fcos/latest.pth --work-dir testOut/fcos --show-dir  testOut/fcos/Img --eval bbox

视频

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
青葱年少的头像青葱年少普通用户
上一篇 2022年5月13日
下一篇 2022年5月13日

相关推荐