numpy的随机数种子可以看:numy.random.seed()函数使用笔记
pytorch中设置随机数种子可以通过:torch.manual_seed()进行设置,从而使每次的参数固定
if args.seed is not None:
random.seed(args.seed)
# 为CPU设置种子用于生成随机数,以使结果是确定的
torch.manual_seed(args.seed)
# 为当前GPU设置种子用于生成随机数,以使结果是确定的
torch.cuda.manual_seed(args.seed)
cudnn.deterministic=True
# 如果使用多个GPU,则为当前所有GPU设置种子
# torch.cuda.manual_seed_all()