DeepFaceEdit is an interactive face generation and editing tool built on top of StyleGAN2-ADA, designed for manipulating facial attributes in a highly intuitive way. It enables users to generate, project, and semantically edit high-quality face images using latent space traversal techniques all through a user-friendly GUI.
Whether you're experimenting with synthetic identity creation or exploring the interpretability of GANs, DeepFaceEdit provides powerful tools to visualize and manipulate the latent space of human faces.
-
𧬠Face Generation
Generate realistic and diverse human faces from random seeds or latent vectors. -
π οΈ Face Editing
Modify facial attributes such as age, gender, expression, and more through semantic vector controls. -
πΌοΈ Face Projection
Project real images into StyleGAN2βs latent space using inversion techniques, enabling you to edit real faces. -
π±οΈ Interactive GUI
Built with FreeSimpleGUI, the interface offers an intuitive editing experience without writing code. -
β‘ Real-time Preview
Instantly visualize changes as you adjust latent parameters or apply vector edits. -
πΎ Vector Reuse
Save and reload latent vectors for consistent editing and iterative experimentation.
Generate unique faces using multiple techniques:
- Random seed generation β Explore diverse identities with different seeds.
- Z-vector based generation β Sample from the standard latent space.
- W-vector based generation β Leverage StyleGAN2βs intermediate latent space for better control.
- Traverse interpretable directions in latent space to control age, gender, smile, and other high-level features.
- Combine multiple edits with fine-grained control over intensity.
- Align real faces using
dlib's facial landmarks. - Perform GAN inversion to embed real images into the latent space for further editing.
git clone --recurse-submodules https://github.com/Haseebasif7/GAN.git
cd GANπ§© The --recurse-submodules flag ensures the stylegan2-ada-pytorch directory is properly cloned.
If you forgot --recurse-submodules, fix it with:
git submodule update --init --recursiveEnsure Python 3.11 is installed. You can download it from: https://www.python.org/downloads/release/python-3110/
Check installation:
python --versionCreate a virtual environment in the project root:
python -m venv venvActivate it:
Windows:
venv\Scripts\activateLinux/macOS:
source venv/bin/activateUpgrade pip:
pip install --upgrade pipThen install all required packages:
pip install -r requirements.txtπ‘ If you face issues installing dlib, make sure C++ build tools are available:
- Windows: Install Microsoft Build Tools
- Linux/macOS: Install cmake, g++, and Python headers
Two model files are required in the models/ folder.
Download from:
https://nvlabs-fi-cdn.nvidia.com/stylegan2-ada-pytorch/pretrained/ffhq.pkl
Then place it in the models/ folder:
GAN/
βββ models/
β βββ ffhq.pkl
Download the compressed file:
http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
Place it in the models/ folder:
GAN/
βββ models/
β βββ shape_predictor_68_face_landmarks.dat.bz2
Decompress it using the included script:
python models/decompress.pyβ After decompression, you will have:
GAN/
βββ models/
β βββ shape_predictor_68_face_landmarks.dat
β βββ shape_predictor_68_face_landmarks.dat.bz2
This project uses the StyleGAN2-ADA repo as a Git submodule.
Hereβs the .gitmodules content:
[submodule "stylegan2-ada-pytorch"]
path = stylegan2-ada-pytorch
url = https://github.com/NVlabs/stylegan2-ada-pytorch.gitGit reads this automatically when you clone with --recurse-submodules.
- Generator β Responsible for generating high-quality face images using the StyleGAN2-ADA model.
- Shifter β Handles latent space edits to apply semantic transformations (e.g., smile, age).
- Projector β Projects real-world face images into the latent space of the generator.
- Controller β Orchestrates the interaction between backend modules and manages workflow logic.
- Graphical Interface (GUI) β A user-friendly front-end built with FreeSimpleGUI for interactive editing and visualization.
## π Final Project Structure (After Setup)
gan-face-editor/
βββ core/
β βββ align_faces.py
β βββ generator.py
β βββ projector.py
β βββ shifter.py
βββ controller.py
βββ facegan-env/
βββ gui/
β βββ main.py
β βββ layouts/
β βββ interface.py
β βββ project.py
β βββ sliders.py
βββ LICENSE
βββ models/
β βββ ffhq.pkl
β βββ shape_predictor_68_face_landmarks.dat
β βββ shape_predictor_68_face_landmarks.dat.bz2
β βββ decompress.py
βββ README.md
βββ requirements.txt
βββ results/
β βββ age(2).png
β βββ m_n(2).png
βββ run.py
βββ settings/
β βββ config.py
β βββ __init__.py
βββ stylegan2-ada-pytorch/
βββ utils/
β βββ helpers.py
β βββ __init__.py
βββ vectors/
β βββ age.npy
β βββ eye_distance.npy
β βββ eye_eyebrow_distance.npy
β βββ eye_ratio.npy
β βββ eyes_open.npy
β βββ gender.npy
β βββ lip_ratio.npy
β βββ mouth_open.npy
β βββ mouth_ratio.npy
β βββ nose_mouth_distance.npy
β βββ nose_ratio.npy
β βββ nose_tip.npy
β βββ pitch.npy
β βββ roll.npy
β βββ smile.npy
β βββ yaw.npy
- Python
- VGG16
- PyTorch
- StyleGAN2-ADA
- dlib
- FreeSimpleGUI

