[PYTHON] Understanding and implementing Style GAN

I had the opportunity to learn GAN and wanted to know new technologies anyway, so I decided to understand Style GAN at the implementation level. I was frustrated by the version problem of TensorFlow and CUDA, so when I investigated if there was any code implemented by PyTorch, I found the following article, so I decided to load the code here.

StyleGAN with PyTorch

The code was easy to understand,

--The Trainer part was complicated ――I wanted to chase after Shape --I wanted to understand the mechanism of individual technologies (Pixel Normalization, etc.) used in Style GAN.

So, I played by adding docstring comments while rearranging some classes.

Implementation

For CUDA, you need to perform "Graphic driver update" and "Install CUDA Toolkit" in Refer to this article I wrote. there is. If you don't have an NVIDIA graphics board, you can't perform GPU calculations. It can be executed even if GPU calculation is not possible, but it takes several seconds to pass one batch, so it is better to introduce the GPU environment quietly.

The source code is here ↓ GitHub: StyleGanPytorch

The setting can be changed from setting.json. With the default settings, the batch size of the 7th layer is reduced to 2, so learning does not proceed properly. If you can afford the GPU, increase this value. If you make it larger than the GPU spec, memory cannot be secured and an error will occur.

Future outlook

Except for the class reorganization and the comment part, the code in the above article is almost the same, so I'm sorry, but it was a very good study. By the way, regarding the operation of machine learning itself, the GPU of my PC is GTX750Ti, so I had to reduce the batch size significantly ... For this reason, learning will definitely not end with the model as described (laugh)

Later, I will try to work on reducing the parameters of the model as a link until I buy a new PC. I hope I can generate illustrations ...

If you use the model used in the original paper of Style GAN as it is, you will not be able to perform a reproduction experiment unless you drop gold in the cloud like hot water, so I gave up from the beginning. (The realistic image generation system is a battle against specs ...)

Recommended Posts

Understanding and implementing Style GAN
Understanding and implementing the Tonelli-Shanks algorithm (2)
Understanding and implementing the Tonelli-Shanks algorithm (1)
GAN and VAE
[Introduction to Style GAN] Mayu Yu and anime smiled ♬
GAN: DCGAN Part3 --Understanding Wasserstein GAN
Python and DB: Understanding DBI cursors