[英]Why is my model overfitting after doing regularization and batchnormalization
This is my CNN model structure.这是我的 CNN model 结构。
def make_dcnn_model():
model = models.Sequential()
model.add(layers.Conv2D(5, (5, 5), input_shape=(9, 128,1), padding='same', strides = (1,2), activity_regularizer=tf.keras.regularizers.l1(0.001)))
model.add(layers.LeakyReLU())
model.add(BatchNormalization())
model.add(layers.AveragePooling2D((4, 4), strides = (2,4)))
model.add(layers.Conv2D(10, (5, 5), padding='same', activity_regularizer=tf.keras.regularizers.l1(0.001)))
model.add(layers.LeakyReLU())
model.add(BatchNormalization())
model.add(layers.AveragePooling2D((2, 2), strides = (1,2)))
model.add(layers.Flatten())
model.add(layers.Dense(50, activity_regularizer=tf.keras.regularizers.l1(0.001)))
model.add(layers.LeakyReLU())
model.add(BatchNormalization())
model.add(layers.Dense(6, activation='softmax'))
return model
The result shows that this model fit well the training data and for the validation data the great fluctuation of validation accuracy occurred.结果表明,这个model与训练数据非常吻合,而对于验证数据,验证准确率出现了很大的波动。
Train on 7352 samples, validate on 2947 samples Epoch 1/3000 7352/7352 [==============================] - 3s 397us/sample - loss: 0.1016 - accuracy: 0.9698 - val_loss: 4.0896 - val_accuracy: 0.5816 Epoch 2/3000 7352/7352 [==============================] - 2s 214us/sample - loss: 0.0965 - accuracy: 0.9727 - val_loss: 1.2296 - val_accuracy: 0.7384 Epoch 3/3000 7352/7352 [==============================] - 1s 198us/sample - loss: 0.0930 - accuracy: 0.9727 - val_loss: 0.9901 - val_accuracy: 0.7855 Epoch 4/3000 7352/7352 [==============================] - 2s 211us/sample - loss: 0.1013 - accuracy: 0.9701 - val_loss: 0.5319 - val_accuracy: 0.9114 Epoch 5/3000 7352/7352 [==============================] - 1s 201us/sample - loss: 0.0958 - accuracy: 0.9721 - val_loss: 0.6938 - val_accuracy: 0.8388 Epoch 6/3000 7352/7352 [==============================] - 2s 205us/sample - loss: 0.0925 - accuracy: 0.9743 - val_loss: 1.4033 - val_accuracy: 0.7472 Epoch 7/3000 7352/7352 [============================
训练 7352 个样本,验证 2947 个样本 Epoch 1/3000 7352/7352 [==============================] - 3s 397us/样本 - 损失:0.1016 - 准确度:0.9698 - val_loss:4.0896 - val_accuracy:0.5816 Epoch 2/3000 7352/7352 [====================== =======] - 2s 214us/样本 - 损失:0.0965 - 准确度:0.9727 - val_loss:1.2296 - val_accuracy:0.7384 Epoch 3/3000 7352/7352 [============= =================] - 1s 198us/样本 - 损失:0.0930 - 准确度:0.9727 - val_loss:0.9901 - val_accuracy:0.7855 Epoch 4/3000 7352/7352 [=== ===========================] - 2s 211us/样本 - 损失:0.1013 - 准确度:0.9701 - val_loss:0.5319 - val_accuracy:0.9114 Epoch 5/3000 7352/7352 [===============================] - 1s 201us/样本 - 损耗:0.0958 - 准确度: 0.9721 - val_loss: 0.6938 - val_accuracy: 0.8388 Epoch 6/3000 7352/7352 [==============================] - 2s 205us/样本 - 损失:0.0925 - 准确度:0.9743 - val_loss:1.4033 - val_accuracy:0.7472 Epoch 7/3000 7352/7352 [======================= ===== ==] - 1s 203us/sample - loss: 0.0948 - accuracy: 0.9740 - val_loss: 0.8375 - val_accuracy: 0.7998
==] - 1s 203us/样本 - 损失:0.0948 - 准确度:0.9740 - val_loss:0.8375 - val_accuracy:0.7998
Reducing overfitting is a matter of trial and error.减少过度拟合是一个反复试验的问题。 There are many ways to deal with it.
有很多方法可以处理它。
Try to add more data to the model or maybe augmenting your data if you're dealing with images.尝试向 model 添加更多数据,或者在处理图像时增加数据。 (very helpful)
(非常有帮助)
Try reducing the complexity of the model by tweaking the parameters of the layers.尝试通过调整层的参数来降低 model 的复杂性。
Try stopping the training earlier.尝试早点停止训练。
Regularization and batch normalization are very helpful but it may be the case that your model is already performing much worse without them in terms of overfitting.正则化和批量归一化非常有帮助,但在过度拟合方面,如果没有它们,您的 model 可能已经表现得更差了。 Try different types of regularization.
尝试不同类型的正则化。 (maybe Dropout)
(也许辍学)
My guess is that by adding more variety in the data you're model will overfit less.我的猜测是,通过在数据中添加更多种类,您的 model 将减少过度拟合。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.