I'm very new to machine learning and I'm not sure about Tensorflow implementation of neural network model. How many layers does the model below have?

model = Sequential() 
    model.add(Dense(200, activation="tanh"))
    model.add(Dense(1, activation='sigmoid'))

I think the answer is 2, because dropout applies to the input layer, but the input shape is (None, 20) and not 200, so does that Dense layer actually follow a implicit input layer?


because dropout applies to the input layer

What you said is True in terms of behavior but Dropout is implemented as a separate layer i.e. keras.layers.Dropout. We can treat it like any other layer.

model = keras.Sequential() 
model.add(keras.layers.Dense(200, input_shape=(50,), activation="tanh"))
model.add(keras.layers.Dense(1, activation='sigmoid'))


enter image description here

for layer in model.layers:

enter image description here

so does that Dense layer actually follow an implicit input layer?

Your model is yet not built. Without providing the input shape or fit with data, it can't know the input shape. So, it can't know the number of weights/biases for the 1st layer.


When talking about feed forward neural networks one distinguishes between input layer, hidden layers and output layer. Usually you have a single input and output layer and one or more hidden layers.

In your case, the input layer with 20 input neurons is not explicitly mentioned in the code but its still there. Further, there is one hidden layer with 200 neurons and one output layer with a single neuron.

So I would say you have a three layer network. But maybe there are other conventions on how to count the number of layers in a feed forward neural network. Some might exclude the input layer.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.