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

Javascript 无法在tensorflow.js中加载python训练的模型,javascript,python,tensorflow,tensorflow.js,Javascript,Python,Tensorflow,Tensorflow.js,当我使用loadModel() 未能加载资源:net::错误\u名称\u未\u解析 未捕获(承诺中)TypeError:无法获取 下面是predict.js文件 目录结构: main -dataset (contains images for training the model) -training_scripts (python scripts to train the model) -user_interface --server.js (server made

当我使用
loadModel()

未能加载资源:net::错误\u名称\u未\u解析

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

下面是predict.js文件

目录结构:

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的节点扩展名。您可以通过安装并要求将
节点获取
加载到您的程序中来加载它。

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

您还可以使用tfjs节点中公开的
文件系统
处理程序,如下所示:

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);

您还可以使用tfjs节点中公开的
文件系统
处理程序,如下所示:

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);

如果您正在使用
http://
作为文件类型,或者如果您正在使用node并希望加载本地文件,则您的url必须是绝对的,您必须使用文件类型
file://
我正在使用node,但我遇到此错误<代码>获取API无法加载file:///keras_model/model.json. 对于CORS请求,URL方案必须是“http”或“https”。
我是否也必须在此处使用绝对路径?您是否需要
tfjs节点
?嘿,谢谢您的帮助。它现在正在工作。如果您正在使用
http://
作为文件类型,或者如果您正在使用node并希望加载本地文件,则您的url必须是绝对的,您必须使用文件类型
file://
我正在使用node,但我遇到此错误<代码>获取API无法加载file:///keras_model/model.json. 对于CORS请求,URL方案必须是“http”或“https”。
我是否也必须在此处使用绝对路径?您是否需要
tfjs节点
?嘿,谢谢您的帮助。它正在工作。