Another way to define a model is the Keras functional API. The Keras functional API is the way to go for defining complex models, such as multi-output models, directed acyclic graphs, or models with shared layers. For example, to define a densely connected network, simply type the following code:
from keras.layers import Input, Densefrom keras.models import Modelinputs = Input(shape=(784,))x = Dense(64, activation='relu')(inputs)x = Dense(64, activation='relu')(x)predictions = Dense(10, activation='softmax')(x)model = Model(inputs=inputs, outputs=predictions)model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'])model.fit(data, labels)
In the following section, we will dive deep into ...