无法在tensorflow.js中加载经过python训练的模型

时间:2018-10-28 13:12:22

标签: javascript python tensorflow tensorflow.js

当我使用loadModel()函数tensorflow.js尝试加载使用Python训练的模型时,遇到以下错误:

  

无法加载资源:net :: ERR_NAME_NOT_RESOLVED

     

未捕获(承诺)TypeError:无法获取

下面是 predict.js 文件

console.log ("hello");

let model;
(async function () {
    model = await tf.loadModel("http://keras_model/model.json");
    $(".progress-bar").hide();
    console.log("it works");
})();

目录结构:

main
  -dataset  (contains images for training the model) 
  -training_scripts (python scripts to train the model)
  -user_interface
     --server.js (server made using node.js(and express))
     --static (this folder contains the trained keras model)
         --index.html (html file to be served)
         --predict.js 
         --keras_model(this folder contains the model.json file)

任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:2)

如果要在tfjs中加载本地文件,则需要使用文件类型file:///,为此,您需要tfjs的节点扩展名。您可以通过在程序中安装node-fetch并将其要求安装来加载它。

答案 1 :(得分:1)

您还可以像这样使用在tfjs-node中公开的fileSystem处理程序:

const tf = require("@tensorflow/tfjs");
const tfn = require("@tensorflow/tfjs-node");
const handler = tfn.io.fileSystem("./path/to/your/model.json");
const model = await tf.loadModel(handler);
相关问题