yaml.constructor.ConstructorError: could not determine a constructor for the tag

yaml.constructor.ConstructorError: could not determine a constructor for the tag

我有一个包含以下几行的 yaml 文件:

grasp_pose: !!python/object/new:geometry_msgs.msg._Pose.Pose
    state:
      - !!python/object/new:geometry_msgs.msg._Point.Point
        state: [0.445, -0.449, 0.116]

使用 yaml 加载没有问题:

with open(os.path.expanduser(config_path), 'r') as f:
    self.config = yaml.load(f, Loader=yaml.Loader)

但是,按照 here 所述使用 hydra 和 @hydra.main(config_path=config_path, strict=True),我收到以下错误:

    main()
  File "/xxx/lib/python3.6/site-packages/hydra/main.py", line 24, in decorated_main
    strict=strict,
  File "xxx/lib/python3.6/site-packages/hydra/_internal/utils.py", line 174, in run_hydra
    overrides=args.overrides,
  File "xxx/lib/python3.6/site-packages/hydra/_internal/hydra.py", line 79, in run
    config_file=config_file, overrides=overrides, with_log_configuration=True
  File "xxx/lib/python3.6/site-packages/hydra/_internal/hydra.py", line 343, in compose_config
    config_file=config_file, overrides=overrides, strict=strict
  File "xxx/lib/python3.6/site-packages/hydra/_internal/config_loader.py", line 61, in load_configuration
    job_cfg = self._create_cfg(cfg_filename=config_file, record_load=False)
  File "xxx/lib/python3.6/site-packages/hydra/_internal/config_loader.py", line 437, in _create_cfg
    cfg = self._load_config_impl(cfg_filename, record_load=record_load)
  File "xxx/lib/python3.6/site-packages/hydra/_internal/config_loader.py", line 253, in _load_config_impl
    loaded_cfg = OmegaConf.load(fullpath)
  File "xxx/lib/python3.6/site-packages/omegaconf/omegaconf.py", line 61, in load
    return OmegaConf.create(yaml.load(f, Loader=get_yaml_loader()))
  File "xxx/lib/python3.6/site-packages/yaml/__init__.py", line 114, in load
    return loader.get_single_data()
  File "xxx/lib/python3.6/site-packages/yaml/constructor.py", line 43, in get_single_data
    return self.construct_document(node)
  File "xxx/lib/python3.6/site-packages/yaml/constructor.py", line 52, in construct_document
    for dummy in generator:
  File "xxx/lib/python3.6/site-packages/yaml/constructor.py", line 404, in construct_yaml_map
    value = self.construct_mapping(node)
  File "xxx/lib/python3.6/site-packages/yaml/constructor.py", line 210, in construct_mapping
    return super().construct_mapping(node, deep=deep)
  File "xxx/lib/python3.6/site-packages/yaml/constructor.py", line 135, in construct_mapping
    value = self.construct_object(value_node, deep=deep)
  File "xxx/lib/python3.6/site-packages/yaml/constructor.py", line 92, in construct_object
    data = constructor(self, node)
  File "xxx/lib/python3.6/site-packages/yaml/constructor.py", line 420, in construct_undefined
    node.start_mark)
yaml.constructor.ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:python/object/new:geometry_msgs.msg._Pose.Pose'
  in "xxxxxxxxx/config/rl_config.yaml", line 85, column 15

不过我不确定问题出在哪里,而且我对 yaml 的工作原理缺乏经验。

OmegaConf——为 Hydra 中的配置对象提供支持的底层库——不支持 YAML 文件中的任意对象。 然而,OmegaConf 和 Hydra 1.0 中有一个称为结构化配置的功能(可作为候选版本安装,并将很快发布),它为您的配置对象添加了强大的静态类型。

我建议您阅读 slides or the docs, as well as the Hydra 1.0 Structured Configs 教程。