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 which helped me with other libraries.
Node:
[{"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:
[{"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?