Skip to content

Commit

Permalink
Add README
Browse files Browse the repository at this point in the history
Update README

Signed-off-by: Yihong Wang <[email protected]>
  • Loading branch information
yhwang committed Jan 24, 2020
1 parent 22fd98c commit a442ca0
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules/
.npmignore
images/
src/
.vscode/
scripts
package-lock.json
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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[]`.
Binary file added images/Config_Node.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/palette.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
29 changes: 17 additions & 12 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,31 @@
</script>

<script type="text/x-red" data-help-name="tf-model">
<p>Tensorflow.js Model</p>
<p>Use this to load Tensorflow.js Model and perform inference. The inference results
will be passed to next node.
</p>

<h3>Inputs</h3>
<dl class="message-properties">
<dt>tensors
<span class="property-type">Object</span>
<dt>payload
<span class="property-type">tf.NamedTensorMap</span>
</dt>
<dd>use the tensors as inputs to run model inference</dd>
<dd>Directly use the payload as inputs to run model inference.
tf.Tensors in the named map would be disposed after inference.
</dd>
</dl>

<h3>Outputs</h3>
<ol class="node-ports">
<dt>prediction
<span class="property-type">Object</span>
<dl class="message-properties">
<dt>payload
<span class="property-type">tf.Tensor | tf.Tensor[]</span>
</dt>
<dd>The prediction</dd>
</ol>
<dd>The ouput tensors of the model</dd>
</dl>

<h3>Details</h3>
<p><code>msg.payload</code> is used as tensor data and create tf.Tensor objects
then use these data to run model inference. The prediction results will be converted
to data array and pass the next node.
<p><code>msg.payload</code> is used as tf.NamedTensorMap and run model inference.
Then the prediction results will be passed to next node. It could be
tf.Tensor or tf.Tensor[]
</p>
</script>

0 comments on commit a442ca0

Please sign in to comment.