CoolFace
Apppublic

cds006/Progan

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

Progressive GAN - Quick Start Guide

Get up and running in 5 minutes!

Prerequisites Check

bash
# Check Python version (need 3.8+)
python --version

# Check CUDA availability
python -c "import torch; print(f'CUDA: {torch.cuda.is_available()}, Version: {torch.version.cuda}')"

# Check GPU
nvidia-smi

Expected output:

  • —Python 3.8 or higher
  • —CUDA available: True
  • —RTX 4000 Ada with ~20GB memory

Step 1: Install Dependencies (2 minutes)

bash
# Install required packages
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
pip install numpy Pillow tqdm gradio pytest

# Verify installation
python -c "import torch; print('PyTorch:', torch.__version__); print('CUDA:', torch.cuda.is_available())"

Step 2: Prepare Dataset (5-10 minutes)

Option A: Use Your CelebA-HQ Dataset

If you already have CelebA-HQ:

bash
# Verify your dataset
python dataset.py /path/to/celeba_hq

# Expected output: "Found 30000 images"

Option B: Download CelebA-HQ

Download from official sources and organize:

celeba_hq/
├── 00000.png
├── 00001.png
├── ...
└── 29999.png

Each image should be 1024×1024 pixels.

Step 3: Run Tests (1 minute)

bash
# Test model architecture
python test_model.py

# All tests should pass ✓

Step 4: Start Training (Recommended: Start Small)

Quick Test Training (1 hour - 64×64 resolution)

bash
# Train only up to 64x64 for testing
python train.py \
    --data_dir /path/to/celeba_hq \
    --max_res 64

# Monitor progress in outputs/samples/

This will train through:

  • —4×4 → 8×8 → 16×16 → 32×32 → 64×64
  • —Total time: ~2 hours
  • —VRAM usage: ~6GB max

Full Training (6 days - 1024×1024 resolution)

bash
# Full progressive training
python train.py \
    --data_dir /path/to/celeba_hq \
    --max_res 1024

# This will take ~140 hours (6 days) on RTX 4000 Ada

Resume Training

If training is interrupted:

bash
python train.py \
    --data_dir /path/to/celeba_hq \
    --resume checkpoints/checkpoint_res256_step50000.pt

Step 5: Monitor Training

Training generates files in:

outputs/
├── samples/                    # Visual samples (every 5000 steps)
│   ├── samples_step5000_res8.png
│   ├── samples_step10000_res16.png
│   └── ...
└── logs/
    └── training_log.json       # Training metrics

Watch the samples directory to see quality improving!

Step 6: Generate Images (After Any Training Stage)

Basic Generation

bash
# Generate 64 images
python inference.py \
    --checkpoint checkpoints/checkpoint_res64_step20000.pt \
    --output generated/my_faces.png \
    --num_images 64 \
    --grid

High-Quality Generation (with Truncation)

bash
# Generate higher quality (less variation)
python inference.py \
    --checkpoint checkpoints/checkpoint_res256_step80000.pt \
    --output generated/high_quality.png \
    --num_images 64 \
    --truncation 0.7 \
    --grid

Reproducible Generation

bash
# Use seed for reproducibility
python inference.py \
    --checkpoint checkpoints/final_model.pt \
    --output generated/seed42.png \
    --num_images 16 \
    --seed 42 \
    --grid

Step 7: Launch Web Interface

bash
# Start Gradio app
python app.py --checkpoint checkpoints/checkpoint_res256_step80000.pt

# Open browser to: http://localhost:7860

Web interface features:

  • —Random generation with seed control
  • —Interpolation between faces
  • —Latent space exploration

Training Schedule & Checkpoints

ResolutionTime per StageCheckpoint NameVRAMQuality
4×430 mincheckpointres4*2GBInitial
8×845 mincheckpointres8*2GBBasic shapes
16×161 hourcheckpointres16*3GBRough faces
32×322 hourscheckpointres32*4GBRecognizable
64×644 hourscheckpointres64*6GBGood quality
128×1288 hourscheckpointres128*8GBHigh quality
256×25616 hourscheckpointres256*12GBVery good
512×51236 hourscheckpointres512*16GBExcellent
1024×102472 hourscheckpointres1024*19GBBest

Common Issues & Solutions

1. Out of Memory Error

RuntimeError: CUDA out of memory

Solution: Reduce batch size in config.py

