Download src/fall_detection/utils.py from minhy112/FallKLTN: direct link, hf CLI and curl.
- Browser
- Download file 818 Bytes
-
https://huggingface.co/minhy112/FallKLTN/resolve/main/src/fall_detection/utils.py
- Command line
-
hf download hf://minhy112/FallKLTN/src/fall_detection/utils.py
-
curl -L -o utils.py https://huggingface.co/minhy112/FallKLTN/resolve/main/src/fall_detection/utils.py
818 Bytes
| from __future__ import annotations | |
| import json | |
| import random | |
| from pathlib import Path | |
| from typing import Any | |
| import numpy as np | |
| import torch | |
| def set_seed(seed: int) -> None: | |
| random.seed(seed) | |
| np.random.seed(seed) | |
| torch.manual_seed(seed) | |
| if torch.cuda.is_available(): | |
| torch.cuda.manual_seed_all(seed) | |
| torch.backends.cudnn.benchmark = False | |
| torch.backends.cudnn.deterministic = True | |
| def write_json(path: str | Path, value: dict[str, Any]) -> None: | |
| path = Path(path) | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| with path.open("w", encoding="utf-8") as file: | |
| json.dump(value, file, ensure_ascii=False, indent=2) | |
| def read_json(path: str | Path) -> dict[str, Any]: | |
| with Path(path).open("r", encoding="utf-8") as file: | |
| return json.load(file) | |