<?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 Mohammad Aaftab V on Medium]]></title>
        <description><![CDATA[Stories by Mohammad Aaftab V on Medium]]></description>
        <link>https://medium.com/@aaftabv3?source=rss-76584bd26aec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*zuaW5R9C2mz6DTaBOI_Vfg.jpeg</url>
            <title>Stories by Mohammad Aaftab V on Medium</title>
            <link>https://medium.com/@aaftabv3?source=rss-76584bd26aec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 04:05:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aaftabv3/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[Hack a Neural Network in just 10 Lines of Code!!!]]></title>
            <link>https://medium.com/analytics-vidhya/hack-a-neural-network-in-just-10-lines-of-code-ecd2192930a1?source=rss-76584bd26aec------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecd2192930a1</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Mohammad Aaftab V]]></dc:creator>
            <pubDate>Sun, 17 Oct 2021 16:00:49 GMT</pubDate>
            <atom:updated>2021-11-10T04:53:41.580Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EVbKTcwZcAyfXSxl" /><figcaption>Photo by <a href="https://unsplash.com/@jefflssantos?utm_source=medium&amp;utm_medium=referral">Jefferson Santos</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Hello everyone! Hope you are doing well. Let’s dive right in.</p><h3>What is Hacking a Neural Network?</h3><blockquote>Hacking a Neural Network is simply fooling a Neural Network. Neural Networks are increasingly being used in various security and moderating systems across different fields. It is very important that they maintain their integrity across different types of attacks. In this article, I am going to explain how we can modify an image (without changing it too much) to force the Neural Network to mis-classify it (that too with a very high degree of certainty).</blockquote><blockquote>Below given is an excerpt from Ian Goodfellow’s paper, <a href="https://arxiv.org/pdf/1412.6572.pdf">EXPLAINING AND HARNESSING ADVERSARIAL EXAMPLES</a>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NAtY_3O5gnpY9tsTGer7NA.png" /></figure><p>In the above example, we can see that adding carefully and mathematically designed noise to an image can throw the neural network’s predictions off by huge amount, whilst managing to keep the image visually unchanged.</p><p>In this article, I am going to hack an MNIST digit classifier Neural Network. Let us take an image of digit 0 (as given below). Since the model I have built has an accuracy of about 96%, It is going to classify this image correctly as 0. Now, I want to modify this image of 0 by adding some strategic noise (this is arrived upon by simple gradient descent) to it, so that MNIST model classifies it as image 8 <strong>AND</strong> the image is not modified too much. Hence, to us humans, we can still clearly see the image is of number 0, yet model thinks the image consists of number 8 with very high probability.</p><p>Here is what the results look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*rHfi3js7IEqLG_icOPmCtw.png" /></figure><p>The above image is recognized by the MNIST classifier as number 0 with a certainty of 99%. Below given is the modified image that is recognized as number 8 by the NN with a certainty of 99.6%.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*fVwxjbg59g8nirkLqacMHQ.png" /></figure><p>In this article, I am going to explain how I was able to modify the first image into 2nd image, i.e., how I fooled the neural network to classify an image that is so obviously 0 as 8 (with a very high degree of certainty).</p><h3><strong><em>Procedure for Hacking an MNIST Classifier:</em></strong></h3><p>The model to be hacked is trained based on the MNIST classifier found in this <a href="https://towardsdatascience.com/handwritten-digit-mnist-pytorch-977b5338e627">article</a>. Now that we have the trained model ready to get hacked, let us get started with hacking.</p><p>We are going to use simple gradient descent to calculate the exact noise that has to be added to the original image so as to throw the NN off. First, I am going to make a loss function for the gradient descent to follow. Loss function is one of the most important parts of any system involving gradient descent. Gradient descent is simply a way to minimize the loss function. Hence, we need to make a loss function that reflects our goals, i.e. make predicted probability of 8 for image maximum and keep the difference between original and modified image to a minimum. And here is what the loss function looks like.</p><pre><strong>def</strong> findloss(diff,pred):</pre><pre>    l1=torch.mean(torch.square(diff))<br>    l2=pred**(-1)<br>    <br>    fl=(l1+l2)**0.5<br>    <br>    <strong>return</strong> fl</pre><p>l1 represents the deviation (diff or noise) between modified and original images. l2 represents the inverse of probability the NN classifies the modified image as digit 8. Thus minimizing square root of sum of l1 and l2, leads to minimizing both l1 and l2 thus minimizing noise and maximizing the probability modified image is classified by NN as 8 simultaneously.</p><p>Now, let us use gradient descent to modify the noise so as to minimize the above defined loss function (this automatically achieves the goals we had set to hack the Neural Network). Below is the code for that.</p><pre>learning_rate=0.0005<br>num_descents=2000000 <br><em>#number of times gradient descent is employed</em><br><br>img=img.cuda()<br>#generate random noise to finetune using gradient descent<br>diff=torch.rand(784).cuda().requires_grad_()</pre><pre><strong>for</strong> i <strong>in</strong> range(num_descents):<br>    <br>    #get the modified image<br>    imagef=img+diff</pre><pre>    pred=torch.exp(model(imagef.reshape([1,784])))[0][8]<br>    <br>    totalloss=findloss(diff,pred)<br>    <strong>if</strong> i%10000 ==0:<br>        print(&#39;Loss and prediction by the model after &#39;+str(i)+&#39; steps of gradient descent are &#39;+str(totalloss.item()),str(pred.item()))<br>     <br>        <br>    <em>#find gradients of totalt wrt yarray.</em><br>    totalloss.backward()<br><br>    gradients=diff.grad<br>    <em>#torch.clip(gradients,max=100.0)</em><br>    <strong>with</strong> torch.no_grad():<br>        diff[1:]=diff[1:]-learning_rate*gradients[1:]<br>    diff.grad.data.zero_()</pre><p>The complete code can be found in my <a href="https://github.com/mohammadaaftabv/HackNN/blob/master/SimpeGradientDescentToHackNN.ipynb">repo</a>. The results achieved by this method have already been written above.</p><p>So, this is how simple gradient descent was able to fool the MNIST classifier.</p><p>Thank You for reading through the article. Here is another article that shows how powerful simple gradient descent can be.</p><p><a href="https://medium.com/analytics-vidhya/neural-networks-vs-simple-gradient-descent-the-age-old-brachistochrone-problem-7503be69d611">Neural Networks Vs Simple Gradient descent: The Age old Brachistochrone Problem.</a></p><p>If you liked the article, let’s connect.</p><p><a href="https://www.linkedin.com/in/mohammadaaftabv/">Linkedin</a>, <a href="https://twitter.com/Aaftab08924859">Twitter</a>, <a href="https://github.com/mohammadaaftabv">Github</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecd2192930a1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/hack-a-neural-network-in-just-10-lines-of-code-ecd2192930a1">Hack a Neural Network in just 10 Lines of Code!!!</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[Neural Networks Vs Simple Gradient descent: The Age old Brachistochrone Problem.]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/analytics-vidhya/neural-networks-vs-simple-gradient-descent-the-age-old-brachistochrone-problem-7503be69d611?source=rss-76584bd26aec------2"><img src="https://cdn-images-1.medium.com/max/2600/0*iAa7yvYFc8e8ncpl" width="4256"></a></p><p class="medium-feed-snippet">Introduction:</p><p class="medium-feed-link"><a href="https://medium.com/analytics-vidhya/neural-networks-vs-simple-gradient-descent-the-age-old-brachistochrone-problem-7503be69d611?source=rss-76584bd26aec------2">Continue reading on Analytics Vidhya »</a></p></div>]]></description>
            <link>https://medium.com/analytics-vidhya/neural-networks-vs-simple-gradient-descent-the-age-old-brachistochrone-problem-7503be69d611?source=rss-76584bd26aec------2</link>
            <guid isPermaLink="false">https://medium.com/p/7503be69d611</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[physics]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Mohammad Aaftab V]]></dc:creator>
            <pubDate>Wed, 23 Dec 2020 09:19:38 GMT</pubDate>
            <atom:updated>2020-12-27T12:38:51.321Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Random Projection Neural Networks]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/analytics-vidhya/random-projection-neural-networks-a9f7b1e6bbc5?source=rss-76584bd26aec------2"><img src="https://cdn-images-1.medium.com/max/2600/0*y6PVQTh3h7UtfUSX" width="5446"></a></p><p class="medium-feed-snippet">For High Dimensional Data. Papers Implemented Series.</p><p class="medium-feed-link"><a href="https://medium.com/analytics-vidhya/random-projection-neural-networks-a9f7b1e6bbc5?source=rss-76584bd26aec------2">Continue reading on Analytics Vidhya »</a></p></div>]]></description>
            <link>https://medium.com/analytics-vidhya/random-projection-neural-networks-a9f7b1e6bbc5?source=rss-76584bd26aec------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9f7b1e6bbc5</guid>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[research]]></category>
            <dc:creator><![CDATA[Mohammad Aaftab V]]></dc:creator>
            <pubDate>Mon, 03 Aug 2020 19:37:07 GMT</pubDate>
            <atom:updated>2020-08-04T04:59:59.755Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Experiment on Neural Networks with MNIST Dataset.]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/analytics-vidhya/experiment-on-neural-networks-with-mnist-dataset-dc276377334a?source=rss-76584bd26aec------2"><img src="https://cdn-images-1.medium.com/max/2600/0*VlwC-sHdlh9mksT9" width="3888"></a></p><p class="medium-feed-snippet">In-depth explanation and subsequent practical application of various concepts in Deep Learning.</p><p class="medium-feed-link"><a href="https://medium.com/analytics-vidhya/experiment-on-neural-networks-with-mnist-dataset-dc276377334a?source=rss-76584bd26aec------2">Continue reading on Analytics Vidhya »</a></p></div>]]></description>
            <link>https://medium.com/analytics-vidhya/experiment-on-neural-networks-with-mnist-dataset-dc276377334a?source=rss-76584bd26aec------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc276377334a</guid>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[keras]]></category>
            <category><![CDATA[convolutional-network]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Mohammad Aaftab V]]></dc:creator>
            <pubDate>Thu, 16 Jul 2020 18:08:10 GMT</pubDate>
            <atom:updated>2020-07-21T06:46:22.887Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[“The Dream” —  A short Story]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/the-creative-cafe/the-dream-a-short-story-95223b3db69f?source=rss-76584bd26aec------2"><img src="https://cdn-images-1.medium.com/max/820/1*lQoM7AE1TIo5g4gPRF6jCw.jpeg" width="820"></a></p><p class="medium-feed-snippet">It&#x2019;s a bright sunny morning, just the way Michael Lee or as everyone called him, Mike likes his day to begin. Lately, he couldn&#x2019;t help but&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/the-creative-cafe/the-dream-a-short-story-95223b3db69f?source=rss-76584bd26aec------2">Continue reading on the Cafe »</a></p></div>]]></description>
            <link>https://medium.com/the-creative-cafe/the-dream-a-short-story-95223b3db69f?source=rss-76584bd26aec------2</link>
            <guid isPermaLink="false">https://medium.com/p/95223b3db69f</guid>
            <category><![CDATA[short-story]]></category>
            <category><![CDATA[fiction]]></category>
            <category><![CDATA[thriller]]></category>
            <category><![CDATA[storytelling]]></category>
            <category><![CDATA[short-fiction]]></category>
            <dc:creator><![CDATA[Mohammad Aaftab V]]></dc:creator>
            <pubDate>Sat, 11 Apr 2020 17:47:14 GMT</pubDate>
            <atom:updated>2020-05-01T20:33:52.792Z</atom:updated>
        </item>
    </channel>
</rss>