cds006/Progan
0
Progressive GAN - Quick Start Guide
Get up and running in 5 minutes!
Prerequisites Check
# 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-smiExpected output:
- Python 3.8 or higher
- CUDA available: True
- RTX 4000 Ada with ~20GB memory
Step 1: Install Dependencies (2 minutes)
# 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:
# 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.pngEach image should be 1024×1024 pixels.
Step 3: Run Tests (1 minute)
# 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)
# 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)
# 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 AdaResume Training
If training is interrupted:
python train.py \
--data_dir /path/to/celeba_hq \
--resume checkpoints/checkpoint_res256_step50000.ptStep 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 metricsWatch the samples directory to see quality improving!
Step 6: Generate Images (After Any Training Stage)
Basic Generation
# Generate 64 images
python inference.py \
--checkpoint checkpoints/checkpoint_res64_step20000.pt \
--output generated/my_faces.png \
--num_images 64 \
--gridHigh-Quality Generation (with Truncation)
# 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 \
--gridReproducible Generation
# Use seed for reproducibility
python inference.py \
--checkpoint checkpoints/final_model.pt \
--output generated/seed42.png \
--num_images 16 \
--seed 42 \
--gridStep 7: Launch Web Interface
# Start Gradio app
python app.py --checkpoint checkpoints/checkpoint_res256_step80000.pt
# Open browser to: http://localhost:7860Web interface features:
- Random generation with seed control
- Interpolation between faces
- Latent space exploration
Training Schedule & Checkpoints
Common Issues & Solutions
1. Out of Memory Error
RuntimeError: CUDA out of memorySolution: Reduce batch size in config.py
# 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/dataSolution: Check dataset path and file extensions
# Verify files exist
ls /path/to/celeba_hq/*.png | wc -l
# Should show 30000 (or your dataset size)3. Training Too Slow
Solutions:
- Check GPU is being used:
python -c "import torch; print(torch.cuda.is_available())"- Increase data loading workers in
config.py:
num_workers = 8 # Use more CPU cores- Ensure mixed precision is enabled (already default):
use_amp = True4. Poor Quality Results
Solutions:
- Train longer: Each stage needs 800k images
- Check training logs: Look for unstable loss values
- Use truncation: Try
--truncation 0.7during inference - Verify dataset: Ensure images are high quality
5. Checkpoint Loading Error
KeyError: 'g_ema_state'Solution: Use --resume with correct checkpoint format
# List available checkpoints
ls -lh checkpoints/
# Use most recent checkpoint
python train.py --data_dir /path/to/data --resume checkpoints/checkpoint_res128_step40000.ptPerformance Optimization Tips
For Faster Training:
- Use AMP (Already enabled by default)
- Increase workers: Set
num_workers=8in config - Pin memory: Already enabled for CUDA
- Start from checkpoint: Resume from previous training
For Better Quality:
- Train longer: Don't stop at minimum
- Use EMA generator: Already used in inference
- Apply truncation: Use
truncation=0.7-0.8 - Verify dataset quality: Check sample images
For Lower VRAM Usage:
- Reduce batch sizes: Edit
config.py - Train lower resolution: Use
--max_res 512 - Reduce workers: Set
num_workers=4
Recommended Training Strategy
Strategy 1: Full Training (Best Quality)
# 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 facesStrategy 2: Quick Test (Fast Results)
# 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 facesStrategy 3: Incremental (Flexible)
# 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*.ptVerification 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:
- Generate samples: Use
inference.py - Launch web app: Use
app.py - Fine-tune: Adjust hyperparameters in
config.py - Experiment: Try different truncation values
- Share: Generate interpolation videos
Support
If you encounter issues:
- Check this quick start guide
- Review error messages carefully
- Verify dataset and checkpoint paths
- Check CUDA availability
- Review training logs in
outputs/logs/
Summary of Commands
# 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.ptThat's it! You're ready to train Progressive GAN and generate high-quality face images. 🎉
