mmcv icon indicating copy to clipboard operation
mmcv copied to clipboard

Support environment variables in config

Open innerlee opened this issue 3 years ago • 8 comments

Motivation

Use environment variable to dynamically change parts of the config. Kind of a template functionality.

Modification

Please briefly describe what modification is made in this PR.

BC-breaking (Optional)

no breaking change.

Use cases (Optional)

If you want to test many datasets on a checkpoint, and the only difference is the dataset path, then you can use environment variable as a placeholder. No need to create many configs anymore.

Before:

cfg1.py

...
data_root = 'data/dataset1'
...

cfg2.py

...
data_root = 'data/dataset2'
...

After:

cfg.py

...
data_root = '{{ _env_.DATA_ROOT }}'
...

Checklist

Tests and docs will be added later. Lets see the general reaction first.

Before PR:

  • [x] I have read and followed the workflow indicated in the CONTRIBUTING.md to create this PR.
  • [x] Pre-commit or linting tools indicated in CONTRIBUTING.md are used to fix the potential lint issues.
  • [x] Bug fixes are covered by unit tests, the case that causes the bug should be added in the unit tests.
  • [ ] New functionalities are covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • [ ] The documentation has been modified accordingly, including docstring or example tutorials.

After PR:

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

innerlee avatar Dec 07 '21 09:12 innerlee

Hi @innerlee , you can merge the upstream master to your branch to fix the error of building documentation

zhouzaida avatar Dec 07 '21 12:12 zhouzaida

https://mmdetection.readthedocs.io/en/latest/1_exist_data_model.html image

Can we use the merge_from_dict to implement the same behavior like --cfg-options checkpoint_config.max_keep_ckpts=1 https://github.com/open-mmlab/mmcv/blob/44e7eee835c3bc138ee0f667228777eca3db1a17/mmcv/utils/config.py#L550

zhouzaida avatar Dec 08 '21 08:12 zhouzaida

  • For simple replacement, yes. But the --cfg-options thing is verbose and hard to use
  • For complex cfgs such as multiple references, the --cfg-options is not powerful enough. Try this example:

image

innerlee avatar Dec 09 '21 02:12 innerlee

  • For simple replacement, yes. But the --cfg-options thing is verbose and hard to use
  • For complex cfgs such as multiple references, the --cfg-options is not powerful enough. Try this example:

image

Got it. Great feature.

zhouzaida avatar Dec 09 '21 02:12 zhouzaida

We also need to update the usage of Config (https://mmcv.readthedocs.io/en/latest/understand_mmcv/config.html) and add some unit tests for the feature.

zhouzaida avatar Dec 09 '21 03:12 zhouzaida

Hi @innerlee , is there any progress?

zhouzaida avatar Dec 20 '21 13:12 zhouzaida

Sorry being busy. Will complete it when I got time

innerlee avatar Dec 21 '21 08:12 innerlee

Hi, is any progess?

zhouzaida avatar Apr 30 '22 01:04 zhouzaida