question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Saving Model on Node: Cannot find any save handlers

See original GitHub issue

To get help from the community, check out our Google group.

TensorFlow.js version

tfjs: 0.13.0 tfjs-node: 0.1.17 node-version: v8.11.2

Browser version

Run with node, so no browser involved

Describe the problem or feature request

I’m trying to save my model like this: const save = await model.save('file:///tmp/my-model-1'); but I get the error:

UnhandledPromiseRejectionWarning: Error: Cannot find any save handlers for URL 'file:///tmp/my-model-1' at new ValueError (/Users/jonas/RestAPITest/node_modules/@tensorflow/tfjs-layers/dist/errors.js:36:28) at Sequential.<anonymous> (/Users/jonas/RestAPITest/node_modules/@tensorflow/tfjs-layers/dist/engine/training.js:1160:39) at step (/Users/jonas/RestAPITest/node_modules/@tensorflow/tfjs-layers/dist/engine/training.js:42:23) at Object.next (/Users/jonas/RestAPITest/node_modules/@tensorflow/tfjs-layers/dist/engine/training.js:23:53) at /Users/jonas/RestAPITest/node_modules/@tensorflow/tfjs-layers/dist/engine/training.js:17:71 at new Promise (<anonymous>) at __awaiter (/Users/jonas/RestAPITest/node_modules/@tensorflow/tfjs-layers/dist/engine/training.js:13:12) at Sequential.Model.save (/Users/jonas/RestAPITest/node_modules/@tensorflow/tfjs-layers/dist/engine/training.js:1152:16) at train (/Users/jonas/RestAPITest/ml.js:41:30) at <anonymous> (node:43798) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3) (node:43798) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejectionsthat are not handled will terminate the Node.js process with a non-zero exit code.

I followed this tutorial

And this is a stackoverflow post with the same issue but there is no solution.

Code to reproduce the bug / link to feature request

Here is my full code:

const tf = require('@tensorflow/tfjs');
const tfNode = require('@tensorflow/tfjs-node');

const model = tf.sequential();

const hidden = tf.layers.dense({ units: 4, inputShape: 3, activation: 'sigmoid' });
const output = tf.layers.dense({ units: 1, activation: 'sigmoid' });

model.add(hidden);
model.add(output);

const optimzer = tf.train.sgd(0.5);
model.compile({
    optimizer: optimzer,
    loss: tf.losses.meanSquaredError
});

const dataTasks = [];
const dataSolutions = [];
for (let i = 0; i < 90; i++) {
    dataTasks[i] = Math.round(Math.random());
    if (i % 3 == 0) {
        if (dataTasks[i] == 0) {
            dataSolutions.push(0)
        } else if (dataTasks[i] == 1) {
            dataSolutions.push(1)
        }
    } 
}
const tasks = tf.tensor2d(dataTasks, [30, 3]);
const solution = tf.tensor2d(dataSolutions, [30, 1]);

train();

async function train() {
    for (let i = 0; i < 1000; i++) {
        const response = await model.fit(tasks, solution, { shuffle: true})
    }
    console.log('trained');

    const save = await model.save('file:///tmp/my-model-1');
    console.log(save);
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
caisqcommented, Sep 22, 2018

@JonasJW This minimal code below works for me, maybe you can try it out:

package.json:

{
  "dependencies": {
    "@tensorflow/tfjs-node": "0.1.17"
  }
}

model-save.js:

const tf = require('@tensorflow/tfjs');
require('@tensorflow/tfjs-node');

const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [1]}));

model.save('file://./model-1a');

Run model-save.js with node model-save.js

1reaction
piercuscommented, Dec 14, 2018

Same problem here, I have fixed it by doing

After editing package.json, i’ve done

rm -rf node_modules
rm package-lock.json
npm install

This problem will occur in many situations :

  • When using npm install --global-style
  • When using npm install --legacy-bundling
  • If package.json contains both @tensorflow/tfjs and @tensorflow/tfjs-node
  • If package.json contains both @tensorflow/tfjs-node-gpu and @tensorflow/tfjs-node on the same project with different versions

I think it would be better to just do

const tf = require('@tensorflow/tfjs-node');

@caisq can you explain the reason behind this ‘double-require’ design ?

Thank you for this great binding

Read more comments on GitHub >

github_iconTop Results From Across the Web

Saving model on node to filesystem - Google Groups
I'm getting an error saving my model: Cannot find any save handlers for URL 'file://model/' ... running on windows, no browser just node,...
Read more >
Tensorflow.js save model using node - Stack Overflow
I had this same problem "Cannot find any save handlers for URL" when trying to use model.save(). The solution to my problem was...
Read more >
TensorFlow.js not able to save model - Reddit
I am using TensorFlow.js in node and I am not able to save my models. ... Error: Cannot find any save handlers for...
Read more >
Save and load models | TensorFlow.js
This tutorial will focus on saving and loading TensorFlow.js models (identifiable by JSON files). We can also import TensorFlow Python models.
Read more >
Troubleshooting errors in AWS Glue
Error : Could not find S3 endpoint or NAT gateway for subnetId in VPC ... to parse XML document with handler class com.amazonaws.services.s3.model.transform....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found