May 2020
Intermediate to advanced
404 pages
10h 52m
English
Unlike tensors, variables are mutable in TF.js. Variables are particularly useful during the training of a neural network as they consist of lots of intermediate data stores and updates. The following is an example of how variables can be used in TF.js:
const initialValues = tf.ones([5]);const weights = tf.variable(initialValues); // initialize weightsweights.print(); // output: [1, 1, 1, 1, 1]const updatedValues = tf.tensor1d([0, 1, 0, 1, 0]);weights.assign(updatedValues); // update values of weightsweights.print(); // output: [0, 1, 0, 1, 0]
Let's now look at operators.
Read now
Unlock full access