我想按照Hydra文档中的通用模式使用专门的配置->专业配置。不同之处在于,我的专门配置是在一个文件中,而不仅仅是一个变量。在下面的例子中,我想选择基于模型和数据集的转换。不同转换的配置都在文件中。如果我在dataset_model/cifar10_alexnet中指定所有转换配置,这将起作用。yaml文件,但是那样会破坏目的,因为在这种情况下我不能重用转换配置。在Hydra的其他地方,如果你指定文件名,它会自动拾取该文件中的配置,但它似乎不能在专门的配置中工作。
我已经将文档中的示例修改如下:
config.yaml:
defaults:
- dataset: cifar10
- model: alexnet
- transform: crop
- dataset_model: ${defaults.0.dataset}_${defaults.1.model}
optional: true
添加名为transform的目录和目录下的两个文件:
crop.yaml:
# @package _group_
type: crop
test1: 7
resize.yaml:
# @package _group_
type: resize
test1: 50
更改文件dataset_model/cifar10_alexnet.yaml:
# @package _global_
model:
num_layers: 5
transform: resize
其他一切都完全按照文档。当我运行这个时,我得到一个异常:
Traceback (most recent call last):
File "/home/natalia/.pyenv/versions/3.7.9/lib/python3.7/site-packages/hydra/_internal/config_loader_impl.py", line 720, in _merge_config
ret = OmegaConf.merge(cfg, loaded_cfg)
File "/home/natalia/.pyenv/versions/3.7.9/lib/python3.7/site-packages/omegaconf/omegaconf.py", line 321, in merge
target.merge_with(*others[1:])
File "/home/natalia/.pyenv/versions/3.7.9/lib/python3.7/site-packages/omegaconf/basecontainer.py", line 331, in merge_with
self._format_and_raise(key=None, value=None, cause=e)
File "/home/natalia/.pyenv/versions/3.7.9/lib/python3.7/site-packages/omegaconf/base.py", line 101, in _format_and_raise
type_override=type_override,
File "/home/natalia/.pyenv/versions/3.7.9/lib/python3.7/site-packages/omegaconf/_utils.py", line 629, in format_and_raise
_raise(ex, cause)
File "/home/natalia/.pyenv/versions/3.7.9/lib/python3.7/site-packages/omegaconf/_utils.py", line 610, in _raise
raise ex # set end OC_CAUSE=1 for full backtrace
File "/home/natalia/.pyenv/versions/3.7.9/lib/python3.7/site-packages/omegaconf/basecontainer.py", line 329, in merge_with
self._merge_with(*others)
File "/home/natalia/.pyenv/versions/3.7.9/lib/python3.7/site-packages/omegaconf/basecontainer.py", line 347, in _merge_with
BaseContainer._map_merge(self, other)
File "/home/natalia/.pyenv/versions/3.7.9/lib/python3.7/site-packages/omegaconf/basecontainer.py", line 296, in _map_merge
dest.__setitem__(key, src_value)
File "/home/natalia/.pyenv/versions/3.7.9/lib/python3.7/site-packages/omegaconf/dictconfig.py", line 262, in __setitem__
self._format_and_raise(key=key, value=value, cause=e)
File "/home/natalia/.pyenv/versions/3.7.9/lib/python3.7/site-packages/omegaconf/base.py", line 101, in _format_and_raise
type_override=type_override,
File "/home/natalia/.pyenv/versions/3.7.9/lib/python3.7/site-packages/omegaconf/_utils.py", line 694, in format_and_raise
_raise(ex, cause)
File "/home/natalia/.pyenv/versions/3.7.9/lib/python3.7/site-packages/omegaconf/_utils.py", line 610, in _raise
raise ex # set end OC_CAUSE=1 for full backtrace
omegaconf.errors.ValidationError:
full_key: transform
reference_type=Optional[Dict[Union[str, Enum], Any]]
object_type=dict
所以,问题是-这个功能是否支持,如果是,我做错了什么?
您的配置正在尝试合并字符串"resize"放入字典中,如:
transform:
type: crop
test1: 7
这不是你能做的。
你没有解释你想做什么很好,但我的猜测是,你想组成一个不同的转换基于选定的数据集。
Hydra 1.1将增加对递归默认列表的支持,这可能会允许你做你想做的。
这是新的默认列表的文档。您可以将此版本作为预发布版本安装(参见主项目自述文件)。