torch.manual_seed()函数

设置CPU生成随机数的种子,方便下次复现实验结果。

torch.manual_seed(seed) → torch._C.Generator

seed(int),返回一个torch.Generator对象。

设置随机数种子之后,每次运行结果会是一样的,但是如果一个.py文件中有多个rand,那每次的不一定相同。

RANDOM_SEED = 42
np.random.seed(RANDOM_SEED)
torch.manual_seed(RANDOM_SEED)  #设置CPU生成随机数的种子,方便下次复现实验结果。

 

posted @ 2021-07-18 15:24  LLLLgR  阅读(469)  评论(0编辑  收藏  举报