• 训练集测试集划分固定
# 通过设置random_state设置固定比例
x_train, x_test, y_train, y_test = train_test_split(x_test, y, test_size = 0.1, random_state=seed)
  • torch中的随机种子
# cpu
torch.manual_seed(seed)
# gpu
torch.cuda.manual_seed_all(seed)    # 通过设置这个,保证每次运行按次序生成的随机数一样。·

#DataLoader的shuffle每一次都是一样的

pytorch之模型参数固定

  • numpy中随机种子的设置
    pytorch之模型参数固定

  • 综合

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

  • 实验结果
    pytorch之模型参数固定

相关文章:

  • 2021-08-04
  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2023-03-20
  • 2021-11-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2021-09-03
  • 2021-11-01
  • 2022-12-23
相关资源
相似解决方案