open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.57k stars 9.46k forks source link

Looking for a complete tutorial for starting from a scratch workflow #3880

Closed colt18 closed 3 years ago

colt18 commented 4 years ago

I used matterport-mrcnn and detectron2 in the last couple of months so far and quite acquainted to the workflow (prepping datasets, configs , training an so on). However I seem to struggle with mmdetection probably I can't concentrate on to it after them. Reacthedocs and colab tutorials seems to cover a lot but I just can't merge them into something useful.

Here is what I have and need to accomplish:

  1. I do have a coco annotated json files for train and valid sets for instance segmentation.
  2. I want to train a mask rcnn model for instance segmentation lets say r101-fpn.

I'm much confused about customdataset class, dataset registration and configs. Initially, do I have to create a new dataset as indicated here? Or is it just for non coco datasets preprocessing stuff. Do I have to register my database by creating a py file in dataset folder or can I do it under main config file.

Actually what I need is a complete example of workflow from scratch that involves dataset creation or registration, config setting and training routine. I heard many times that indeed mmdet is an easy to learn and flexible to implement framework but looks like I'm not able to find my way inside.

Thanks.

ZwwWayne commented 4 years ago

Hi @colt18 , Thanks for your kind suggestion. We are reorganizing the documentation, which may be released in v2.6.0, your suggestion and question are very valuable for us.

Since there will be a while before the new release of documentation, here is the answer to your question:

  1. If you have coco annotated JSON files, you do not need to implement a new dataset because you can directly use the CocoDataset in your config. For the dataset, you only need to modify the paths related to your annotation and data including ann_file, img_prefix, and classes.
  2. As for the model, after modifying the dataset, you only need to modify the num_classes in box head and mask head.

Here is an example of the config for your case:

_base_ = [
    '../_base_/models/mask_rcnn_r50_fpn.py',
    '../_base_/datasets/coco_instance.py',
    '../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py'
]
# Use r101 model
model = dict(
    pretrained='torchvision://resnet101',
    backbone=dict(depth=101),
    roi_head=dict(
        bbox_head=dict(num_classes=N),
        mask_head=dict(num_classes=N)))

classes = ('a', 'b', 'c')
data = dict(
    train=dict(
        ann_file='path/to/your/annotation',
        img_prefix='root path/to/your/image'
        classes=classes),
    val=dict(
        ann_file='path/to/your/annotation',
        img_prefix='root path/to/your/image'
        classes=classes),
    test=dict(
        ann_file='path/to/your/data',
        img_prefix='root path/to/your/image'
        classes=classes))

# in case you want to use mask r101 pretrain
load_from = 'http://download.openmmlab.com/mmdetection/v2.0/mask_rcnn/mask_rcnn_r101_fpn_1x_coco/mask_rcnn_r101_fpn_1x_coco_20200204-1efe0ed5.pth'  # noqa

With this config, you should be able to train mask r101 on your own dataset without any further modification.

Hope it helps and feel free to ask if you have any further questions.

ZwwWayne commented 3 years ago

As the documentation have been refactored, now we have quick run sections for training and testing models on existing datasets or on customized datasets.