我正在尝试实例化变压器的组合。
在本机Python中,这看起来像这样:
import albumentations as A
transforms = A.Compose([
A.Rotate(limit=10),
A.ToGray(p=1),
])
print(transforms)
输出:
Compose([
Rotate(always_apply=False, p=0.5, limit=(-10, 10), interpolation=1, border_mode=4, value=None, mask_value=None),
ToGray(always_apply=False, p=1),
], p=1.0, bbox_params=None, keypoint_params=None, additional_targets={})
我正在尝试使用Hydra实例化相同的转换,但由于某种原因,递归实例化失败,并且仅实例化了转换列表,但没有实例化外部 ( A.Compose
) 函数。
from omegaconf import OmegaConf
import hydra
conf = OmegaConf.create({"compose": {"_traget_": "albumentations.Compose", "_recursive_": True, "transforms": [{"_target_": "albumentations.Rotate", "limit": 10}, {"_target_": "albumentations.ToGray", "p": 1}]}})
print(OmegaConf.to_yaml(conf))
输出:
compose:
_traget_: albumentations.Compose
_recursive_: true
transforms:
- _target_: albumentations.Rotate
limit: 10
- _target_: albumentations.ToGray
p: 1
但实例化失败:
print(hydra.utils.instantiate(conf.compose))
输出:
{'_traget_': 'albumentations.Compose', 'transforms': [Rotate(always_apply=False, p=0.5, limit=(-10, 10), interpolation=1, border_mode=4, value=None, mask_value=None), ToGray(always_apply=False, p=1)]}