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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- pytorch
|
| 5 |
+
- diffusers
|
| 6 |
+
- unconditional-image-generation
|
| 7 |
+
- diffusion-models
|
| 8 |
+
- anime
|
| 9 |
+
- anime-faces
|
| 10 |
+
- ddpm
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# Anime Face Diffusion Model 🎨
|
| 14 |
+
|
| 15 |
+
A fine-tuned diffusion model for generating high-quality anime faces using DDPM. This model is based on Google's pre-trained `ddpm-celebahq-256` model and fine-tuned on 7,000+ anime face images.
|
| 16 |
+
|
| 17 |
+
## Model Details
|
| 18 |
+
|
| 19 |
+
- **Model Type**: Denoising Diffusion Probabilistic Model (DDPM)
|
| 20 |
+
- **Base Model**: [google/ddpm-celebahq-256](https://huggingface.co/google/ddpm-celebahq-256)
|
| 21 |
+
- **Task**: Unconditional Image Generation (256×256 anime faces)
|
| 22 |
+
- **Training Data**: 7,000+ high-quality anime face images
|
| 23 |
+
- **Framework**: 🧨 Diffusers
|
| 24 |
+
- **License**: MIT
|
| 25 |
+
|
| 26 |
+
## Training Parameters
|
| 27 |
+
|
| 28 |
+
- **Learning Rate**: 2e-5
|
| 29 |
+
- **Epochs**: 15
|
| 30 |
+
- **Batch Size**: 4
|
| 31 |
+
- **Gradient Accumulation Steps**: 2
|
| 32 |
+
- **Training Steps**: ~26,250 (1750 steps/epoch × 15 epochs)
|
| 33 |
+
- **Optimizer**: AdamW
|
| 34 |
+
- **Loss**: MSE (Mean Squared Error)
|
| 35 |
+
|
| 36 |
+
## Usage
|
| 37 |
+
|
| 38 |
+
### Basic Usage
|
| 39 |
+
|
| 40 |
+
```python
|
| 41 |
+
from diffusers import DDPMPipeline
|
| 42 |
+
import torch
|
| 43 |
+
|
| 44 |
+
# Load the model
|
| 45 |
+
pipeline = DDPMPipeline.from_pretrained("abcd2019/Anime-face-generation")
|
| 46 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 47 |
+
pipeline = pipeline.to(device)
|
| 48 |
+
|
| 49 |
+
# Generate a single image
|
| 50 |
+
image = pipeline(num_inference_steps=100).images[0]
|
| 51 |
+
image.save("anime_face.png")
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
### Generate Multiple Images
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
from diffusers import DDPMPipeline
|
| 58 |
+
|
| 59 |
+
pipeline = DDPMPipeline.from_pretrained("abcd2019/Anime-face-generation")
|
| 60 |
+
pipeline = pipeline.to("cuda")
|
| 61 |
+
|
| 62 |
+
# Generate 5 anime faces
|
| 63 |
+
images = pipeline(batch_size=5, num_inference_steps=100).images
|
| 64 |
+
|
| 65 |
+
for i, image in enumerate(images):
|
| 66 |
+
image.save(f"anime_face_{i}.png")
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
### Adjust Inference Steps for Quality vs Speed
|
| 70 |
+
|
| 71 |
+
```python
|
| 72 |
+
# Fast generation (fewer steps, less quality)
|
| 73 |
+
fast_image = pipeline(num_inference_steps=50).images[0]
|
| 74 |
+
|
| 75 |
+
# High quality (more steps, slower)
|
| 76 |
+
quality_image = pipeline(num_inference_steps=150).images[0]
|
| 77 |
+
|
| 78 |
+
# Recommended: 100 steps for good balance
|
| 79 |
+
balanced_image = pipeline(num_inference_steps=100).images[0]
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
### Use Different Scheduler
|
| 83 |
+
|
| 84 |
+
```python
|
| 85 |
+
from diffusers import DDPMPipeline, DDIMScheduler
|
| 86 |
+
|
| 87 |
+
pipeline = DDPMPipeline.from_pretrained("abcd2019/Anime-face-generation")
|
| 88 |
+
|
| 89 |
+
# Switch to DDIM for faster sampling
|
| 90 |
+
scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
|
| 91 |
+
scheduler.set_timesteps(num_inference_steps=50)
|
| 92 |
+
pipeline.scheduler = scheduler
|
| 93 |
+
|
| 94 |
+
fast_image = pipeline().images[0] # Generates in ~50 steps instead of 1000
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
## Model Performance
|
| 98 |
+
|
| 99 |
+
- **Training Loss**: ~0.0077 (final epoch)
|
| 100 |
+
- **Image Resolution**: 256×256 pixels
|
| 101 |
+
- **Inference Speed**: ~30-60 seconds per image (depending on steps)
|
| 102 |
+
- **Recommended Inference Steps**: 100 (for best quality)
|
| 103 |
+
- **Generated Face Styles**: Wide diversity of anime faces with various:
|
| 104 |
+
- Hair colors and styles
|
| 105 |
+
- Eye colors and expressions
|
| 106 |
+
- Face shapes and features
|
| 107 |
+
- Skin tones
|
| 108 |
+
|
| 109 |
+
## Limitations & Bias
|
| 110 |
+
|
| 111 |
+
- **Resolution**: Limited to 256×256 pixels (inherent to model architecture)
|
| 112 |
+
- **Style**: Specifically trained on anime faces, may not generate realistic/photorealistic faces
|
| 113 |
+
- **Diversity**: Generated faces are limited to patterns in training data
|
| 114 |
+
- **Quality Variation**: Face shape clarity depends on inference steps (higher = better)
|
| 115 |
+
|
| 116 |
+
## Training Details
|
| 117 |
+
|
| 118 |
+
### Data Preparation
|
| 119 |
+
- **Dataset**: Anime Face Dataset (Kaggle)
|
| 120 |
+
- **Total Images**: 7,000
|
| 121 |
+
- **Selection Method**: Top quality images by file size
|
| 122 |
+
- **Preprocessing**:
|
| 123 |
+
- Resized to 256×256
|
| 124 |
+
- Random horizontal flip (50% probability)
|
| 125 |
+
- Normalized to [-1, 1]
|
| 126 |
+
|
| 127 |
+
### Fine-tuning Approach
|
| 128 |
+
- Started from pre-trained `ddpm-celebahq-256`
|
| 129 |
+
- Fine-tuned with low learning rate to preserve general face generation knowledge
|
| 130 |
+
- Adapted to anime-specific features (large eyes, stylized features, etc.)
|
| 131 |
+
|
| 132 |
+
### Training Dynamics
|
| 133 |
+
- **Epoch 0-3**: Model adapts from photorealistic to anime style
|
| 134 |
+
- **Epoch 4-8**: Loss continues to decrease, anime features solidify
|
| 135 |
+
- **Epoch 9+**: Marginal improvements, risk of overfitting
|
| 136 |
+
|
| 137 |
+
## Ethical Considerations
|
| 138 |
+
|
| 139 |
+
This model generates synthetic anime faces and should not be used to:
|
| 140 |
+
- Create misleading/deceptive content
|
| 141 |
+
- Generate non-consensual images of real people
|
| 142 |
+
- Violate any local laws or regulations
|
| 143 |
+
|
| 144 |
+
## Recommended Citation
|
| 145 |
+
|
| 146 |
+
If you use this model in your research or project, please credit:
|
| 147 |
+
- The original DDPM paper
|
| 148 |
+
- Google's pre-trained `ddpm-celebahq-256` model
|
| 149 |
+
- This fine-tuned adaptation
|
| 150 |
+
|
| 151 |
+
## Future Improvements
|
| 152 |
+
|
| 153 |
+
Potential enhancements for future versions:
|
| 154 |
+
- Higher resolution (512×512 or more)
|
| 155 |
+
- Conditional generation (text-to-image for anime faces)
|
| 156 |
+
- Better diversity through larger training datasets
|
| 157 |
+
- Improved training with advanced schedulers or techniques
|
| 158 |
+
|
| 159 |
+
## Resources
|
| 160 |
+
|
| 161 |
+
- 📚 [Diffusion Models Class](https://github.com/huggingface/diffusion-models-class)
|
| 162 |
+
- 📖 [Diffusers Documentation](https://huggingface.co/docs/diffusers)
|
| 163 |
+
- 📄 [DDPM Paper](https://arxiv.org/abs/2006.11239)
|
| 164 |
+
- 🤗 [Hugging Face Hub](https://huggingface.co)
|
| 165 |
+
|
| 166 |
+
---
|
| 167 |
+
|
| 168 |
+
**Created**: 2025-12-28
|
| 169 |
+
|
| 170 |
+
**Model Card Contact**: [Your Name/Username]
|