0.0.2 • Published 6 years ago

tfjs-node-save v0.0.2

Weekly downloads
11
License
Apache-2.0
Repository
github
Last release
6 years ago

tfjs-node-save

The official way for saving models in Node environment is tfjs-node.
It also enhances the performance, registrers backend and allows us to use GPUs.

But tfjs-node is not supported on all operating systems, node versions, ect.

Here comes 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.

IF YOU USE tfjs-node THE FUNCTIONALITY OF THIS MODULE IS ALREADY AVAILABLE AND YOU DON'T NEED IT AT ALL

Usage

Import this module after the official tensorflow.js package:

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:

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:

More related stuff