B.4. Calculating gradients
This section is for readers who are interested in performing derivative and gradient calculation in TensorFlow.js. For most deep-learning models in this book, the calculation of derivatives and gradients is taken care of under the hood by model.fit() and model.fitDataset(). However, for certain problem types, such as finding maximally activating images for convolution filters in chapter 7 and RL in chapter 11, it is necessary to calculate derivatives and gradients explicitly. TensorFlow.js provides APIs to support such use cases. Let’s start from the simplest scenario—namely, a function that takes a single input tensor and returns a single output tensor:
const f = x => tf.atan(x);
In order to calculate the derivative ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access