如何在Keras中设置自适应学习率 [英] How to Setup Adaptive Learning Rate in Keras
问题描述
下面是我的代码:
model = Sequential([
Dense(32, input_shape=(32,), activation = 'relu'),
Dense(100, activation='relu'),
Dense(65, input_shape=(65,), activation='softmax')
])
model.summary()
model.compile(SGD(lr=.1), loss='binary_crossentropy', metrics=['accuracy'])
model.fit(train_samples, train_labels, batch_size=1000, epochs=1000,shuffle = True, verbose=2)
如何设置模型的自适应学习率?
How will I set an adaptive learning rate of my model?
推荐答案
您可以使用解决方法.
对于范围(0,MaxEpoch)中的each_iteration:
For each_iteration in range(0, MaxEpoch):
-
指定您自己的学习率函数,该函数针对每个时期输出学习率lr.然后将lr传递给your_optimiser
Specify your own learning rate function that outputs a learning rate lr with respect to per epoch. The lr is then passed to your_optimiser
运行model.compile(... optimizer = your_optimiser ...)
run model.compile(...optimizer=your_optimiser...)
运行model.fit(... epochs = 1 ...)
run model.fit(...epochs = 1...)
第一个纪元后,使用model.save_weights(...)
After the ONE epoch, use model.save_weights(...)
通过model.load_weights(...)加载权重以进行下一次迭代.详情请参见此处 https://keras .io/getting-started/faq/#how-can-i-save-a-keras-model
Load weights by model.load_weights(...) for next iteration. See here for details https://keras.io/getting-started/faq/#how-can-i-save-a-keras-model
实际上,#4和#5使您能够进行迁移学习
In fact, #4 and #5 enables you to do a transfer learning
这篇关于如何在Keras中设置自适应学习率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!