<?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 Lawrence Francis on Medium]]></title>
        <description><![CDATA[Stories by Lawrence Francis on Medium]]></description>
        <link>https://medium.com/@lawrencedikeu?source=rss-bed0cbdb91b9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Lawrence Francis on Medium</title>
            <link>https://medium.com/@lawrencedikeu?source=rss-bed0cbdb91b9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 22:08:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lawrencedikeu/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[Easy Neural Style Transfer With Google Colab]]></title>
            <link>https://medium.com/@lawrencedikeu/easy-neural-style-transfer-with-google-colab-a3264789d6ed?source=rss-bed0cbdb91b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3264789d6ed</guid>
            <category><![CDATA[neural-style-transfer]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Lawrence Francis]]></dc:creator>
            <pubDate>Tue, 05 Jun 2018 13:07:29 GMT</pubDate>
            <atom:updated>2018-06-05T13:07:29.163Z</atom:updated>
            <content:encoded><![CDATA[<p>One use of neural networks that interests me a lot is the generation of styled images, popularly known as ‘Neural Style Transfer’. This concept was introduced in the 2015 paper <a href="https://arxiv.org/abs/1508.06576">A Neural Algorithm of Artistic Style</a> and an open source tensorflow implementation of it was made available in this article <a href="http://www.chioka.in/tensorflow-implementation-neural-algorithm-of-artistic-style">http://www.chioka.in/tensorflow-implementation-neural-algorithm-of-artistic-style</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*WiWNhwqj8_uZmfG1TJ9XIQ.jpeg" /><figcaption>A generated image using John Cena’s photo as content and starry night as style.</figcaption></figure><p>I recently played around with the implementation, generated some cool images and then decided to build a package on top of the implementation so that anyone can generate cool images too without having to worry about the implementation. I chose for this post, to use the image I generated using John Cena’s picture.</p><h4>The brief</h4><p>Here is a summary on how to easily generate cool images. You should have two images, a content image and a style image. The content image is the image that we want to transfer style unto while the style image is the style that we want our generated image to have. The aim here is to generate an image that is similar to both the style and content images (i.e the image will look like the content image and have the style of the style image). Here is a sample of content image, style image and generated/mixed image triple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YQYnNoqUXwDyhPqDqJ7CzA.jpeg" /><figcaption>content image: John Cena; style image: starry night</figcaption></figure><p>I used google colaboratory (colab) as the platform here. It is as simple as uploading your images to colab, changing some settings, running the cells, and downloading the generated image.</p><h3>Google Colaboratory</h3><p>This is a Jupyter notebook environment that runs in the cloud and has almost all packages for machine learning installed. It is free to use and the best part is the free GPU runtime that is offered.</p><p>Open colab by following this link <a href="https://colab.research.google.com/">https://colab.research.google.com</a></p><p>Open a new notebook on colab and change the runtime type to use the GPU hardware accelerator.</p><p>Below are steps to generate images using Neural Style Transfer on colab:</p><h4>Clone the repository</h4><p>Paste the code below in a code cell and run it. This piece of code will remove the folders named ‘ComputerVision’ and ‘NeuralStyleTransfer’ if they exist in the current working directory, then it clones the repo from <a href="https://github.com/ldfrancis/ComputerVision.git">https://github.com/ldfrancis/ComputerVision.git</a> and copies the ‘NeuralStyleTransfer’ folder unto the current working directory.</p><pre>!rm -r ComputerVision NeuralStyleTransfer</pre><pre>!git clone <a href="https://github.com/ldfrancis/ComputerVision.git">https://github.com/ldfrancis/ComputerVision.git</a><br>  <br>!cp -r ComputerVision/NeuralStyleTransfer .</pre><h4>Upload</h4><p>Having cloned the repo, you then upload your images (the content and style images). Ensure that both images are of the same dimension and the content image is named ‘content.jpg’ while the style image is named ‘style.jpg’</p><pre>from google.colab import files<br>files.upload()</pre><h4>Settings</h4><p>Both images should be of the same dimension. Hence, if the content image is 400 x 300, the style image should also be 400 x 300. Set the image height and width in the variables IMAGE_HEIGHT and IMAGE_WIDTH. Also, you specify the number of iterations to use for training. The default is 200 which is very small. The maximum iteration number I have used so far is 5000.</p><pre>CONTENT_IMAGE = &quot;content.jpg&quot; <br>STYLE_IMAGE = &quot;style.jpg&quot;</pre><pre>IMAGE_HEIGHT = 300<br>IMAGE_WIDTH = 400</pre><pre>ITERATION = 200</pre><p>The paths to the content image and style image are specified below. This should not be changed when running on colab.</p><pre>path_to_content_image = &quot;/content/&quot;+CONTENT_IMAGE<br>path_to_style_image = &quot;/content/&quot;+STYLE_IMAGE</pre><h4>View the images that were uploaded</h4><p>It is good practice to view the images you are working with. So, we use matplotlib to view the content and style images. The code below reads in the images.</p><pre>import matplotlib.pyplot as plt<br>c_image = plt.imread(path_to_content_image)<br>s_image = plt.imread(path_to_style_image)</pre><p>Display the content image and its size. It should be of the same dimension as the style image.</p><pre>print(&quot;Content Image of size (height, width) =&gt; {0}&quot;.format(c_image.shape[:-1]))</pre><pre>plt.imshow(c_image)</pre><p>Display the style image with the code below.</p><pre>print(&quot;Style Image of size (height, width) =&gt; {0}&quot;.format(s_image.shape[:-1]))</pre><pre>plt.imshow(s_image)</pre><h4>Perform training iterations to generate image</h4><p>With all settings intact, import the ‘implementNTS’ module, set the image dimension and the run the style transfer to generate the mixed image. This will iterate for the number of iterations set. To obtain better results, try increasing the iteration number.</p><pre><br>from NeuralStyleTransfer import implementNTS as NST</pre><pre>NST.setImageDim(IMAGE_WIDTH,IMAGE_HEIGHT)</pre><pre>NST.run(ITERATION, style_image=path_to_style_image, content_image=path_to_content_image)</pre><h4>View generated image</h4><p>View the image that is generated from the style transfer.</p><pre>generated_image_path = &quot;/content/NeuralStyleTransfer/output/generated_image.jpg&quot;<br>image = plt.imread(generated_image_path)<br>plt.imshow(image)</pre><h4>The final generated image can be downloaded by running the code below</h4><pre>files.download(&quot;NeuralStyleTransfer/output/generated_image.jpg&quot;)</pre><p>Now, go ahead and generate as many images as you can. I’ll like to see the images you generate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*D2RV24zYexpmGI8SeL3DKg.jpeg" /><figcaption>who is this ?</figcaption></figure><p><a href="https://github.com/ldfrancis/ComputerVision/blob/master/easyNST%20on%20google%20colab.ipynb">Here is a link to the full notebook to be run on colab</a>.</p><p>repository link:<br><a href="https://github.com/ldfrancis/ComputerVision">https://github.com/ldfrancis/ComputerVision</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3264789d6ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>