pytorch 设置种子

目的:

固定住训练的顺序等变量,使实验可复现

def setup_seed(seed):
    torch.manual_seed(seed)
    torch.cuda.manual_seed_all(seed)
    np.random.seed(seed)
    random.seed(seed)
    torch.backends.cudnn.deterministic = True

setup_seed(1)

Ref:

http://www.ishenping.com/ArtInfo/3265474.html
https://www.lizenghai.com/archives/30179.html

-------------------------------------------------------------逆水行舟,不进则退。
原文地址:https://www.cnblogs.com/alilliam/p/12022452.html