Skip to content

ancilcrayton/create_anime_dcgan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Creating Anime Characters using a DCGAN

Purpose

This project is an implementation of a Deep Convolutional Generative Adversarial Network, which is a an extension of the Generative Adversarial Network to allow for convolutional layers in both the generator and discriminator networks. I apply this to generate anime character faces such as those from the danbooru gallery.

Usage

Dependencies should be installed by running the command pip install -r requirements.txt

First, scrape anime images from danbooru using the gallery-dl package:

$ gallery-dl https://danbooru.donmai.us/posts?tags=face

Next, run the preprocessing script to detect faces and crop images to 64x64x3 which will save into a directory named data/:

$ python preprocess.py

Finally, run the main script to train the model and record results into results/:

$ python run.py

After 10,000 epochs, the trained generator and discriminator networks will be saved with the file paths results/models/generator_model.h5 and results/models/discriminator_model.h5, respectively.

Samples of data

Important features

Training GANs are tough and this includes DCGANs.

A big issue with learning this dataset was mode collapse. Mode collapse is the case when your generator shows a lack of diversity in its output when given random noise as an input. Another issue was domination of the discriminator during training, which often signalled mode collapse. I took the following steps to address these issues in training:

  1. Label Smoothing: Instead of using hard assignments to train the discriminator network (1=real, 0=fake), I take random draws from a uniform distribution of U(0.7,1.2) for the real images and U(0,0.3) for the fake images. This introduces randomness into the training and aids in avoiding the discriminator loss from reaching 0 rapidly. Training for the generator network should remain the same as the goal for the generator is to learn the distribution of the input data.
  2. Label Flipping: Every third epoch, I flip the labels of the real and fake images in training the discriminator network. This method helps with the gradient flow as well as avoids the discriminator from rapidly approaching 0 too quickly by essentially flipping the training process of the discriminator to work with the generator.
  3. Reduce Discriminator Complexity: The original model choice of the discriminator included three convolutional layers. This included a layer with 128 5x5 filters, a layer with 256 3x3 filters following this, and a layer with 512 3x3 filters. I excluded the middle convolutional layer to reduce the complexity of the model.

About

Create anime characters using a DCGAN

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages