This project leverages deep learning to generate facial expressions from labeled data using an autoencoder architecture trained on the CelebA dataset. The model learns facial features (e.g., "Smiling") and can reconstruct or generate faces conditioned on these attributes.
Facial expression generation is a complex area in computer vision. This notebook uses the CelebA dataset, focusing on labeled facial attributes to generate or classify expressions using an autoencoder structure.
Facial_Expression_Generation_Labeled.ipynb
README.md
- ๐ Loads and filters CelebA facial attribute dataset
- ๐ง Trains a custom encoder-decoder (autoencoder) network
- ๐จ Generates expressions based on labeled features (e.g., "Smiling")
- ๐ Tracks and visualizes accuracy, loss, and outputs
- ๐งช Evaluates generation quality and classification accuracy
- Python 3.x
- PyTorch
- torchvision
- Google Colab
- Matplotlib, Pandas
- PIL, NumPy
CelebA โ a large-scale face dataset with 202,599 celebrity images, each annotated with 40 attribute labels (e.g., Smiling, Male, Eyeglasses).
This project focuses on the "Smiling" label to:
- Train the encoder to learn a latent representation of smiling vs non-smiling faces
- Use the decoder to generate corresponding facial images
The training process monitors:
- Reconstruction Loss (MSE or BCE): Measures how well the decoder recreates the input.
- Attribute Accuracy: A simple classifier is sometimes used on the latent representation to test if attributes like "Smiling" are preserved.
- Loss & Accuracy Visualization: The notebook includes plots to visualize training dynamics.
- Clone the repo or download the notebook.
- Upload the CelebA dataset and attribute file (
img_align_celeba.zipandlist_attr_celeba.txt) to your Google Drive. - Run the notebook on Google Colab (recommended).
- All required packages will be installed at runtime.
The notebook generates:
-
Images with changed expression attributes
-
Loss and accuracy graphs per epoch
-Confusion Matrix
-Hyperparamater Tuning

- The model uses a custom
CelebAZipDatasetclass to read images from a ZIP file without extracting. - Ensure you have enough runtime memory in Colab (recommended: GPU backend).
- The model can be extended to other labels like โHappy,โ โSad,โ or โSurprisedโ by changing attribute filters.
- Extend to full expression classification (multi-label)
- Use a Conditional GAN for sharper results
- Evaluate with metrics like FID or IS scores
- Add a web demo using Streamlit or Gradio
Sanya Shresta Jathanna
