random - 在 Pytorch 上重置随机初始化
问题描述
我想对前馈神经网络做一些实验。为了进行公平比较,我需要它们具有完全相同的随机初始化。我该怎么做?
有没有办法保存相同的初始权重,以便我可以训练一个网络,然后像以前一样重新初始化它?
我一直在尝试将初始参数保存在名为 'init' 的列表中,然后重新分配参数,但它不起作用:
i = 0
for name, param in model.named_parameters():
param = init[i]
i += 1
有什么建议吗?
解决方案
You can try seeding random via:
torch.manual_seed(seed)
torch.manual_seed_all(seed)
Note you have to seed random before each model initialisation. If this doesn't work, try the following:
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
推荐阅读
- pyspark - 如何从 pyspark 中的模式 json 文件创建 DataFrame 模式?
- python - 我尝试使用 python openpyxl 在 excel 中创建多个工作表以在循环中存储不同的值,但它只创建一个工作表
- java - 表达式的非法开始:Java 方法
- ipaf - PAF 中的 Chrome 驱动程序问题
- javascript - Chart.js 缩放显示小数点
- c# - 在 Gridview 中显示 Gridview
- python - 使用 ruamel.yaml 在 YAML 中解析前面的注释
- winforms - 同步调用异步函数响应更快
- java - 使用循环填充具有不同对象类型的数组(并随机为其参数分配一个值)?
- android - Android 8-9 - OnPause Rotation back to Portrait for - 当手机处于纵向时 screenOrientation="sensorLandscape" 锁定导致问题