python
# In config.py, change:
batch_sizes = {
    256: 8,   # Reduced from 14
    512: 4,   # Reduced from 6
    1024: 2   # Reduced from 3
}

2. Dataset Not Found

ValueError: No images found in /path/to/data

Solution: Check dataset path and file extensions

bash
# Verify files exist
ls /path/to/celeba_hq/*.png | wc -l

# Should show 30000 (or your dataset size)

3. Training Too Slow

Solutions:

  1. 1.Check GPU is being used:
python
python -c "import torch; print(torch.cuda.is_available())"
  1. 1.Increase data loading workers in config.py:
python
num_workers = 8  # Use more CPU cores
  1. 1.Ensure mixed precision is enabled (already default):
python
use_amp = True

4. Poor Quality Results

Solutions:

  1. 1.Train longer: Each stage needs 800k images
  2. 2.Check training logs: Look for unstable loss values
  3. 3.Use truncation: Try --truncation 0.7 during inference
  4. 4.Verify dataset: Ensure images are high quality

5. Checkpoint Loading Error

KeyError: 'g_ema_state'

Solution: Use --resume with correct checkpoint format

bash
# List available checkpoints
ls -lh checkpoints/

# Use most recent checkpoint
python train.py --data_dir /path/to/data --resume checkpoints/checkpoint_res128_step40000.pt

Performance Optimization Tips

For Faster Training:

  1. 1.Use AMP (Already enabled by default)
  2. 2.Increase workers: Set num_workers=8 in config
  3. 3.Pin memory: Already enabled for CUDA
  4. 4.Start from checkpoint: Resume from previous training

For Better Quality:

  1. 1.Train longer: Don't stop at minimum
  2. 2.Use EMA generator: Already used in inference
  3. 3.Apply truncation: Use truncation=0.7-0.8
  4. 4.Verify dataset quality: Check sample images

For Lower VRAM Usage:

  1. 1.Reduce batch sizes: Edit config.py
  2. 2.Train lower resolution: Use --max_res 512
  3. 3.Reduce workers: Set num_workers=4

Recommended Training Strategy

Strategy 1: Full Training (Best Quality)

bash
# Start fresh, train to 1024×1024
python train.py --data_dir /path/to/celeba_hq --max_res 1024

# Time: ~6 days
# Result: Highest quality 1024×1024 faces

Strategy 2: Quick Test (Fast Results)

bash
# Train only to 128×128
python train.py --data_dir /path/to/celeba_hq --max_res 128

# Time: ~12 hours
# Result: Good quality 128×128 faces

Strategy 3: Incremental (Flexible)

bash
# Train to 256×256
python train.py --data_dir /path/to/celeba_hq --max_res 256

# Later: Resume and extend to 512×512
python train.py --data_dir /path/to/celeba_hq --max_res 512 \
    --resume checkpoints/checkpoint_res256_step*.pt

# Later: Extend to 1024×1024
python train.py --data_dir /path/to/celeba_hq --max_res 1024 \
    --resume checkpoints/checkpoint_res512_step*.pt

Verification Checklist

Before starting full training, verify:

  • —[ ] CUDA is available (torch.cuda.is_available() == True)
  • —[ ] GPU has sufficient memory (20GB for RTX 4000 Ada)
  • —[ ] Dataset path is correct and contains images
  • —[ ] Test training works (python test_model.py)
  • —[ ] Sufficient disk space (~50GB for checkpoints + outputs)

Next Steps

After successful training:

  1. 1.Generate samples: Use inference.py
  2. 2.Launch web app: Use app.py
  3. 3.Fine-tune: Adjust hyperparameters in config.py
  4. 4.Experiment: Try different truncation values
  5. 5.Share: Generate interpolation videos

Support

If you encounter issues:

  1. 1.Check this quick start guide
  2. 2.Review error messages carefully
  3. 3.Verify dataset and checkpoint paths
  4. 4.Check CUDA availability
  5. 5.Review training logs in outputs/logs/

Summary of Commands

bash
# Install
pip install -r requirements.txt

# Test
python test_model.py

# Train
python train.py --data_dir /path/to/celeba_hq

# Generate
python inference.py --checkpoint checkpoints/final_model.pt --output generated.png --grid

# Web UI
python app.py --checkpoint checkpoints/final_model.pt

That's it! You're ready to train Progressive GAN and generate high-quality face images. 🎉