0

我正在使用nesterov 动量来更新卷积神经网络的权重。我正在使用千层面来构建 CNN。如何实现每个时期的学习率衰减?

prediction = lasagne.layers.get_output(network)
loss = lasagne.objectives.categorical_crossentropy(prediction, target_var)
params = lasagne.layers.get_all_params(network, trainable=True)
lasagne.updates.nesterov_momentum(loss, params, learning_rate, momentum=0.9)
train_fn = theano.function([input_var_1, input_var_2, target_var], loss, updates=updates)
4

2 回答 2

3

将您的学习率定义为图形元素

...
learning_rate = T.scalar(name='learning_rate')
updates = lasagne.updates.nesterov_momentum(loss, params, learning_rate, momentum=0.9)
...

将您的学习率节点添加到 train_fn

train_fn = theano.function([input_var_1, input_var_2, target_var, learning_rate], loss, updates=updates)

现在您可以像这样调整学习率:

base_lr = 1e-4
lr_decay = 0.8

for epoch in range(epochs):
    lr = base_lr * (lr_decay ** epoch)
    loss, updates = train_fn(input_1, input_2, target, lr)
于 2016-06-02T15:01:57.540 回答
0

我认为你错过了一些东西:

prediction = lasagne.layers.get_output(network)
loss = lasagne.objectives.categorical_crossentropy(prediction, target_var)
params = lasagne.layers.get_all_params(network, trainable=True)
updates = lasagne.updates.nesterov_momentum(loss, params, learning_rate, momentum=0.9)
train_fn = theano.function([input_var_1, input_var_2, target_var], loss, updates=updates)
于 2016-05-30T22:15:15.300 回答