A JavaScript library for training and deploying ML models in the browser and on Node.js.
In order to run tensorflow.js in node.js on Mac, you should install tensorflow.js as following:
$ npm install @tensorflow/tfjs-node |
If your system NVIDIA GPU, it will be recommended to install below package as well.
$ npm install @tensorflow/tfjs-node-gpu |
The below is the example of tensorflow.js based on node.js
const tf = require('@tensorflow/tfjs'); // Load the binding: require('@tensorflow/tfjs-node'); // Use '@tensorflow/tfjs-node-gpu' if running with GPU. // Train a simple model: const model = tf.sequential(); model.add(tf.layers.dense({units: 100, activation: 'relu', inputShape: [10]})); model.add(tf.layers.dense({units: 1, activation: 'linear'})); model.compile({optimizer: 'sgd', loss: 'meanSquaredError'}); const xs = tf.randomNormal([100, 10]); const ys = tf.randomNormal([100, 1]); model.fit(xs, ys, { epochs: 100, callbacks: { onEpochEnd: async (epoch, log) => { console.log(`Epoch ${epoch}: loss = ${log.loss}`); } } }); |
Reference URL: https://js.tensorflow.org/