Pytorch使用manual_seed

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ying86615791/article/details/80817536


seed = 2018
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
a=torch.rand([1,5])
b=torch.rand([1,5])
关闭进程,重新运行上面代码,发现得到的a和b和上一次的a和b是一样的




seed = 2018
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
a=torch.rand([1,5])
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
b=torch.rand([1,5])
每次获取随机数时,设置seed,发现每次获得的都一样(前提是函数调用方式一样),上面的a==b

猜你喜欢

转载自blog.csdn.net/ying86615791/article/details/80817536