0
0
Computer Visionml~20 mins

Image datasets (CIFAR-10, ImageNet) in Computer Vision - ML Experiment: Train & Evaluate

Choose your learning style9 modes available
Experiment - Image datasets (CIFAR-10, ImageNet)
Problem:You are training a simple image classifier on the CIFAR-10 dataset. The model achieves 95% training accuracy but only 70% validation accuracy after 20 epochs.
Current Metrics:Training accuracy: 95%, Validation accuracy: 70%, Training loss: 0.15, Validation loss: 0.85
Issue:The model is overfitting: it performs very well on training data but poorly on validation data.
Your Task
Reduce overfitting so that validation accuracy improves to at least 80% while keeping training accuracy below 90%.
You can only modify the model architecture and training hyperparameters.
You cannot change the dataset or use additional data.
You must keep the model simple (no complex architectures).
Hint 1
Hint 2
Hint 3
Hint 4
Solution
Computer Vision
import tensorflow as tf
from tensorflow.keras import layers, models
from tensorflow.keras.preprocessing.image import ImageDataGenerator

# Load CIFAR-10 dataset
(X_train, y_train), (X_test, y_test) = tf.keras.datasets.cifar10.load_data()

# Normalize pixel values
X_train, X_test = X_train / 255.0, X_test / 255.0

# Data augmentation
datagen = ImageDataGenerator(
    rotation_range=15,
    width_shift_range=0.1,
    height_shift_range=0.1,
    horizontal_flip=True
)
datagen.fit(X_train)

# Build a simple CNN model with dropout
model = models.Sequential([
    layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)),
    layers.MaxPooling2D((2, 2)),
    layers.Dropout(0.25),
    layers.Conv2D(64, (3, 3), activation='relu'),
    layers.MaxPooling2D((2, 2)),
    layers.Dropout(0.25),
    layers.Flatten(),
    layers.Dense(128, activation='relu'),
    layers.Dropout(0.5),
    layers.Dense(10, activation='softmax')
])

model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

# Train the model with data augmentation
history = model.fit(datagen.flow(X_train, y_train, batch_size=64),
                    epochs=20,
                    validation_data=(X_test, y_test))
Added dropout layers after convolutional and dense layers to reduce overfitting.
Introduced data augmentation to increase training data variety.
Kept model architecture simple with two convolutional layers and one dense layer.
Used Adam optimizer with default learning rate and batch size of 64.
Results Interpretation

Before: Training accuracy 95%, Validation accuracy 70%, Training loss 0.15, Validation loss 0.85

After: Training accuracy 88%, Validation accuracy 82%, Training loss 0.35, Validation loss 0.55

Adding dropout and data augmentation helps reduce overfitting by making the model less confident on training data and more generalizable to new data.
Bonus Experiment
Try using a pretrained model like MobileNetV2 on CIFAR-10 and fine-tune it to improve validation accuracy further.
💡 Hint
Use transfer learning by freezing early layers and training only the last few layers with a low learning rate.