pytorch 固定随机数种子,使实验可复现
def same_seeds(seed):
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed) # 固定随机种子(CPU)
torch.cuda.manual_seed(seed) # 为当前GPU设置
torch.cuda.manual_seed_all(seed) # 为所有GPU设置
torch.backends.cudnn.benchmark = True # 加快卷积运算
torch.backends.cudnn.deterministic = True # 固定网络结构
same_seeds(args.seed)