Tensorflow.js extension for saving models to the filesystem in ANY node environment.
npm install tfjs-node-savetfjs-node.
tfjs-node is not supported on all operating systems, node versions, ect.
tfjs-node-save! It allows you to use the native filesystem feature of tfjs-node, but excludes EVERYTHING ELSE, so it's supported in ANY Node environment.
tfjs-node THE FUNCTIONALITY OF THIS MODULE IS ALREADY AVAILABLE AND YOU DON'T NEED IT AT ALL
javascript
var tf = rquire("@tensorflow/tfjs");
require("tfjs-node-save");
/// YOUR CODE HERE
model.save("file://PATH");
`
Now you'll be able to use the filesystem saving as described in the official documentation:
> The file:// URL scheme can be used for model saving and loading. For model saving, the scheme is followed by the path to the directory in which the model artifacts are to be saved, for example:
`javascript
await model.save("file:///tmp/my-model-1");
// or
model.save("file://C:/tmp/").then(function() {
console.log("Successfully saved the artifacts.");
});
`
Real world use case
Interesting use case might be saving model to the temporary filesystem of _GCP Cloud Functions_ / _AWS Labda_ and exporting it to a storage service.
As soon as you try to use tfjs-node you might end up with similar error:
`
Error: libtensorflow.so: cannot open shared object file
`
But importing tfjs-node-save instead should work without any drawbacks.
Contributing
As soon as you open the source of this tiny module you'll realize that it's only 5 lines of javascript.
But if you wanna to contribute to the concept of saving models in the Node fs and wanna help the TF community, you can:
- Contribute to the tfjs-node repo so support for more environments can be rolled out.
- Contribute to the tfjs` repo.