Optimizing Facial Emotion Recognition Model Hyperparameters using Genetic Algorithms

33 Views Asked by At

I'm building a facial emotion recognition system that can classify emotions such as happiness, sadness, anger, surprise, etc. I've trained a convolutional neural network model using TensorFlow/Keras, and currently, it achieves an accuracy of around 50%. However, I believe that fine-tuning the hyperparameters could potentially improve the accuracy further.

Now, I'm interested in optimizing the hyperparameters of my model to achieve better accuracy. I've heard about using genetic algorithms for hyperparameter optimization, but I'm not sure how to proceed. Could someone guide me on how to apply genetic algorithms to fine-tune the hyperparameters of my model? Specifically, how can I modify my code to incorporate genetic algorithms for hyperparameter optimization?

Here's a summary of my code:

import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras import models,layers

# Data Augmentation
augmentor = ImageDataGenerator(
    rescale=1.0/255,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True
)

# Loading data and resizing images to 48x48 pixels
augmented_trained_data = augmentor.flow_from_directory(
    "Facial Recognition Dataset/Train",
    target_size=(48, 48),
    batch_size=32,
    color_mode="grayscale",
    class_mode="categorical"
)

augmented_validation_data = augmentor.flow_from_directory(
    "Facial Recognition Dataset/Validation",
    target_size=(48, 48),
    batch_size=32,
    color_mode="grayscale",
    class_mode="categorical"
)

augmented_testing_data = augmentor.flow_from_directory(
    "Facial Recognition Dataset/Test",
    target_size=(48, 48),
    batch_size=32,
    color_mode="grayscale",
    class_mode="categorical"
)

# Model Definition
model = models.Sequential([
    layers.Conv2D(32, (2, 2), activation="relu", input_shape=(48, 48, 1)),
    layers.MaxPool2D((2, 2)),
    layers.Conv2D(64, (2, 2), activation="relu"),
    layers.MaxPool2D((2, 2)),
    layers.Conv2D(128, (2, 2), activation="relu"),
    layers.MaxPool2D((2, 2)),
    layers.Flatten(),
    layers.Dense(128, activation="relu"),
    layers.Dropout(0.25),
    layers.Dense(6, activation="softmax")
])

# Model Compilation
model.compile(
    optimizer='adam',
    loss=tf.keras.losses.CategoricalCrossentropy(from_logits=False),
    metrics=["accuracy"]
)

# Model Training
model.fit(
    augmented_trained_data,
    validation_data=augmented_validation_data,
    epochs=10
)

# Model Evaluation
test_loss, test_accuracy = model.evaluate(augmented_testing_data)
print(f"Test Accuracy: {test_accuracy * 100:.2f}%")'''


0

There are 0 best solutions below