CoolFace
Apppublic

bilal3406/DDPM-Face-Generator

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

DDPM Face Generator & Reconstructor (From Scratch)

This Space hosts a Denoising Diffusion Probabilistic Model (DDPM) built entirely from scratch using base PyTorch, without relying on abstracted pipelines like HuggingFace Diffusers. It was trained on a subset of the FFHQ (Flickr-Faces-HQ) dataset.

๐Ÿ—๏ธ Architecture Details

  • โ€”Framework: Pure PyTorch.
  • โ€”Backbone: Custom U-Net with a channel progression of 64 โ†’ 128 โ†’ 256.
  • โ€”Time Awareness: Sinusoidal Positional Embeddings injected into every Residual Block.
  • โ€”Global Structure: A Self-Attention block deployed at the $32 \times 32$ bottleneck to help the model learn spatial symmetry.
  • โ€”Forward Process: Linear variance schedule over $T = 300$ timesteps.

โš ๏ธ Training & Hardware Constraints

This model was engineered to train within the strict hardware limits of a Kaggle Notebook (Dual T4 GPUs with 16GB VRAM, and a 30GB System RAM limit).

  • โ€”To prevent VRAM fragmentation, it utilizes Automatic Mixed Precision (AMP) and aggressive garbage collection.
  • โ€”To prevent System RAM leaks, the PyTorch DataLoader is restricted to the main thread.
  • โ€”Note on Visual Quality: Due to compute time limitations, these weights were trained for ~20 epochs. Therefore, the model has successfully learned local distributions (skin tones, hair textures) but lacks the compute time required to fully lock in global facial symmetry (resulting in the current abstract, "Picasso-style" outputs).

๐Ÿš€ How to Use This Space

This interactive Gradio application features two main tabs:

  1. 1.Generate Face: Performs unconditional generation. The model starts with a tensor of pure Gaussian noise and iteratively removes the noise over 300 steps to hallucinate a novel face. No input required.
  2. 2.Reconstruct & Evaluate: Upload a target image. The script will apply maximum noise to destroy the image, and then force the U-Net to walk backward to reconstruct it. The app calculates PSNR and SSIM scores to quantitatively evaluate the spatial accuracy of the reconstruction.

๐Ÿ‘ฅ Authors

Engineered and trained by:

  • โ€”Muhammad Bilal Ahmad Ali Hamza FAST National University of Computer and Emerging Sciences (FAST NUCES)