1

I am getting the following errors when I am trying to load a Model, which I trained in Python, when I use the loadModel() function tensorflow.js:

Failed to load resource: net::ERR_NAME_NOT_RESOLVED

Uncaught (in promise) TypeError: Failed to fetch

Below is the predict.js file

console.log ("hello");

let model;
(async function () {
    model = await tf.loadModel("http://keras_model/model.json");
    $(".progress-bar").hide();
    console.log("it works");
})();

The directory structure:

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)

Any help will be appreciated!!

6
  • Your url has to be absolute if you are using http:// as file type Commented Oct 28, 2018 at 13:14
  • Or if you are using node and want to load a local file you have to use the file type file:/// Commented Oct 28, 2018 at 13:15
  • I am using node but i get this error. Fetch API cannot load file:///keras_model/model.json. URL scheme must be "http" or "https" for CORS request. Do I have to use absolute path here too?? Commented Oct 28, 2018 at 13:24
  • did you require tfjs-node? Commented Oct 28, 2018 at 13:31
  • hey, thanks for ur help. It's working now. Commented Oct 28, 2018 at 14:31

2 Answers 2

3

If you want to load local files in tfjs you need to use the file type file:/// and for this to work you need the node extension of tfjs. You can load it by installing and requiring node-fetch into your program.

Sign up to request clarification or add additional context in comments.

Comments

2

You can also use the fileSystem handler exposed in tfjs-node like this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.