Extended implementation of StyleGAN2 for eye feature manipulation on CPU
Based on StyleGAN2: Analyzing and Improving the Image Quality of StyleGAN
- CPU-compatible StyleGAN2 implementation
- Eye feature manipulation (size, openness, distance, color)
- Pre-computed eye direction vectors
- Robust tensor dimension handling
- Direct image processing alternative
# Run the simplified notebook
.\run_eye_manipulation_simple.bat
# OR run the direct image processing script (fallback)
.\run_simple.batFor a complete step-by-step guide, see the USER_GUIDE.md. This guide provides detailed instructions for both beginners and advanced users.
- README_CPU_EYE_MANIPULATION.md: Complete project overview
- TECHNICAL_DETAILS.md: Technical implementation details
- PROCESS_DOCUMENTATION.md: Step-by-step process documentation
- TROUBLESHOOTING.md: Solutions for common issues
Tested on:
- PyTorch 1.3.1
- CUDA 10.1/10.2
python prepare_data.py --out LMDB_PATH --n_worker N_WORKER --size SIZE1,SIZE2,SIZE3,... DATASET_PATHThis converts images to JPEG and pre-resizes them. You can create multi-resolution datasets with comma-separated --size arguments.
python -m torch.distributed.launch --nproc_per_node=N_GPU --master_port=PORT train.py --batch BATCH_SIZE LMDB_PATH- Supports Weights & Biases logging via
--wandb.
This implementation supports SWAGAN:
python -m torch.distributed.launch --nproc_per_node=N_GPU --master_port=PORT train.py --arch swagan --batch BATCH_SIZE LMDB_PATHClone the official StyleGAN2 repo and download .pkl checkpoints.
Convert weights:
python convert_weight.py --repo ~/stylegan2 stylegan2-ffhq-config-f.pklpython generate.py --sample N_FACES --pics N_PICS --ckpt PATH_CHECKPOINTSet --size if you trained at a different resolution.
python projector.py --ckpt [CHECKPOINT] --size [GENERATOR_OUTPUT_SIZE] FILE1 FILE2 ...See Closed-Form Factorization:
Extract eigenvectors:
python closed_form_factorization.py [CHECKPOINT]Apply extracted directions:
python apply_factor.py -i [INDEX_OF_EIGENVECTOR] -d [DEGREE_OF_MOVE] -n [NUMBER_OF_SAMPLES] --ckpt [CHECKPOINT] [FACTOR_FILE]Example:
python apply_factor.py -i 19 -d 5 -n 10 --ckpt [CHECKPOINT] factor.ptWill generate 10 random samples, with latents moved along the 19th eigenvector with degree ±5.
This CPU-compatible eye manipulation implementation involved:
-
CPU Operation Implementation
- Replacements for CUDA-specific operations
- Simplified
upfirdn2dandfused_leaky_relu - CPU-friendly noise injection
-
Dimension Handling Fixes
- Fixed tensor dimension issues in latent vectors
- Robust shape checking and validation
- Automatic shape correction
-
Pre-Computed Eye Directions
- Direction vectors for eye size, openness, distance, color
- Support for combined feature manipulation
- Normalized vectors for consistency
-
Alternative Solutions
- Direct image processing for eye manipulation
- Automated model downloading
- Robust error handling and diagnostics
-
Core Files:
eye_manipulation_simple.ipynb: Main notebook for StyleGAN2-based eye manipulationsimple_eye_manipulation.py: Direct image processing alternativeeye_directions.py: Pre-computed eye feature direction vectorsdownload_models.py: Download official StyleGAN2 weightsop/cpu_ops.py: CPU-compatible operations for StyleGAN2
-
Support Files:
TROUBLESHOOTING.md: Guide for fixing common issuessetup_stylegan2_ada.py: StyleGAN2-ADA integration setup utilityrun_eye_manipulation_simple.bat: Run the simplified notebook (Windows)run_simple.bat: Run the direct image processing approach (Windows)

Sample from FFHQ (trained on 3.52M images)

Sample from MetFaces with Non-leaking augmentations (150,000 iterations, trained on 4.8M images)

Sample from LSUN Church (256px)
- Model details and custom CUDA kernel codes from NVIDIA StyleGAN2
- LPIPS code from PerceptualSimilarity
- FID Inception V3 from pytorch-fid

