# Tensorflow in node-red

**URL:** <https://discourse.nodered.org/t/tensorflow-in-node-red/7822>\
**Category:** General\
**Created:** [11 February 2019 09:56 UTC](https://discourse.nodered.org/t/tensorflow-in-node-red/7822 "2019-02-11T09:56:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KarolisL](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@KarolisL](https://discourse.nodered.org/u/KarolisL)\
**Post date:** [11 February 2019 09:56 UTC](https://discourse.nodered.org/t/tensorflow-in-node-red/7822/1 "2019-02-11T09:56:23Z")

</div>

Hello,

I try to use tensorflow npm without luck.  
What is done: npm module is in .node-red\node\_modules@tensorflow via npm i @tensorflow/tfjs

I tried using: [https://www.npmjs.com/package/node-red-contrib-function-npm](https://www.npmjs.com/package/node-red-contrib-function-npm) which helped me with other libraries.

Node:

```auto
[{"id":"f6ae15b3.57f0a8","type":"function-npm","z":"f44e3317.597e7","name":"tensorflow","func":"\n\n//const assert = require('assert');\nconst tf = require('@tensorflow/tfjs');\n//import * as tf from '@tensorflow/tfjs';\n \n// Define a model for linear regression.\nconst model = tf.sequential();\nmodel.add(tf.layers.dense({units: 1, inputShape: [1]}));\n \n// Prepare the model for training: Specify the loss and the optimizer.\nmodel.compile({loss: 'meanSquaredError', optimizer: 'sgd'});\n \n// Generate some synthetic data for training.\nconst xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);\nconst ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);\n \n// Train the model using the data.\nmodel.fit(xs, ys).then(() => {\n // Use the model to do inference on a data point the model hasn't seen before:\n model.predict(tf.tensor2d([5], [1, 1])).print();\n})\n","outputs":1,"noerr":0,"x":340,"y":100,"wires":[[]]}] 

```

I get error: `Error: Cannot find module 'C:\Users\KAROLI~1\AppData\Local\Temp\d-119111-12464-1epjuwk.vorz/node_modules/'`

When I try to use:

functionGlobalContext: {  
tf:require('@tensorflow/tfjs')

Node:

```auto
[{"id":"d7cdfe07.39642","type":"function","z":"f44e3317.597e7","name":"","func":"//const assert = require('assert');\nconst tf = global.get('tf');\n//import * as tf from '@tensorflow/tfjs';\n \n// Define a model for linear regression.\nconst model = tf.sequential();\nmodel.add(tf.layers.dense({units: 1, inputShape: [1]}));\n \n// Prepare the model for training: Specify the loss and the optimizer.\nmodel.compile({loss: 'meanSquaredError', optimizer: 'sgd'});\n \n// Generate some synthetic data for training.\nconst xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);\nconst ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);\n \n// Train the model using the data.\nmodel.fit(xs, ys).then(() => {\n // Use the model to do inference on a data point the model hasn't seen before:\n model.predict(tf.tensor2d([5], [1, 1])).print();\n})\n\nmsg.payload = xs;\n\nreturn msg;","outputs":1,"noerr":0,"x":440,"y":420,"wires":[["b2aa70b.0641c9"]]}]

```

I receive error: `TypeError: Cannot read property 'Sequential' of undefined`

What am I missing?

---

<div class="post-metadata">

**Author:** ![KarolisL](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@KarolisL](https://discourse.nodered.org/u/KarolisL)\
**Post date:** [11 February 2019 11:42 UTC](https://discourse.nodered.org/t/tensorflow-in-node-red/7822/2 "2019-02-11T11:42:53Z")

</div>

My bad, I found problem.

I have 2 node-red insances, and was modifying wrong settings.js file

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [11 February 2019 15:10 UTC](https://discourse.nodered.org/t/tensorflow-in-node-red/7822/3 "2019-02-11T15:10:07Z")

</div>

Hey @KarolisL,

Glad that you have found the cause (by yourself 😉 ) ...

If you ever find an interesting use case for Tensorflow in Node-RED, it would be nice if you could share your experiences here with us. I'm interested a lot in Tensorflow, but have no time to dig into it myself ...

Thanks in advance!!  
Bart

---

<div class="post-metadata">

**Author:** ![KarolisL](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@KarolisL](https://discourse.nodered.org/u/KarolisL)\
**Post date:** [11 February 2019 19:07 UTC](https://discourse.nodered.org/t/tensorflow-in-node-red/7822/4 "2019-02-11T19:07:45Z")

</div>

Will try for sure. But all the experience is limited at tutorials level, which is hard to find at beginner level:

I started with: [https://github.com/BrainJS/brain.js](https://github.com/BrainJS/brain.js) but problem was with training models and as I found it was stable only with sigmoid and leaky-relu.

First steps to start for me was: [https://medium.freecodecamp.org/get-to-know-tensorflow-js-in-7-minutes-afcd0dfd3d2f](https://medium.freecodecamp.org/get-to-know-tensorflow-js-in-7-minutes-afcd0dfd3d2f)

If anyone has better info than git tutorials please share
