I. Environment configuration

1.1 Related Addresses

  • Code address: github.com/open-mmlab/…
  • Address: document mmdetection. Readthedocs. IO/zh_CN/lates…

1.2 Installing the Environment on Linux

conda create -n open-mmlab python=3.7 -y
conda activate open-mmlab

conda install pytorch==1.6. 0 torchvision==0.7. 0 cudatoolkit=10.1 -c pytorch -y

Install the latest version of MMCV
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu101/torch16.. 0/index.html

# installation MMDetection
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
pip install -r requirements/build.txt
pip install -v -e .
Copy the code

1.3 Checking whether the installation is successful

  • Changing hardware

Download FasterRCNN checkpoint file, put it at checkpoints folder download.openmmlab.com/mmdetection…

  • Run the inference code to see if it succeeds

from mmdet.apis import init_detector, inference_detector
import mmcv

# specify the model configuration file and checkpoint file path
config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'

Build a model based on configuration files and checkpoint files
model = init_detector(config_file, checkpoint_file, device='cuda:0')

# Test a single image and show the results
img = 'test.jpg'  # or img = mmcv.imread(img), the image will be read only once
result = inference_detector(model, img)
Visualize the results in a new window
model.show_result(img, result)
Or save the visualizations as images
model.show_result(img, result, out_file='result.jpg')
Copy the code

Ii. Training standard data set

2.1 VOC data set download and preparation

  • Location of data set

Mmdetection ├ ─ ─ mmdet ├ ─ ─ the tools ├ ─ ─ configs ├ ─ ─ data │ ├ ─ ─ VOCdevkit │ │ ├ ─ ─ VOC2007 │ │ ├ ─ ─ VOC2012Copy the code
  • Data set download

   # VOC2012
   wget http://pjreddie.com/media/files/VOCtrainval_11-May-2012.tar 
   tar -xvf VOCtrainval_11-May-2012.tar && rm VOCtrainval_11-May-2012.tar 
   wget http://pjreddie.com/media/files/VOC2012test.tar 
   tar -xvf VOC2012test.tar 
   rm VOC2012test.tar mv VOCdevkit/VOC2012/ ./
   # VOC2007
   wget http://pjreddie.com/media/files/VOCtrainval_06-Nov-2007.tar
   tar -xvf VOCtrainval_06-Nov-2007.tar 
   rm VOCtrainval_06-Nov-2007.tar 
   wget http://pjreddie.com/media/files/VOCtest_06-Nov-2007.tar 
   tar -xvf VOCtest_06-Nov-2007.tar && rm VOCtest_06-Nov-2007.tar 
   mv VOCdevkit/VOC2007/ ./ 
   rm -rf VOCdevkit
Copy the code

2.2 Data set training

   python tools/train.py configs/pascal_voc/faster_rcnn_r50_fpn_1x_voc0712.py
Copy the code

3. Train your own data set

3.1 Data set Preparation

Mmdetection ├ ─ ─ mmdet ├ ─ ─ the tools ├ ─ ─ configs ├ ─ ─ data │ ├ ─ ─ VOCdevkit │ │ ├ ─ ─ VOC2007 | | │ ├ ─ ─ Annotations | | │ ├ ─ ─ ImageSets | | │ ├ ─ ─ JPEGImages | | │ ├ ─ ─ SegmentationClass | | │ ├ ─ ─ SegementationObject │ │ ├ ─ ─ VOC2012Copy the code

3.2 File Modification

  • Modified the category configuration file

Modify mmdetection/mmdet/datasets/voc. Py and mmdetection/mmdet/core/evaluation/class_names category under the py, it changed to category name to the training data set.

  • Model configuration file modification

1. Modify the mmdetection/configs/pascal_voc/faster_rcnn_r50_fpn_1x_voc0712 py num_classeses for training data set in the number of categories



2. Modify mmdetection/configs /base/models/faster_rcnn_r50_fpn.py in num_classeses is the number of categories of the dataset to be trained

  • Data set configuration file modification

Without VOC2012 file, you need to delete the dataset of VOC2012 Settings, its location is mmdetection/configs/base/datasets/voc0712 py

3.3 training

   python tools/train.py configs/pascal_voc/faster_rcnn_r50_fpn_1x_voc0712.py
Copy the code