[Introduction to StyleGAN2] Independent learning with 10 anime faces ♬

Following StyleGAN, I also tried original learning of anime faces in StyleGAN2. In conclusion, I was able to learn config-a, but config-b to config-f are not in a good environment. That said, I've almost seen the code, so I'll summarize it once. Especially this time, I tried to learn how much I could learn with only 10 anime faces. 【reference】 ①NVlabs/stylegan2Learning method of original model with stylegan2

What i did

·environment ・ Learn with 10 anime faces ・ Try to output ・ Output image and original image

·environment

The environment of StyleGAN2 is as follows

Requirements
-Both Linux and Windows are supported. 
-Linux is recommended for performance and compatibility reasons.
・ 64-bit Python 3.6 installation. We recommend Anaconda3 with numpy 1.14.3 or newer.
・ TensorFlow 1.14 or 1.15 with GPU support. The code does not support TensorFlow 2.0.
・ On Windows, you need to use TensorFlow 1.14 — TensorFlow 1.15 will not work.
・ One or more high-end NVIDIA GPUs, NVIDIA drivers, CUDA 10.0 toolkit and cuDNN 7.5.・ To reproduce the results reported in the paper, 
     you need an NVIDIA GPU with at least 16 GB of DRAM.
・ Docker users: use the provided Dockerfile to build an image with the required library dependencies.

・ StyleGAN2 relies on custom TensorFlow ops that are compiled on the fly using NVCC. 
To test that your NVCC installation is working correctly, run:
nvcc test_nvcc.cu -o test_nvcc -run
| CPU says hello.
| GPU says hello.
・ On Windows, the compilation requires Microsoft Visual Studio to be in PATH. 
We recommend installing Visual Studio Community Edition and adding into PATH 
using "C:\Program Files (x86)\Microsoft
VisualStudio\2019\Community\VC\Auxiliary\Build\vcvars64.bat".

However, when I thought it was ready, except for config -a, it stopped with the following error.

 File "C:\Users\user\Anaconda3\envs\keras-gpu\lib\site-packages\tensorflow\python\framework\tensor_shape.py", line 185, in __init__
    self._value = int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Tensor'

・ Learn with 10 anime faces

So, this time I tried learning with config-a, that is, StyleGAN. First, as a preparation ⓪ Select 10 anime faces and Create custom_dataset-r02.tfrecords as before

The code is as follows, changing it to work with 1060. The entire code is below. StyleGAN2/run_training.py / The main parts of the change are as follows ① Target resolution = 64 If you read with the following code, the image of size (128,128) can also be read in (64,64), and it will be the one of StyleGAN network structure.

run_training.py


    dataset_args = EasyDict(tfrecord_dir=dataset, resolution=64)  #, resolution=64

(2) The initial resolution is also 64 Since StyleGAN is pGAN, the dimension gradually increases as learning progresses, but this time it does not work well, so I adopted this because it started to converge when I tried it with the target resolution of 64 from the beginning.

run_training.py


sched.lod_initial_resolution = 64 #8

See the entire code above for other changes to run_training.py (3) If this is all, a memory error will be thrown and it will stop, so change the following part of dataset.py. StyleGAN2/training/dataset.py

training/dataset.py


# Load labels.
        assert max_label_size == 'full' or max_label_size >= 0
        #self._np_labels = np.zeros([1<<30, 0], dtype=np.float32)
        self._np_labels = np.zeros([1<<20, 0], dtype=np.float32)

④ At the end, it takes time to learn and the HDD memory seems to be insufficient, so change to output every time StyleGAN2/training/training_loop.py

training/training_loop.py


    image_snapshot_ticks    = 1,  #50     # How often to save image snapshots? None = only save 'reals.png' and 'fakes-init.png'.
    network_snapshot_ticks  = 1, #50      # How often to save network snapshots? None = only save 'networks-final.pkl'.
...
            if network_snapshot_ticks is not None and (cur_tick % network_snapshot_ticks == 0 or done):
                #pkl = dnnlib.make_run_dir_path('network-snapshot-%06d.pkl' % (cur_nimg // 1000))
                pkl = dnnlib.make_run_dir_path('network-snapshot-.pkl')
                misc.save_pkl((G, D, Gs), pkl)

・ Try to output

Try mixing the output example

# Example of style mixing (matches the corresponding video clip)
python run_generator.py style-mixing-example --network=./results/00007-stylegan2-custom_dataset-1gpu-config-a/network-final.pkl --row-seeds=85,100,75,458,1500 --col-seeds=55,821,1789,293 --truncation-psi=1.0

