【发布时间】:2018-07-13 04:13:16
【问题描述】:
我正在使用来自 github 的 Pytorch 代码
我正在尝试将其移植到 Keras。
特别是,Keras 使用model.fit 来训练神经网络,并有一个batch_size 参数。我正在尝试设置它,但无法在上面链接的 Pytorch 脚本中确定它。
在脚本中,在方框 4 中有一个名为 sliding_window 的函数,其中有一个名为 step 的参数。我不确定这是否是 batch_size 的等效设置。
另外,我正在研究如何从 Pytorch 代码中的框 11 设置学习率调度程序:
base_lr = 0.01
params_dict = dict(net.named_parameters())
params = []
for key, value in params_dict.items():
if '_D' in key:
# Decoder weights are trained at the nominal learning rate
params += [{'params':[value],'lr': base_lr}]
else:
# Encoder weights are trained at lr / 2 (we have VGG-16 weights as initialization)
params += [{'params':[value],'lr': base_lr / 2}]
optimizer = optim.SGD(net.parameters(), lr=base_lr, momentum=0.9, weight_decay=0.0005)
# We define the scheduler
scheduler = optim.lr_scheduler.MultiStepLR(optimizer, [25, 35, 45], gamma=0.1)
我一直使用 Keras 的默认学习率。任何有关如何将此调度程序转换为 Keras 代码的见解也将不胜感激。
【问题讨论】:
-
如果您转到您的链接并搜索“batch”,您会发现 BATCH_SIZE = 10
-
@MatiasValdenegro 找到了它。关于如何将类似的学习率调度程序应用到 Keras 有什么见解吗?
标签: python machine-learning deep-learning keras pytorch