Model Inferencing using CartoonGAN
Hopefully, by the end of this blog you should be able to generate high-quality cartoon images from real-world photos.
Purpose of the blog:
This blog is a walk through to train your custom model based on the state of the technique in deep learning.
Resources
The paper can be found here at cartoon-gan paper. Majority of the codes are taken from cartoon-gan-github-source cartoon-gan-github-source. I have merely changed anything in the source code. You could follow the instructions there as well.
Prerequisites
This blog would be useful for those who have very basic knowledge of Python programming language and some familiarity with unix shell programming. If you are not sure please go ahead to watch some useful tutorials
Introduction
“Every adult is an obsolete children”
Cartoons are something which we have all watched while growing up. It impacts our lives in a positive way. They are entertaining, simple, and being utilized to convey very important messages. Our objective is to learn how to use GAN in order to transform real world images into a cartoon character of our desired choice. While task might seem similar to painting but making cartoons are much more challenging. Cartoons have some high level simplification & abstraction, clear edges, smooth color shading with simple textures.
What is GAN?
“GAN is the most interesting idea in the last ten years in machine learning” -Yann LeCun, Director, Facebook AI
GAN(Generative Adversarial Network) is one of the best architecture of the past decade when it comes to deep learning. These are generative models, implies, your models objective is to yield. Yields can be anything images,text, videos, the potential is enormous.
Basic architecture consists of generator and discriminator. Generators, basically, generate some arbitraty guesses. Discriminator, on the other hand is learning to classify real v fake entities. The objective of the generator is to convince(fool) the discriminator that generated data is real enough.
Let us try to under the paper. I hope you have read it once, if not please go ahead.
The architecture of CartoonGAN is shown below:
Two player game(min-max objective function)
Time for action with some codes
Hope you have signed in and opened the colab notebook in your browser. Paste the code snippets below and run one after the other. Check your outputs!!!
Here is the code to perform model inferencing with the trained model found in this paper.
Clone the repository from github
"""Code copied from "https://github.com/mnicnc404/CartoonGan-tensorflow" """
import os
repo = "CartoonGan-tensorflow"
!git clone https://github.com/HiteshAI/CartoonGan-tensorflow.git
os.chdir(os.path.join(repo))
Import necessary dependancies
from IPython.display import clear_output, display, Image
!pip install tensorflow-gpu==2.0.0-alpha0
!git clone https://www.github.com/keras-team/keras-contrib.git \
&& cd keras-contrib \
&& python convert_to_tf_keras.py \
&& USE_TF_KERAS=1 python setup.py install
import tensorflow as tf
tf.__version__
clear_output()
Use the script to perform model infrencing on your image.
!python cartoonize.py \
--batch_size 4 \
--all_styles \
--comparison_view horizontal \
--max_resized_height 800
If you want to contribute, please raise an PR here