-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
35 lines (25 loc) · 814 Bytes
/
utils.py
File metadata and controls
35 lines (25 loc) · 814 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
29
30
31
32
33
34
35
# set_randomness
import random
import torch
import numpy as np
# log_print
from pathlib import Path
from absl import flags
FLAGS = flags.FLAGS
def set_randomness(seed):
rng = torch.Generator()
rng.manual_seed(seed)
random.seed(seed)
np.random.seed(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
return rng
def config_log_print(log_file_path):
log_file_path = Path(log_file_path)
assert not log_file_path.exists(), f'Log file {log_file_path} already exists.'
assert log_file_path.parent.exists(), f'Invalid save directory {log_file_path.parent}.'
def log_print(*args, **kwargs):
with log_file_path.open('a') as f:
print(*args, **kwargs)
print(*args, **kwargs, file=f)
return log_print