Skip to content

Tensorflow.js

Don Jayamanne edited this page Sep 1, 2021 · 8 revisions

TensorFlow.js is a JavaScript Library for training and deploying machine learning models in the browser and in Node.js.

Features

  • Render plots/tables using the tfjs-vis API (from within node.js)

Notes:

  • Not all of the tfjs-vis is supported.
  • Please file issues for missing/broken features.

Samples

1. Tensorflow in notebooks with visualizations

Scatter plot
Screen Shot 2021-08-24 at 22 06 33

Model Summary
Screen Shot 2021-08-24 at 22 08 42

Scatter plot
Screen Shot 2021-08-24 at 22 11 45

2. Train a model in Tensorflow.js and view the Tensorboard in VS Code

  1. Train a model and generate data using the sample provided here
  2. Create two cell as follows
import * as tf from '@tensorflow/tfjs-node'
import * as path from 'path';
// Constructor a toy multilayer-perceptron regressor for demo purpose.
const model = tf.sequential();
model.add(
    tf.layers.dense({ units: 100, activation: 'relu', inputShape: [200] }));
model.add(tf.layers.dense({ units: 1 }));
model.compile({
    loss: 'meanSquaredError',
    optimizer: 'sgd',
    metrics: ['MAE']
});

// Generate some random fake data for demo purpose.
const xs = tf.randomUniform([10000, 200]);
const ys = tf.randomUniform([10000, 1]);
const valXs = tf.randomUniform([1000, 200]);
const valYs = tf.randomUniform([1000, 1]);

// Start model training process.
await model.fit(xs, ys, {
    epochs: 10,
    validationData: [valXs, valYs],
    // Add the tensorBoard callback here.
    callbacks: tf.node.tensorBoard(path.join(__dirname, 'tmp/fit_logs_1'))
});
  1. Train the model (by running the two code cells).
  2. Use the command Python: Launch TensorBoard to launch the tensorboard

Tensorboard

3. Train MNIST in Tensorflow.js

mnist

4. Tensorflow Visualizations using @tensorflow/tfjs-vis

tfvis