You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

A JavaScript library for training and deploying ML models in the browser and on Node.js.


Setup Tensorflow.js on Mac

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/

  • No labels