npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tfjs-node-save

v0.0.2

Published

Tensorflow.js extension for saving models to the filesystem in ANY node environment.

Downloads

1,346

Readme

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

  • https://stackoverflow.com/questions/52131457/nodejs-compile-shared-cpp-libraries-in-gcp-cloud-functions
  • https://github.com/tensorflow/tfjs/issues/666
  • http://jamesthom.as/blog/2018/08/13/serverless-machine-learning-with-tensorflow-dot-js/