Does dropout layer go before or after dense layer in TensorFlow?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The usual default is to place dropout after a dense hidden layer, typically after its activation output. That said, dropout can also be applied before a dense layer when you want to regularize the inputs instead, so the correct answer depends on what part of the network you are trying to make more robust.
The Standard Dense-Then-Dropout Pattern
In TensorFlow and Keras, the most common fully connected block is a dense hidden layer followed by dropout:
This pattern means the dense layer first computes a learned hidden representation, and dropout then randomly masks part of that representation during training. The goal is to discourage the model from relying too heavily on any one hidden unit.
When people ask this question about ordinary hidden layers, this is usually the arrangement they mean.
Understand Where the Activation Happens
Keras can place the activation inside the dense layer:
If you write the model that way, a following Dropout layer acts on the activated outputs, not on the raw linear combination.
You can make the same structure more explicit by separating the activation:
Conceptually, both versions place dropout after the hidden representation has been formed.
When Dropout Before Dense Makes Sense
Dropout can also go before a dense layer:
This behaves more like input-feature dropout. Instead of regularizing learned hidden activations, you are making the model less dependent on individual input features.
That can be useful in some cases, especially when inputs are noisy or you want the model to tolerate missing features better. It is simply a different regularization goal from the standard hidden-layer pattern.
So the real question is not only "before or after" but also "what exactly do I want dropout to regularize."
Training Behavior Is Different from Inference
Dropout is active only during training. During inference, the layer passes values through without randomly zeroing them.
This matters because the model architecture includes the dropout layer in both modes, but the layer behaves differently depending on the training flag.
In practice, that means a dropout layer should usually be placed where regularization during training helps generalization, not just where it happens to make the model compile.
Practical Guidance
For a standard dense network, a sensible default is:
- dense hidden layer
- activation
- dropout
- next dense layer
That is why examples often show Dense followed by Dropout.
You generally do not put dropout after the final prediction layer unless you have a special experimental reason. Most of the time, dropout is meant for hidden representations, not for the final output probabilities or regression values.
Also remember that dropout is only one regularization tool. If the model is underfitting, adding more dropout can make things worse. Weight decay, better data, early stopping, or architectural changes may have a larger effect than moving dropout by one line.
Common Pitfalls
The biggest mistake is forgetting that Dense(..., activation="relu") already includes the activation. In that setup, a following dropout layer is operating after activation, even if you do not see a separate activation layer in the code.
Another issue is applying dropout to the output layer casually. That is unusual in standard classifiers and regressors.
Developers also often copy a dropout rate such as 0.5 from tutorials without checking whether it fits the model size or dataset. A high dropout rate on a small model can easily cause underfitting.
Finally, placement matters less than people sometimes assume if the overall modeling choices are weak. Good data handling and sensible model capacity often matter more than tiny adjustments to dropout order.
Summary
- The standard default is to place dropout after a dense hidden layer.
- In Keras, that usually means dropout acts on the dense layer’s activated outputs.
- Dropout before a dense layer is possible, but it regularizes inputs rather than hidden activations.
- Hidden layers are the usual place for dropout, not the final output layer.
- Choose placement based on what part of the model you want to regularize.

