<?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 Meet on Medium]]></title>
        <description><![CDATA[Stories by Meet on Medium]]></description>
        <link>https://medium.com/@meet-minimalist?source=rss-4caeac878222------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*M1lhGt7muyff1OjDRFXxWQ.jpeg</url>
            <title>Stories by Meet on Medium</title>
            <link>https://medium.com/@meet-minimalist?source=rss-4caeac878222------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 21:27:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@meet-minimalist/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[How to SSH into Google Colab? and run scripts from Terminal instead of Jupyter Notebook?]]></title>
            <link>https://medium.com/@meet-minimalist/how-to-ssh-into-google-colab-and-run-scripts-from-terminal-instead-of-jupyter-notebook-3931f2674258?source=rss-4caeac878222------2</link>
            <guid isPermaLink="false">https://medium.com/p/3931f2674258</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[notebook]]></category>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[google-colaboratory]]></category>
            <dc:creator><![CDATA[Meet]]></dc:creator>
            <pubDate>Fri, 22 Nov 2019 17:14:07 GMT</pubDate>
            <atom:updated>2019-11-22T17:15:53.879Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to SSH into Google Colab?</h3><p>Have you ever wanted to have terminal based GPU system instead of Notebook based system in Colab?</p><p>Of course, notebooks are great for displaying already computed outputs, step wise code block etc. But sometimes, it is very boring to convert your project consisting multiple .py files into a jupyter notebook. :(</p><p>So, I wanna show you how to connect to Google Colab terminal using SSH protocol.</p><p>1) Create a new notebook. Make sure to enable GPU before going ahead if you plan to use one.</p><p>2) [Optional] Connect to google drive using below two lines of code.</p><blockquote>from google.colab import drive</blockquote><blockquote>drive.mount(‘/content/gdrive’)</blockquote><p>3) Now, You need to create an account on ngrok.com. But, wait what is ngrok.com. So, I googled the same and got the below answer.</p><blockquote>Ngrok is a multiplatform tunneling, reverse proxy software that establishes secure tunnels from a public endpoint such as the internet to a locally running network service while capturing all traffic for detailed inspection and replay.</blockquote><blockquote>In short, it captures the global internet traffic through its own server and transmits them to the locally running network. By this you can give a demo of your service running on local network to the targeted customer for demo purpose.</blockquote><p>4) Copy and paste below code in colab which installs ngrok and creates a tunnel for us (code taken from <a href="https://gist.github.com/yashkumaratri/204755a85977586cebbb58dc971496da#file-google-colab-ssh">this </a>source)</p><blockquote>#CODE</blockquote><blockquote>#Generate root password</blockquote><blockquote>import random, string</blockquote><blockquote>password = ‘’.join(random.choice(string.ascii_letters + string.digits) for i in range(20))</blockquote><blockquote>#Download ngrok</blockquote><blockquote>! wget -q -c -nc https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip</blockquote><blockquote>! unzip -qq -n ngrok-stable-linux-amd64.zip</blockquote><blockquote>#Setup sshd</blockquote><blockquote>! apt-get install -qq -o=Dpkg::Use-Pty=0 openssh-server pwgen &gt; /dev/null</blockquote><blockquote>#Set root password</blockquote><blockquote>! echo root:$password | chpasswd</blockquote><blockquote>! mkdir -p /var/run/sshd</blockquote><blockquote>! echo “PermitRootLogin yes” &gt;&gt; /etc/ssh/sshd_config</blockquote><blockquote>! echo “PasswordAuthentication yes” &gt;&gt; /etc/ssh/sshd_config</blockquote><blockquote>! echo “LD_LIBRARY_PATH=/usr/lib64-nvidia” &gt;&gt; /root/.bashrc</blockquote><blockquote>! echo “export LD_LIBRARY_PATH” &gt;&gt; /root/.bashrc</blockquote><blockquote>#Run sshd</blockquote><blockquote>get_ipython().system_raw(‘/usr/sbin/sshd -D &amp;’)</blockquote><blockquote>#Ask token</blockquote><blockquote>print(“Copy authtoken from https://dashboard.ngrok.com/auth&quot;)</blockquote><blockquote>import getpass</blockquote><blockquote>authtoken = getpass.getpass()</blockquote><blockquote>#Create tunnel</blockquote><blockquote>get_ipython().system_raw(‘./ngrok authtoken $authtoken &amp;&amp; ./ngrok tcp 22 &amp;’)</blockquote><blockquote>#Print root password</blockquote><blockquote>print(“Root password: {}”.format(password))</blockquote><blockquote>#Get public address</blockquote><blockquote>! curl -s http://localhost:4040/api/tunnels | python3 -c \</blockquote><blockquote>“import sys, json; print(json.load(sys.stdin)[‘tunnels’][0][‘public_url’])”</blockquote><p>(Note: you can set your own password instead of generating the random string because you will need to enter the same again in your local machine)</p><p>This will prompt you to enter the authorization token which can be found in your ngrok account. So copy and paste it. Then you will be given output as following.</p><blockquote>Root password: &lt;Password generated or you entered earlier&gt;</blockquote><blockquote>tcp://0.tcp.ngrok.io:&lt;port_num_randomly_generated&gt;</blockquote><p>5) Now, in your local machine (mine is Windows), open command prompt and type</p><blockquote><strong><em>ssh root@0.tcp.ngrok.io -p &lt;port_num_generated_above&gt;</em></strong></blockquote><p>to connect to the Colab System. You will be asked to enter root password which was created earlier.</p><p>There you go. Now you have access to the whole system through SSH terminal.</p><p>But wait, what if I want to transfer files from my local machine to the Colab System.</p><p>6) Install WinSCP (or any other alternate software).</p><p>7) Login using following credentials to access the filesystem and upload your files to Colab System.</p><blockquote>Host name: 0.tcp.ngrok.io</blockquote><blockquote>Port number: &lt;Port number generated above&gt;</blockquote><blockquote>User name: root</blockquote><blockquote>Password: &lt;Generated above&gt;</blockquote><p>That’s it.</p><p>Credits:</p><ol><li><a href="https://twitter.com/theshawwn/status/1194603919151775745?s=08">https://twitter.com/theshawwn/status/1194603919151775745?s=08</a></li><li><a href="https://gist.github.com/yashkumaratri/204755a85977586cebbb58dc971496da#file-google-colab-ssh">https://gist.github.com/yashkumaratri/204755a85977586cebbb58dc971496da#file-google-colab-ssh</a></li><li><a href="https://imadelhanafi.com/posts/google_colal_server/">https://imadelhanafi.com/posts/google_colal_server/</a></li><li><a href="https://medium.com/@archie9211/guide-to-connect-to-google-colab-with-ssh-from-terminal-and-run-jupyter-lab-7ed60258368">https://medium.com/@archie9211/guide-to-connect-to-google-colab-with-ssh-from-terminal-and-run-jupyter-lab-7ed60258368</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3931f2674258" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Notes on implementation of Cross Entropy Loss]]></title>
            <link>https://medium.com/@meet-minimalist/notes-on-implementation-of-cross-entropy-loss-2a8e3408413c?source=rss-4caeac878222------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a8e3408413c</guid>
            <category><![CDATA[implementation]]></category>
            <category><![CDATA[cross-entropy]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[loss-function]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Meet]]></dc:creator>
            <pubDate>Sat, 03 Aug 2019 15:55:43 GMT</pubDate>
            <atom:updated>2019-08-03T15:55:43.492Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a reference note for myself if I ever want to recall the formulas and the implementations.</p><ol><li>Cross Entropy Loss for Binary classification</li></ol><p><strong><em>loss = label * (-1) * log(pred) + (1 — label) * (-1) * log(1 — pred)</em></strong></p><p>Here “label” can be either 0 or 1 and “pred” can be a probability value between 0 to 1 — any real value. The loss is a scalar value.</p><p>So, for label=1, the loss will be</p><p><strong><em>loss_label_1 = label * (-1) * log(pred) + 0</em></strong></p><p><strong><em>loss_label_1 = — log(pred)</em></strong></p><p>Same way for label=0, the loss will be</p><p><strong><em>loss_label_0 = 0 + (1 — label) * (-1) * log(1 — pred)</em></strong></p><p><strong><em>loss_label_0 = -log(1-pred)</em></strong></p><p>So, the first equation actually handles both the cases.</p><p>2. Softmax Cross Entropy Loss for Binary Classification</p><p><strong><em>softmax_logits = softmax(logits)</em></strong></p><p><strong><em>loss_softmax_cross = label * (-1) * log(softmax_logits) + (1 — label) * (-1) * log(1 — softmax_logits)</em></strong></p><p>Here, because the logits are softmaxed, they contain the probability of being a positive class.</p><p>3. Softmax Cross Entropy Loss for Multi Class Classification</p><p><strong><em>softmax_logits = softmax(logits)loss_softmax_cross_multi = sum(label * (-1) * log(softmax_logits))</em></strong></p><p>Here, labels and logits both are a vector / single column array. E.g. for 10 classes it is [10,] array. The sum represents the sum across the dimension depicted by num_of_classes which is in this case last dims. So, the loss is a scalar value.</p><p>4. Weighted Softmax Cross Entropy Loss for Multi Class Classification</p><p><strong><em>softmax_logits = softmax(logits)loss_softmax_cross_multi = sum(cls_weight * label * (-1) * log(softmax_logits))</em></strong></p><p>Here, labels, logits and cls_weights all are having same shape — a vector / single column array. E.g. for 10 classes it is [10,] array. The loss is a scalar value. The cls_weight has a separate weight for each class.</p><p>5. Sigmoid Cross Entropy Loss The sigmoid cross entropy is same as softmax cross entropy except for the fact that instead of softmax, we apply sigmoid function on logits before feeding them.</p><h3>Notes on implementation part:</h3><p>Now that we know the mathematical formula, we can implement the loss function by ourselves. But when Tensorflow has made a wheel then why to reinvent the same wheel. The Tensorflow provides several APIs for the cross entropy losses.</p><p><strong><em>tf.nn.sigmoid_cross_entropy_with_logits(label, logit)</em></strong></p><p><strong><em>tf.losses.sigmoid_cross_entropy(label, logit)</em></strong></p><p><strong><em>tf.nn.softmax_cross_entropy_with_logits(label, logit)</em></strong></p><p><strong><em>tf.losses.softmax_cross_entropy(label, logit)</em></strong></p><p>Now the key difference between tf.nn and tf.losses — is that tf.nn is low level api and tf.losses is high level API.</p><p>Now let’s take an example to see how these two APIs differ computing the same function and resulting in different shapes. a) E.g. Label as well as Logits are having shape: [Batch x num_classes]</p><p><strong><em>tf.nn.sigmoid_cross_entropy_with_logits</em></strong> will compute the loss as per the above formulas. So at first the shape remains intact. Then it sums across the last axis — which represents num_classes. And then returns the final tensor which is having shape [Batch] in our case. If we want the single value of loss per batch then we can take mean or sum of all the values across rest of the dimensions.</p><p>On the other hand, <strong><em>tf.losses.sigmoid_cross_entropy</em></strong> will compute the loss as per the same above formula. But, it returns a single scalar value for the loss. It first takes the sum across last axis which is num_class axis, and then take the mean of all the values across all axis. That’s why it returns a single value.</p><p>b) E.g. Let’s take a tough shape which I have faced during the implementation of Yolo Loss function. Label and Logit both have shape [batch x 13 x 13 x 3 x 20]</p><p>Now, <strong><em>tf.losses.sigmoid_cross_entropy</em> </strong>will give us single value and the loss for a batch of 64 is in the range of 0.0038 which is very low because it takes sum across last axis and takes mean across rest of the axis. In case of <strong>tf.nn.sigmoid_cross_entropy_with_logits </strong>— it gives me a tensor having shape [b x 13 x 13 x 3] by only taking sum across last axis. Now i can multiply this with another [b x 13 x 13 x 3] shaped tensor.</p><p>After these examples you can use the API which suit your needs.</p><blockquote>*** <em>If you want to use cls_weights then you have to implement the cross entropy loss from scratch as per formula given in (3) because there are one APIs in Tensorflow for that which is </em><strong><em>tf.nn.weighted_cross_entropy_with_logits</em></strong><em> but it is deprecated.</em></blockquote><h3>How to compute the cls_weight for imbalance class problem?</h3><ol><li>First count the freq of each class: E.g. [cls_1: 1000, cls_2: 2300, cls_3: 20310, cls_4: 6700]</li><li>Then take the ration (sum_of_all_freqs / cls_freq) for all classes E.g. [cls_1: 30.31, cls_2: 13.17, cls_3: 1.492, cls_4: 4.523]</li><li>Take log of it. E.g. [cls_1: 3.41, cls_2: 2.57, cls_3: 0.40, cls_4: 1.50]</li><li>Now take the max between the value and 1.0 to clip lower values at 1.0 E.g. [cls_1: 3.41, cls_2: 2.57, cls_3: 1.00, cls_4: 1.50] 4a [Optional]. Take the max value from 3 and divide all values with that. E.g. [cls_1: 1.00, cls_2: 0.755, cls_3: 0.117, cls_4: 0.442]</li></ol><p>Now, these are your class weights. As you can see the cls_3 which has highest occurrence is given least weight and cls_1 which has the least freq. is given highest weight. As per <a href="https://www.tensorflow.org/api_docs/python/tf/nn/weighted_cross_entropy_with_logits?hl=en">link</a>, these weights greater than 1 which decrease false negative counts which improves recall. And if we want to reduce false positive and improve precision than use weights computed in 4a. — again as per the above link.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a8e3408413c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Artistic Style Transfer — Paper Summary and Implementation]]></title>
            <link>https://medium.com/@meet-minimalist/artistic-style-transfer-paper-summary-and-implementation-8615e4e44899?source=rss-4caeac878222------2</link>
            <guid isPermaLink="false">https://medium.com/p/8615e4e44899</guid>
            <category><![CDATA[style-transfer]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Meet]]></dc:creator>
            <pubDate>Wed, 12 Dec 2018 11:21:42 GMT</pubDate>
            <atom:updated>2018-12-13T10:02:34.216Z</atom:updated>
            <content:encoded><![CDATA[<h3>Artistic Style Transfer — Paper Summary and Tensorflow Implementation</h3><p>Back in 2016, there was a new app called <a href="https://prisma-ai.com/">Prisma </a>which had got great popularity among celebrities and also people belong to the Computer vision and deep learning domain. That was fascinating for me at that moment and I was even more attracted to this field. If you haven’t explored that app then just download and check it out. See the sample results below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*mpZNEar2KpnqfnhmjG9yeg.jpeg" /><figcaption>Source: <a href="https://ipadwisdom.com/2016/08/24/prisma-app-review-convert-images-drawings-amazing-works-art/">https://ipadwisdom.com/2016/08/24/prisma-app-review-convert-images-drawings-amazing-works-art/</a></figcaption></figure><p>So this paper is all about the algorithm which generates such beautiful blended images. This thing falls under the segment called non photo-realistic rendering. Before we move on to explanation, I urge you to read <a href="https://arxiv.org/abs/1508.06576">this</a> beautifully written paper.</p><p>The key finding of the paper is that the representations of content and style are separable for a given image in pretrained Convolutional Neural Network. Their work provides better understanding on how neural networks can independently capture content of an image and style of an image.</p><p>The authors have used pretrained VGG19 model with average pooling instead of max pooling to better propagate the gradients to the input noise image.</p><p>It is now a well known fact that the CNNs develop internal patterns in their filters at various depth of architecture. In the initial layers the patterns are very basic. But as we go deeper the pattern becomes more complex. This phenomenon can be seen <a href="https://blog.keras.io/how-convolutional-neural-networks-see-the-world.html">here</a> (Keras blog) and <a href="https://github.com/meet-minimalist/Visualize-CNN-Filters">here</a> (Implementation). So we can use this knowledge to reconstruct the specific part / segment of an image which is style of an image and content of an image.</p><p>The pretrained model is fed with a reference content image (whose content to be copied), a reference style image (whose style to be adopted) and a white noise image (each pixel having value between 0 to 255 using random uniform / normal distribution). Here we will not update any weights but instead we will optimize the input image which is random white noise. So we will backprop the grads of loss through the network into the input image.</p><p><strong><em>Content Loss</em></strong><em>:</em></p><p>The authors have proposed a way to reconstruct the given content image from scratch white noise image using pretrained CNN filters. For that the mean squared difference will be computed between feature representations of the CNN filters at a given layer for both content and noise image. The feature representation is the activation (output) of the given layer which is having (L x W x no of filters) shape which reshaped into (L * W x no of filters) before taking mean squared difference. This <em>content loss </em>is responsible for image reconstruction. The following visualizations will help it understand further.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*WMZ1W47J1p5bHNXYNWyYHA.png" /><figcaption>Source: <a href="https://arxiv.org/abs/1508.06576">https://arxiv.org/abs/1508.06576</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mhQc7Gv7BEVURTRVpoBorA.png" /><figcaption>Source: <a href="https://www.youtube.com/watch?v=CzN_-gVgTno">https://www.youtube.com/watch?v=CzN_-gVgTno</a></figcaption></figure><p>The authors have concluded that as we select deeper layer for content reconstruction the actual content of image is preserved but the exact detailing are lost. If we want a ditto image to be reconstructed then we should select layers which are close to input layer.</p><p><strong><em>Style Loss:</em></strong></p><p>For style reconstruction, they have used the exact same approach when synthesizing the texture from the given sample image as shown in the paper <a href="https://arxiv.org/abs/1505.07376">Texture Synthesis using Convolutional Neural Networks</a> (<a href="https://medium.com/@meet_patel/tensorflow-implementation-of-paper-texture-synthesis-using-convolutional-neural-networks-c9a03ba5b2f4">explanation</a>). The style loss is similar to content loss but the mean squared difference will be taken between the Gram Matrices of style image and white noise image over a given selected layers. The Gram Matrix is a measure that shows how the elements of a vector are correlated to each other. Higher the value of gram matrix, higher the correlation between its each element of vector.</p><p>To compute the Gram Matrix first we need to transform the output of a given layer into ( L * W x no of filters) as we did in content loss. Then the transpose of this matrix will be multiplied by the matrix itself to have the required Gram Matrix. The mean squared difference will provide the required Style Loss which is responsible for the reconstruction of the style.</p><p>Remember that the style reconstruction will recreate the style which is SIMILAR to the reference image not the EXACT style.</p><p>Unlike, content loss where we compute the loss over single layer, here we compute style loss over different layers and we do weighted sum of all the mean squared differences to obtain the final style loss.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*J8mdHEeS7M-H5rlSFaUulA.png" /><figcaption>Source: <a href="https://arxiv.org/abs/1508.06576">https://arxiv.org/abs/1508.06576</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bLB1pGhwnlrGM2W5vE63kg.png" /><figcaption>Source: <a href="https://www.youtube.com/watch?v=CzN_-gVgTno">https://www.youtube.com/watch?v=CzN_-gVgTno</a></figcaption></figure><p><strong><em>Total Loss:</em></strong></p><p>The loss function that we will try to minimize is the weighted sum of both the content loss and style loss. A content loss factor alpha is multiplied with content loss and style loss factor beta is multiplied with style loss. The weights provide significance to individual losses. Typically the ratio of alpha / beta = 10^-3 will produce better results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*BrzToTNr7JNexNAHM6ExnA.png" /><figcaption>Source: <a href="https://arxiv.org/abs/1508.06576">https://arxiv.org/abs/1508.06576</a></figcaption></figure><p><strong><em>My Results:</em></strong></p><p>Following are the results that I obtained when successfully implementing the paper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tn2NeR8mEU3wxd6_A6oJJQ.jpeg" /><figcaption>Final Result</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*lwuasT6t_IN7BzJ7AhixtQ.gif" /><figcaption>GIF of the whole training process.</figcaption></figure><p><strong><em>My Tensorflow Implementation:</em></strong></p><p>Below is the Tensorflow implementation of the said paper. The implementation contains Jupyter Notebook which is created in a manner to facilitate self-learning approach.</p><p><a href="https://github.com/meet-minimalist/A-Neural-Algorithm-of-Artistic-Style-Paper-Implementation">meet-minimalist/A-Neural-Algorithm-of-Artistic-Style-Paper-Implementation</a></p><p>Cheers!!! :D</p><p>As opposed to the content loss where we used only single layer to compute</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8615e4e44899" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Capsule Networks Paper Implementation]]></title>
            <link>https://medium.com/@meet-minimalist/capsule-networks-paper-implementation-e1d6e8061f95?source=rss-4caeac878222------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1d6e8061f95</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[capsule-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Meet]]></dc:creator>
            <pubDate>Mon, 29 Oct 2018 08:49:15 GMT</pubDate>
            <atom:updated>2019-03-06T16:02:12.357Z</atom:updated>
            <content:encoded><![CDATA[<ul><li><strong>Intro:</strong></li></ul><p>As we already know that from 2012 CNNs have shown their significance in computer vision tasks such as ImageNet competition. They are outperforming every domain in the world such as self driving cars, medical imaging, manufacturing, reinforcement learning etc.</p><p>If you have trained a CNN on non-standard small sized dataset, you definitely might have used data augmentations to explicitly train CNNs to identify original image and rotated / cropped image as same object. This is were the limitations of the CNNs began to float.</p><p>Now consider following two images where a CNN misunderstood when there is change in the relative orientation of the features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7z9U1ZVEvjrIU8ap8C19Og.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*wsf4tsOH77T1lpylPUIhbA.png" /><figcaption>CNNs misunderstanding the change in relative orientation of features. Source:<a href="https://hackernoon.com/capsule-networks-are-shaking-up-ai-heres-how-to-use-them-c233a0971952"> Image-1</a> and <a href="http://sharenoesis.com/wp-content/uploads/2010/05/7ShapeFaceRemoveGuides.jpg">Image-2</a></figcaption></figure><p>To the human, us, if someone asks us to describe what is a face? We describe it as it should have 2 eyes, above which eyebrows and below which there will be nose which also should be the center of the face, below the nose there will be mouth having two lips in horizontal direction. etc..</p><p>When we describe the image as this way, we remember the relative positioning of each of the features such as eyes, eyebrows, nose, mouth etc. and then reconstruct the face based on that.</p><p>But CNNs do the identification of face little bit differently. They identify each of the features but the failed to preserve / maintain / remember the relative positioning of the features. This is because of “Maxpooling” operation which takes out max value from a given window size and due to this the important information such as relative positioning details of the features gets lost.</p><p>That’s why in the above two examples, even though the both sub images contain all the required features to be identified as a predicted class, the image on the right don’t look like a face to human as the features aren’t as per the relative positioning that we knew. But CNNs are identifying them as a face just because CNNs have found the sufficient features to classify them as a face irrespective of their relative positioning.</p><p>This limitations have been clearly explained <a href="https://medium.com/ai%C2%B3-theory-practice-business/understanding-hintons-capsule-networks-part-i-intuition-b4b559d1159b">here</a> in a great way and that has helped me understand better. I would recommend it.</p><ul><li><strong>Capsule Networks:</strong></li></ul><p>Geoffrey Hinton had proposed an idea of Capsule Networks in long back but recently came up with a <a href="https://arxiv.org/abs/1710.09829">paper </a>and its great results. Before moving ahead, I strongly encourage you to quickly glance over the paper. Don’t go much in detail just take a look at what the authors’ want to say and what are their results.</p><p>The Capsule net is different than CNN in many ways.</p><ol><li>Capsule Networks deal with vectors instead of scalar value.</li><li>There are no Pooling operations due to them there is loss of information.</li><li>The activation function for “Capsules” is different than the one which we regularly use.</li><li>The training of Capsule Parameters (I will explain these) are done separately in the feed forward operation unlike in the back-propagation in CNNs.</li><li>Regarding how inputs are gathered and processed following image will show the difference between CapsNet and ANN.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*0i6J_enQju1xAAnBt3sl6g.png" /><figcaption>Source: <a href="https://medium.com/ai%C2%B3-theory-practice-business/understanding-hintons-capsule-networks-part-ii-how-capsules-work-153b6ade9f66">1</a> and <a href="https://github.com/naturomics/CapsNet-Tensorflow">2</a></figcaption></figure><ul><li>Architecture of CapsNet:</li></ul><p>Let’s quickly go through the following visualization that I made to understand the CapsNet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dJp6bFZnllYTh0mndlynFw.jpeg" /><figcaption>Capsule Network Architecture Visualization</figcaption></figure><p>In the paper, authors’ had tried their model on standard MNIST dataset.</p><p>1) The initial step is to take 28 x 28 MNIST images.</p><p>2) The first operation is similar to ordinary convolutional neural networks to extract the low level features from the input image to obtain “conv1”</p><p>3) Now, apply 32 times convolution on the “conv1” with stride 2 and 8 filters. This is equivalent to applying convolution on “conv1” with stride 2 and filters = 8*32 = 256. After the operation we have obtained “primaryCaps”. Till now we have nothing new.</p><p>4) Now, we are having 6x6 modules of 8 depth capsule and total 32 such group of modules. So, by flattening / stacking capsules with 8d dimension, we will have 1152 capsules and each is having 8 dimension. Applying squashing will make it primaryCaps : “u” (notation as per paper).</p><p>5) Now the stack of 1152 capsules will be tiled (make identical copies) upto 10 (which is equal to classes to be predicted) to facilitate the matmul operation.</p><p>6) After that, each of the 8d capsules will be mapped to 16d capsules as we want 16d capsules in output layer (digitCaps). So for each capsule in (from 1152) will be multiplied by 8x16 weights to obtain 1x16 capsule output (1x8 * 8x16 = 1x16). There are total 1152 capsules and total 10 such copies. So weights will be having shape : [10 x 1152 x 8 x 16]. Also, these weights will be tf.Variable so they will be trained during backprop as usual.</p><p>7) Due to last operation, we will be having 10 x 1152 capsules having 16 dimensions which is primaryCaps : “u_hat”. Now that we have done the mapping, this step is similar to what we do in ANNs which is multiplying input with weight (and add bias) and apply activation. So, here we will apply a scalar value for each of the capsules. So there will be total 10 x 1152 scalar values “b_ij” for each capsules. These “b_ij”s are initialized at 0 in the beginning. It will be trained in feed forward process by algorithm called “Routing by Agreement”. Now, b_11 will be scalar for first capsule in first stack (out of 10 such stacks) of 1152 to get connected with first capsule of output layer (10 x 16). There will be 9 more such scalar values for first capsule in first stack (out of 10 such stacks) of 1152 to be mapped with rest of the 9 capsules in output layer (10 x 16). So for each capsule there will be 10 scalars to map the single input capsule to 10 different output capsules. And there are total 1152 capsules in single stack in the input layer. So there will be total 10 x 1152 scalars for a given single stack. This pair of b_ijs will be reused for the second stack of 10 x 1152. Note that the value of b_ij should be such that the all the scalars connecting to single capsule in output layer should sum to 1. This is done by applying softmax on b_ijs across single output capsule dimension and we will get c_ij = softmax(b_ij) and c_ij will be used as a scalar multiplier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/222/1*RCAKe6p5ssK-_1cuDY-B7g.png" /></figure><p>Note: The value of b_ij will be changed during training explicitly. During the feed forward operation to obtain v_j as per below pseudo code we will update value of b_ij. So b_ij will be tf.constant instead of tf.Variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*pVYLUJDSjjLBIErTCkBoMA.png" /></figure><p>8) Now that we have done the scalar multiplication, we will get the s_j as per below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*ORRQirVHV6wTc3QWTZtGPw.png" /></figure><p>9) The s_j will be having dims : 1152 x 10 x 16. But we need to reduce 1152 to get the output shape of 10 x 16. So, we will sum all the values across 1152 dims to get the 10 x 16 output dimension. Then we apply squashing (see below pic) activation to obtain final output of capsule network: digitCaps which is v_j. Squashing is equivalent to compute unit vector first and then scale it down little bit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/1*_0BQLdnmlDnUBYxfy9nZyA.png" /></figure><p>10) The authors have proposed a stack of FC layers to visualize the 16 dimensional output v_j. The FC layers will be in following fashion. 16 neurons -&gt; 512 -&gt; 1024 -&gt; 784 neurons. The final layer output will be reshaped to obtain reconstructed version on input. Also, these FC layers can be taken account while training. (it is optional.)</p><ul><li>Loss functions: There will be 2 loss functions.</li></ul><ol><li>Reconstruction Loss (To be used in case if we opt for FC reconstruction layers) : It is the mean squared error between reconstructed input and input.</li><li>Margin Loss: The network has predicted the input and if that prediction is more confident than 0.9 (margin) then the maximum of (“squared difference between 0.9 and pred. value” &amp; “0&quot;) will be the part of margin loss. If it has correctly predicted with more that 0.9 probability then the squared diff will be -ve and max value will be 0. So the correct prediction wont account the margin loss. On the other hand if the prediction is wrong then the maximum of (“squared difference between wrong pred. value and 0.1” &amp; “0”) will be accounted in the margin loss. If the prediction is heavily wrong then the probability of that prediction is more than 0.1 and difference will be +ve value. That will account for bad prediction in margin loss.</li></ol><p>Following image will help us understand further.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*iarB9L3k4B2RX-jQGfORnA.png" /></figure><p>This is all about the capsule network architecture.</p><p>Following is the Jupyter Notebook TensorFlow implementation of the Capsule Networks. Please check that out, too.</p><p><a href="https://github.com/meet-minimalist/Capsule-Network">meet-minimalist/Capsule-Network</a></p><p>Cheers. :D</p><p>References:</p><ol><li>Great explanation series on Capsnet: <a href="https://medium.com/ai%C2%B3-theory-practice-business/understanding-hintons-capsule-networks-part-i-intuition-b4b559d1159b">https://medium.com/ai%C2%B3-theory-practice-business/understanding-hintons-capsule-networks-part-i-intuition-b4b559d1159b</a></li><li>Simple implementation: <a href="https://github.com/dasayan05/capsule-net-TF">https://github.com/dasayan05/capsule-net-TF</a></li><li>Visualizing the outputs: <a href="https://github.com/bourdakos1/CapsNet-Visualization">https://github.com/bourdakos1/CapsNet-Visualization</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1d6e8061f95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Udacity Deep Learning Nanodegree Review]]></title>
            <link>https://medium.com/@meet-minimalist/udacity-deep-learning-nanodegree-review-5e16aa16477f?source=rss-4caeac878222------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e16aa16477f</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[udacity]]></category>
            <category><![CDATA[neural-networks]]></category>
            <dc:creator><![CDATA[Meet]]></dc:creator>
            <pubDate>Sat, 13 Oct 2018 07:45:14 GMT</pubDate>
            <atom:updated>2018-10-13T07:45:14.554Z</atom:updated>
            <content:encoded><![CDATA[<p>I have recently completed Deep Learning paid course offered by Udacity. Udacity provide the course every month. I had enrolled for May cohort. It was a 4 month course consists of 5 important topics /modules of the field.</p><p>Each module is supported by many mini coding exercises, quizzes and final assignment. The assignment needs to be completed in terms of all the requirements that are given by Udacity. Once you complete all the assignments for each module you will be graduated and soon after verification you will get the Udacity certified certificate.</p><p>Also, Udacity has made all the assignment such that it only focuses on the implementation part of the things that you learned in that module. The supporting things such as data pre-processing etc will be already provided in the assignment Jupyter Notebook. So you only need to focus on the things which matter a lot. Each module comes with a soft dead line just as a reminder. It was meant to be followed but not mandatory. The final dead line of the course needs to be stringently followed. Also, in case if a candidate is not being able to complete some of the assignments, then Udacity will provide 28 days extension to complete all the pending assignments.</p><p>The assignments when submitted are review by experts and they will provide detailed feedback on the submission. What are the areas of improvement, what are the best parts of the submission, some of the articles to enhance our knowledge for better understanding etc.</p><p>As the field of Deep Learning deals with lot of data, we often need great computing power for the course assignments and small coding sessions. For that Udacity provides 100 $ credits for Amazon Web Services. Also, they provide dedicated module on how to setup the AWS EC2 instance to make it ready to use. The best part is that the 100 $ credits can be used even after the completion of the course.</p><p>Regarding the prerequisites, Udacity wants the candidate to have basic knowledge of Python and Mathematics (e.g. Linear Algebra, Calculus, Probability). You don’t need to be an expert Mathematician or expert in Python. You just need enough to understand the basic underlying concepts. Whenever you will encounter something new, just google it and learn that portion. Simple.</p><p>As I mentioned the course is divided in following parts.</p><ol><li>Artificial Neural Network:</li></ol><ul><li>As this was the first module and foundational module, they explained each and every thing in detail. How the intuition behind neural network developed, how I can visualize neural networks as universal function approximators, how data has been feed forward to neural networks and back propagation happens in neural networks. Also, the important topic which is backpropagation was taught in detail and in the final project I was asked to implement it from the scratch using numpy only. That had boasted my confidence.</li></ul><p>2. Convolutional Neural Network:</p><ul><li>In the second module, I was taught about convolutional neural networks which deals with Images as an input and finds pattern in the images. In this module, I was also taught about TensorFlow library which is widely used. There were mini coding sessions and quizzes which helped a lot to digest heavy concepts. The assignment was to create a Dog App to identify whether the provided image contains dog or not and if it contains a dog then what is the breed of the dog. It was a challenging task. Here I had made multiple failed attempts till my assignment was successfully submitted.</li></ul><p>3. Recurrent Neural Network:</p><ul><li>In this module, I was taught about Recurrent neural networks which deals with time dependent data instead of static data. Here I was taught about BPTT — Backpropagation Through Time — underlying concept for RNNs. Along with RNNs I was taught about limitations of RNNs, a better RNN which are LSTMs and GRUs. In the assignment we need to generate TV script based on the given data set of Simpson’s conversation. Loved this project.</li></ul><p>4. Generative Adversarial Networks:</p><ul><li>The GANs are the coolest part of this course. They were proposed in 2014 by Ian Goodfellow and he was teaching this module (How coooool!!). I felt that I was learning something cutting edge technology. The best part was assignment. We were supposed to generate human faces based on CelebA dataset. Here, I was fortunate that I had AWS credits as it took a long to train on my local machine. It took me multiple attempts to successfully submit the assignment. The best part was that they had provided a stringent criterion of single epoch on training which was very crucial and challenging. Loved this project.</li></ul><p>5. Deep Reinforcement Learning:</p><ul><li>In the start of this module, I thought that the things which are taught not related to Deep Learning. But as I proceeded further to the section of Deep Q Learning, I get to the importance of initial concept building. They also taught concepts and taught about implementing them in OpenAI environment (Which was a big plus as it is currently used by researcher). Here I was also taught about Actor Critic method and DDPG methods which were proposed couple of years back. Here also I felt like I am actually learning something cutting edge technology. The final assignment was to make a Quadcopter fly using Deep Reinforcement learning algorithms that had been taught. Here as the task was difficult to achieve, they provided number of resources and provided less stringent criteria to implement the concept successfully.</li></ul><p>Overall, I would definitely recommend this course as it has number of benefits over other paid courses that are available on internet. To summarize, following are the key benefits.</p><p>1. Curriculum was designed by some of the best industrial experts</p><p>2. Concepts were taught in details and they had provided support of forums where people can post and solve each other’s queries.</p><p>3. The modules were perfectly designed and consist of mini coding sessions, quizzes and final assignment at the end of each module.</p><p>4. They provide 100 $ AWS credits for the term exercises.</p><p>Link to the course: <a href="https://in.udacity.com/course/deep-learning-nanodegree--nd101">https://in.udacity.com/course/deep-learning-nanodegree--nd101</a></p><p>Happy Learning. Peace. :D</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e16aa16477f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tensorflow implementation of paper “Texture Synthesis Using Convolutional Neural Networks”]]></title>
            <link>https://medium.com/@meet-minimalist/tensorflow-implementation-of-paper-texture-synthesis-using-convolutional-neural-networks-c9a03ba5b2f4?source=rss-4caeac878222------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9a03ba5b2f4</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[style-transfer]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[convolutional-network]]></category>
            <category><![CDATA[tensorflow]]></category>
            <dc:creator><![CDATA[Meet]]></dc:creator>
            <pubDate>Tue, 02 Oct 2018 14:06:45 GMT</pubDate>
            <atom:updated>2018-10-02T14:06:45.098Z</atom:updated>
            <content:encoded><![CDATA[<p>In this <a href="https://github.com/meet-minimalist/Texture-Synthesis-Using-Convolutional-Neural-Networks">tutorial</a>, we have implemented the foundation paper for Algorithmic Style Transfer, which is <a href="https://arxiv.org/abs/1505.07376">“Texture Synthesis Using Convolutional Neural Networks” by Leon A. Gatys, Alexander S. Ecker, Matthias Bethge</a>.</p><p>The paper is all about generating / synthesizing texture from a sample texture image from noisy image. Basically it is an attempt to get the insights of a convolutional neural network.</p><p>Here, we have used VGG16 tensorflow network as opposed to the one which is used by the authors (VGG19 network). The key concept here that we try to minimize the difference in feature response of sample image and noisy image.</p><p>For that, the authors have used Gram Matrix which is a measure that shows how the elements of a vector are correlated to each other. Higher the value of gram matrix, higher the correlation between its each element of vector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*5nXkpchUhp1FuDKLrMUcWQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*dgjpVENx_rT036nddKN1sA.png" /><figcaption>Gram Matrix</figcaption></figure><p>We compute gram matrix for both sample image and noisy image for a particular layer. Then we take the squared difference of these to form a following loss function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*XuGr5T9KuN_WVC3jt6Mz_Q.png" /><figcaption>Loss function</figcaption></figure><p>In the similar fashion, one can compute loss for multiple layer and do a weighted sum to get the final loss function value.</p><p>At last, we will compute the loss function for different configurations of the layers and then try to minimize the loss function to generate the optimized noisy image.</p><p>Following are the samples that have been generated using the paper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*d_9U8srwN7s3vtc4brtO9g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*45uT0gvUN9lvYzWj9Jts2Q.png" /></figure><p>As you can see that the samples are closely resembling to the sample texture images as we go deeper and use deeper layers to compute the loss and optimize the noise.</p><p>Based on this paper, the same authors have published another paper which is the first paper for <a href="https://arxiv.org/abs/1508.06576">Algorithmic Style Transfer </a>which was a great breakthrough.</p><p>Following Jupyter Notebook guides you through the implementation of the paper.</p><p><a href="https://github.com/meet-minimalist/Texture-Synthesis-Using-Convolutional-Neural-Networks/blob/master/Texture%20Synthesis%20Using%20Convolutional%20Neural%20Networks%20-%20Tensorflow%20Implementation.ipynb">meet-minimalist/Texture-Synthesis-Using-Convolutional-Neural-Networks</a></p><p>References:</p><p>1. VGG16 Tensorflow Model — <a href="https://github.com/machrisaa/tensorflow-vgg">https://github.com/machrisaa/tensorflow-vgg</a><br>Pre-trained VGG16 tensorflow model along with helper files. Big shout-out to the owner. Also, vgg16.npy can be downloaded from the link provided in this repository. I have modified the vgg16.py file to facilitate average pooling instead of max pooling.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9a03ba5b2f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>