Reputation: 6339
I am trying to load a tensorflow js model that is saved in downloads directory as mentioned in the tutorials of tensorflowjs. But I am facing cors error please find the image below.
Code:
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script>
<script>
async function app() {
const t = await tf.loadLayersModel('downloads://model');
console.log("done");
console.log(t);
}
app();
</script>
<script>
</script>
</head>
<body>
</body>
</html>
Any pointers on how to resolve this.
Tried disabling cors for chrome but still didnt work.
Upvotes: 3
Views: 2853
Reputation: 51
I have the similar issue when I was doing my Coursera assignment.
The problem was not exactly with the tensorflow.js.
I solved the problem by pointing the CSV directly to github URL like
https://raw.githubusercontent.com/...../...../testingdata.csv
instead of putting them in my own laptop directories.
Then it should work.
Upvotes: 0
Reputation: 18371
Fetch API cannot load downloads://model. URL scheme must be“https” for CORS request error
The error says it all. According to the official docs, here is what we can read for the url parameter
A string path to the ModelAndWeightsConfig JSON describing the model in the canonical TensorFlow.js format. For file:// (tfjs-node-only), http:// and https:// schemas, the path can be either absolute or relative.
download
does not mean anything, at least not when loading a model. It is instead used when downloading the model to the file system.
Therefore, if you're loading your model in the browser, consider first serving your model by a server and use a syntax like
const t = await tf.loadLayersModel('http://path/to/downloads/model.json'); // it can also be https if the server has a ssl certificate
If working in a nodejs server environment, then the file can be accessed directly using file
identifier
const t = await tf.loadLayersModel('file://path/to/downloads/model.json');
Upvotes: 0
Reputation: 687
The protocol you specified looks invalid. You can specify file://
or just omitting it should work. And also you need to specify the path to model.json
file created by tfjs-converter. So overall, the code to load the model may look like this.
const t = await tf.loadLayersModel('file:///path/to/downloads/model.json');
Upvotes: 0