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/stylegan2 ② Learning method of original model with stylegan2
·environment ・ Learn with 10 anime faces ・ Try to output ・ Output image and original image
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'
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 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. Also, the previous StyleGAN mixing could be done with the following code. Then, when I tried to output 100 sheets appropriately, it was output as follows. StyleGAN2/pretrained_example.py
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 | |||||
---|---|---|---|---|---|
Generated image |
The original image | |||||
---|---|---|---|---|---|
Generated image |
・ 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