numpy的随机数种子可以看:numy.random.seed()函数使用笔记

    pytorch中设置随机数种子可以通过:torch.manual_seed()进行设置,从而使每次的参数固定

    1. if args.seed is not None:
    2. random.seed(args.seed)
    3. # 为CPU设置种子用于生成随机数,以使结果是确定的
    4. torch.manual_seed(args.seed)
    5. # 为当前GPU设置种子用于生成随机数,以使结果是确定的
    6. torch.cuda.manual_seed(args.seed)
    7. cudnn.deterministic=True
    8. # 如果使用多个GPU,则为当前所有GPU设置种子
    9. # torch.cuda.manual_seed_all()