November 2019
Intermediate to advanced
296 pages
7h 52m
English
The Core API provides us with the most flexibility when it comes to machine learning, but the Layers API also supports elasticity. Defining the class of tf.layers.Layer allows us to do custom computing, which can be applied to the Layers API seamlessly:
class NegativeLayer extends tf.layers.Layer { constructor() { super({}); } computeOutputShape(inputShape) { return []; } call(input, kwargs) { return input.neg();} getClassName() { return 'Negative'; }}
By doing this, you can add a custom layer, as well as other layers:
const input = tf.tensor([-2, 1, 0, 5]);const output = new NegativeLayer().apply(input);output.print(); // [2, -1, 0, -5]
One caveat of using a custom layer is serialization. The model of TensorFlow.js can be saved ...
Read now
Unlock full access