How to create two fields from the same group in hydra-python?

Viewed 119

My config files structure:

config
├── train_dataset
│   ├── adobe5k.yaml
│   ├── my_train_data1.yaml
│   └── cifar10.yaml
├── valid_dataset
│   ├── adobe5k.yaml
│   └── cifar10.yaml
└── config.yaml

And my config.yaml is:

# other configs
...

defaults:
  - train_dataset: adobe5k
  - valid_dataset: adobe5k

As you see, I have 2 fields named valid_dataset and train_dataset in my config, whose value is selected from its own config group. What should I do to make values of the two fields selected from the same group?

2 Answers

You can use Defaults List interpolation to achieve that. The Default List page high level information and you find a more practical example here for some details.

defaults:
  - train_dataset: adobe5k
  - valid_dataset: ${train_dataset}

This way, it will be enough for you to override train_dataset and the validation dataset would match it automatically (unless you override it too).

You can use a config group more than once. Assume that you moved your dataset configurations into a single datasets directory. Then you can re-use them as follows.

- defaults:
  - datasets@train_dataset: adobe5k
  - datasets@valid_dataset: adobe5k
Related