Adding Layers to the Keras Model
All the layers mentioned in the previous section need to be added to the model we created earlier. In the following sections, we describe how to add the layers using the functional API and the sequential API.
Sequential API to add layers to the Keras model
In the sequential API, you can create layers by instantiating an object of one of the layer types given in the preceding sections. The created layers are then added to the model using the model.add()
function. As an example, we will create a model and then add two layers to it:
model = Sequential()
model.add(Dense(10, input_shape=(256,))
model.add(Activation('tanh'))
model.add(Dense(10))
model.add(Activation('softmax'))
Functional API to add layers to the Keras Model
In the functional API, the layers are created first in a functional manner, and then while creating the model, the input and output layers are provided as tensor arguments, as we covered in the previous section.
Here is an example:
- First, create...