Refactor run directory creation to use a unique naming function in training scripts
This commit is contained in:
@@ -3,6 +3,8 @@ from __future__ import annotations
|
||||
import json
|
||||
import logging
|
||||
import sys
|
||||
import time
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Iterable, Tuple
|
||||
|
||||
@@ -15,6 +17,18 @@ from dataset import AllFutureHealthDataset, HealthDataset
|
||||
from models import DeepHealth
|
||||
|
||||
|
||||
def create_unique_run_dir(name_fn, runs_root: Path = Path("runs")) -> tuple[Path, str]:
|
||||
while True:
|
||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
run_name = name_fn(timestamp)
|
||||
run_dir = runs_root / run_name
|
||||
try:
|
||||
run_dir.mkdir(parents=True, exist_ok=False)
|
||||
return run_dir, run_name
|
||||
except FileExistsError:
|
||||
time.sleep(1.0)
|
||||
|
||||
|
||||
def setup_logging(run_dir: Path) -> logging.Logger:
|
||||
run_dir.mkdir(parents=True, exist_ok=True)
|
||||
logger = logging.getLogger("DeepHealth")
|
||||
|
||||
Reference in New Issue
Block a user