Article Directory
Preface
Used to record mmdetection training and test your own data set (using mask-rcnn). The source code knowledge about mmdetection will be added later.
1. Use mmdetection to train and test Mask-Rcnn
mmdetection is a Pytorch-based deep learning target detection toolbox open sourced by Shangtang Technology (2018COCO Target Detection Challenge Champion) and the Chinese University of Hong Kong. It supports multiple target detection frameworks, such as Faster RCNN, Mask RCNN, and RetinaNet. Source code: mmdetection source code
The master branch works with PyTorch 1.3 to 1.6. The old v1.x branch works with PyTorch 1.1 to 1.4
1. Data set conversion
Most of the configuration files that come with mmdetection are in the COCO data set format by default. When using, convert your data and labels into coco data format. If it is a txt type annotation, first convert it to json and then to coco (see mask-rcnn tooth segmentation document for details)
2. Prepare the configuration file
mmdetection/configs/ contains the configuration files of multiple network models. Copy the required model files such as maskr_rcnn_r50_fpn_1x.py to a new wyk_configs folder, modify num_classes in the model dictionary, and num_classes=3,#类别数+1
modify img_scale: in the data dictionary img_scale=(540,960), #输入图像尺寸(train、val、test这三处都要修改)
. Copy a copy of mmdetection/mmdet/datasets/coco.py to wyk_configs and modify the categories in CLASSES.
For detailed modification, please refer to adding link description
3. Training
python tools/train.py configs/faster_rcnn_r50_fpn_1x.py --gpus 1 --validate --work_dir work_dirs
Optional parameters:
–validate: evaluate every k epochs, the default k is 1
–work-dir: the path to save the training results
–resume-from: if you interrupt, you can use this parameter to continue training, such as –resume-from work_dirs/ lastest.pt
4. Test
python tools/test.py ./configs/faster_rcnn_r50_fpn_1x.py ./work_dirs/cascade_rcnn_r50_c4_1x/latest.pth --eval mAP
./configs/faster_rcnn_r50_fpn_1x.py is the configuration file, ./work_dirs/cascade_rcnn_r50_c4_1x/latest.pth is the tested model file, and –eval mAP is the evaluation method
Two, mmdetection supplementary knowledge
The mmdetection model is mainly composed of the following four parts:
①backbone: usually a fully convolutional network such as ResNet for extracting feature map
②neck: connecting backbone and head part, such as FPN
③head: used for specific tasks such as bbox prediction, maskyuce, etc. module
④ROI extractor: extracting a feature from the feature map, such as ROI Align, RoIPooling etc.