node.js - 如何更新 TensorFlow.js 保存/训练的模型

标签 node.js machine-learning keras model tensorflow.js

您好,我想知道如何更新 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/

相关文章:

node.js - Node.js 的集中错误处理和报告

angularjs - Protractor - 在 webstorm 中调试

lua - 重写 torch 中的 updateGradInput 方法不适用于我的自定义模块

python - 在多个 GPU 上进行训练会导致 Keras 中出现 NaN 验证错误

python - 在keras中使用ANN制作偶奇分类器,没有得到好的结果?

node.js - 如何在新的 Grunt 0.4 中编写助手

json - 如何在不挂起的情况下对大型 JSON 对象进行 JSON.stringify?

machine-learning - LIBSVM 对未训练类的样本给出相同的预测。为什么?

machine-learning - 如何使用 libsvm matlab 固定参数 cost 和 gamma 来提高精度?

python - 我可以在 "model.fit()"循环中使用 "for"来更改每次迭代中的训练数据吗