您好,我想知道如何更新 Node js 中的 TensorFlow js 保存的模型,
我使用 NodeJS 在 TensorFlow js 中创建了一个基本的神经网络,并保存了经过训练的模型,它生成了 model.json 和weights.bin 文件。
我发现我们可以用 Python 更新 keras 中经过训练的模型。
但是没有在 TensorFlow js、NodeJS 和 JS 中更新模型的示例。
请有人帮助更新训练后的模型。
模型加载和更新代码
var tf = require('@tensorflow/tfjs-node')
async funtion load(){
const model = await tf.loadLayersModel(url);
}
load().then(() => {
model.predict(tf.tensor1d([5]))
model.predict(tf.tensor1d([5]), tf.tensor1d([15]));
model.predict(tf.tensor1d([5]))
})
最佳答案
可以加载保存的模型并用于进一步训练。
const model = await tf.loadLayersModel(url);
model.predict(feature) // predict with old model
await model.fit(features, labels); // this will update the weights of the model
model.predict(feature) // predict with new model
重新训练的模型可以保存回来,这将更新其权重。就好像模型接受了初始数据和当前数据的训练,这意味着它可以预测来自两个来源的数据。
但是,如果新数据与初始数据显着不同,模型将无法再次根据初始数据进行良好预测。这个问题讨论得很好here
关于node.js - 如何更新 TensorFlow.js 保存/训练的模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60433410/