javascript - 无法在 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)
任何帮助将不胜感激!!
解决方案
如果要在 tfjs 中加载本地文件,则需要使用文件类型file:///
,为此,您需要 tfjs 的节点扩展名。您可以通过安装并要求将其加载node-fetch
到您的程序中。
推荐阅读
- bootstrap-4 - 带有多列幻灯片的 Bootstrap 4 Carousel
- c++ - 如何在用户按下空格之前继续输入?
- asp.net-mvc - 当前上下文错误VS2017中不存在名称'Url'
- javascript - 测试异步 SQS sendMessage
- c# - 如何使用 PdfiumViewer 将 PDF 转换为位图图像?
- java - Java程序获取gradle构建文件中的版本号
- karate - 空手道模式验证,在使用匹配包含断言时它是否适用于嵌套数组?
- c# - 表示 TFS 服务挂钩事件的 C# 对象
- xslt-2.0 - 如何检查给定的逗号分隔值是否为升序数字序列
- javascript - 取消异常传播