其他分享
首页 > 其他分享> > Pytorch固定随机数

Pytorch固定随机数

作者:互联网

import random
import torch
import numpy as np


def same_seeds(seed):
    # Python built-in random module
    random.seed(seed)
    # Numpy
    np.random.seed(seed)
    # Torch
    torch.manual_seed(seed)
    if torch.cuda.is_available():
        torch.cuda.manual_seed(seed)
        torch.cuda.manual_seed_all(seed)
    torch.backends.cudnn.benchmark = False
    torch.backends.cudnn.deterministic = True

same_seeds(2021)

标签:torch,随机数,random,manual,Pytorch,seed,cuda,固定,import
来源: https://www.cnblogs.com/kervias/p/15773264.html