🚀 Open Source • Powered by Stable Diffusion & ControlNet

Parametric Face Generation
With Precise Feature Control

A powerful ControlNet-based system that enables precise control over individual facial features during face generation. Create entirely new synthetic faces by composing and manipulating 8 distinct facial components with parametric control over position, scale, and composition.

8
Facial Features
512×512
Resolution
Real-time
Generation

Built for Education

This project serves as a comprehensive template for bachelor students at the University of Bremen, where I supervise their theses. It provides a solid foundation for students to explore parametric face generation, test hypotheses, and build upon established best practices.

While designed for educational purposes, everyone is welcome to use, learn from, and contribute to this project.

University of Bremen Logo

Powerful Features

Everything you need for precise face generation

🎯

Parametric Control

Independently control 8 distinct facial features including eyes, nose, mouth, hair, and more. Adjust position, scale, and composition for complete creative freedom.

🧩

Feature Composition

Mix and match features from different faces in your dataset. Create entirely new, synthetic faces with precise control over each component.

Real-time Preview

See immediate visual feedback as you compose masks. The intuitive GUI provides instant preview of your feature selections before generation.

🎨

Semantic Segmentation

Leverages BiSeNet for accurate facial parsing. Automatically segments faces into 19 regions, enabling precise feature extraction and manipulation.

🔧

Customizable Training

Train on your own face datasets. Full control over training parameters, validation, and checkpoint management with accelerate support.

📊

Interactive GUI

User-friendly Gradio interface for seamless face generation. Browse feature galleries, compose masks, and adjust generation parameters effortlessly.

Interactive Demo

Experience the power of parametric face generation

ControlNet Face Generator GUI
1

Dataset Loading

Scan and index facial feature masks from your dataset

2

Feature Selection

Browse galleries and select features for each facial component

3

Composition Canvas

Real-time preview of combined masks before generation

4

Generation Controls

Adjust seed, steps, and ControlNet scale for perfect results

How It Works

From face images to generated faces in three simple steps

01

Prepare Dataset

Use BiSeNet face parsing to generate semantic segmentation masks from your face images. The model automatically segments 19 facial regions, from which 8 features are selected.

python inference.py \
  --model resnet34 \
  --weight ./resnet34.pt \
  --input ./faces \
  --output ./dataset/output/resnet34
BiSeNet ResNet34 Segmentation
02

Train ControlNet

Fine-tune a ControlNet model on your face-mask pairs. The training script automatically handles multi-channel mask stacking, validation, and checkpoint management.

accelerate launch train.py \
  --data_root ./dataset \
  --output_dir ./trained_model \
  --batch_size 4 \
  --max_steps 50000
Stable Diffusion ControlNet PyTorch
03

Generate Faces

Launch the interactive GUI to compose and generate new faces. Select features, adjust parameters, and see results in real-time with instant visual feedback.

python face-mask/gui-inference.py \
  --controlnet_dir ./trained_model/final_model \
  --share
Gradio Real-time Interactive

Architecture

Built on proven diffusion model technology

Training Pipeline

Face RGB
512×512
VAE Encoder
Frozen
Latents
4×64×64
8-Ch Masks
Features
ControlNet
Trainable
Conditioning
Features
UNet + Noise
DDPM
MSE Loss
Optimize

Inference Pipeline

Feature Masks
8 Channels
ControlNet
Trained
Conditioning
Guidance
Text Prompt
Optional
CLIP Text
Encoder
Text Embed
Context
UNet Denoising
DDPM
VAE Decoder
512×512

Technology Stack

Built with industry-standard tools and frameworks

🔥

PyTorch

Deep learning framework for model training and inference

🎨

Stable Diffusion

Foundation model for high-quality image generation

🎮

ControlNet

Conditional control for precise guidance during generation

🧠

BiSeNet

Face parsing model for semantic segmentation

Accelerate

Distributed training with multi-GPU support

🖥️

Gradio

Interactive web interface for user-friendly interaction

🤗

Diffusers

HuggingFace library for diffusion model pipelines

📦

Transformers

Text encoding with CLIP for prompt conditioning

Get Started

Start generating faces in minutes

1

Clone Repository

git clone https://github.com/danial-barazandeh/ControlNetFaceGenerator.git
cd controlnet-face-generator
2

Install Dependencies

pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118
pip install diffusers transformers accelerate safetensors
pip install gradio opencv-python pillow matplotlib tqdm
3

Prepare Dataset & Train

Follow the detailed instructions in the README to generate masks with BiSeNet and train your ControlNet model.

Requirements

  • Python 3.8+
  • CUDA-capable GPU (8GB+ VRAM)
  • 16GB+ VRAM for training
  • Face dataset for training
For inference only, 8GB VRAM is sufficient

Ready to Start Generating?

Join the community and start creating parametric faces with precise control