<?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 Arnav Kundu on Medium]]></title>
        <description><![CDATA[Stories by Arnav Kundu on Medium]]></description>
        <link>https://medium.com/@arnav1993k?source=rss-dc01ab0df73------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qS-8F8lgzGZxd8nHJRbUZg.jpeg</url>
            <title>Stories by Arnav Kundu on Medium</title>
            <link>https://medium.com/@arnav1993k?source=rss-dc01ab0df73------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 23:47:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arnav1993k/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[Compressing deep networks for on device computations]]></title>
            <link>https://medium.com/@arnav1993k/compressing-deep-networks-for-on-device-computations-a83e62eee9ef?source=rss-dc01ab0df73------2</link>
            <guid isPermaLink="false">https://medium.com/p/a83e62eee9ef</guid>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Arnav Kundu]]></dc:creator>
            <pubDate>Tue, 30 Oct 2018 05:19:24 GMT</pubDate>
            <atom:updated>2018-10-30T05:59:41.388Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deep neural networks for on device computations</h3><p>The field of deep learning has prospered significantly in last couple of years and there has been significant improvement in the performance of various deep learning models for tasks like image classification, speech recognition, machine translation etc. But these deep networks are often poor at their computation complexity and memory consumption.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*TAOOklL3PeY0CnjcoXJ3Uw.jpeg" /><figcaption>Model to Phone</figcaption></figure><p>For a deep learning model(ResNet-50) used for image classification to run on device the main constraints are:-</p><ol><li>Memory — Limited SRAM space</li><li>Compute capability — Lower clock speeds on mobile processors</li><li>Power consumption — 1 DRAM read takes around 6400 times more power than a 32-bit addition.</li></ol><p>An obvious answer for reducing both space and time complexity of the network is to have a smaller network and quantize the weights to lower number of bits. But this might lead to loss in accuracy.</p><p>So how do we actually use deep networks for inference on device without loosing out on accuracy?</p><p><strong>Deep Compression</strong></p><p>→ Network pruning — Prune the weights that are nearly equal to zero</p><p>→ Weight sharing — Lesser number of bits per weight in a smarter way</p><p>→ Huffman coding — Keep more frequent weights at low resolution</p><ol><li><strong>Network pruning</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*iAAo2EJRlsWMbANNCogp7A.jpeg" /><figcaption>Pruning of weights</figcaption></figure><p>The idea is very simple. Remove all such connections from the network graph which have connection weights below a threshold first. Then remove all those nodes from the graph that have lower values after activation.</p><p>Ideally for convolutional layers this leads to a reduction in number of parameters by 3 times and for dense layers by 10 times. After this step the network is retrained for a few iterations to achieve the baseline accuracy.</p><p>Ideally, for convolutional layers, filters are pruned and this affects the current layer and the layer next since the dimension of propagation will be reduced. If the last layer of convolution is pruned the size of the dense layer following this layer needs to be adjusted accordingly.</p><p>The weights are affected in the following manner after pruning and retraining.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*epnb3SpGvwMDzThO1Dl4iw.png" /></figure><p><strong>2. Weight sharing and approximation</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*jIDcsCpq4sxM3cclL7YvZw.jpeg" /><figcaption>Image Courtesy: Deep Compression: Compressing Deep Neural Networks with Pruning, Trained Quantization and Huffman Coding</figcaption></figure><p>Weight sharing is the principle of quantizing and sharing similar weights in a network to reduce the memory footprint. A blatant quantization might lead to loss of accuracy to a greater scale therefore a smarter approach is adapted for quantization described below.</p><p>Step 1: Run k-means clustering on weights to cluster them into fixed brackets and assign centroids to each of them. Therefore each weight is replaced by the value of its centroid.</p><p>Step 2: Generate a codebook to store these centroids and their mapping into the network graph.</p><p>Step 3: Quantize the network using this codebook. This reduces the overall memory consumed by the network because a lot of redundant information is removed.</p><p>Step 4: Retrain the codebook using gradient descent on gradients quantized using a similar approach.</p><p>This process helps to not only reduce a lot of redundant information from the network but also maintain comparable accuracy and it has been found that most of the convolutional weights can be stored in 6 bit channels and those of the dense layers in 2 bit channels without compromising a lot on the accuracy.</p><p>Note: Quantization should be followed by pruning because the k-means step in quantization is expensive and pruning helps to reduce the dimension of the feature space. Also quantization on pruned features is often redundant because it is believed that they belong to the same cluster and have no effect on the final model.</p><p><strong>3. Huffman coding</strong></p><p>This is a lossless compression mechanism that uses variable length codes to encode variables based on their probability of occurrence. The weights which are accessed more often have a lower bit representation than the ones which occur more often.</p><p><strong>Modified Convolutions</strong></p><p>In CNNs one of the most expensive steps is computing matrix multiplications over the entire input steps by step for <strong><em>k</em></strong><em> </em>separate kernels. Let us assume an <strong>m<em>× m× c</em></strong><em> </em>convolutional filter over an input image of <strong><em>n× n× c</em></strong> dimensions. In this case number of computations are of the order of <strong><em>k× m² × n² × c</em></strong><em>.</em></p><p>The number of computations at each convolutional layer can be reduced significantly by depthwise and pointwise convolutions.</p><p><strong><em>Depth-wise convolutions —</em></strong> In this step convolution is applied to single channel at a time instead of all channels. Therefore, instead of using a <strong><em>m× m× c</em></strong><em> </em>convolutional filter <strong><em>c m× m </em></strong>filters are used. The resulting number of computations are <strong><em>c × m² × n²</em></strong> .</p><p><strong><em>Point-wise convolutions — </em></strong>In this step a <strong><em>1× 1 </em></strong>convolution is applied on <strong><em>c</em></strong> channels in <strong><em>k</em> </strong>different kernels. Therefore, number of computations in this step is of the order <strong><em>c × n² × k. </em></strong>Therefore total number of computations till this step is given as</p><blockquote><strong>c× n²× (m²+k)</strong></blockquote><p>This helps to reduce the number of computations significantly by order of <strong><em>k</em>.</strong></p><p><strong>Additional benefits</strong></p><p>Since there are lesser number of parameters it reduces overfitting to an extent.</p><p>References:-</p><p><a href="https://arxiv.org/pdf/1510.00149.pdf">https://arxiv.org/pdf/1510.00149.pdf</a></p><p><a href="https://arxiv.org/pdf/1610.02357.pdf">https://arxiv.org/pdf/1610.02357.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a83e62eee9ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>