种子
def set_seed(seed):
# python&numpy:
random.seed(seed)
np.random.seed(seed)
# cpu&gpu:
torch.manual_seed(seed) # 为cpu设置随机种子
torch.cuda.manual_seed(seed) # 为当前GPU设置随机种子
torch.cuda.manual_seed_all(seed) # 为所有GPU设置随机种子
# cudnn:(对结果影响不大,会影响性能)
torch.backends.cudnn.deterministic = True
torch.backends.benchmark = False
Mode:
将神经网络设置成eval模式