-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Support using variables in base config directly as normal variables. #1651
base: master
Are you sure you want to change the base?
Conversation
0193d0a
to
546a366
Compare
Need to add test to show case the new features |
mmcv/utils/config.py
Outdated
with open(temp_config_file.name, 'r') as f: | ||
content = f.read() | ||
codeobj = compile(content, '', mode='exec') | ||
eval(codeobj, base_cfg_dict, cfg_dict) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, these interval variables will be removed after merged in to the cfg_dict in line 272-276
cfg_dict = {
k: v
for k, v in cfg_dict.items() if not k.startswith('__')
}
546a366
to
1716d5d
Compare
Done |
_base_ = './base.py'
list_variable[1] = 5
x, y = tuple_variable
dict_variable = dict(
a=dict(third=3, _delete_=True),
b=dict(third=3)
) Does the usage of Would the follow design be more appropriate? _base_ = './base.py'
_base_.list_variable[1] = 5
x, y = tuple_variable
dict_variable = dict(
a=dict(third=3, _delete_=True),
b=dict(third=3)
) |
Sounds good, I will try it. |
Done, and the usage and the unit tests are updated. |
We also need to add the example in the following documentation. |
In the doc, don't forget to mark it as python-config-only feature. |
Motivation
A config feature improvement draft. You can directly use the variables in the base config as normal variables virtually in the Python format config file.
Modification
Parse the base config before loading the entire config file. And use
eval
instead ofimport_module
to load configs.BC-breaking (Optional)
Should be no BC-breaking. It can pass the original unit tests. But please check it carefully.
Use cases (Optional)
base.py
:final.py
:Checklist
Before PR:
After PR: