<?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 Dmytro Filatov on Medium]]></title>
        <description><![CDATA[Stories by Dmytro Filatov on Medium]]></description>
        <link>https://medium.com/@dim25?source=rss-b630c306e640------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*K5XiXhniI8xehMx9Pcy_3Q.jpeg</url>
            <title>Stories by Dmytro Filatov on Medium</title>
            <link>https://medium.com/@dim25?source=rss-b630c306e640------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 18:17:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dim25/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[Computer vision and machine learning classification inTensorFlow.]]></title>
            <link>https://medium.com/@dim25/computer-vision-and-machine-learning-classification-intensorflow-7543b5f06b15?source=rss-b630c306e640------2</link>
            <guid isPermaLink="false">https://medium.com/p/7543b5f06b15</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Dmytro Filatov]]></dc:creator>
            <pubDate>Mon, 27 Nov 2017 09:49:35 GMT</pubDate>
            <atom:updated>2017-11-27T09:49:35.193Z</atom:updated>
            <content:encoded><![CDATA[<h3>Computer vision and machine learning classification inTensorFlow. CIFAR-10 sample execution process.</h3><p>Crosspost from: <a href="http://www.aimechanic.com/2016/10/17/d246-tensorflow-cifar-10-tutorial-detailed-review-part-2/">http://www.aimechanic.com/2016/10/17/d246-tensorflow-cifar-10-tutorial-detailed-review-part-2/</a></p><p>Convolutional Neural Networks, review of TensorFlow CIFAR-10 classification in machine learning and computer vision: <a href="https://medium.com/@dim25/convolutional-neural-networks-review-of-tensorflow-cifar-10-classification-in-machine-learning-and-c7e636f12d58">https://medium.com/@dim25/convolutional-neural-networks-review-of-tensorflow-cifar-10-classification-in-machine-learning-and-c7e636f12d58</a></p><h3>Execution process of ‘python cifar10_train.py’</h3><ol><li>Initialising flags and constants from cifar10.py and cifar10_input.py:</li></ol><ul><li>data_dir</li><li>batch_size</li><li>use_fp16</li><li>IMAGE_SIZE</li><li>NUM_CLASSES</li><li>NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN</li><li>NUM_EXAMPLES_PER_EPOCH_FOR_EVAL</li><li>MOVING_AVERAGE_DECAY</li><li>NUM_EPOCHS_PER_DECAY</li><li>LEARNING_RATE_DECAY_FACTOR</li><li>INITIAL_LEARNING_RATE</li><li>Detailed description of all flags and constants: <a href="http://www.aimechanic.com/2016/10/13/d242-tensorflow-cifar-10-tutorial-detailed-step-by-step-review-part-1/">CIFAR-10 TensorFlow tutorial review, part 1</a></li></ul><ol><li>Downloading and unpacking a ‘<strong><em>cifar-10-binary.tar.gz</em></strong>‘ dataset.</li><li>Calling the ‘<strong><em>cifar10_train.py</em></strong>‘ with default parameters.</li><li>Setting up the required variables.</li><li>Calling ‘<strong><em>distorted_inputs()</em></strong>‘ from ‘<strong><em>cifar10_input.py</em></strong><em>‘</em></li></ol><ul><li>Preparing images and labels from the downloaded dataset .</li><li>Filling the queue with 20’000 CIFAR images.</li><li>Generating images and labels batch (shape: 128, 24, 24, 3; dtype:float32)</li></ul><ol><li>Calling ‘<strong><em>distorted_inputs()</em></strong>‘ from ‘<strong><em>cifar10.py</em></strong><em>‘</em> to construct distorted input for CIFAR training.</li><li>Returns images to ‘<strong>cifar10_train.py/train()’</strong></li><li>Building CIFAR-10 model ‘<strong>inference(images)</strong>‘ in ‘<strong>cifar10.py</strong>‘ with following layers:</li></ol><ul><li>conv1</li><li>pool1</li><li>norm1</li><li>conv2</li><li>norm2</li><li>pool2</li><li>local3</li><li>local4</li><li>softmax</li></ul><ol><li>Defines ‘<strong>weight_decay</strong>‘ for each layer (tf.Variable).</li><li>Assigns the ‘<strong>loss_summaries</strong>‘ for each layer.</li><li>Builds and applies the gradients.</li><li>Builds histograms of weights and biases for each layer.</li><li>Creating a saver function, to be able to recover from checkpoints later.</li><li>Builds the summary operation.</li><li>Creates and starts the ‘<strong>tf.Session’</strong>.</li><li>Starting the queue runners, begins the training loop.</li></ol><h3>Prediction (CIFAR-10 TensorFlow evaluation example outputs labels and probabilities)</h3><p>Labels and probabilities output for single image of CIFAR-10 TensorFlow tutorial:</p><pre>from PIL import Image</pre><p>We will use the Python Imaging Library (PIL) to process images into JPEG files supported by out mode without additional losses.</p><pre>width = 24<br>height = 24</pre><pre>categories = [ &quot;airplane&quot;,&quot;automobile&quot;,&quot;bird&quot;,&quot;cat&quot;,&quot;deer&quot;,&quot;dog&quot;,&quot;frog&quot;,&quot;horse&quot;,&quot;ship&quot;,&quot;truck&quot; ]</pre><pre>filename = &quot;/tmp/images/dog1.png&quot; # absolute path to input image</pre><pre>im = Image.open(filename)<br>im.save(filename, format=&#39;JPEG&#39;, subsampling=0, quality=100)</pre><p>Converting the file from input format to JPEG with 100% quality and without subsampling.</p><pre>input_img = tf.image.decode_jpeg(tf.read_file(filename), channels=3)<br>tf_cast = tf.cast(input_img, tf.float32)</pre><p>Decoding image into 3 channels (red, green, blue) float32 array.</p><pre>float_image = tf.image.resize_image_with_crop_or_pad(tf_cast, height, width)</pre><p>Reshaping image.</p><pre>images = tf.expand_dims(float_image, 0)</pre><p>Creating a batch of images with just one image.</p><pre>logits = cifar10.inference(images)</pre><p>Get logits from main model (cifar10.py).</p><pre>_, top_k_pred = tf.nn.top_k(logits, k=5)</pre><p>Get top 5 predicions (‘top_k_pred’) and their values (‘_’).</p><pre>init_op = tf.initialize_all_variables()</pre><p>Initialising variables.</p><pre>with tf.Session() as sess:<br>  sess.run(init_op)<br>  _, top_indices = sess.run([_, top_k_pred])<br>  for key, value in enumerate(top_indices[0]):<br>    print (categories[value] + &quot;, &quot; + str(_[0][key]))</pre><p>Runing <strong>tf.Session() </strong>and processing the output.</p><p><strong>Example of input:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/32/0*nRAbXv95dvmu80N2." /><figcaption>sample image, commercial truck</figcaption></figure><p><strong>Example of output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/244/0*XafuWXaIjukZQft6." /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7543b5f06b15" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Convolutional Neural Networks, review of TensorFlow CIFAR-10 classification in machine learning and…]]></title>
            <link>https://medium.com/@dim25/convolutional-neural-networks-review-of-tensorflow-cifar-10-classification-in-machine-learning-and-c7e636f12d58?source=rss-b630c306e640------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7e636f12d58</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Dmytro Filatov]]></dc:creator>
            <pubDate>Mon, 27 Nov 2017 06:50:28 GMT</pubDate>
            <atom:updated>2017-11-27T06:52:08.106Z</atom:updated>
            <content:encoded><![CDATA[<h3>Convolutional Neural Networks, review of TensorFlow CIFAR-10 classification in machine learning and computer vision</h3><p>Detailed overview of CIFAR-10 classification machine learning and computer vision problem solution in TensorFlow.</p><p>Previously posted at: <a href="http://www.aimechanic.com/2016/10/13/d242-tensorflow-cifar-10-tutorial-detailed-step-by-step-review-part-1/">http://www.aimechanic.com/2016/10/13/d242-tensorflow-cifar-10-tutorial-detailed-step-by-step-review-part-1/</a></p><h3>Intro</h3><p><strong>What is cifar-10 computer vision problem?</strong><br> “<a href="http://www.cs.toronto.edu/~kriz/cifar.html">CIFAR-10 </a>is an established computer-vision dataset used for object recognition. It is a subset of the <a href="http://groups.csail.mit.edu/vision/TinyImages/">80 million tiny images dataset</a> and consists of 60,000 32x32 color images containing one of 10 object classes, with 6000 images per class. It was collected by Alex Krizhevsky, Vinod Nair, and Geoffrey Hinton.” <a href="https://www.kaggle.com/c/cifar-10">https://www.kaggle.com/c/cifar-10</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/0*8xIb_9YyaEwXtjH6." /><figcaption>CIFAR-10 data sample</figcaption></figure><p>“CIFAR-10 classification is a common benchmark problem in machine learning. The problem is to classify RGB 32×32 pixel images across 10 categories: airplane, automobile, bird, cat, deer, dog, frog, horse, ship, and truck.” <a href="https://www.tensorflow.org/versions/r0.10/tutorials/deep_cnn/index.html">https://www.tensorflow.org/versions/r0.10/tutorials/deep_cnn/index.html</a></p><p>“The classes are completely mutually exclusive. There is no overlap between automobiles and trucks. “Automobile” includes sedans, SUVs, things of that sort. “Truck” includes only big trucks. Neither includes pickup trucks.” <a href="http://www.cs.toronto.edu/~kriz/cifar.html">http://www.cs.toronto.edu/~kriz/cifar.html</a></p><p><strong>Cifar-10 dataset download links</strong><br> Original: <a href="http://www.cs.toronto.edu/~kriz/cifar.html">http://www.cs.toronto.edu/~kriz/cifar.html</a><br> Hosted by Kaggle: <a href="https://www.kaggle.com/c/cifar-10/data">https://www.kaggle.com/c/cifar-10/data</a></p><h3>Goal of TensorFlow CIFAR-10 tutorial:</h3><p><strong>Learn TensorFlow and “Building a small convolutional neural network (CNN) for image recognition”</strong></p><p><strong>What is Convolutional neural network (CNN)?</strong>: Convolutional neural network (convnets) are neural networks that share their parameters across space. Detailed explanation of Convolutional networks:</p><p><strong>How convolutional neural network works? </strong><a href="https://www.youtube.com/watch?v=SQ67NBCLV98">https://www.youtube.com/watch?v=SQ67NBCLV98</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FSQ67NBCLV98%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DSQ67NBCLV98&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FSQ67NBCLV98%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1af317eed62b90637681bdc03d356f9/href">https://medium.com/media/f1af317eed62b90637681bdc03d356f9/href</a></iframe><p><strong>Kashif Rasul — Intro to convolutional neural network</strong>: <a href="https://www.youtube.com/watch?v=W9_SNGymRwo">https://www.youtube.com/watch?v=W9_SNGymRwo</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FW9_SNGymRwo%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DW9_SNGymRwo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FW9_SNGymRwo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c17e2a6638c817c514475049278b8776/href">https://medium.com/media/c17e2a6638c817c514475049278b8776/href</a></iframe><p>Learn about <strong>image recognition</strong>: <a href="https://www.quora.com/Computer-Vision-What-are-the-best-resources-for-learning-about-image-recognition">https://www.quora.com/Computer-Vision-What-are-the-best-resources-for-learning-about-image-recognition</a> | Deep learning and recent progress in image recognition: <a href="http://neuralnetworksanddeeplearning.com/chap6.html#recent_progress_in_image_recognition">http://neuralnetworksanddeeplearning.com/chap6.html#recent_progress_in_image_recognition</a></p><h3>Methods used in this tutorial</h3><p><strong>Rectified linear activations (ReLU)</strong> — activation function defined by</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/140/0*kBWr5o-PgZ6dPO68." /></figure><p>, it returns 0 for all values below 0 and value itself for anything &gt; 0. It’s much simpler in computation. Read more on “<a href="https://www.quora.com/What-are-the-benefits-of-using-rectified-linear-units-vs-the-typical-sigmoid-activation-function">ReLU vs Sigmoind</a>“.</p><p><strong>Max pooling </strong>— pools the biggest value from the sample.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*WIIogpDBWLx5zdnd." /></figure><p>(<a href="https://en.wikipedia.org/wiki/Convolutional_neural_network#Pooling_layer">https://en.wikipedia.org/wiki/Convolutional_neural_network#Pooling_layer</a>)</p><p><strong>Local response normalization</strong> — permits the detection of high-frequency features with a big neuron response, while damping responses that are uniformly large in a local sample. Original description could be found in chapter “3.3 Local Response Normalization” here: <a href="http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf">http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf</a>). Additional reading: “<a href="http://stats.stackexchange.com/questions/145768/importance-of-local-response-normalization-in-cnn">Importance of local response normalization in CNN</a>” | “<a href="https://prateekvjoshi.com/2016/04/05/what-is-local-response-normalization-in-convolutional-neural-networks/">What Is Local Response Normalization In Convolutional Neural Networks</a>”</p><p>“<em>These layers have recently fallen out of favor because in practice their contribution has been shown to be minimal</em>” (Stanford CS class: <a href="http://cs231n.github.io/convolutional-networks/">CS231n Convolutional Neural Networks for Visual Recognition</a>)</p><p><strong>Learning rate schedule</strong> — applies exponential decay to the learning rate. Computed as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/0*3_NYJ0hIvOOJurtG." /></figure><p>(<a href="https://www.tensorflow.org/versions/r0.11/api_docs/python/train.html#exponential_decay">https://www.tensorflow.org/versions/r0.11/api_docs/python/train.html#exponential_decay</a>)</p><p><strong>Threading and Queues </strong>— mechanism for asynchronous computation. <a href="https://www.tensorflow.org/versions/r0.11/how_tos/threading_and_queues/index.html">Threading and Queues in TensorFlow</a>.</p><p><strong>Softmax classifier — </strong>provides “probabilities” for each class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/0*VhkusRGuk0vLYbCq." /></figure><p>Detailed Lecture by Geoffrey Hinton: <a href="https://www.youtube.com/watch?v=mlaLLQofmR8">https://www.youtube.com/watch?v=mlaLLQofmR8</a></p><p>Learn more on softmax: <a href="http://cs231n.github.io/linear-classify/#softmax">http://cs231n.github.io/linear-classify/#softmax</a> | Full playlist: <a href="https://www.youtube.com/watch?v=mlaLLQofmR8&amp;list=PLoRl3Ht4JOcdU872GhiYWf6jwrk_SNhz9&amp;index=18">https://www.youtube.com/watch?v=mlaLLQofmR8&amp;list=PLoRl3Ht4JOcdU872GhiYWf6jwrk_SNhz9&amp;index=18</a> | <a href="http://cs231n.github.io/linear-classify/#svmvssoftmax">SVM vs SoftMax</a> (CS231n)</p><h3>Files in this tutorial</h3><ul><li>cifar10_input.py — processes the CIFAR-10 binary file format</li><li>cifar10.py — builds the TensorFlow CIFAR-10 model</li><li>cifar10_train.py — trains a TensorFlow CIFAR-10 model</li><li>cifar10_eval.py — evaluates the performance of model</li></ul><h3>cifar10_input.py — processing the binary CIFAR-10</h3><p><strong>Methods:</strong></p><p><strong>read_cifar10(filename_queue)</strong> — reads and parse examples from data files (from ‘filename_queue’), returns object representing the single example (fields: height, width, depth, key, label, uint8image)</p><p><strong>_generate_image_and_label_batch(image, label, min_queue_examples, batch_size, shuffle)</strong> — constructs shuffled (if shuffle == true) queue of images with labels, returns images (4D tensor: batch_size, height, width, depth), and labels (1d tensor: batch_size).</p><p><strong>distorted_inputs(data_dir, batch_size)</strong> — construct distorted input, returns distorted images and labels. Distortions applied to the image: crop; flip the image horizontally; brightness change, contrast change.</p><p><strong>inputs(eval_data, data_dir, batch_size)</strong> — construct input for CIFAR evaluation.</p><p><strong>libraries used:</strong><br> <strong>numpy</strong> — scientific computing with Python<br> <strong>six.moves</strong> — support codebases towork on Python 2 and Python 3<br> “from tensorflow.models.image.cifar10 import cifar10” shall be replaced with “import cifar10” if you want to modify the code.</p><h3>cifar10.py — builds the model</h3><p>“from tensorflow.models.image.cifar10 import cifar10_input” shall be replaced with “import cifar10_input“:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/0*2Esbk-ds7RpPuraO." /></figure><p><strong>Default flags:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/196/0*Ng-Zat4MCxE93Vyl." /></figure><ul><li>data_dir (path to the CIFAR-10 data directory): ‘/tmp/cifar10_data’</li><li>batch_size (number of images to process in a batch): 128</li><li>use_fp16 (train the model using fp16): False</li></ul><p>defined here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/0*5HfRi4p2EHY_vRQj." /></figure><p><strong>Global constants describing the CIFAR-10 dataset:</strong></p><pre>IMAGE_SIZE: 24 | &lt;type &#39;int&#39;&gt;<br>NUM_CLASSES: 10 | &lt;type &#39;int&#39;&gt;<br>NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN: 50000 | &lt;type &#39;int&#39;&gt;<br>NUM_EXAMPLES_PER_EPOCH_FOR_EVAL: 10000 | &lt;type &#39;int&#39;&gt;</pre><p>defined here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/0*cgLnQEpvQ2vqZvNi." /></figure><p>and in cifar10_input.py:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/0*WAB-1isWcDYsVnjm." /></figure><p><strong>Constants describing the training process:</strong></p><pre>MOVING_AVERAGE_DECAY: 0.9999 | &lt;type &#39;float&#39;&gt;<br>NUM_EPOCHS_PER_DECAY: 350.0 | &lt;type &#39;float&#39;&gt;<br>LEARNING_RATE_DECAY_FACTOR: 0.1 | &lt;type &#39;float&#39;&gt;<br>INITIAL_LEARNING_RATE: 0.1 | &lt;type &#39;float&#39;&gt;</pre><p>defined here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/0*G-rmq9PgMHd-Ihr0." /></figure><pre>TOWER_NAME = &#39;tower&#39;<br>DATA_URL = &#39;<a href="http://www.cs.toronto.edu/~kriz/cifar-10-binary.tar.gz">http://www.cs.toronto.edu/~kriz/cifar-10-binary.tar.gz</a>&#39;</pre><p><strong>Methods:</strong></p><p><strong>_activation_summary(x)</strong> — helper creates summaries for activations of tensor ‘<em>x’</em>, provides a histogram and measures the sparsity of activations.</p><p><strong>_variable_on_cpu(name, shape, initializer)</strong> — helper creates and returns a Variable stored on CPU memory with following params: <strong>name</strong> (name of the variable), <strong>shape </strong>(list of integers), and <strong>initializer</strong> (initializer for Variable). dtape (DataType) is set to float32 if use_fp16==False.</p><p><strong>_variable_with_weight_decay(name, shape, stddev, wd)</strong> — helper creates and returns an initialized Variable with weight decay with following params: <strong>name</strong> (name of the variable), <strong>shape </strong>(list of integers), <strong>stddev</strong> (standard deviation of a truncated Gaussian), and <strong>wd</strong> (L2Loss weight decay will be multiplied by this float, if == None, no weight decay). dtape (DataType) is set to float32 if use_fp16==False. Reference material: <a href="https://en.wikipedia.org/wiki/Truncated_normal_distribution">Truncated normal distribution</a> (wiki).</p><p><strong>distorted_inputs()</strong> — construct distorted input for CIFAR training, returns distorted images and labels. See ‘<em>cifar10_input.py/distorted_inputs</em>‘ for details. Returns images (4D tensor: batch_size, height, width, depth), and labels (1d tensor: batch_size).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/0*_O8HvAfmVMi9a-71." /></figure><p><strong>inputs(eval_data)</strong> — constructs input for CIFAR evaluation with ‘<em>eval_data’.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/0*uRoHqf8niw2YK4A5." /></figure><p><strong>inference(images)</strong> — builds the TensorFlow CIFAR-10 model with ‘<em>images</em>‘ from <em>distorted_inputs</em> or <em>inputs, </em>returns<em> softmax_linear.</em></p><p><strong>This CIFAR-10 model consist from the following layers:</strong></p><ul><li><strong>conv1</strong>–2D <a href="https://www.tensorflow.org/versions/r0.11/api_docs/python/nn.html#conv2d">convolution</a> and <a href="https://www.tensorflow.org/versions/r0.11/api_docs/python/nn.html#relu">rectified linear</a> activation (<a href="http://www.songho.ca/dsp/convolution/convolution2d_example.html">Example of 2D Convolution</a>)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/0*3jf1G5D7gjjegfwJ." /></figure><ul><li><strong>pool1</strong> — <a href="https://www.tensorflow.org/versions/r0.11/api_docs/python/nn.html#max_pool">max pooling</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/0*TlUDeX67KRc4oaew." /></figure><ul><li><strong>norm1 </strong>— <a href="https://www.tensorflow.org/versions/r0.11/api_docs/python/nn.html#local_response_normalization">Local Response Normalization</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/0*cFC-j0GMAO-FnAPc." /></figure><ul><li><strong>conv2 (same as conv1)</strong></li><li><strong>norm2 (same as norm1)</strong></li><li><strong>pool2 (same as pool1)</strong></li><li><strong>local3</strong> — <a href="https://www.tensorflow.org/versions/r0.11/api_docs/python/nn.html">fully connected layer with rectified linear activation</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/0*fuzKINPVrkU3Rp-e." /></figure><ul><li><strong>local4</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/0*Dzuo0s_TXWdyXyg8." /></figure><ul><li><strong>softmax_linear</strong> — Softmax classifier (see explanation above).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/0*D9Lk-oVennLpRY1_." /></figure><p><strong>loss(logits, labels)</strong> — Add L2Loss (summary of loss and loss/avg) to all the trainable variables, uses logits (logits from inference), and labels from ‘<em>distorted_inputs</em>‘ or ‘<em>inputs</em>‘. Read more on <a href="http://www.aimechanic.com/2016/10/12/d241-loss-function-in-machine-learning-study-material/">loss function in machine learning</a>.</p><p><strong>_add_loss_summaries(total_loss)</strong> — generates average for all losses and summaries for visualizing the performance of the network. Called from ‘<em>train’:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/0*zWn8OANtRwWOZFBt." /></figure><p><strong>train(total_loss, global_step)</strong> — trains TensorFlow CIFAR-10 model: creates an optimizer and applies to all trainable variables, adds moving averages for all trainable variables, uses ‘total_loss’ (‘<em>loss’</em>) and ‘<em>global_step’ (</em>Integer, the number of training steps processed). Decays the learning rate (‘<em>LEARNING_RATE_DECAY_FACTOR</em>‘).Generates moving averages of all losses (‘<em>total_loss</em>‘). Computes and applies gradients (‘tf.train.GradientDescentOptimizer(lr)‘ and ‘tf.train.GradientDescentOptimizer(lr).apply_gradients(tf.train.GradientDescentOptimizer(lr).compute_gradients(total_loss), global_step=global_step)‘). Creates histograms for trainable variables and gradients. Tracks the moving averages of variables.</p><p><strong>maybe_download_and_extract()</strong> — downloads and extracts the tarball from ‘<a href="http://www.cs.toronto.edu/~kriz/cifar-10-binary.tar.gz"><em>http://www.cs.toronto.edu/~kriz/cifar-10-binary.tar.gz</em></a>‘ to ‘<em>FLAGS.data_dir</em>‘ (by default ‘<em>/tmp/cifar10_data</em>‘).</p><h3>cifar10_train.py — Training the TensorFlow CIFAR-10 model</h3><p>Uses “six.moves” and “tensorflow” libraries.</p><p>“<em>from tensorflow.models.image.cifar10 import cifar10</em>” shall be replaced with “<em>import cifar10</em>” if you want to make changes in the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/0*RioBxlFrgoq9Gydp." /></figure><p><strong>Cifar-10 training — default flags:</strong></p><ul><li><strong>train_dir</strong> (directory where to write event logs and checkpoint): ‘<strong>/tmp/cifar10_train</strong>‘</li><li><strong>max_steps</strong> (number of batches to run): <strong>1’000’000</strong></li><li><strong>log_device_placement</strong> (whether to log device placement): <strong>False</strong> (‘<strong>log_device_placement</strong>‘ set to ‘<strong>True’</strong> helps to find out which devices your operations and tensors are assigned to, used in Multi GPU Computations in TensorFlow).</li></ul><p><strong>main(argv=None)</strong> — checks if ‘FLAGS.train_dir’ directory exists, if not, creates the directory and downloads the dataset, otherwise runs the <strong>train().</strong></p><p><strong>train()</strong> — the main function of Cifar-10 training, trains for a number of steps specified in ‘<em>FLAGS.max_steps</em>‘ (Default value: 1’000’000).</p><ul><li>Gets dataset (</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/0*wiozyjom_OU8eSu-." /></figure><ul><li>).</li><li>Builds a Graph that computes the logits predictions from the inference model ‘<em>cifar10.inference(images)</em>‘.</li><li>Calculates ‘<em>loss</em>‘ (cifar10.loss(logits, labels)). Defines train_op (<strong>train_op = cifar10.train(loss, global_step)</strong>).</li><li>Creates saver (<strong>tf.train.Saver</strong>) which saves and restores (if required) all variables:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/0*xsSUfm8_o7Ifh30p." /></figure><ul><li>Builds a summary operation based on TensorFlow collection of Summaries (‘<em>summary_op’</em>).</li><li>Builds an initialization operation init:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/0*kLs6Rk77O_keNNuZ." /></figure><ul><li>Creates and runs a ‘<a href="https://www.tensorflow.org/versions/r0.11/api_docs/python/client.html#Session"><em>tf.Session</em></a>‘ (<em>sess.run</em>), with ‘<em>init</em>‘ and ‘<em>config=tf.ConfigProto(log_device_placement=FLAGS.log_device_placement)</em>‘.</li><li>Starts threads for all queue runners collected in the graph and returns the list of all threads.</li><li>Writes the summary protocol buffers with ‘<em>tf.train.SummaryWriter</em>‘ to event files.</li><li>Runs the ‘<em>tf.Session</em>‘ with ‘train_op‘ and ‘loss‘ functions:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/192/0*4VwNh6DuFJc9BejL." /></figure><ul><li>in the loop until ‘FLAGS.max_steps’ (1’000’000 steps) will be reached.</li><li>Periodically reports (every 10th step) and saves (every 1000th step) the model checkpoints.</li></ul><h3>cifar10_eval.py — evaluating the performance of TensorFlow CIFAR-10 model</h3><p><strong>Cifar-10 evaluation — default flags:</strong></p><ul><li><strong>eval_dir</strong> (directory where to write event logs and checkpoint): ‘<strong>/tmp/cifar10_eval</strong>‘</li><li><strong>eval_data</strong> (either ‘test’ or ‘train_eval’): ‘<strong>test’</strong></li><li><strong>checkpoint_dir</strong> (where to read model checkpoints): ‘<strong>/tmp/cifar10_train</strong>‘</li><li><strong>eval_interval_secs</strong> (how often to run the evaluation) — every 5 minutes <strong>(60*5)</strong></li><li><strong>num_examples</strong> (number of examples to evaluate) — <strong>10’000</strong></li><li><strong>run_once</strong> (if True will run the evaluation only once) — <strong>False</strong></li></ul><p><strong>main(argv=None)</strong> — checks if ‘FLAGS.eval_dir’ directory exists, if required creates the directory and runs the <strong>evaluate().</strong></p><p><strong>eval_once(saver, summary_writer, top_k_op, summary_op) </strong>— runs one evaluation:</p><ul><li>Checks if any checkpoints are recorded in <strong>FLAGS.checkpoint_dir</strong><em> (‘/tmp/cifar10_train’). </em>If none found, returns ‘<em>No checkpoint file found</em>‘. If you are getting this error make sure that you run the ‘cifar10_train.py’ for at least 1’000 steps.</li><li>Starts the queue runners (Read more: <a href="https://www.tensorflow.org/versions/r0.11/api_docs/python/train.html#coordinator-and-queuerunner">TensorFlow Coordinator and QueueRunner</a>) which counts the number of correct predictions and computes the precision.</li></ul><p><strong>evaluate() </strong>— evaluate TensorFlow CIFAR-10 model for a number of steps.</p><ul><li>Gets labels and images</li><li>Builds a Graph that computes the logits predictions from the inference model</li><li>Calculates predictions</li><li>Restores the moving average version of the learned variables for evaluation</li><li>Builds the summary operation based on the TF collection of Summaries</li></ul><p><strong>Additional reading:</strong></p><ul><li><a href="http://stackoverflow.com/questions/37578876/how-to-feed-cifar10-trained-model-with-my-own-image-and-get-label-as-output">How to feed TensorFlow Cifar10 trained model with my own image and get label as output?</a></li><li><a href="http://www.aimechanic.com/2016/09/22/d221-svhn-tensorflow-deep-learning/">SVHN TensorFlow example</a></li><li><a href="http://stackoverflow.com/questions/35032675/how-to-create-dataset-similar-to-cifar-10">How to create dataset similar to cifar-10</a></li><li><a href="http://stackoverflow.com/questions/36495253/tensorflow-cifar-10-evaluation-example-softmax-outputs">tensorflow cifar-10 evaluation example softmax outputs</a></li></ul><p><a href="http://www.aimechanic.com/2016/10/17/d246-tensorflow-cifar-10-tutorial-detailed-review-part-2/?relatedposts_hit=1&amp;relatedposts_origin=2163&amp;relatedposts_position=0">d246: TensorFlow CIFAR-10 tutorial, detailed step-by-step review, Part 2</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7e636f12d58" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>