MMDetection training custom data set

foreword

Because of the training plan and other reasons, I recently worked as an intern in a machine vision company. I am currently using the MMDetection framework. I want to try to use Mask-RCNN for custom (company) data set training and record the training process.

1. Dataset production

I use labelme. First, conda activates an environment (assuming it is openmmlab), pip install labelme, and starts in the environment after the installation is complete (directly enter labelme). The specific method of labeling the data set is skipped, it is relatively simple and the online tutorial is very friendly. After marking, a json file will be generated, which needs to be converted into a coco or voc file, but for training, it must be converted into a COCO dataset or a VOC dataset. The specific method is as follows: 1. Divide the dataset verification set, but the pictures cannot be saved
automatically 2
. Official to COCO dataset link
3. Official to VOC dataset link
4. Try his method next time when making a dataset
5. A note when labeling instances and segmenting datasets

Two, MMdetection training part

The official website custom data set method
is still in the imitation stage because of beginners. Refer to the official website to train the custom balloon data set. First, create a configuration file box_img in the configs folder, and create a py file in it. The file is named according to the format, and it can also be customized, as long as you are comfortable. code show as below:
insert image description here

# 官方文档里的配置代码
# 新配置继承了基本配置,并做了必要的修改
# 不同数据集他继承的文件也不一样
_base_ = '../mask_rcnn/mask-rcnn_r101_fpn_2x_coco.py'

# 我们还需要更改 head 中的 num_classes 以匹配数据集中的类别数
model = dict(
    roi_head=dict(
        bbox_head=dict(num_classes=1), mask_head=dict(num_classes=1)))

# 修改数据集相关配置
data_root = '../data/box_img/'
metainfo = {
    
    
    'classes': ('box', ),
    'palette': [
        (220, 20, 60),
    ]
}
# 根据自己放数据集的位置进行修改
train_dataloader = dict(
    batch_size=1,
    dataset=dict(
        data_root=data_root,
        metainfo=metainfo,
        ann_file='annotations/instances_train2017.json',
        data_prefix=dict(img='train2017/')))
val_dataloader = dict(
    dataset=dict(
        data_root=data_root,
        metainfo=metainfo,
        ann_file='annotations/instances_val2017.json',
        data_prefix=dict(img='val2017/')))
test_dataloader = val_dataloader

# 修改评价指标相关配置
val_evaluator = dict(ann_file=data_root + 'annotations/instances_val2017.json')
test_evaluator = val_evaluator

# 使用预训练的 Mask R-CNN 模型权重来做初始化,可以提高模型性能 他会下载到一个cache文件夹内,不知道在哪里改,强迫症犯了
load_from = 'https://download.openmmlab.com/mmdetection/v2.0/mask_rcnn/mask_rcnn_r101_fpn_2x_coco/mask_rcnn_r101_fpn_2x_coco_bbox_mAP-0.408__segm_mAP-0.366_20200505_071027-14b391c7.pth'

After that, you can run train.py, just add a few necessary parameters, and you don’t need to change the rest.
insert image description here
After starting the training, a time-named folder and a more detailed configuration file will be created in output/boxImg_maskRCNN_101, which is the py file in the figure below (epoch was generated during my last training process, and it is reasonable that it is not there yet)
insert image description here
Afterwards, in this file, the model is further modified, such as how many epochs are saved every time, what is the interval of log saving, etc. After modification, change the py file in the train configuration to the one above , re-run the train.py file, and start training.

3. Test part

There is not much to say, the test.py is quite detailed, just add configuration items according to the format
insert image description here

Guess you like

Origin blog.csdn.net/dashenfeng1/article/details/131825633