[Python] Why is my CNN model overfitting even with dropout and data augmentation?

Discussão em 'Python' iniciado por Stack, Junho 26, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on a CNN-based image classification task using Keras and TensorFlow. My dataset contains around 5,000 labeled images across 5 classes. I'm applying data augmentation and using dropout layers, but the model still overfits — training accuracy reaches ~95%, while validation accuracy stays around 70%.

    model = tf.keras.models.Sequential([
    tf.keras.layers.Conv2D(32, (3,3), activation='relu', input_shape=(128, 128, 3)),
    tf.keras.layers.MaxPooling2D(2,2),
    tf.keras.layers.Dropout(0.2),

    tf.keras.layers.Conv2D(64, (3,3), activation='relu'),
    tf.keras.layers.MaxPooling2D(2,2),
    tf.keras.layers.Dropout(0.3),

    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dropout(0.5),
    tf.keras.layers.Dense(5, activation='softmax')
    ])

    model.compile(optimizer='adam',
    loss='categorical_crossentropy',
    metrics=['accuracy'])
    I’m using ImageDataGenerator for augmentation:

    datagen = ImageDataGenerator(
    rescale=1./255,
    rotation_range=20,
    zoom_range=0.2,
    width_shift_range=0.1,
    height_shift_range=0.1,
    horizontal_flip=True,
    validation_split=0.2
    )
    What I’ve tried:

    Increased dropout rates

    Reduced model complexity

    Added L2 regularization

    Tried early stopping

    Played with learning rate

    Questions:

    What could be the reason for continued overfitting?

    Are there other techniques I can try to regularize the model better?

    Could this be due to an issue with my dataset or preprocessing?

    Any advice or suggestions are welcome!

    Continue reading...

Compartilhe esta Página