Keras Sequential model input layer

Well, it actually is an implicit input layer indeed, i.e. your model is an example of a “good old” neural net with three layers – input, hidden, and output. This is more explicitly visible in the Keras Functional API (check the example in the docs), in which your model would be written as:

inputs = Input(shape=(784,))                 # input layer
x = Dense(32, activation='relu')(inputs)     # hidden layer
outputs = Dense(10, activation='softmax')(x) # output layer

model = Model(inputs, outputs)

Actually, this implicit input layer is the reason why you have to include an input_shape argument only in the first (explicit) layer of the model in the Sequential API – in subsequent layers, the input shape is inferred from the output of the previous ones (see the comments in the source code of core.py).

You may also find the documentation on tf.contrib.keras.layers.Input enlightening.

Leave a Comment