Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tutuorial of config #487

Merged
merged 17 commits into from
Oct 26, 2021
Merged

Add tutuorial of config #487

merged 17 commits into from
Oct 26, 2021

Conversation

Ezra-Yu
Copy link
Collaborator

@Ezra-Yu Ezra-Yu commented Oct 14, 2021

Motivation

Add tutuorial of config that let user kown the name suler of config, meanning of lines in config, and how to write a config.

Modification

Add tutuorial of config in doc and doc_zh_CN

Checklist

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, like docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects, like MMDet or MMSeg.
  • CLA has been signed and all committers have signed the CLA in this PR.

@codecov
Copy link

codecov bot commented Oct 14, 2021

Codecov Report

Merging #487 (47666d8) into master (10e8495) will increase coverage by 0.81%.
The diff coverage is 93.54%.

❗ Current head 47666d8 differs from pull request most recent head 6f3023a. Consider uploading reports for the commit 6f3023a to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #487      +/-   ##
==========================================
+ Coverage   77.96%   78.77%   +0.81%     
==========================================
  Files         102      103       +1     
  Lines        5619     5702      +83     
  Branches      923      927       +4     
==========================================
+ Hits         4381     4492     +111     
+ Misses       1111     1088      -23     
+ Partials      127      122       -5     
Flag Coverage Δ
unittests 78.77% <93.54%> (+0.81%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmcls/apis/train.py 22.72% <0.00%> (ø)
mmcls/models/backbones/resnet.py 100.00% <ø> (ø)
mmcls/models/backbones/vision_transformer.py 93.79% <92.03%> (+16.25%) ⬆️
mmcls/models/utils/attention.py 98.72% <92.85%> (-1.28%) ⬇️
mmcls/models/backbones/res2net.py 95.50% <95.50%> (ø)
mmcls/models/backbones/__init__.py 100.00% <100.00%> (ø)
mmcls/models/heads/vision_transformer_head.py 93.18% <100.00%> (+1.28%) ⬆️
mmcls/models/utils/__init__.py 100.00% <100.00%> (ø)
mmcls/utils/logger.py 100.00% <0.00%> (+25.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 10e8495...6f3023a. Read the comment docs.

@Ezra-Yu Ezra-Yu changed the title [WIP] Add tutuorial of config Add tutuorial of config Oct 19, 2021
@Ezra-Yu Ezra-Yu requested a review from mzr1996 October 19, 2021 10:05
@@ -0,0 +1,380 @@
# Tutorial 1:Learn about Configs

MMCls uses python files as configs. The design of our configuration file system integrates modularity and inheritance, facilitating users to conduct various experiments. All configuration files are placed in the `$MMCls/configs` folder, which mainly contains the original configuration folder of `_base_` and many algorithm folders such as `resnet`, `swin_transformer`, `vision_transformer`, etc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best to use MMClassification.
And we support not only python files, but YAML files and JSON files, which refer to mmcv docs, but the most common config format is python files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$MMcls is confusing and not necessary.


## Config File Naming Convention

We follow the below convention to name config files. Contributors are advised to follow the same style。The config file names are divided into four parts: model information, module information, training information and data information. Logically, different parts are concatenated by underscores `'_'`, and words in the same part are concatenated by dashes `'-'`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> .

docs/tutorials/config.md Outdated Show resolved Hide resolved
- `seresnext101-32x4d` : `SeResNet101` network structure, `32x4d` means that `groups` and `width_per_group` are 32 and 4 respectively in `Bottleneck`;

### module information
Refers to some special `neck`, `head` or `pretrain` information, which is commonly used as pretraining information in classification tash:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Refers to some special `neck`, `head` or `pretrain` information, which is commonly used as pretraining information in classification tash:
Some special `neck`, `head` and `pretrain` information. In classification tasks, `pretrain` information is the most commonly used:

- `training info`:Training information, some training schedule, including batch size, lr schedule, data augment and the like;
- `data info`:Data information, dataset name, input size and so on, such as imagenet, cifar;

### model information
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use upper case

Suggested change
### model information
### Model information

- `ft` : Configuration file for fine-tuning
- `pt` : Configuration file for pretraining

Training strategy information, the training strategy is based on the recurrence profile, and the basic training strategy does not need to be marked. However, if improvements are made on this basis, the training strategy needs to be indicated and arranged in the order, such as: `{pipeline aug}-{train aug}-{loss trick}-{scheduler}-{epochs}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Training strategy information, the training strategy is based on the recurrence profile, and the basic training strategy does not need to be marked. However, if improvements are made on this basis, the training strategy needs to be indicated and arranged in the order, such as: `{pipeline aug}-{train aug}-{loss trick}-{scheduler}-{epochs}`
Training recipe. Usually, only the part that is different from the original paper will be marked. These methods will be arranged in the order `{pipeline aug}-{train aug}-{loss trick}-{scheduler}-{epochs}`.

repvgg-D2se_deploy_4xb64-autoaug-lbs-mixup-coslr-200e_in1k.py
```

Among them, `repvgg-D2se` represents algorithm information, `RepVGG` model, `D2se` is structure information; `deploy` represents module information, and this model is in the inference state; `4xb64-autoaug-lbs-mixup-coslr-200e` represents training information, 4 GPUs, the number of batches per GPU is 64, using the `auto augment`, `label smooth` and `cosine scheduler` techniques to train 200 epoches; `in1k` is the data information, which means using `224x224` input image size to train in `ImageNet1k`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Among them, `repvgg-D2se` represents algorithm information, `RepVGG` model, `D2se` is structure information; `deploy` represents module information, and this model is in the inference state; `4xb64-autoaug-lbs-mixup-coslr-200e` represents training information, 4 GPUs, the number of batches per GPU is 64, using the `auto augment`, `label smooth` and `cosine scheduler` techniques to train 200 epoches; `in1k` is the data information, which means using `224x224` input image size to train in `ImageNet1k`.
- `repvgg-D2se`: Algorithm information
+ `repvgg`: The main algorithm.
+ `D2se`: The architecture.
- `deploy`: Module information, means the backbone is in the deploy state.
- `4xb64-autoaug-lbs-mixup-coslr-200e`: Training information.
+ `4xb64`: Use 4 GPUs and the size of batches per GPU is 64.
+ `autoaug`: Use `AutoAugment` in training pipeline.
+ `lbs`: Use label smoothing loss.
+ `mixup`: Use `mixup` training augment method.
+ `coslr`: Use cosine learning rate scheduler.
+ `200e`: Train the model for 200 epoches.
- `in1k`: Dataset information. The config is for `ImageNet1k` dataset and the input size is `224x224`.


## Config File Structure

There are four kind basic component file in the `configs/_base_` folder, namely:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
There are four kind basic component file in the `configs/_base_` folder, namely:
There are four kinds of basic component files in the `configs/_base_` folder, namely:

- [schedules](https://github.com/open-mmlab/mmclassification/tree/master/configs/_base_/schedules)
- [default_runtime](https://github.com/open-mmlab/mmclassification/blob/master/configs/_base_/default_runtime.py)

Many methods, such as ResNet, Swin_Transformer, ViT, RepVGG and etc, can be easily implemented by combining these components. The configs that are composed by components from `_base_` are called _primitive_.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use these components to implement ResNet or Swin-Transformer? I think it's a little misleading.

Suggested change
Many methods, such as ResNet, Swin_Transformer, ViT, RepVGG and etc, can be easily implemented by combining these components. The configs that are composed by components from `_base_` are called _primitive_.
You can easily build your own training config file by inherit some base config files. And the configs that are composed by components from `_base_` are called _primitive_.


Many methods, such as ResNet, Swin_Transformer, ViT, RepVGG and etc, can be easily implemented by combining these components. The configs that are composed by components from `_base_` are called _primitive_.

For easy understanding, we use [ResNet50 primitive config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnet/ resnet50_b32x8_imagenet.py) as a example and comment the meaning of each line. For more detaile, please refer to the API documentation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link is broken.

Copy link
Member

@mzr1996 mzr1996 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pay attention to modify the corresponding part of the Chinese documentation


### model
The parameter `"model"` is a python dictionary in the configuration file, which mainly includes information such as network structure and loss function:
- `type` : Classifier name, MMCls supports `ImageClassifier`, refer to [API 文档](https://mmclassification.readthedocs.io/zh_CN/latest/api.html#module-mmcls.models.classifiers)。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add a note about type? type is not an argument, but the class name. Many fresh users may confuse about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the link to English version

### model
The parameter `"model"` is a python dictionary in the configuration file, which mainly includes information such as network structure and loss function:
- `type` : Classifier name, MMCls supports `ImageClassifier`, refer to [API 文档](https://mmclassification.readthedocs.io/zh_CN/latest/api.html#module-mmcls.models.classifiers)。
- `backbone` : Backbones name, refer to [API document](https://github.com/open-mmlab/mmclassification/blob/master/mmcls/models/backbones) for available options.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backbones name -> Backbone configs

type='ImageClassifier', # Classifier name
backbone=dict(
type='ResNet', # Backbones name
depth=50, # depth of backbone, ResNet has optionsof 18, 34, 50, 101, 152.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> ,
optionsof -> options of

- `train | val | test` : construct dataset
- `type`: Dataset name, MMCls supports `ImageNet`, `Cifar` etc., refer to [API documentation](https://mmclassification.readthedocs.io/zh_CN/latest/api.html#module-mmcls.datasets)
- `data_prefix` : Dataset root directory
- `pipeline` : Data processing pipeline, refer to related tutorial documents [如何设计数据处理流水线](https://mmclassification.readthedocs.io/zh_CN/latest/tutorials/data_pipeline.html)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to English version

Comment on lines 223 to 224
dict(type='TextLoggerHook'), # The Tensorboard logger is also supported
# dict(type='TensorboardLoggerHook') # also support Tensorboard logger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeated comment


### Use some fields in the base configs

Sometimes, you can refer to some fields in the `__base__` config, so as to avoid duplication of definitions. You can refer to [mmcv](https://mmcv.readthedocs.io/en/latest/understand_mmcv/config.html#reference-variables-from-base) for some more instructions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_base_ instead of __base__


Sometimes, you can refer to some fields in the `__base__` config, so as to avoid duplication of definitions. You can refer to [mmcv](https://mmcv.readthedocs.io/en/latest/understand_mmcv/config.html#reference-variables-from-base) for some more instructions.

The following is a example of using `auto augment` in the training data preprocessing pipeline, refer to ["configs/_base_/datasets/imagenet_bs64_autoaug.py"](https://github.com/open-mmlab/mmclassification/blob/master/configs/_base_/datasets/imagenet_bs64_autoaug.py). When defining `train_pipeline`, just add the definition file name of `auto augment` to `__base__`, and then use `{{_base_.auto_increasing_policies}}` to reference the variables:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The following is a example of using `auto augment` in the training data preprocessing pipeline, refer to ["configs/_base_/datasets/imagenet_bs64_autoaug.py"](https://github.com/open-mmlab/mmclassification/blob/master/configs/_base_/datasets/imagenet_bs64_autoaug.py). When defining `train_pipeline`, just add the definition file name of `auto augment` to `__base__`, and then use `{{_base_.auto_increasing_policies}}` to reference the variables:
The following is an example of using `auto augment` in the training data preprocessing pipeline, refer to [`configs/_base_/datasets/imagenet_bs64_autoaug.py`](https://github.com/open-mmlab/mmclassification/blob/master/configs/_base_/datasets/imagenet_bs64_autoaug.py). When defining `train_pipeline`, just add the definition file name of `auto augment` to `_base_`, and then use `{{_base_.auto_increasing_policies}}` to reference the variables:

If use quotes, _base_ will be rendered as base.

- `type` : Classifier name, MMCls supports `ImageClassifier`, refer to [API 文档](https://mmclassification.readthedocs.io/zh_CN/latest/api.html#module-mmcls.models.classifiers)。
- `backbone` : Backbones name, refer to [API document](https://github.com/open-mmlab/mmclassification/blob/master/mmcls/models/backbones) for available options.
- `neck` :Neck network name, MMCls supports `GlobalAveragePooling`, please refer to [API documentation](https://mmclassification.readthedocs.io/zh_CN/latest/api.html#module-mmcls.models.necks).
-`head`: Head network name, MMCls supports single-label and multi-label classification head networks, available options refer to [API 文档](https://github.com/open-mmlab/mmclassification/blob/master/mmcls/models/heads).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to English version

@@ -0,0 +1,403 @@
# Tutorial 1:Learn about Configs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ':' instead of ":"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

docs/tutorials/config.md Outdated Show resolved Hide resolved
docs/tutorials/config.md Outdated Show resolved Hide resolved
docs/tutorials/config.md Outdated Show resolved Hide resolved
docs_zh-CN/tutorials/config.md Outdated Show resolved Hide resolved
Copy link
Member

@mzr1996 mzr1996 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mzr1996 mzr1996 merged commit 3a35b6f into open-mmlab:master Oct 26, 2021
@Ezra-Yu Ezra-Yu deleted the config branch October 27, 2021 03:25
mzr1996 added a commit to mzr1996/mmpretrain that referenced this pull request Nov 24, 2022
* add cn tutorials/config.md

* add heads api and doc title link

* Update tutorials index

* Update tutorials index

* Update config.md

* add english version

* Update config.md

* Update docs

* Update css

* Update docs/tutorials/config.md

Co-authored-by: Ma Zerun <[email protected]>

* Update docs_zh-CN/tutorials/config.md

Co-authored-by: Ma Zerun <[email protected]>

* modify according to suggestion

* Use GitHub style `code` css

* change some mmcv API link to CN version

* remove default in default_runtime

Co-authored-by: mzr1996 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants