-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutils.py
37 lines (27 loc) · 1.07 KB
/
utils.py
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
import random
import numpy as np
from dataset import *
from distutils import util
## Adapted from https://github.com/pytorch/audio/tree/master/torchaudio
## https://github.com/nii-yamagishilab/project-NN-Pytorch-scripts/blob/newfunctions/
def str2bool(v):
return bool(util.strtobool(v))
def setup_seed(random_seed, cudnn_deterministic=True):
""" set_random_seed(random_seed, cudnn_deterministic=True)
Set the random_seed for numpy, python, and cudnn
input
-----
random_seed: integer random seed
cudnn_deterministic: for torch.backends.cudnn.deterministic
Note: this default configuration may result in RuntimeError
see https://pytorch.org/docs/stable/notes/randomness.html
"""
# # initialization
# torch.manual_seed(random_seed)
random.seed(random_seed)
np.random.seed(random_seed)
os.environ['PYTHONHASHSEED'] = str(random_seed)
if torch.cuda.is_available():
torch.cuda.manual_seed_all(random_seed)
torch.backends.cudnn.deterministic = cudnn_deterministic
torch.backends.cudnn.benchmark = False