<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by shiva shankar on Medium]]></title>
        <description><![CDATA[Stories by shiva shankar on Medium]]></description>
        <link>https://medium.com/@shivshankar.hc?source=rss-747bd5d04176------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*UEdOfXtcSNMSRSh63F2-Vw.png</url>
            <title>Stories by shiva shankar on Medium</title>
            <link>https://medium.com/@shivshankar.hc?source=rss-747bd5d04176------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 04:59:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shivshankar.hc/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding And Implementing Neural Style Transfer .]]></title>
            <link>https://medium.com/analytics-vidhya/understanding-and-implementing-neural-style-transfer-7d752d3cfe74?source=rss-747bd5d04176------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d752d3cfe74</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[keras]]></category>
            <category><![CDATA[neural-style-transfer]]></category>
            <dc:creator><![CDATA[shiva shankar]]></dc:creator>
            <pubDate>Mon, 04 Nov 2019 07:24:05 GMT</pubDate>
            <atom:updated>2019-11-14T08:25:53.396Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding And Implementing Neural Style Transfer</h3><p><strong><em>Neural style transfer is a artistic method of combining style and content of two seperate images into a single image using Deep learning methods.</em></strong></p><blockquote>Pre-requisites: Basic understanding of CNN’s and Keras.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h4IxtXcHG7b84upKkr7p_g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*2yQdIoiDWXRj6QeIztF8lg.png" /><figcaption>Photo by <a href="https://unsplash.com/@timwhybrow?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Tim Whybroe</a> on <a href="https://unsplash.com/search/photos/vibrany?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a> transformed by applying NST.</figcaption></figure><h3>So what is Neural Style Transfer (NST) ???</h3><p>According to Wikipedia,</p><blockquote>Neural Style Transfer refers to a class of software algorithms that manipulate digital images, or videos, to adopt the appearance or visual style of another image.</blockquote><p>The NST algorithm which we are going to study is based on the paper <a href="https://arxiv.org/pdf/1508.06576.pdf"><em>A Neural Algorithm of Artistic Style</em></a> by Leon A. Gatys et.al . NST algorithms provide an artificial system based on Deep Neural Network that creates artistic images of high percptual quality.</p><p>Creation of artistic kind of images is a branch of computer vision called <a href="http://ieeexplore. ieee.org/xpls/abs_all.jsp?arnumber=6243138"><em>non-photorealistic rendering</em></a> but these methods involve direct manipulation of image pixels rather than on feature space of an image.</p><p>As we deal with feature space of an image we make use of Convolution Neural Networks(here we use VGG-19 architecture) which are already trained on huge datasets like Imagenet(1000 classes) for object detection task.</p><h3>Why do we make use of CNN in NST??</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*KEkiGmv1a20uzxvRG66HWQ.jpeg" /></figure><ol><li>CNN’s are class of Deep Neural Network which are powerful in image processing tasks. Each layer of a CNN produce a feature maps of an input image which are filtered versions of input images.</li><li>We can use the feature maps of each layer to reconstruct the input image. The feature maps are the multi layer representation of an image which are produced as an output by the layers of CNN.</li><li>CNN’s help in capturing the representation of images in feature space rather than in pixel space.</li><li>The higher layers of CNN’s capture the global information of an image rather than pixel representations. The global representation capture the <strong>high level content</strong> of an image. In contrast the lower level layers capture the exact pixel values of the original image. So we use feature responses from higher layers for <strong>“content representation”. </strong>Here we use feature maps of <strong>“conv5_1”</strong> layer of VGG-19 which is top most convolution layer.</li><li>The <strong>“style representation”</strong> of an image is obtained by building a multi-scale feature space. This feature space contains correlations between the different filter responses of multiple layers. Here we will use the feature maps of <strong>“conv1_1”, “conv2_1”, “conv3_1”, “conv4_1”, “conv5_1”</strong> in a cummulative way.</li></ol><blockquote>By including the feature correlations of multiple layers, we obtain a stationary, multi-scale representation of the input image, which captures its texture information but not the global arrangement.</blockquote><h3>Implementation of NST</h3><p>The process involved in implementing this algorithm :</p><ol><li>Select two images where one of them is style reference image and another is content base/target image. We will get better results if the chosen style reference image has more texture and patterns.</li></ol><pre>from keras.preprocessing.image import load_img, img_to_array<br>target_image_path = &#39;img/portrait.jpg&#39;<br>style_reference_image_path = &#39;img/transfer_style_reference.jpg&#39;<br>width, height = load_img(target_image_path).size<br>img_height = 400<br>img_width = int(width * img_height / height)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*0fk_Mk1PUa5n8NB-KdaKzg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h4IxtXcHG7b84upKkr7p_g.jpeg" /><figcaption>Style reference image(Starry nigth by Van Gogh) and content base image.</figcaption></figure><p><strong>2. </strong>Select a network (here we use VGG19) which is already trained on some dataset for some specific tasks like object detection. The reason we are using already trained network is that they already have a fair idea about extracting features of an image as they have been trained on huge image datasets like ImageNet.</p><p><strong>3.</strong> So we compute the layer activations of style-reference image , target/content base image and the generated image at the same time by passing it through the network. Initially generated image is taken as a white noise image. The input to the network is a combination of style reference image, content image and combination image(initially its a blank image).</p><pre>from keras import backend as K<br>target_image = K.constant(preprocess_image(target_image_path))</pre><pre>style_reference_image = K.constant(preprocess_image(style_reference_image_path))</pre><pre>combination_image = K.placeholder((1, img_height, img_width, 3))<br>input_tensor = K.concatenate([target_image,<br>style_reference_image,<br>combination_image], axis=0)</pre><pre>model = vgg19.VGG19(input_tensor=input_tensor,<br>weights=&#39;imagenet&#39;,<br>include_top=False)<br>print(&#39;Model loaded.&#39;)</pre><p>Here the preprocess_image is a auxillary function which we are using it convert an image to numpy array and we also do normalization using imagenet’s mean and standard deviation because the VGG19 is trained on imagenet dataset so we have to make sure that we are training the network on same input distribution.</p><p><strong>4.</strong> Next we define the loss functions</p><ul><li><strong>Content loss function : </strong>The content loss function takes in features generated by last convolution layer of both target/content image and generated image. We then define squared-error loss between the two feature representation.</li></ul><pre>def content_loss(base, combination):<br>     return K.sum(K.square(combination - base))</pre><ul><li><strong>Style loss function :</strong> As I said earlier that the style representation of an image is formed from the correlation between features of conv layers we make use of gram matrix which is defined as G = (A ^ T) A . So style loss takes in gram matrix of style reference image and generated image and perform square loss error.</li></ul><pre>def gram_matrix(x):<br>    features = K.batch_flatten(K.permute_dimensions(x, (2, 0, 1)))<br>    gram = K.dot(features, K.transpose(features))<br>    return gram</pre><pre>def style_loss(style, combination):<br>    S = gram_matrix(style)<br>    C = gram_matrix(combination)<br>    channels = 3<br>    size = img_height * img_width<br>    return K.sum(K.square(S - C)) / (4. * (channels ** 2) * (size ** 2))</pre><ul><li><strong>Total variation loss : </strong>Total variation loss is a regularization loss which operates on pixels of generated combination image. We use this loss to encourage spatial continuity in the generated image which will avoid overly pixelated results.</li></ul><pre>def total_variation_loss(x):<br>    a = K.square(<br>x[:, :img_height - 1, :img_width - 1, :] -<br>x[:, 1:, :img_width - 1, :])<br>    b = K.square(<br>x[:, :img_height - 1, :img_width - 1, :] -<br>x[:, :img_height - 1, 1:, :])<br>return K.sum(K.pow(a + b, 1.25))</pre><p><strong>5. </strong>The loss which we are going to minimize is weighted average of all these three losses using gradient descent optimization technique.</p><p><strong>6.</strong> In the book <a href="https://www.amazon.in/Deep-Learning-Python-Francois-Chollet/dp/1617294438/ref=sr_1_1?crid=6P8X7GZR6GDK&amp;keywords=deep+learning+with+python&amp;qid=1564554245&amp;s=gateway&amp;sprefix=deeplea%2Caps%2C307&amp;sr=8-1">Deep Learning with python by Francois Chollet </a>he mentions that in the original paper they have performed the optimization using L-BFGS algorithm but to be honest when I read the paper I didn’t find any reference to that algorithm (I may have overlooked). But we will be using L-BFGS algorithm for optimization. You can refer to the below blog for L-BFGS algotrithm.</p><p><a href="http://aria42.com/blog/2014/12/understanding-lbfgs">Numerical Optimization: Understanding L-BFGS</a></p><p><strong>7. </strong>The authors also mention that we get better results if we use average pooling rather than max pooling. The reason for this may be due to discarding of pixels in max pooling which may lead to loss of information.</p><h3>Experimentation</h3><h4>1. Using blank image as content image.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*S5WiMF1FYvy3IJvoowgcFA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*da941Eq8b1rhdMMEKEFqhQ.png" /><figcaption>1) Self portrait of Van Gogh used as style reference image. 2) Generated image when content image is blank image.</figcaption></figure><h4>2. Using blank image as style reference image.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/1*OlvNo0NBdGgHMXoaxhJ41g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/1*MYxLXGN9CMKv0rXbMzMknA.png" /><figcaption>Results after one epoch and after ten epochs.</figcaption></figure><h4>3. Using black image as style reference image.</h4><p>One thing we can notice is that black colouration of background not the face region. NST algorithm transfer is effective if the style reference image are highly texturized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/1*wOnWD4Ffu7XBNwg57M_OlQ.png" /><figcaption>Generated image after 30 epochs.</figcaption></figure><h3>Code</h3><p><a href="https://github.com/shiv-u/neural_style_transfer">shiv-u/neural_style_transfer</a></p><h3>References</h3><ol><li><a href="https://www.amazon.in/Deep-Learning-Python-Francois-Chollet/dp/1617294438/ref=sr_1_1?crid=6P8X7GZR6GDK&amp;keywords=deep+learning+with+python&amp;qid=1564554245&amp;s=gateway&amp;sprefix=deeplea%2Caps%2C307&amp;sr=8-1">Deep learning with python by francois chollet.</a></li><li>Original paper : <a href="https://arxiv.org/pdf/1508.06576.pdf">https://arxiv.org/pdf/1508.06576.pdf</a>.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d752d3cfe74" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/understanding-and-implementing-neural-style-transfer-7d752d3cfe74">Understanding And Implementing Neural Style Transfer .</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On February 8 of 2018 I was eagerly waiting for the results of Udacity’s AndroidBasicScholarship…]]></title>
            <link>https://medium.com/@shivshankar.hc/on-february-8-of-2018-i-was-eagerly-waiting-for-the-results-of-udacitys-androidbasicscholarship-79d2fb0cac0f?source=rss-747bd5d04176------2</link>
            <guid isPermaLink="false">https://medium.com/p/79d2fb0cac0f</guid>
            <category><![CDATA[udacity]]></category>
            <dc:creator><![CDATA[shiva shankar]]></dc:creator>
            <pubDate>Mon, 14 May 2018 18:09:46 GMT</pubDate>
            <atom:updated>2018-07-07T04:29:56.283Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Unexpected journey.</blockquote><p>On February 8 of 2018 I was eagerly waiting for the results of Udacity’s AndroidBasicScholarship and finally received the e-mail that I have been selected . I was actually wasn’t expecting that I would be selected but when I received the mail I was over the clouds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8dxEOBnbPk5EuXswsIeIXA.png" /><figcaption>This is the badge I received for getting selected .</figcaption></figure><h3>First month of scholarship</h3><p>The course started on February 14 ,first we were instructed on how to get on with the course and we were instructed on how to join forums and slack communities.They encouraged to participate in forums and slack communities regularly and this was the best suggestion I got .Slack and forums are the best part of this scholarships I think because the way the mentors guide you in forums is brilliant and slack helps you in working in group as a community to help and support each other.If you spend at-least an hour for this course you can finish it off with flying colors without any problems.It would certainly take time to get on with the people in forums and slack communities that is the reason they have provided 3 months instead of 2 months so that you can get on with it.</p><h3>Second month of scholarship</h3><p>First month went away like wind because it was February.In the second month I started posting my projects which were part of the scholarship in forums , the way they responded baffled me totally.Mentors in forums constantly encourage to try harder and get better .I really loved the response I got from my peers in slack community whenever I posted my project I can’t explain how much grateful I am for them.They encouraged you to do even better and share their views and provide their feedback.By the end of second month I had finished about 90 percent of my course and at this time I think collaborative projects were announced in slack community this was a sign that the competition was getting tougher for phase-2 of the scholarship where you will get “Android Nanodegree from Udacity” because I got to know that this is the first time this kind of projects are being adopted in this scholarship.</p><h3>Final month of scholarship</h3><p>Starting this month I got involved so much in forums and in slack communities that I was addicted to them that’s the beauty of this program . I had finished 100 percent of my course and had submitted all the projects I had done in this course for feedback .Now it was the time to step into collaborative projects but initially it was easy because as projects kicked off we were in designing the basic structure of the app like designing sign-up or login page , designing layouts for the apps but after few weeks it got tough to get on with it because I didn’t know the new concepts like “firebase” which I had to learn from scratch which is why I didn’t find much time for collaborative projects but I did my best in contributing to them.I was active in both slack and forums which is the essential part of this course.For 2–3 weeks to spare they rolled out new groups called “donut” groups where we were paired with 2 people who are not so much active in slack but unfortunately how much ever I tried they weren’t active in the group.And finally the D-day has arrived i.e May-14 which is the last day of this course and I am writing this blog to inform this whole world that if you get any chance in getting enrolled into this course don’t miss this you’ll regret that for your entire life.</p><h3>Last Note</h3><p>This journey has been wonderful I thank Google and Udacity for rolling this wonderful program for reaching out millions of young talents over there.I request them to continue this initiative in future.The only thing I regret is from tomorrow I wouldn’t be able to access my forum and slack peers.I will miss them forever.</p><p>Signing off…</p><p><em>shivu</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79d2fb0cac0f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>