Dropout 层是一种正则化技术,用于防止模型过拟合。它可以在训练过程中随机“丢弃”(即设置为 0)神经元输出,从而迫使网络学习更加鲁棒的特征。
使用方法
以下是一个使用 Dropout 层的例子:
import tensorflow as tf
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10, activation='softmax')
])
参数
rate
:丢弃的比例,默认为 0.5。noise_shape
:噪声的形状,默认与输入相同。
扩展阅读
Dropout 示例