-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
28 lines (26 loc) · 932 Bytes
/
Copy pathutils.py
File metadata and controls
28 lines (26 loc) · 932 Bytes
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
# utils.py
import random
import numpy as np
import torch
import os
def set_seeds(seed_value):
"""Sets random seeds for reproducibility."""
random.seed(seed_value)
np.random.seed(seed_value)
torch.manual_seed(seed_value)
if torch.cuda.is_available():
torch.cuda.manual_seed(seed_value)
torch.cuda.manual_seed_all(seed_value)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
print(f"Seeds set to {seed_value}")
def ensure_dir(directory_path):
"""Ensures that a directory exists, creating it if necessary."""
if not os.path.exists(directory_path):
try:
os.makedirs(directory_path)
print(f"Directory created: '{directory_path}'")
except OSError as e:
print(f"Error creating directory '{directory_path}': {e}")
# else:
# print(f"Directory already exists: '{directory_path}'")