首页 > 解决方案 > 无法在 tensorflow.js 中加载 python 训练的模型

问题描述

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

加载资源失败:net::ERR_NAME_NOT_RESOLVED

Uncaught (in promise) TypeError: Failed to fetch

下面是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)

任何帮助将不胜感激!!

标签: javascriptpythontensorflowtensorflow.js

解决方案


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


推荐阅读