-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.py
46 lines (36 loc) · 954 Bytes
/
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
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
"""
Implements utility functions for the training pipeline.
"""
### IMPORTS ###
# Built-in imports
import os
import random
# Lib imports
import numpy as np
import torch
# Custom imports
import const
### AUTHORSHIP INFORMATION ###
__author__ = ["Michelle Halbheer", "Dominik Mühlematter"]
__email__ = ["[email protected]", "[email protected]"]
__credits__ = ["Michelle Halbheer", "Dominik Mühlematter"]
__version__ = "0.0.1"
__status__ = "Development"
### FUNCTIONS ###
def set_seed(seed: int) -> None:
"""
Set random seeds for reproducability of results
Parameters
----------
seed : int
Random seed number.
"""
np.random.seed(seed)
random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
os.environ["PYTHONHASHSEED"] = str(seed)