open-mmlab / mmdetection

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

Hi guys, do you have any fixed schema for your configurations? #1793

Closed petrochenko-pavel-a closed 3 years ago

petrochenko-pavel-a commented 4 years ago

Hi guys, we are working on the new open-source IDE for data science called Musket ML

And we are basing our instance segmentation tools on MM Detection - This is a demo

Typically we use YAML to represent our configurations, and ideally, we would like to map your configs into YAML files, but unfortunately, there is no schema or clear documentation which allows us to do it reliably, so for now, we are using half YAML, half Python way.

So the questions are:

Thanks in advance, Pavel

hellock commented 4 years ago

We adopt MMCV to parse the config file, which naturally supports python/yaml/json file types. You may use yaml to serve as configs and here is an example for testing.

# model settings
model:
    type: 'FasterRCNN'
    pretrained: 'open-mmlab://resnet50_caffe'
    backbone:
        type: 'ResNet'
        depth: 50
        num_stages: 4
        out_indices: !!python/tuple [0, 1, 2, 3]
        frozen_stages: 1
        norm_cfg:
            type: 'BN'
            requires_grad: False
        norm_eval: True
        style: 'caffe'
    neck:
        type: 'FPN'
        in_channels: [256, 512, 1024, 2048]
        out_channels: 256
        num_outs: 5
    rpn_head:
        type: 'RPNHead'
        in_channels: 256
        feat_channels: 256
        anchor_scales: [8]
        anchor_ratios: [0.5, 1.0, 2.0]
        anchor_strides: [4, 8, 16, 32, 64]
        target_means: [.0, .0, .0, .0]
        target_stds: [1.0, 1.0, 1.0, 1.0]
        loss_cls:
            type: 'CrossEntropyLoss'
            use_sigmoid: True
            loss_weight: 1.0
        loss_bbox:
            type: 'SmoothL1Loss'
            beta: 0.11111
            loss_weight: 1.0
    bbox_roi_extractor:
        type: 'SingleRoIExtractor'
        roi_layer:
            type: 'RoIAlign'
            out_size: 7
            sample_num: 2
        out_channels: 256
        featmap_strides: [4, 8, 16, 32]
    bbox_head:
        type: 'SharedFCBBoxHead'
        num_fcs: 2
        in_channels: 256
        fc_out_channels: 1024
        roi_feat_size: 7
        num_classes: 81
        target_means: [0., 0., 0., 0.]
        target_stds: [0.1, 0.1, 0.2, 0.2]
        reg_class_agnostic: False
        loss_cls:
            type: 'CrossEntropyLoss'
            use_sigmoid: False
            loss_weight: 1.0
        loss_bbox:
            type: 'SmoothL1Loss'
            beta: 1.0
            loss_weight: 1.0
# model training and testing settings
test_cfg:
    rpn:
        nms_across_levels: False
        nms_pre: 1000
        nms_post: 1000
        max_num: 1000
        nms_thr: 0.7
        min_bbox_size: 0
    rcnn:
        score_thr: 0.05
        nms:
            type: 'nms'
            iou_thr: 0.5
        max_per_img: 100
# dataset settings
dataset_type: 'CocoDataset'
data_root: 'data/coco/'
img_norm_cfg:
    mean: [102.9801, 115.9465, 122.7717]
    std: [1.0, 1.0, 1.0]
    to_rgb: False
train_pipeline: &train_pipeline
    - type: 'LoadImageFromFile'
    - type: 'LoadAnnotations'
      with_bbox: True
    - type: 'Resize'
      img_scale: !!python/tuple [1333, 800]
      keep_ratio: True
    - type: 'RandomFlip'
      flip_ratio: 0.5
    - type: 'Normalize'
      mean: [102.9801, 115.9465, 122.7717]
      std: [1.0, 1.0, 1.0]
      to_rgb: False
    - type: 'Pad'
      size_divisor: 32
    - type: 'DefaultFormatBundle'
    - type: 'Collect'
      keys: ['img', 'gt_bboxes', 'gt_labels']
test_pipeline: &test_pipeline
    - type: 'LoadImageFromFile'
    - type: 'MultiScaleFlipAug'
      img_scale: !!python/tuple [1000, 600]
      flip: False
      transforms:
        - {type: 'Resize', keep_ratio: True}
        - {type: 'RandomFlip'}
        - {type: 'Normalize', mean: [102.9801, 115.9465, 122.7717], std: [1.0, 1.0, 1.0], to_rgb: False}
        - {type: 'Pad', size_divisor: 32}
        - {type: 'ImageToTensor', keys: ['img']}
        - {type: 'Collect', keys: ['img']}
data:
    imgs_per_gpu: 2
    workers_per_gpu: 2
    train:
        type: 'CocoDataset'
        ann_file: 'data/coco/annotations/instances_train2017.json'
        img_prefix: 'data/coco/train2017/'
        pipeline: *train_pipeline
    val:
        type: 'CocoDataset'
        ann_file: 'data/coco/annotations/instances_val2017.json'
        img_prefix: 'data/coco/val2017/'
        pipeline: *test_pipeline
    test:
        type: 'CocoDataset'
        ann_file: 'data/coco/annotations/instances_val2017.json'
        img_prefix: 'data/coco/val2017/'
        pipeline: *test_pipeline
petrochenko-pavel-a commented 4 years ago

This sounds, pretty cool. But we want to support validation and content assist for config files, so we need a way to discover a set of configuration options that are available in context. So we need some kind of schema that describes them.

Thanks in advance, Pavel

hellock commented 4 years ago

There is not a fixed scheme since different models can have different config fields. However, there are some common top-level fields, such as model, train_cfg, test_cfg, data. It may not be easy to have some schema, but you may share some idea or expectations and we can see if it is possible.

petrochenko-pavel-a commented 4 years ago

Hi @hellock

One thought that we have is that we can generate schema basing on the options that are used in existing configs. (It is less or more error prone, but it is doable). We will be glad to implement and contribute it, but I am 100% sure that we can not check and maintain it.

Another option is to annotate code with decorators, so it will be possible to generate schema from existing models code. And again we will be glad to do it, but we will not be able to check it for correctness.

So some body who has better knowledge of code base will be needed to ensure that it is done ok.

Regards, Pavel