javascript - 无法在 tensorflow.js 中加载 python 训练模型

标签 javascript python tensorflow 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 来加载它。

关于javascript - 无法在 tensorflow.js 中加载 python 训练模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53031887/

相关文章:

javascript - 欧芹错误消息类覆盖

javascript - 为什么Flow在访问数组元素时会忽略undefined的可能性?

php - 不同编程语言中术语的破译图表

Python - 生成 string.ascii_lowercase 的紊乱

python - 使用 RNN 和 Layer 类在 Keras 中实现最小的 LSTMCell

python - 为什么隐蔽的 Tensorflow 升级到 2.9.1 会破坏使用 GPU 而不是 CPU 的 Google Colab Jupyter 笔记本?

php - PHP 和 Javascript 中的 Zend Framework URI 空间编码

javascript - 在 Safari 3+ 中将 window.location.hash 设置为 null 会导致它被设置为 #

python - 选择具有多列条件的列的唯一值

python - 如何从字符串加载Python模块?