Saving Model on Node: Cannot find any save handlers
See original GitHub issueTo 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.
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:
- Created 5 years ago
- Comments:9 (3 by maintainers)
Top GitHub Comments
@JonasJW This minimal code below works for me, maybe you can try it out:
package.json:
model-save.js:
Run model-save.js with
node model-save.js
Same problem here, I have fixed it by doing
After editing package.json, i’ve done
This problem will occur in many situations :
npm install --global-style
npm install --legacy-bundling
package.json
contains both@tensorflow/tfjs
and@tensorflow/tfjs-node
package.json
contains both@tensorflow/tfjs-node-gpu
and@tensorflow/tfjs-node
on the same project with different versionsI think it would be better to just do
@caisq can you explain the reason behind this ‘double-require’ design ?
Thank you for this great binding