How it works...

To create a model using the functional API, we need to create the input and output layers independently, and then pass them to the keras_model() function in order to define the complete model. In the previous section, we created a model with two different output layers that share an input layer/tensor.

In step 1, we created an input tensor using the layer_input() function, which is an entry point into a computation graph that's been generated by the keras model. In step 2, we defined two different output layers. These output layers have different configurations; that is, activation functions and the number of perceptron units. The input tensor flows through these and produces two different outputs.

In step 3, we defined our model using the keras_model() function. It takes two arguments: inputs and outputs. These arguments specify which layers act as the input and output layers of the model. In the case of multi-input or multi-output models, you can use a vector of input layers and output layers, as shown here:

keras_model(inputs= c(input_layer_1, input_layer_2), outputs= c(output_layer_1, output_layer_2))

After we configured our model, we defined the learning process, trained our model, and visualized the loss and accuracy metrics. The compile() and fit() functions, which we used in steps 4 and 5, were described in detail in the How it works section of the Sequential API recipe.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset