【问题标题】:Fixing the seed for torch random_split()修复torch random_split() 的种子
【发布时间】:2019-09-13 04:12:33
【问题描述】:

是否可以在拆分数据集时修复 torch.utils.data.random_split() 的种子,以便重现测试结果?

【问题讨论】:

    标签: pytorch torch


    【解决方案1】:

    documentation 中可以看出,可以将生成器传递给 random_split

    random_split(range(10), [3, 7], generator=torch.Generator().manual_seed(42))
    

    【讨论】:

      【解决方案2】:

      您可以使用torch.manual_seed 函数全局播种脚本:

      import torch
      torch.manual_seed(0)
      

      更多信息请参见reproducibility documentation

      如果您想专门播种torch.utils.data.random_split,您可以在之后将种子“重置”为其初始值。只需像这样使用torch.initial_seed()

      torch.manual_seed(torch.initial_seed())
      

      AFAIK pytorch 提供seedrandom_state 之类的参数(例如,可以在sklearn 中看到)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-04-18
        • 2017-09-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多