python 人像生成_GAN漫画人物生成实战

My MangaGAN!- Building My First Generative Adversarial Network

A complete walk through to build a Generative Adversarial Network to make your very own anime characters with Keras.

I have always been amazed by vivid animations, especially Manga and their bold looks and strokes. Wouldn't it be awesome to be able to draw a few ourselves, with the thrill of creating them with the help of a self-developed Neural Network Architecture!!!

So, what makes a GAN different?

The best way to master a skill is to practice it and improvise it until you're satisfied with yourself and your efforts. For a MACHINE or a NEURAL NETWORK, the best output it can generate is the one that Matches Human Generated outputs or even fool a human to believe that a human ACTUALLY produced the output. That's exactly what a GAN does, well, at least figuratively;) Generative Adversarial Networks have lately been a hot topic in the Deep Learning field. Introduced by Ian Goodfellow et al., they have the ability to generate outputs from scratch.

Quick Overview of Generative Adversarial Networks

In Generative Adversarial Networks, two networks train and compete against each other, resulting in mutual improvisation. The generator misleads the discriminator by creating compelling fake inputs and tries to fool the discriminator into thinking of these as real inputs . The discriminator tells if an input is real or fake.

There are 3 major steps in the training of a GAN:

using the generator to create fake inputs based on random noise or in our case., random normal noise.

training the discriminator with both real and fake inputs(either simultaneously by concatenating real and fake inputs, or one after the other, the latter one being preferred).

train the whole model: the model is built with the discriminator combined with the generator.

An important point to Note is that discriminator's weights are frozen during the last step.

The reason for combining both networks is that there is no feedback on the generator's outputs. The ONLY guide is if the discriminator accepts the generator's output.

You can say that they are rival destined to each other. The main character is the Generator who strive better and better to make our purpose realized by learning from the fight from its rival.

OUR GAN

We use a DCGAN(Deep convolutional generative adversarial networks) for the task at hand. A few key points about DCGAN- Replace all max pooling with convolutional strides Use transposed convolution for UpSampling. Eliminate fully connected layers. Use Batch normalization except the output layer for the generator and the input layer of the discriminator. Use ReLU in the generator except for the output which uses tanh. Use LeakyReLU in the discriminator.

Setup Details

keras version==2.2.4  tensorflow==1.8.0 jupyter notebook matplotlib and other utility libraries like NumPy, Pandas. python==3.5.7

DATASET

The dataset for anime faces can be generated by curling through various manga websites and downloading images, cropping faces out of them and resizing them to a standard size. Given below is the link for A Python code depicting the same:-

I managed to be lucky enough to find a pre-processed(faces-cropped) dataset from the following sites:-

A Glimpse of the Dataset-

THE MODEL

Now, Let's have a look at the Neural Networks Architectures! Do remember the points we discussed earlier about DCGANs.

THE GENERATOR

It consists of Convolution Transpose Layers followed by Batch Normlisation and A Leaky ReLU activation function for Upsampling. We will use strides parameter in the Convolution Layer. This is done to avoid unstable training of the GAN.

THE DISCRIMINATOR

It also consists of Convolution Layers where we use strides to do Downsampling and Batch Normalisation for stability.

THE COMPILED GAN

To conduct backpropagation for the Generator for keeping a check on it's outputs, we compile a network in Keras, which is Generator followed by Discriminator. In this network, the input would be the random noise for the generator, and the output being the generator's output fed to the discriminator, keeping the Discriminator's weights frozen to avoid the adversarial collapse.

TRAINING THE MODEL

I trained this code on my Acer-Predator helios 300 which took a time of almost half an hour for 10000 steps and around 32k images, with an nvidia GTX GeForce 1050Ti GPU.

SOURCE CODE

find it in anime-facegan.py

CHECK OUT MY ARTICLE ON MEDIUM

MANGA-GENERATOR RESULTS

After training for 10000 steps, the results came out to be pretty cool ad satisfying. Have A Look!

I think training for a longer duration and on a Bigger dataset would improve the results further(Some of the faces were scary weird!. Not the conventional Manga, I must say:D)

SOURCES

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值