This time, I tried to implement StarGAN. Basically, we will implement it based on the code published on github. On this page, we will explain and implement a light paper. I would like to do it next time when I apply it using my own dataset.
--About StarGAN Super easy --Implementation on Linux
It's easy, but I'll explain it according to the above two items.
Paper: https://arxiv.org/abs/1711.09020
** StarGAN ** is a type of Generative Adversarial Netwok (GAN) that enables conversion between different domains ** CycleGAN ** and GAN with multi-class classification learning ** AC-GAN It is a combination of **.
** CycleGAN ** can only do domain conversion between two domains. In order to achieve domain conversion between two or more k domains, k (k-1) Generators must be trained. This is practically possible, but annoying. This image is from the paper, but if k = 4, it means that 4 * 3 = 12 Generators are needed.
To solve such a problem, StarGAN has introduced an algorithm that converts multiple domains with one Generator. If you have 5 domains, they will look like the image above. It has a star shape. That's why it's StarGAN. Somehow you can tickle your heart.
There was a polite explanation other articles, so I will share it. (I can't explain any more)
Public code https://github.com/yunjey/StarGAN
Implementation environment
First, clone git to any directory.
Then change to the StarGAN /
directory.
This time, we will download the CelebA dataset and RaFD dataset that were also used in the paper.
$ git clone https://github.com/yunjey/StarGAN.git
$ cd StarGAN/
$ bash download.sh celeba
The download is complete.
.
.
.
inflating: ./data/celeba/images/072137.jpg
inflating: ./data/celeba/images/027742.jpg
inflating: ./data/celeba/images/188764.jpg
inflating: ./data/celeba/list_attr_celeba.txt
This dataset called CelebA dataset is here Is published.
This dataset contains 202,599 celebrity color facial images in 178 x 218 pixels. In addition to this, 40 types of attributes are assigned to each image. For example, Black_Hair, Blonde_Hair, Brown_Hair, Male, Young, etc. For more information, please refer to here.
The download directory will contain an image like the one above and a txt file called list_attr_celeba.txt
with the attributes for each image.
The contents here are
[Image folder name] 1 1 -1 1 -1 1 1 ... 1 -1
It has become. There are 1 or -1 for the number of attributes (40). When it is 1, it means that it is an attribute, and when it is -1, it means that it is not that attribute. Keep in mind that this needs to be generated when training with your own dataset.
First, let's learn StarGAN using CelebA dataset.
$ python main.py --mode train --dataset CelebA --image_size 128 --c_dim 5 \
--sample_dir stargan_celeba/samples --log_dir stargan_celeba/logs \
--model_save_dir stargan_celeba/models --result_dir stargan_celeba/results \
--selected_attrs Black_Hair Blond_Hair Brown_Hair Male Young
Describes the command.
--mode
: mode
--dataset
: Dataset to use
--image_size
: image size
--c_dim
: number of classes of attribute
--sample_dir
: Folder where the sample is saved
--log_dir
: Folder to save logs
--model_save_dir
: Folder to save the model
--result_dir
: Folder to save results
--selected_attrs
: attribute you want to learn
It's like that.
Next, we will test.
$ python main.py --mode test --dataset CelebA --image_size 128 --c_dim 5 \
--sample_dir stargan_celeba/samples --log_dir stargan_celeba/logs \
--model_save_dir stargan_celeba/models --result_dir stargan_celeba/results \
--selected_attrs Black_Hair Blond_Hair Brown_Hair Male Young
It's easy to do.
Next, I wanted to download RaFD data as well, but I needed to apply. Perhaps even if you can apply, you will not be able to post it on this page either.
For those who find it difficult to learn, we will download the learned network.
$ bash download.sh pretrained-celeba-128x128
The downloaded model is saved in ./stargan_celeba_128/models
.
Next, use the following command to convert the image using the trained network.
$ python main.py --mode test --dataset CelebA --image_size 128 --c_dim 5 \
--selected_attrs Black_Hair Blond_Hair Brown_Hair Male Young \
--model_save_dir='stargan_celeba_128/models' \
--result_dir='stargan_celeba_128/results'
It's super easy.
The converted image is saved in ./stargan_celeba_128/results
.
This completes a simple implementation on a public dataset.
Next time, I will apply it to the dataset I prepared.
Paper: https://arxiv.org/pdf/1703.10593.pdf Github:https://github.com/yunjey/StarGAN CelebA:http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html 7 Change! Change your face with AI: https://qiita.com/uyuutosa/items/5dd9b2b80a9aaca67050
Recommended Posts