November 2019
Intermediate to advanced
296 pages
7h 52m
English
Another way to create a model with the Layers API is to use the functional model API. This API allows you to add an arbitrary layer to the model, as long as it doesn't have cycles. If you were to rewrite the previous model with the functional model API, we would use the following code:
const input = tf.input({shape: [784]});const dense1 = tf.layers.dense({units: 16, activation: 'relu'}).apply(input);const dense2 = tf.layers.dense({units: 10, activation: 'softmax'}).apply(dense1);const model = tf.model({inputs: input, outputs: dense2});
In the functional model API, the apply() method is used to connect each layer. The value that's returned by the apply() method is a SymbolicTensor instance, which almost behaves like a tensor, ...
Read now
Unlock full access