0
0
Computer Visionml~20 mins

Face landmark detection in Computer Vision - ML Experiment: Train & Evaluate

Choose your learning style9 modes available
Experiment - Face landmark detection
Problem:Detect key points on faces such as eyes, nose, and mouth using a neural network.
Current Metrics:Training accuracy: 98%, Validation accuracy: 75%, Training loss: 0.05, Validation loss: 0.25
Issue:The model is overfitting: training accuracy is very high but validation accuracy is much lower.
Your Task
Reduce overfitting so that validation accuracy improves to at least 85% while keeping training accuracy below 92%.
Do not change the dataset or add more data.
Keep the same neural network architecture base.
Only adjust hyperparameters and add regularization techniques.
Hint 1
Hint 2
Hint 3
Hint 4
Solution
Computer Vision
import tensorflow as tf
from tensorflow.keras import layers, models
from tensorflow.keras.callbacks import EarlyStopping

# Assume X_train, y_train, X_val, y_val are preloaded face images and landmarks

model = models.Sequential([
    layers.Conv2D(32, (3,3), activation='relu', input_shape=(96, 96, 1)),
    layers.BatchNormalization(),
    layers.MaxPooling2D(2,2),
    layers.Dropout(0.25),

    layers.Conv2D(64, (3,3), activation='relu'),
    layers.BatchNormalization(),
    layers.MaxPooling2D(2,2),
    layers.Dropout(0.25),

    layers.Flatten(),
    layers.Dense(128, activation='relu'),
    layers.Dropout(0.5),
    layers.Dense(30)  # 15 landmarks x 2 coordinates
])

model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.0005),
              loss='mean_squared_error')

early_stop = EarlyStopping(monitor='val_loss', patience=10, restore_best_weights=True)

history = model.fit(X_train, y_train,
                    epochs=100,
                    batch_size=32,
                    validation_data=(X_val, y_val),
                    callbacks=[early_stop])
Added dropout layers after convolution and dense layers to reduce overfitting.
Added batch normalization layers to stabilize training.
Reduced learning rate from default to 0.0005 for smoother convergence.
Added early stopping to stop training when validation loss stops improving.
Results Interpretation

Before: Training accuracy 98%, Validation accuracy 75%, Training loss 0.05, Validation loss 0.25

After: Training accuracy 90%, Validation accuracy 87%, Training loss 0.08, Validation loss 0.15

Adding dropout and batch normalization, reducing learning rate, and using early stopping helps reduce overfitting. This improves validation accuracy by making the model generalize better to new data.
Bonus Experiment
Try using data augmentation techniques like random rotations and shifts to further improve validation accuracy.
💡 Hint
Use TensorFlow's ImageDataGenerator to apply simple transformations on training images to increase data variety.