【问题标题】:Despite employing Dropout, MaxPooling, Early Stopping, and Regularizers, my CNN model is still overfitting. How can I further prevent overfitting?尽管使用了 Dropout、MaxPooling、Early Stopping 和正则化器,我的 CNN 模型仍然过拟合。如何进一步防止过拟合?
【发布时间】:2021-04-30 15:42:15
【问题描述】:

正如标题清楚地描述了我正在经历的情况,尽管使用了 DropoutMaxPoolingEarlyStoppingRegularizers,但我的 CNN 模型仍然过拟合。此外,我尝试了各种learning_ratedropout_rateL1/L2 regularization weight decay。如何进一步防止过拟合?

这是模型(在TensorFlow 后端使用Keras):

batch_size = 128
num_epochs = 200
weight_decay = 1e-3
num_filters = 32 * 2
n_kernel_size = 5
num_classes = 3
activation_fn = 'relu'
nb_units = 128
last_dense_units = 128
n_lr = 0.001
n_momentum = 0.99
n_dr = 0.00001
dropout_rate = 0.8

model.add(Embedding(nb_words, EMBEDDING_DIM, input_length=max_seq_len))
model.add(Dropout(dropout_rate))
model.add(Conv1D(num_filters, n_kernel_size, padding='same', activation=activation_fn,
                 kernel_regularizer=regularizers.l2(weight_decay)))
model.add(MaxPooling1D())
model.add(GlobalMaxPooling1D())
model.add(Dense(128, activation=activation_fn, kernel_regularizer=regularizers.l2(weight_decay)))
model.add(Dropout(dropout_rate))
model.add(Dense(num_classes, activation='softmax'))

adam = Adam(lr=n_lr, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=n_dr)
model.compile(loss='categorical_crossentropy', optimizer=adam, metrics=['acc'])

early_stopping = EarlyStopping(
    monitor='val_loss',
    patience=3,
    mode='min',
    verbose=1,
    restore_best_weights=True
)

model.fit(...)

以下是训练和验证的准确度图:

【问题讨论】:

  • 这不是过拟合。
  • 那么,这种情况的定义是什么?以及如何使验证准确度更接近训练准确度?
  • 这被称为“泛化差距” - 请参阅(自己的)答案herehere。至于我们如何关闭它,嗯,这正是十亿美元的问题......!

标签: keras deep-learning neural-network conv-neural-network overfitting-underfitting


【解决方案1】:

还有过拟合的方法可以尝试:

您的模型似乎确实过度拟合了大约 10%。但是多少过拟合才算过拟合呢?我会关注this 的帖子和相关对话,以便您最好地评估您的具体情况。

【讨论】:

  • 是的,没错,这 10% 对我的研究至关重要。 #2 已经完成,因为我的测试集与训练集和验证集是分开的。 #3 & #4 尚未应用,因此输入是文本。
  • 如果您输入的是文本,数据增强仍然是一个选项,请参阅arxiv.org/pdf/1901.11196.pdf
猜你喜欢
  • 2020-08-24
  • 2022-02-20
  • 1970-01-01
  • 1970-01-01
  • 2019-02-10
  • 2021-09-03
  • 2016-07-08
  • 2018-03-21
  • 2021-10-17
相关资源
最近更新 更多