简体   繁体   English

为什么我的 model 在进行正则化和批量标准化后会过拟合

[英]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.

相关问题 为什么我的 model 在第二个时期过拟合? - Why is my model overfitting on the second epoch? BatchNormalization in tensorflow model - BatchNormalization in tensorflow model 为什么model.losss返回正则化损失? - Why does model.losses return regularization losses? 为什么 keras 和 BatchNormalization 有下划线? - Why is keras and BatchNormalization underlined? CatBoost过度拟合后,有没有办法保存经过训练的模型? - Is there way to save trained model after overfitting occurs in CatBoost? CNN model 在达到 50% 的准确度后对数据过度拟合 - CNN model is overfitting to data after reaching 50% accuracy 这是过拟合的情况吗? 我该怎么做才能修复我的 model? - Is this a case of Overfitting? what can i do to fix my model? 我怎么知道我的神经网络模型是否过度拟合(Keras) - How do I know if my Neural Network model is overfitting or not (Keras) 在使用多个时期进行训练时如何检查我的模型是否过拟合 - How to check if my model is overfitting or not when training with many epochs 我的 model 是过拟合还是欠拟合? .如何从这个损失曲线上识别出来呢? - Is my model overfitting or underfitting ? .How to identify it from this loss curve?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM