mmdetection的一些使用记录

mmdetection 训练自己的模型

COCO数据集格式:

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

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

需要修改的地方在mmdetection/mmdet/datasets/coco.py。把CLASSES的那个tuple改为自己数据集对应的种类tuple。
在mmdetection/mmdet/core/evaluation/class_names.py修改coco_classes数据集类别,这个关系到后面test的时候结果图中显示的类别名称
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'''

    samples_per_gpu=8,
    workers_per_gpu=8,

    samples_per_gpu=8,
    workers_per_gpu=8,

    optimizer = dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001)

    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

多GPU训练(以两张卡为例)

bash tools/dist_test.sh ${CONFIG_FILE} ${CHECKPOINT_FILE} ${GPU_NUM} [--out ${RESULT_FILE}] [--eval ${EVAL_METRICS}]
bash tools/dist_test.sh  configs/fcos/fcos_x101_64x4d_fpn_gn-head_mstrain_640-800_2x_coco.py 2 --work-dir logs/fcos

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

--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,可做以下修改:


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

Original: https://blog.csdn.net/qq_42145862/article/details/124724849
Author: SmallSweetWang
Title: mmdetection的一些使用记录

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/681173/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球