Rollover scene: I used pytorch and Gan to make a failure model to generate Magic Baby

Time:2020-4-24

Preface

Magic baby is already a household animation. Let’s confirm whether we can use deep learning to automatically create a new Pokemon for him.
Rollover scene: I used pytorch and Gan to make a failure model to generate Magic Baby
I finally managed to generate a Pokemon like image using the generation countermeasure network (GAN), but this image doesn’t look like a magic baby.
Although this attempt failed, I think other people may like the process and share it now.

Gan generation countermeasure network

Rollover scene: I used pytorch and Gan to make a failure model to generate Magic Baby
I don’t want to spend a lot of time here discussing what Gan is, but the above picture is just a very simple explanation process.
Two networks, discriminator and generator, are trained. Generators learn how to absorb random noise and generate images that look like images from training data. By sending the generated image to the discriminator network, the discriminator network can identify the real image and the generated image after training.
After optimization, the generator can cheat the discriminator better. After optimization, the discriminator can detect the generated image better. So they both made progress together.

data

So, my assumption is that I can train Gan with real magic baby images as a training set. The result will be a generator, and then it will be able to create new magic babies!
My first challenge was to find the image of the magic baby. Fortunately, the kaggle dataset was rescued!
Some people have thought about similar ideas. Although it sounds that he has not been very successful in generating new Pokemon images, he has spent time collecting 800 images, so he decided to upload them to the kaggle dataset. It saves me a lot of time.
Let’s look at this dataset:
Rollover scene: I used pytorch and Gan to make a failure model to generate Magic Baby
This is a picture of the seeds of the frog, the size is 256 * 256

Now that you have the data, the next step is to choose the Gan type to use. There may be hundreds of variants of Gan, but in the past, using dcgan can see good results.
Dcgan removes all fully connected layers from the neural network, uses transposed convolution for up sampling, and uses convolution span (among other things) instead of maximum pooling.
I like dcgans because they seem to be more robust than other Gans I’ve tried, so it’s easier to train without major tweaks to the super parameters.
In fact, dcgan is so popular that pytorch’s example is well implemented. Equally important, their example can read input directly from the folder. So I was able to start training my Gan with the following command:

python main.py –dataset folder –dataroot /pokemon/ –cuda –niter 10000 –workers 8

The command reads images from folders, runs on a GPU with eight working programs to load data, and runs 10000 iterations.

It turns out that this problem requires 10000 iterations, but I want to see how far I can push it. Let’s see!

Result

The first step starts with an unknown network, so all it produces is noise:
Rollover scene: I used pytorch and Gan to make a failure model to generate Magic Baby
Each box is a 64 x 64 pixel image, which is an attempt to generate a magic baby from our generator. Because our grid is 8 x 8, we try to generate 64 different kinds of magic babies. I shrink the image to 64 x 64 because the algorithm becomes unstable when trying to generate a larger image.

After 50 iterations, it’s interesting
Rollover scene: I used pytorch and Gan to make a failure model to generate Magic Baby
150 iterations, the image becomes clear
Rollover scene: I used pytorch and Gan to make a failure model to generate Magic Baby
After 3700, there will be some good pictures. Since then, it has tended to produce worse results:
Rollover scene: I used pytorch and Gan to make a failure model to generate Magic Baby

These don’t look like magic babies at all!
But please reduce your browser to about 25% and check again. In the distance, they look amazingly like real wonder babies.
Why? Since we are training 64 x 64 images, the discriminator is easily confused by images with shapes and colors similar to those of Pokemon, so the generator does not need to be improved.

next step?

In my opinion, the obvious next step is to train higher resolution Gan. In fact, I’ve made some attempts at it.
My first attempt was to rewrite pytorch code to scale to 256 x 256 images. The code is valid, but dcgan crashes and I can’t stabilize Xinlian. I believe the main reason is that I only have about 800 images. Moreover, although I have made some data expansion, it is not enough to train higher resolution dcgan.
Then, I tried to use the relativistic Gan, which has successfully trained for high-resolution data with smaller data sets, but also failed to make it work properly.
At present, the problem should appear in the data. The data volume is too small to meet the training needs. But I will continue to try other ideas to produce higher resolution Pokemon, and if I have to work, I will release the technology I use.
Rollover scene: I used pytorch and Gan to make a failure model to generate Magic Baby