How to reuse a package multiple times in a config?

753 views Asked by At

I have a general camera config yaml, where the only thing that usually changes between specific cameras is the IP address. Some fields (in the following example fps) remain the same.

Can I do something like this in Hydra/OmegaConf?

any_camera.yaml

any_camera:
  stream_url: ???
  fps: 25

all_cameras.yaml

all_cameras:
  cam1:
    @{any_camera}
    stream_url: rtsp://10.0.0.1

  cam2:
    @{any_camera}
    stream_url: rtsp://10.0.0.2

2

There are 2 answers

0
Jieru Hu On BEST ANSWER

I can see two potential options:

  1. In Hydra you can try: extending configs and select_multiple_configs_from_config_group

Basically you could have cam1 and cam2 both extend from any_camera and have specific overrides. Then in all_cameras.yaml, you can select multiple config groups to have the config list.

  1. You can also look into omegaconf's node interpolation. But that might require you change the cam config's structure.
2
Omry Yadan On

The canonical answer to using the same config more than once is to override the config package.

defaults:
 - server/db@src: mysql
 - server/db@dst: mysql

Will result in the content of server/db/mysql.yaml in two places in the config object, src and dst.

See this section in the packages page.