无法在 tensorflow.js 中加载 python 个经过训练的模型
Unable to load python trained model in tensorflow.js
当我尝试加载我在 Python 中训练的模型时,当我使用 loadModel()
函数时出现以下错误 tensorflow.js:
Failed to load resource: 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)
任何帮助将不胜感激!!
如果你想在 tfjs 中加载本地文件,你需要使用文件类型 file:///
,为此你需要 tfjs 的节点扩展。您可以通过在程序中安装和要求 node-fetch
来加载它。
您还可以像这样使用 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);
当我尝试加载我在 Python 中训练的模型时,当我使用 loadModel()
函数时出现以下错误 tensorflow.js:
Failed to load resource: 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)
任何帮助将不胜感激!!
如果你想在 tfjs 中加载本地文件,你需要使用文件类型 file:///
,为此你需要 tfjs 的节点扩展。您可以通过在程序中安装和要求 node-fetch
来加载它。
您还可以像这样使用 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);