diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..384b8f3 --- /dev/null +++ b/.npmignore @@ -0,0 +1,7 @@ +node_modules/ +.npmignore +images/ +src/ +.vscode/ +scripts +package-lock.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..96b1fe8 --- /dev/null +++ b/README.md @@ -0,0 +1,57 @@ +# node-red-contrib-tf-model +This is a Node-RED custom node which is used to load tensorflow models and +perform inference. Currenctly, it only supports Web friendly JSON format model +which mainly used by Tensorflow.js. SavedModel format will be added soon. + +## Installation + +### Prerequisite +For Tensorflow.js on Node.js +([@tensorflow/tfjs-node](https://www.npmjs.com/package/@tensorflow/tfjs-node) +or +[@tensorflow/tfjs-node-gpu](https://www.npmjs.com/package/@tensorflow/tfjs-node-gpu)), +it depends on Tensorflow shared libraries. Putting Tensorflow.js as the +dependency of custom Node-RED node may run into a situation that multiple +custom nodes install multiple `tfjs-node` module as their dependencies. While +loading multiple Tensorflow shared libraries in the same process, the process +would abord by hitting protobuf assertion. + +Therefore, this module put `@tensorflow/tfjs-node` as peer dependency. You need +to install it with the Node-RED manully. + +Install `@tensorflow/tfjs-node`: +``` +npm install @tensorflow/tfjs-node +``` + + +### Install this module: +Once you install the peer dependency, you can install this module: +``` +npm install node-red-contrib-tf-model +``` + +## Usage + +You can see the `tf-model` node in the `Models` category, like this: + +![Palette](images/palette.png "Palette") + +Then you can use `tf-model` node in your flow. It only needs one property: +`Model URL`. + +![Config Node](images/Config_Node.png "Config Node") + +The `Model URL` should point to a Tensorflow.js model which is in web friendly +format. Typically, it should be a model JSON file. After you specify the +`Model URL` and deploy the flow, it will fetch the model files, including +shard files, and store them in `${HOME}/.node-red/tf-model` directory. +The new node will load the model and maintain the cache entry. + +## Data Format + +When performing the inference of a Tensorflow.js model, you need to pass the +corresponding `msg.payload` to `tf-model` node. The `msg.payload` would be a +`tf.NamedTensorMap` object containing all the needed features in `tf.Tensor` +data type for the model. Then the results are passed to the next node in +`msg.payload`. It could be a `tf.Tensor` or `tf.Tensor[]`. \ No newline at end of file diff --git a/images/Config_Node.png b/images/Config_Node.png new file mode 100644 index 0000000..910ef4a Binary files /dev/null and b/images/Config_Node.png differ diff --git a/images/palette.png b/images/palette.png new file mode 100644 index 0000000..258d98a Binary files /dev/null and b/images/palette.png differ diff --git a/package.json b/package.json index 563f750..b4414bb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "node-red-contrib-tf-model", - "version": "0.1.0", - "description": "a tf.js model node to retrieve/execute a tf model", + "version": "0.1.1", + "description": "a custom Node-RED node to retrieve/execute a Tensorflow model", "main": "dist/index.js", "scripts": { "build": "tsc && npm run copy", diff --git a/src/index.html b/src/index.html index e59d8c2..94aba94 100644 --- a/src/index.html +++ b/src/index.html @@ -27,26 +27,31 @@