-
Notifications
You must be signed in to change notification settings - Fork 41
Tensorflow.js
Don Jayamanne edited this page Aug 22, 2021
·
8 revisions
TensorFlow.js is a JavaScript Library for training and deploying machine learning models in the browser and in Node.js.
- Render plots/tables using the tfjs-vis API (from within node.js)
- Not all of the tfjs-vis is supported.
- E.g. embedding images into the tfjs-vis Visor is not yet supported.
- Please file issues for missing/broken features.
- Please download this notebook to get started. Notice how the plots and model summary is displayed in the notebook (this is something that currently works only when using Tensorflow.js in the browser).
https://github.com/DonJayamanne/typescript-notebook/blob/main/resources/docs/tensorflow/sample.nnb
2. Train a model in Tensorflow.js and view the Tensorboard in VS Code
- Train a model and generate data using the sample provided here
- 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'))
});
- Train the model (by running the two code cells).
- Use the command
Python: Launch TensorBoard
to launch the tensorboard
Home