AnimeGAN is a deep learning project that uses Generative Adversarial Networks (GANs) to generate anime character faces. Built using PyTorch, this implementation trains a DCGAN (Deep Convolutional GAN) on over 63,000 anime face images to produce new, unique anime character designs.
- DCGAN architecture optimized for anime face generation
- Training visualization tools to monitor progress
- Batch processing for efficient training
- Pre-processing pipeline for the Anime Face Dataset
- Customizable hyperparameters for model tuning
- Video output of training progression
- Python 3.6+
- PyTorch 1.7.0+
- torchvision 0.8.1+
- matplotlib
- OpenCV (for video generation)
- numpy
- tqdm (for progress bars)
# Clone the repository
git clone https://github.com/yourusername/anime-gan.git
cd anime-gan
# Install dependencies
pip install numpy matplotlib torch==1.7.1 torchvision==0.8.2 tqdm opencv-pythonThis project uses the Anime Face Dataset from Kaggle, which contains over 63,000 high-quality anime character face images.
To download the dataset:
# Using the opendatasets library
import opendatasets as od
od.download('https://www.kaggle.com/splcher/animefacedataset')You'll need a Kaggle account and API credentials. See the Kaggle API documentation for details on setting up your API key.
The generator transforms random noise vectors into anime face images using transposed convolutional layers:
- Input: Random latent vector of size
(batch_size, 128, 1, 1) - 5 transposed convolutional layers with batch normalization and ReLU activations
- Output: Generated image of size
(batch_size, 3, 64, 64)with Tanh activation
The discriminator evaluates whether an image is real or generated:
- Input: Image of size
(batch_size, 3, 64, 64) - 5 convolutional layers with batch normalization and LeakyReLU activations
- Output: Probability score between 0-1 (fake vs. real)
Training happens through adversarial learning, where the generator and discriminator networks compete with each other:
# Quick start training
python train.py --epochs 40 --learning_rate 0.0001 --batch_size 128--epochs: Number of training epochs (default: 40)--learning_rate: Learning rate for Adam optimizer (default: 0.0001)--batch_size: Batch size for training (default: 128)--image_size: Size of the images (default: 64)--latent_size: Size of the latent vector (default: 128)--sample_interval: Interval to save sample images (default: 1)
The model progressively learns to generate anime faces over training epochs:
- Early epochs (1-10): Blurry shapes and colors
- Middle epochs (10-25): Recognizable facial features
- Later epochs (25-40): Refined details and style
Training Process:
gans_training.1.mp4
anime-gan/
├── train.py # Main training script
├── models/ # Model architecture definitions
│ ├── generator.py
│ └── discriminator.py
├── utils/ # Utility functions
│ ├── data_loader.py
│ └── visualization.py
├── generated/ # Output directory for generated images
├── checkpoints/ # Model checkpoints during training
├── README.md
└── requirements.txt
import torch
from models.generator import Generator
# Load a trained generator
generator = Generator()
generator.load_state_dict(torch.load('G.pth'))
generator.eval()
# Generate images
latent_vectors = torch.randn(16, 128, 1, 1)
with torch.no_grad():
fake_images = generator(latent_vectors)
# Save images
from torchvision.utils import save_image
save_image(fake_images, 'generated_anime_faces.png', normalize=True)Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Anime Face Dataset for the training data
- DCGAN Paper for the model architecture inspiration
For any questions or issues, please open an issue on GitHub: @Siddharth Mishra
Made with ❤️ and lots of ☕
