简体   繁体   English

在本地 Z2567A5EC9705EB7AC2C984033E06189D 中的 javascript 中加载 json 预训练 model 时出错

[英]Error when load json pretrained model in javascript in local web application

currently I am using TensorFlow to train a model in python and save it as model.json together with the BIN file in folder named models as shown as below. currently I am using TensorFlow to train a model in python and save it as model.json together with the BIN file in folder named models as shown as below. I want to do a web application that can load this pre-trained model for prediction.我想做一个 web 应用程序,它可以加载这个预训练的 model 进行预测。 However, I encountered the error Failed to load resource: net::ERR_NAME_NOT_RESOLVED I have googled the solutions and tried several ways, but the error still unable to be solved.但是,我遇到了错误Failed to load resource: net::ERR_NAME_NOT_RESOLVED我已经搜索了解决方案并尝试了多种方法,但仍然无法解决该错误。

在此处输入图像描述

The model was trained in.py file and save into.json by using this line model 在.py 文件中训练并使用此行保存到.json

tfjs.converters.save_keras_model(model, 'models')

For your information, I using node.js and ExpressJs in the application, therefore, the EJS file is used instead of HTML file.供您参考,我在应用程序中使用 node.js 和 ExpressJs,因此,使用 EJS 文件而不是 HTML 文件。

EJS file EJS 文件

<!DOCTYPE html>
<html>
<head>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" >
    <link rel="stylesheet" type="text/css" href="/style/digit.css">
</head>
<body>
    <main>
        <p1>text here</p1>
    </main>   
    <script src="/js/digit-recognition.js"></script>
</body>
</html>

In the digit-recognition.js filedigit-recognition.js文件中

let model;

async function loadModel() {
    console.log("model loading..");
    model = undefined;
    model = await tf.loadLayersModel("models/model.json");
    console.log("model loaded..");
}
loadModel();

$("#predict-button").click(async function () {

    let predictions = await model.predict(tensor).data();
    let results = Array.from(predictions);
    console.log(results);
});

I get the following error as displayed in the console:我收到控制台中显示的以下错误:

Failed to load resource: net::ERR_NAME_NOT_RESOLVED

Updated at 27 Nov 2020 1131am更新于 2020 年 11 月 27 日上午 1131

I have tried many suggested solutions online but it still not works, and the error I get is this now我在网上尝试了许多建议的解决方案,但仍然无效,我得到的错误是现在

GET http://localhost:3000/models/model.json 404 (Not Found)

I believe this is a pathing issue.我相信这是一个路径问题。 If you move the models/ folder into the js/ folder, the digit-recognition.js file should be able to find it.如果将models/文件夹移到js/文件夹下, digit-recognition.js文件应该可以找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 加载本地JSON文件时XMLHttpRequest无法加载错误 - XMLHttpRequest cannot load error when loading local JSON file 如何在html div中加载网址? 该网址可以是使用html,javascript的公共域或本地Web应用程序网址 - How to load a url in a html div ? that url may be public domain or local web application url using html,javascript 如何在javascript中加载本地网页 - How to load a local web page in javascript 将json命令发送到本地应用程序,该应用程序通过Web浏览器中的javascript侦听TCP端口5500 - Send json command to local application that listens to TCP port 5500 via javascript from web browser javascript(无jquery)-加载本地json文件 - javascript (no jquery) - load a local json file 如何在Javascript中加载本地JSON文件 - How to load local JSON files in Javascript 将本地JSON文件中的数据加载到javascript中 - Load data from local JSON file into javascript 如何使用JavaScript将JSON加载到Web应用程序中并选择一个随机词? - How can I load some JSON into my web application with JavaScript and select a random word? 将应用程序从本地移动到Web服务器时,出现400错误的请求错误 - 400 Bad Request error when when moving application from local to web server 错误不允许在 javaScript 中加载本地资源 - Error Not allowed to load local resource in javaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM