[PYTHON] Easily try automatic image generation with DCGAN-tensorflow

DCGAN is an abbreviation for Deep Convolutional Generative Adversarial Networks, which is an algorithm that generates images using a convolutional neural network. In addition to the original paper, there are many articles that explain in Japanese.

-First GAN -Understanding GAN and DCGAN as carefully as possible --Nap 2:40

You can use this to generate an idol's face image, generate an illustration, and so on. If you google, you will find many interesting cases.

I had the image of such ** "somewhat amazing" ** DCGAN, ** "it seems difficult to use" **, but the implementation using TensorFlow has been released.

In fact, if you just want to try the demo, you can easily execute it by ** just executing the command according to the procedure **.

Below is a memo of the procedure I tried at hand. (Updated in May 2017)

Data download

git clone it and run the download script.

$ python download.py celebA

I got the following error in my environment.

Traceback (most recent call last):
  File "download.py", line 20, in <module>
    from tqdm import tqdm
ImportError: No module named 'tqdm'

It seems that there is no module called tqdm, so install it.

$ pip install tqdm

Run download.py again to start downloading and unzipping the data.

By the way, celebA in the argument of the above command example specifies the data for the celebrity face generation demo, and if you want to try the demo that generates handwritten numbers

$ python download.py mnist

will do.

Learning

Just run main.py with TensorFlow active.

(tensorflow)$ python main.py --dataset celebA --input_height=108 --train --crop

For MNIST

(tensorflow)$ python main.py --dataset mnist --input_height=28 --output_height=28 --train

It takes a long time, but it outputs ** generated sample images ** in the middle of the process to the samples folder, so you can see how the model is trained without waiting for the training to complete. ..

train_00_0099_celeb.png

(CELEB, Epoch0, 100 sheets learning)

train_00_0498.png

(CELEB, Epoch0, 500 sheets learning)

train_00_1098.png

(CELEB, Epoch0, 1100 sheets learning)

train_01_0033.png

(CELEB, Epoch1)


train_00_0099.png

(MNIST, Epoch0)

train_01_0006.png

(MNIST, Epoch1)

train_06_0041.png

(MNIST, Epoch6)

train_08_0755.png

(MNIST, Epoch8)

You can see that the accuracy of image generation improves as the learning progresses.

test

After training is complete, you can use the model to perform image generation as follows:

$ python main.py --dataset mnist --input_height=28 --output_height=28
$ python main.py --dataset celebA --input_height=108 --crop

Try with self-learning data

When this happens, you will want to try it with your own data. Continue to another article (planned)

→ I tried & wrote: Automatically generate "dot picture" of game application by deep learning

Recommended Posts

Easily try automatic image generation with DCGAN-tensorflow
Automatic quiz generation with COTOHA
Image caption generation with Chainer
Try blurring the image with opencv2
Gradation image generation with Python [1] | np.linspace
Automatic document generation from docstring with sphinx
Automatic PowerPoint generation with python-pptx (personal memo)
Try to generate an image with aliasing
Automatic mosaic generation
[Small story] Test image generation with Python / OpenCV
Easily try Amazon EMR / Cloud Dataproc with Python [mrjob]
Easily daemonized with Supervisor
Image recognition with keras
Try SNN with BindsNET
Easily beep with python
Image processing with Python
Collage template automatic generation
Try regression with TensorFlow
Image Processing with PIL
Try hitting the Twitter API quickly and easily with Python
Image analysis with Object Detection API to try in 1 hour
I tried to easily create a high-precision 3D image with one photo [2]. (Try processing depth with numpy)