Skip to content Skip to sidebar Skip to footer

Keras Clarification On Definition Of Hidden Layer

I am following a tutorial on building a simple deep neural network in Keras, and the code provided was: # create model model = Sequential() model.add(Dense(12, input_dim=8, activat

Solution 1:

You're right.

When you're creating a Sequential model, the input "layer"* is defined by input_dim or by input_shape, or by batch_input_shape.

* - The input layer is not really a layer, but just a "container" for receiving data in a specific format.

Later you might find it very useful to use functional API models instead of sequential models. In that case, then you will define the input tensor with:

inputs = Input((8,))

And pass this tensor through the layers:

outputs = Dense(12, input_dim=8, activation='relu')(inputs)
outputs = Dense(8, activation='relu')(outputs)
outputs = Dense(1, activation='sigmoid')(outputs)

To create the model:

model = Model(inputs,outputs)

It seems too much trouble at first, but soon you will feel the need to create branches, join models, split models, etc.

Post a Comment for "Keras Clarification On Definition Of Hidden Layer"