np、torch以及python自带的随机种子

概念应该介绍的很多了,不清楚的铁铁可以去看这篇文章:

python中random.seed()究竟做什么用? - 知乎

fix_seed = 2021

random.seed(fix_seed)

torch.manual_seed(fix_seed)

np.random.seed(fix_seed)

torch.manual_seed(seed) – 官方文档说明:设置 (CPU) 生成随机数的种子,并返回一个torch.Generator对象。 

torch.cuda.manual_seed(seed) – 设置当前GPU的随机数生成种子
torch.cuda.manual_seed_all(seed) – 设置所有GPU的随机数生成种子 

写这篇博客的动机

就是看见别人代码里面的随机种子用了这么多函数把我惊呆了,所以记录一下继续学习,看好的代码真的会让人心情愉悦。


参考资料

torch中manual_seed的作用_风筝大晒的博客-CSDN博客_torch.manual_seed 

np.random.seed()函数_北木.的博客-CSDN博客_np.random.seed(seed) 

猜你喜欢

转载自blog.csdn.net/weixin_43332715/article/details/124617442