Styling image based on image using Artistic Neural Algorithm in Tensorflow

Have you thought modifying an image based on other image features? I tried the same to understand how CNN works in terms of understanding the image.

Neural Algorithm of the Artistic Style (Gatys et al.http://arxiv.org/abs/1508.06576)

Here is the final/result Image:

avkash-samurai

Source Image Style Image
avkash512 samurai

 

Coding Source: https://github.com/janivanecky/Artistic-Style

Above is a very simple implementation of Neural Algorithm of the Artistic Style (Gatys et al.http://arxiv.org/abs/1508.06576) in Tensorflow. I used VGG implementation from Chris and modified it slightly, stripping away unnecessary layers.

In the examples below I used content image as an initialization, it seems to provide more consistent image, but in the code, you can switch easily to noise initialization on line 109 in style.py. I used Adam for optimizer and let it run for 500 iterations.

To run it, you’re going to need:

Usage

python style.py content_image_path style_image_path [output_image] 
[{top,center,bottom,left,right}] [content_scale] [style_weight]

Pre-requsite:

Running Command:

$ python style.py avkash.jpg samurai.jpg result.jpg center 1 1

Iteration 0: 101205584.0
Iteration 5: 28933696.0
Iteration 10: 12709578.0
Iteration 15: 6670791.0
……….
……….
Iteration 480: 104311.460938
Iteration 485: 97180.828125
Iteration 490: 91784.2890625
Iteration 495: 88249.4609375

Configuration:

  • Total 500 iteration – Line # 144 in style.py
  • It is using tensorflow adam oprimizer – Line #137 style.py – tf.train.AdamOptimizer
  • This network has 4 CNN as defined in vgg.py

Helpful Tips

  • Make sure vgg.py & vgg19.npy is in the same folder along with style.py
  • Try to chage the optimizer and see the results:

Apendix:

ubuntu@XXXXX:~$ pip show Pillow
Name: Pillow
Version: 3.4.2
Summary: Python Imaging Library (Fork)
Home-page: http://python-pillow.org
Author: Alex Clark (Fork Author)
Author-email: aclark@aclark.net
License: Standard PIL License
Location: /usr/local/lib/python2.7/dist-packages
Requires:
ubuntu@XXXXX:~$ pip show tensorflow
Name: tensorflow
Version: 0.11.0rc2
Summary: TensorFlow helps the tensors flow
Home-page: http://tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
License: Apache 2.0
Location: /home/ubuntu/.local/lib/python2.7/site-packages
Requires: mock, protobuf, numpy, wheel, six

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s