deepfake-server / src /utils.py
DevQueen's picture
Sync from GitHub via hub-sync
1dc2504 verified
raw
history blame contribute delete
568 Bytes
from __future__ import annotations
import random
from pathlib import Path
from typing import Any, Dict
import numpy as np
import torch
import yaml
def set_seed(seed: int) -> None:
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
def load_yaml(path: str | Path) -> Dict[str, Any]:
with Path(path).open("r", encoding="utf-8") as f:
return yaml.safe_load(f)
def ensure_dir(path: str | Path) -> Path:
target = Path(path)
target.mkdir(parents=True, exist_ok=True)
return target