|
Download README.md from MuhammadQasimShabbir3/HumanFace2ComicFaceGenerator: direct link, hf CLI and curl.
- Browser
- Download file 5.93 kB
-
https://huggingface.co/spaces/MuhammadQasimShabbir3/HumanFace2ComicFaceGenerator/resolve/main/README.md
- Command line
-
hf download hf://spaces/MuhammadQasimShabbir3/HumanFace2ComicFaceGenerator/README.md
-
curl -L -o README.md https://huggingface.co/spaces/MuhammadQasimShabbir3/HumanFace2ComicFaceGenerator/resolve/main/README.md
5.93 kB
| 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 | |