<?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 Rajit Nikhare on Medium]]></title>
        <description><![CDATA[Stories by Rajit Nikhare on Medium]]></description>
        <link>https://medium.com/@rajitnikhare?source=rss-b56661862459------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WS4ypYyEJnnQ5ZSnLpzEBw.jpeg</url>
            <title>Stories by Rajit Nikhare on Medium</title>
            <link>https://medium.com/@rajitnikhare?source=rss-b56661862459------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 01:01:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rajitnikhare/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[Image Classification using Convolutional Neural Networks on MNIST data-set.]]></title>
            <link>https://medium.com/data-science/image-classification-using-convolutional-neural-networks-on-mnist-data-set-406db0c265ed?source=rss-b56661862459------2</link>
            <guid isPermaLink="false">https://medium.com/p/406db0c265ed</guid>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Rajit Nikhare]]></dc:creator>
            <pubDate>Sun, 17 Jun 2018 22:09:23 GMT</pubDate>
            <atom:updated>2019-02-03T21:47:20.877Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LmxW8FDfXZJl5yvESvjP7Q.jpeg" /></figure><p>This article is meant for people who are interested in Machine Learning and are looking for a less-complicated source to start from.</p><p>I am a graduate student at the University of Utah and I have developed an interest in Machine Learning (ML) and Artificial Intelligence (AI) in the short duration of my course-work. I like to study different datasets and make notes which I publish online so that others who are finding it difficult to understand deep research papers can get a more simplified and easy to understand perspective on ML and AI.</p><p>If I had to explain a 5th grader what is Machine Learning, I would say that every small step you take results in an outcome where you learn what is favorable and what is unfavorable. This is the very basic of Machine Learning. Similarly, when we train computer systems on large data-sets, we are feeding them with information on what is favorable and what is not. For example, when pictures of dogs and cats are fed to the system, the system trains itself on the information and on the basis of that information, the system is now able to recognize what is a cat and what is a dog. How a computer system can be trained to do such sorcery, we will find out in the later section of this article.</p><h3>MNIST handwritten images:</h3><p>It is a data-set, consisting images of handwritten digits from 0 to 9. Each image is a monochrome, 28 * 28 pixels. See the example below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/1*4HVsamLrsRuBrZe1gHZmVA.png" /><figcaption>Source: <a href="https://www.tensorflow.org/tutorials/layers">https://www.tensorflow.org/tutorials/layers</a></figcaption></figure><h3>Objective:</h3><p>Train a computer system to first understand what are handwritten images of digits a then test the system to predict new handwritten images correctly. We will feed our system with MNIST dataset and test it with random images to check the accuracy of its predictions.</p><h3>Pre-requisite:</h3><ol><li>Basic knowledge of python scripting, Python 3.6.</li><li>An idea of what is Machine learning and TensorFlow.</li><li>Vigor to learn something new.</li></ol><h3>How to do it:</h3><p><strong>Importing TensorFlow and the MNIST data:</strong></p><pre>import tensorflow as tf</pre><pre>from tensorflow.examples.tutorials.mnist import input_data<br>mnist = input_data.read_data_sets(&quot;MNIST_data/&quot;, one_hot=True)</pre><p><strong>Placeholders:</strong></p><p>Placeholders are different from variables. They are parameters which are created to hold the training data, in this case, it would be training images. MNIST images are in the shape of (28*28). These would be flattened into (None *784) shape tensor. ‘None’ indicates that it could be of any size.</p><pre>x = tf.placeholder(tf.float32, [None, 784])</pre><p><strong>Weights and Biases:</strong></p><p>The initial values are set to zeros for Weight and Bias because it is going to be changed when the computation happens. Thus, it does not matter what are the initial values. ‘w’ is of (784 * 10) shape because 784 features and 10 outputs are present. ‘b’ is of the shape 10 because there are 10 outputs from 0 till 9 (digits).</p><pre>w = tf.Variable(tf.zeros([784,10]))<br>b = tf.Variable(tf.zeros([10]))</pre><p><strong>Prediction Model:</strong></p><p>x and w are matrices which are multiplied and added to a bias. The softmax function takes values and makes the total to be 1. This way it can be used as probability values making it uniform to judge which digit (0 -9) has higher chances of being predicted.</p><pre>y = tf.nn.softmax(tf.matmul(x,w) + b)<br>#training our model<br>y_ = tf.placeholder(tf.float32, [None,10])</pre><p><strong>Cross-Entropy function:</strong></p><p>The cross-entropy function is a cost or loss function. It compares the true values to the predicted values. The goal is to minimize the loss.</p><pre>cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))</pre><p><strong>Gradient Descent Optimizer:</strong></p><p>When a model graph is formed using the cross-entropy function, we would want to find a point where the loss is at the minimum. This is done using the Gradient Descent optimizer. It moves towards the part of the graph where the value of the graph is lesser. The steps or the learning rate can be set manually. If a very small learning rate like 0.001 is set it would take forever for the system to reach to the point where the loss is minimum but it would be more accurate. If the learning is rate is set high then the system might produce quick but false results a false results.</p><pre>train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)</pre><p><strong>Training model:</strong></p><p>Here, we are training our model to learn the MNIST data in batches of 100.</p><pre>y_ = tf.placeholder(tf.float32, [None,10])</pre><pre>cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))</pre><pre>train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)</pre><p><strong>Evaluating and Testing the model:</strong></p><p>Here, the model is evaluated and tested with an accuracy of 0.8916. tf.argmax gives the highest value in one axis. So, y_ are the correct values and y are the predicted values. tf.equal is used to find if they are equal or not.</p><pre>prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))</pre><p><strong>Multi-Convolutional Layer:</strong></p><p>Here, we are using more layers, weights, and biases to refine our model and increase accuracy.</p><p>Our first convolutional layer has 32 features for each 5*5 patch. Its weight tensor will be of a shape of [5,5,1,32]. First two dimensions are the patch size, the next is the input channel and the last number is the output channel.</p><p>To apply the convolutional layer, x is reshaped to 4D tensor. 28*28 is the image width and height and the final dimension is the number of color channels.</p><p>Then ReLU function is applied to bring the negative values to 0 and keep the positive values as it is. Max pool reduces the image size to 14*14.</p><p>The second convolutional layer has 64 features for each 5*5 patch.</p><p>Now that the image size has been reduced to 7*7 we add a fully-connected layer with 1024 neurons.</p><p><strong>Dropout and Readout Layer:</strong></p><p>To reduce overfitting we would drop some data randomly. Dropout layer thus helps in improving the accuracy of predictions. The next layer is used to read the data.</p><p><strong>Final Accuracy:</strong></p><p>0.9919</p><p><strong>Complete Python Code:</strong></p><p><a href="https://github.com/rajitnikhare/MNIST/blob/master/MNIST_Softmax.py">rajitnikhare/MNIST</a></p><p><strong>References:</strong></p><ol><li><a href="https://www.tensorflow.org/versions/r1.0/get_started/mnist/pros">https://www.tensorflow.org/versions/r1.0/get_started/mnist/pros</a></li><li><a href="https://codelabs.developers.google.com/codelabs/cloud-tensorflow-mnist/#2">https://codelabs.developers.google.com/codelabs/cloud-tensorflow-mnist/#2</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=406db0c265ed" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/image-classification-using-convolutional-neural-networks-on-mnist-data-set-406db0c265ed">Image Classification using Convolutional Neural Networks on MNIST data-set.</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>