【发布时间】:2019-06-30 00:53:40
【问题描述】:
对于 tensorflow.js,如何设置 node.js 中 Adam 优化器的学习率?我收到一个错误:
model.optimizer.setLearningRate 不是函数
const optimizer = tf.train.adam(0.001)
model.compile({
loss: 'sparseCategoricalCrossentropy',
optimizer,
shuffle: true,
metrics: ['accuracy']
});
await model.fit(trainValues, trainLabels, {
epochs: 50,
validationData: [testValues, testLabels],
callbacks: {
onEpochBegin: async (epoch) => {
const newRate = getNewRate();
model.optimizer.setLearningRate(newRate);
}
}
});
【问题讨论】:
-
你提供的代码有什么问题?
-
这是我得到的错误:model.optimizer.setLearningRate is not a function
-
@Andrew 那是因为这个功能只存在于
sgd。您必须使用非官方 API 来更改其他优化器的 learningRate。我把它放在我的答案中。
标签: node.js tensorflow.js