일단 리스트업/기타

OmegaConf 타입의 dictionary 디버깅 시

hyunkookim 2024. 11. 15. 19:27
  • pycahrm 의 Expression Evaluator 를 사용해서
  • OmegaConf 타입의 dictionary 디버깅 시

 

TypeError: get_str() takes 2 positional arguments but 3 were given 에러 발생

 

이때는 당황하지 않고

 

OmegaConf 값을 일반 dict로 변환

디버깅 과정에서 OmegaConf 객체를 일반 딕셔너리로 변환하여 평가하면 문제를 피할 수 있습니다.

OmegaConf.to_container 함수를 사용해서 변환해서 보자!

from omegaconf import OmegaConf

cfg = OmegaConf.create({"model": {"type": "resnet"}})
cfg_dict = OmegaConf.to_container(cfg, resolve=True)  # OmegaConf -> dict 변환

# 디버깅 시 cfg_dict 사용
print(cfg_dict["model"]["type"])  # "resnet"