Spaces:
Sleeping
Sleeping
File size: 568 Bytes
1dc2504 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 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
|