By setting global random seeds, the same training results can be repeated every time

PyTorch

def seed_torch(seed=42) : Seed = int(seed) random.seed(seed) os.environ[' PYTHONHASHSEED '] = STR (seed) np.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 = FalseCopy the code

Tensorflow

def seed_tensorflow(seed=42): random.seed(seed) os.environ[' PYTHONHASHSEED '] = STR (seed) np.random.seed(seed) tf.set_random_seed(seed)Copy the code