tf.keras.layers.Dropout
Stay organized with collections
Save and categorize content based on your preferences.
Applies dropout to the input.
Inherits From: Layer
, Operation
tf.keras.layers.Dropout(
rate, noise_shape=None, seed=None, **kwargs
)
Used in the notebooks
Used in the guide |
Used in the tutorials |
|
|
The Dropout
layer randomly sets input units to 0 with a frequency of
rate
at each step during training time, which helps prevent overfitting.
Inputs not set to 0 are scaled up by 1 / (1 - rate)
such that the sum over
all inputs is unchanged.
Note that the Dropout
layer only applies when training
is set to True
in call()
, such that no values are dropped during inference.
When using model.fit
, training
will be appropriately set to True
automatically. In other contexts, you can set the argument explicitly
to True
when calling the layer.
(This is in contrast to setting trainable=False
for a Dropout
layer.
trainable
does not affect the layer's behavior, as Dropout
does
not have any variables/weights that can be frozen during training.)
Args |
rate
|
Float between 0 and 1. Fraction of the input units to drop.
|
noise_shape
|
1D integer tensor representing the shape of the
binary dropout mask that will be multiplied with the input.
For instance, if your inputs have shape
(batch_size, timesteps, features) and
you want the dropout mask to be the same for all timesteps,
you can use noise_shape=(batch_size, 1, features) .
|
seed
|
A Python integer to use as random seed.
|
Call arguments |
inputs
|
Input tensor (of any rank).
|
training
|
Python boolean indicating whether the layer should behave in
training mode (adding dropout) or in inference mode (doing nothing).
|
Attributes |
input
|
Retrieves the input tensor(s) of a symbolic operation.
Only returns the tensor(s) corresponding to the first time
the operation was called.
|
output
|
Retrieves the output tensor(s) of a layer.
Only returns the tensor(s) corresponding to the first time
the operation was called.
|
Methods
from_config
View source
@classmethod
from_config(
config
)
Creates a layer from its config.
This method is the reverse of get_config
,
capable of instantiating the same layer from the config
dictionary. It does not handle layer connectivity
(handled by Network), nor weights (handled by set_weights
).
Args |
config
|
A Python dictionary, typically the
output of get_config.
|
Returns |
A layer instance.
|
symbolic_call
View source
symbolic_call(
*args, **kwargs
)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-06-07 UTC.
[null,null,["Last updated 2024-06-07 UTC."],[],[],null,["# tf.keras.layers.Dropout\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/layers/regularization/dropout.py#L6-L76) |\n\nApplies dropout to the input.\n\nInherits From: [`Layer`](../../../tf/keras/Layer), [`Operation`](../../../tf/keras/Operation) \n\n tf.keras.layers.Dropout(\n rate, noise_shape=None, seed=None, **kwargs\n )\n\n### Used in the notebooks\n\n| Used in the guide | Used in the tutorials |\n|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Effective Tensorflow 2](https://www.tensorflow.org/guide/effective_tf2) - [Migrate checkpoint saving](https://www.tensorflow.org/guide/migrate/checkpoint_saver) - [Migrate evaluation](https://www.tensorflow.org/guide/migrate/evaluator) - [Migrate the fault tolerance mechanism](https://www.tensorflow.org/guide/migrate/fault_tolerance) - [Migrate TensorBoard: TensorFlow's visualization toolkit](https://www.tensorflow.org/guide/migrate/tensorboard) | - [Overfit and underfit](https://www.tensorflow.org/tutorials/keras/overfit_and_underfit) - [Using DTensors with Keras](https://www.tensorflow.org/tutorials/distribute/dtensor_keras_tutorial) - [Simple audio recognition: Recognizing keywords](https://www.tensorflow.org/tutorials/audio/simple_audio) - [Deep Convolutional Generative Adversarial Network](https://www.tensorflow.org/tutorials/generative/dcgan) - [Basic text classification](https://www.tensorflow.org/tutorials/keras/text_classification) |\n\nThe `Dropout` layer randomly sets input units to 0 with a frequency of\n`rate` at each step during training time, which helps prevent overfitting.\nInputs not set to 0 are scaled up by `1 / (1 - rate)` such that the sum over\nall inputs is unchanged.\n\nNote that the `Dropout` layer only applies when `training` is set to `True`\nin `call()`, such that no values are dropped during inference.\nWhen using `model.fit`, `training` will be appropriately set to `True`\nautomatically. In other contexts, you can set the argument explicitly\nto `True` when calling the layer.\n\n(This is in contrast to setting `trainable=False` for a `Dropout` layer.\n`trainable` does not affect the layer's behavior, as `Dropout` does\nnot have any variables/weights that can be frozen during training.)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `rate` | Float between 0 and 1. Fraction of the input units to drop. |\n| `noise_shape` | 1D integer tensor representing the shape of the binary dropout mask that will be multiplied with the input. For instance, if your inputs have shape `(batch_size, timesteps, features)` and you want the dropout mask to be the same for all timesteps, you can use `noise_shape=(batch_size, 1, features)`. |\n| `seed` | A Python integer to use as random seed. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Call arguments -------------- ||\n|------------|-----------------------------------------------------------------------------------------------------------------------------------|\n| `inputs` | Input tensor (of any rank). |\n| `training` | Python boolean indicating whether the layer should behave in training mode (adding dropout) or in inference mode (doing nothing). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|----------|------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `input` | Retrieves the input tensor(s) of a symbolic operation. \u003cbr /\u003e Only returns the tensor(s) corresponding to the *first time* the operation was called. |\n| `output` | Retrieves the output tensor(s) of a layer. \u003cbr /\u003e Only returns the tensor(s) corresponding to the *first time* the operation was called. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `from_config`\n\n[View source](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/ops/operation.py#L191-L213) \n\n @classmethod\n from_config(\n config\n )\n\nCreates a layer from its config.\n\nThis method is the reverse of `get_config`,\ncapable of instantiating the same layer from the config\ndictionary. It does not handle layer connectivity\n(handled by Network), nor weights (handled by `set_weights`).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------|----------------------------------------------------------|\n| `config` | A Python dictionary, typically the output of get_config. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A layer instance. ||\n\n\u003cbr /\u003e\n\n### `symbolic_call`\n\n[View source](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/ops/operation.py#L58-L70) \n\n symbolic_call(\n *args, **kwargs\n )"]]