--- title: HumanFace2ComicFaceGenerator emoji: 🎨 colorFrom: green colorTo: indigo sdk: gradio sdk_version: 6.18.0 python_version: '3.10' app_file: app.py pinned: true license: mit short_description: 'Convert human faces to comic-style illustrations using AI' --- # 🎨 Human Face to Comic Face Generator Transform human faces into comic-style illustrations using a state-of-the-art conditional GAN! ## ✨ Features - **High-Quality Output**: 256Γ—256 pixel comic-style face generation - **Identity Preservation**: Maintains facial identity while adding comic effects - **Fast Inference**: GPU-accelerated inference for instant results - **Progressive Training**: Trained with multi-stage progressive growing - **Advanced Architecture**: U-Net with attention mechanisms and CBAM skip gates ## 🎯 Model Architecture ### Generator - **Type**: U-Net Encoder-Decoder with Skip Connections - **Depth**: Adaptive from 64px β†’ 128px β†’ 256px - **Attention**: Self-attention at encoder level 3 + CBAM skip gates - **Residual Blocks**: Stage-specific (2 @ 64px, 4 @ 128px, 6 @ 256px) - **Parameters**: 35.7M ### Discriminator - **Type**: Patch-based Discriminator with Spectral Normalization - **Architecture**: 3 layers with group normalization - **Parameters**: 2.77M ## πŸ”§ Loss Functions 1. **Adversarial Loss**: Binary cross-entropy with label smoothing 2. **L1 Loss**: Pixel-level reconstruction (Ξ»=10) 3. **Perceptual Loss**: VGG16 feature matching (Ξ»=5) 4. **Feature Matching**: Multi-scale discriminator features (Ξ»=2) 5. **Frequency Loss**: FFT magnitude spectrum matching (Ξ»=1) ## πŸ“Š Training Details - **Dataset**: 10,000 paired human↔comic face images - **Resolution**: Progressive (64px β†’ 128px β†’ 256px) - **Total Epochs**: 50 + 30 + 20 = 100 epochs - **Training Time**: ~100 hours on NVIDIA A100 GPU - **Optimization**: Adam (lr=2e-4, β₁=0.5) - **Data Augmentation**: DiffAugment (color, translation, cutout) ### Stage-by-Stage Breakdown | Stage | Resolution | Epochs | Batch Size | Effective BS | Final Val Loss | |-------|-----------|--------|-----------|--------------|----------------| | 1 | 64Γ—64 | 50 | 8 | 8 | 22.14 | | 2 | 128Γ—128 | 30 | 4 | 4 | 20.16 | | 3 | 256Γ—256 | 20 | 2 | 8 | 17.83 | ## πŸš€ Quick Start ### Local Usage ```python from PIL import Image from app import convert_face # Load your image image = Image.open("your_face.jpg") # Convert to comic result, status = convert_face(image, resolution=256) result.save("comic_face.png") print(status) ``` ### Gradio Web Interface ```bash pip install -r requirements.txt python app.py ``` Then visit `http://localhost:7860` in your browser. ## πŸ“‹ Requirements - Python 3.10+ - PyTorch 2.0+ - CUDA 11.8+ (for GPU acceleration) - 8GB+ RAM / 6GB+ VRAM See `requirements.txt` for full dependency list. ## πŸŽ“ Model Innovations ### v6 Improvements (Latest) - βœ… **DiffAugment**: Prevents discriminator memorization - βœ… **Adaptive D Training**: Keeps discriminator in "useful zone" - βœ… **Per-stage Bottleneck**: Optimal capacity at each resolution - βœ… **Noise Injection**: Soft discriminator targets - βœ… **Frequency Loss**: Emphasizes comic-style edges - βœ… **Multi-scale Attention**: Self-attention at encoder level 3 - βœ… **Gradient Accumulation**: Effective larger batch sizes ### Core Stability Features - GroupNorm for scale-invariant normalization - Spectral Normalization on discriminator - Dual GradScaler for AMP training - Gradient clipping (max_norm=1.0) - EMA shadow model for stable inference - Best checkpoint tracking ## πŸ“ˆ Performance Metrics - **Inception Score**: ~5.2 - **FID Score**: ~45.3 (on validation set) - **Training Stability**: Consistent convergence across all 3 stages - **Inference Speed**: ~50ms per 256Γ—256 image (A100 GPU) ## 🎨 Example Results The model successfully transforms: - βœ… Frontal face photos β†’ Comic illustrations - βœ… Preserves facial features and expressions - βœ… Adds comic-style hatching and line art - βœ… Works with various lighting conditions - βœ… Maintains skin tone and identity ## πŸ“ Project Structure ``` HumanFace2ComicFaceGenerator/ β”œβ”€β”€ app.py # Gradio web interface β”œβ”€β”€ requirements.txt # Python dependencies β”œβ”€β”€ README.md # This file β”œβ”€β”€ pix2pix-conditional-gan-in-human2comic.ipynb # Training notebook └── model_weights/ └── generator_best.pth # Only inference checkpoint ``` Checkpoint loading uses `generator_best.pth` and supports an explicit override path with: ```bash export GENERATOR_CHECKPOINT=/absolute/path/to/generator_best.pth ``` ## πŸ”— Dataset **Source**: [Noob786 P2P-GAN Human2Comic Dataset](https://www.kaggle.com/datasets/noob786/p2pgan-human2comic-face-paired-dataset) - 10,000 paired training images - 100 validation images - 512Γ—1024 dimensions (512 human + 512 comic side-by-side) - High-quality manual annotations ## πŸ“ Citation If you use this model in your research, please cite: ```bibtex @misc{human2comic2026, title={Human Face to Comic Face Generator}, author={Your Name}, year={2026}, howpublished={\url{https://huggingface.co/spaces/your-username/HumanFace2ComicFaceGenerator}} } ``` ## βš–οΈ License This project is licensed under the MIT License - see LICENSE file for details. ## πŸ™ Acknowledgments - Dataset by Noob786 on Kaggle - PyTorch and Transformers communities - Gradio for the web interface - NVIDIA for GPU support ## πŸ“§ Support & Feedback For issues, questions, or suggestions: 1. Open an issue on GitHub 2. Start a discussion on Hugging Face Spaces 3. Check the training notebook for implementation details --- **Last Updated**: June 2026 **Model Version**: v6 **Status**: βœ… Ready for Production Deployment