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.

Here is the final/result Image:


Source Image Style Image
avkash512 samurai


Coding Source:

Above is a very simple implementation of Neural Algorithm of the Artistic Style (Gatys et al. 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 I used Adam for optimizer and let it run for 500 iterations.

To run it, you’re going to need:


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


Running Command:

$ python 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


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

Helpful Tips

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


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


Leave a Reply

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

You are commenting using your 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 )

Connecting to %s