At the moment, I am using TensorFlow in Python to train a model and saving it as model.json along with the BIN file in a folder named models. My goal is to develop a web application that can load this pre-trained model for prediction. However, I have been facing an error message
Failed to load resource: net::ERR_NAME_NOT_RESOLVED
. Despite trying various solutions found through research, the error persists.
https://i.sstatic.net/amx6e.png
The model was trained in a .py file and saved into .json using the following line of code:
tfjs.converters.save_keras_model(model, 'models')
Just to provide context, my application utilizes node.js and ExpressJs, hence the use of EJS files instead of HTML files.
EJS File Example
<!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/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4430222e3704766a746a74">[email protected]</a>/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 file
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);
});
The error displayed on the console is:
Failed to load resource: net::ERR_NAME_NOT_RESOLVED
Last updated on 27th November 2020 at 11:31 AM
Despite attempting multiple online fixes, the issue still persists, and now I encounter the following error:
GET http://localhost:3000/models/model.json 404 (Not Found)