[6969be]: / rocaseg / repro / _seed.py

Download this file

19 lines (17 with data), 555 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
def set_ultimate_seed(base_seed=777):
import os
import random
os.environ['PYTHONHASHSEED'] = str(base_seed)
random.seed(base_seed)
try:
import numpy as np
np.random.seed(base_seed)
except ModuleNotFoundError:
print('Module `numpy` has not been found')
try:
import torch
torch.manual_seed(base_seed + 1)
torch.cuda.manual_seed_all(base_seed + 2)
torch.backends.cudnn.deterministic = True
except ModuleNotFoundError:
print('Module `torch` has not been found')