【pytorch】torch.manual_seed()

torch.manual_seed(args.seed) #为CPU设置种子用于生成随机数,以使得结果是确定的
if args.cuda:
	torch.cuda.manual_seed(args.seed)#为当前GPU设置随机种子;

#如果使用多个GPU,应该使用torch.cuda.manual_seed_all()为所有的GPU设置种子。

上面所说的固定指的是,在每次运行此程序时,程序后面产生的随机数与上次运行程序产生的随机数是相同的。

参考文献:pytorch中的torch.manual_seed()

猜你喜欢

转载自blog.csdn.net/YJYS_ZHX/article/details/113582822
今日推荐