工具代碼粘貼1——pytorch設置隨機種子seed

通過設置隨機種子可使訓練結果可復現。

    

def setup_seed(seed):
    np.random.seed(seed)
    random.seed(seed)
    torch.manual_seed(seed) #cpu
    torch.cuda.manual_seed_all(seed)  #並行gpu
    torch.backends.cudnn.deterministic = True  #cpu/gpu結果一致
    torch.backends.cudnn.benchmark = True   #訓練集變化不大時使訓練加速


def main():
    setup_seed(args.seed)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章