Elierze's picture
Initial Space upload
fc33673 verified
Raw
History Blame Contribute Delete
811 Bytes
from __future__ import annotations
import json
from pathlib import Path
from typing import Any, Dict
import torch
import yaml
def load_yaml_config(config_path: str | Path) -> Dict[str, Any]: #yaml 파일의 설정 내용을 dict로 반환
with Path(config_path).open(encoding="utf-8") as file:
return yaml.safe_load(file) #안전한 기본 자료형만 허용
def load_torch_checkpoint(checkpoint_path: str | Path, map_location: torch.device | str) -> Dict[str, Any]:
return torch.load(Path(checkpoint_path), map_location=map_location)
#pytorch로 저장된checkpoint 를 읽어와 dict로 반환
def write_json(data: Dict[str, Any], output_path: str | Path) -> None: #dict 데이터를 json 파일로 저장
Path(output_path).write_text(json.dumps(data, indent=2), encoding="utf-8")