I have learned as follows. grid.png Also, the previous StyleGAN mixing could be done with the following code. example_256_4705_50_52x11.gif Then, when I tried to output 100 sheets appropriately, it was output as follows. example256_1000_100.gif StyleGAN2/pretrained_example.py

・ Output image and original image

Finally, my main interest is to attach the following image to help interpret the question whether the image generated in this way is different from the original.

The original image 0.png 1.png 2.png 3.png 4.png
Generated image example0_11.png example1_14.png example2_79.png example3_13.png example4_91.png
The original image 5.png 6.png 7.png 8.png 9.png
Generated image example5_2.png example6_1.png example7_21.png example8_78.png example9_51.png

Summary

・ I was able to learn StyleGAN with 10 anime faces. ・ It can be interpreted that the generated image contains the original image.

・ Next time, I would like to challenge high resolution with a 1080 machine.

Recommended Posts

[Introduction to StyleGAN2] Independent learning with 10 anime faces ♬
[Introduction to StyleGAN] Unique learning of anime with your own machine ♬
Classify anime faces with deep learning with Chainer
[Python] Easy introduction to machine learning with python (SVM)
Introduction to machine learning
Classify anime faces by sequel / deep learning with Keras
[Learning memorandum] Introduction to vim
An introduction to machine learning
Introduction to RDB with sqlalchemy Ⅰ
Introduction to Deep Learning ~ Learning Rules ~
Deep Reinforcement Learning 1 Introduction to Reinforcement Learning
Super introduction to machine learning
Introduction to Deep Learning ~ Backpropagation ~
Introduction to Machine Learning with scikit-learn-From data acquisition to parameter optimization
Machine learning to learn with Nogizaka46 and Keyakizaka46 Part 1 Introduction
Introduction to machine learning Note writing
Introduction to Deep Learning ~ Function Approximation ~
Introduction to RDB with sqlalchemy II
Introduction to Deep Learning ~ Coding Preparation ~
Introduction to Machine Learning Library SHOGUN
Introduction to Deep Learning ~ Dropout Edition ~
Introduction to Deep Learning ~ Forward Propagation ~
Introduction to Deep Learning ~ CNN Experiment ~
[Introduction to StyleGAN] I played with "The Life of a Man" ♬
I read "Reinforcement Learning with Python: From Introduction to Practice" Chapter 1
Introduction to Deep Learning (2) --Try your own nonlinear regression with Chainer-
[Introduction to StyleGAN] I played with "A woman transforms into Mayuyu" ♬
I read "Reinforcement Learning with Python: From Introduction to Practice" Chapter 2
[Introduction to WordCloud] Let's play with scraping ♬
Introduction to Machine Learning: How Models Work
[Introduction to machine learning] Until you run the sample code with chainer
Introduction to Deep Learning ~ Convolution and Pooling ~
Introduction to Python Image Inflating Image inflating with ImageDataGenerator
An introduction to OpenCV for machine learning
[Introduction to Python] Let's use foreach with Python
[Python] Introduction to CNN with Pytorch MNIST
Introduction to ClearML-Easy to manage machine learning experiments-
[Introduction to Pytorch] I played with sinGAN ♬
[Introduction to StyleGAN] I played with style_mixing "Woman who takes off glasses" ♬
An introduction to Python for machine learning
Introduction to TensorFlow-Machine Learning Terminology / Concept Explanation
Python learning notes for machine learning with Chainer Chapters 11 and 12 Introduction to Pandas Matplotlib
Introduction to Statistical Hypothesis Testing with stats models
Introduction to Artificial Intelligence with Python 1 "Genetic Algorithm-Theory-"
[Super Introduction to Machine Learning] Learn Pytorch tutorials
An introduction to machine learning for bot developers
Markov Chain Chatbot with Python + Janome (1) Introduction to Janome
Markov Chain Chatbot with Python + Janome (2) Introduction to Markov Chain
Introduction to Artificial Intelligence with Python 2 "Genetic Algorithm-Practice-"
Introduction to Tornado (1): Python web framework started with Tornado
Introduction to formation flight with Tello edu (Python)
[Introduction to minimize] Data analysis with SEIR model ♬
[Super Introduction to Machine Learning] Learn Pytorch tutorials
Introduction to Python with Atom (on the way)
Introduction to Deep Learning ~ Localization and Loss Function ~
Introduction to Vector Autoregressive Models (VAR) with stats models
Introduction to Generalized Linear Models (GLM) with Python
[Introduction to Udemy Python3 + Application] 9. First, print with print
[For beginners] Introduction to vectorization in machine learning
Introduction to MQTT (Introduction)
Introduction to Scrapy (1)