<?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 Alex Gude on Medium]]></title>
        <description><![CDATA[Stories by Alex Gude on Medium]]></description>
        <link>https://medium.com/@Alex.Gude?source=rss-a6ad23d03f88------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ujaNrV-4A1J_TIprVWttaw.jpeg</url>
            <title>Stories by Alex Gude on Medium</title>
            <link>https://medium.com/@Alex.Gude?source=rss-a6ad23d03f88------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 08:24:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Alex.Gude/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[Plotting the 2019 Tour de France]]></title>
            <link>https://medium.com/@Alex.Gude/plotting-the-2019-tour-de-france-35be0882f11b?source=rss-a6ad23d03f88------2</link>
            <guid isPermaLink="false">https://medium.com/p/35be0882f11b</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[tour-de-france]]></category>
            <category><![CDATA[matplotlib]]></category>
            <category><![CDATA[cycling]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Alex Gude]]></dc:creator>
            <pubDate>Mon, 05 Aug 2019 00:00:00 GMT</pubDate>
            <atom:updated>2019-08-06T04:28:23.587Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="A black and white photo of the competitors in the 1932 Tour de France." src="https://cdn-images-1.medium.com/max/1024/1*PqbA4SCciydtW00jGDL02g.jpeg" /></figure><p>There is no bigger event in cycling than the <a href="https://en.wikipedia.org/wiki/Tour_de_France">Tour de France</a>, a race which takes most of July as it crisscrosses France before bringing the riders to a fateful final sprint in Paris on the Champs-Élysées. I love both cycling and plots (as I <a href="https://alexgude.com/blog/hour-record-plot-improvements/">mentioned last month</a>), so once again I found a way to combine the two, by graphically exploring how the race unfolded.</p><p>The code that generated the plots can be found <a href="https://alexgude.com/files/tour-de-france//Tour%20de%20France%20Plot.ipynb">here</a> (<a href="https://github.com/agude/agude.github.io/blob/master/files/tour-de-france//Tour%20de%20France%20Plot.ipynb">rendered on Github</a>). The data <a href="https://alexgude.com/files/tour-de-france//2019-tdf-dataframe.json">is here</a>.</p><h3>The Race for Yellow</h3><p>The <a href="https://en.wikipedia.org/wiki/General_classification_in_the_Tour_de_France">yellow jersey</a> is awarded to the rider with the lowest combined time across all 21 stages of the tour. Only a few riders are really in contention for yellow; the vast majority of the others are brought along to support their team leaders. Going into the 2019 Tour, defending champion <a href="https://en.wikipedia.org/wiki/Geraint_Thomas">Geraint Thomas</a> was the favorite, but there were several strong challengers.</p><p>Below I show how the top riders did throughout the race by plotting how far behind the leader they were after each stage. Where a rider’s line is near the top they are close to taking the lead; when they drop down they are losing time.</p><figure><img alt="A line plot showing how far behind the leader each top-finishing rider was after each stage." src="https://cdn-images-1.medium.com/max/890/1*_BCpsF64CdZggnWLCxbMSg.png" /></figure><p><a href="https://en.wikipedia.org/wiki/Julian_Alaphilippe">Julian Alaphilippe</a> held the jersey for the most days, even defending it on the <a href="https://en.wikipedia.org/wiki/Individual_time_trial">individual time trial</a> against expert time trialist Thomas. But Alaphilippe is not a climber, and after a brave defense of the jersey in the Pyrenees, he lost time in the Alps to <a href="https://en.wikipedia.org/wiki/Egan_Bernal">Egan Bernal</a>, <a href="https://en.wikipedia.org/wiki/Steven_Kruijswijk">Steven Kruijswijk</a>, <a href="https://en.wikipedia.org/wiki/Emanuel_Buchmann">Emanuel Buchmann</a>, and <a href="https://en.wikipedia.org/wiki/Thibaut_Pinot">Thibaut Pinot</a>. Pinot had looked out of contention earlier, but stormed back with a massive attack on stage 15. Unfortunately, he was forced to withdraw on stage 19 due to an injury.</p><p>Alaphilippe finally fell behind during that stage as well, losing the yellow jersey to Bernal. He lost his podium spot on stage 20 when he cracked during the final part of the climb. Alaphilippe finished 5th when they rolled through the Champs-Élysées.</p><h3>The Rest of the Race</h3><p>From the above plot you might think that all the riders in the Tour finish within a few minutes of each other. But they do not. The last place rider, the <a href="https://en.wikipedia.org/wiki/Lanterne_rouge">lanterne rouge</a>, was four and a half <strong>hours</strong> behind Egan Bernal.</p><figure><img alt="A line plot showing how far behind the leader every rider was for each stage." src="https://cdn-images-1.medium.com/max/913/1*d6zMnvkUrDNcEaIz_GcNrw.png" /></figure><p>Bernal and Alaphilippe, who looked so far apart in the first plot, are now seen to be neck-and-neck. <a href="https://en.wikipedia.org/wiki/Yoann_Offredo">Yoann Offredo</a> looked like a lock to win the lanterne rogue when he fell ill on stage 8, but <a href="https://en.wikipedia.org/wiki/Sebastian_Langeveld">Sebastian Langeveld</a> took it in the penultimate stage after suffering an injury in the second week of the race.</p><p><a href="https://en.wikipedia.org/wiki/Peter_Sagan">Peter Sagan</a>, the <a href="https://en.wikipedia.org/wiki/Points_classification_in_the_Tour_de_France">green jersey</a> winner, was only interested in sprints. He took it easy on the mountain stages to conserve energy, as you can see in the steep declines on stages 14 and 15 (in the Pyrenees) and Stages 18–20 (in the Alps). Most other riders performed similarly, although some recovered time on stage 17 when the favorites let a large breakaway group escape and gain a 20 minute advantage. Sagan did not make that group, which is clear from his lack of rise on the plot.</p><p><a href="https://en.wikipedia.org/wiki/Romain_Bardet">Romain Bardet</a>, the <a href="https://en.wikipedia.org/wiki/Mountains_classification_in_the_Tour_de_France">polka dot jersey</a> winner, was fighting for the yellow jersey until stage 14 where he cracked and lost 20 minutes. This forced him to pivot to trying to win the climbing jersey, which meant he needed to be one of the first riders to reach the top of the remaining climbs. For the last few climbing stages he stayed with the favorites or attacked early, keeping his time behind pretty consistent.</p><p><em>Originally published at </em><a href="https://alexgude.com/blog/2019-tour-de-france-plot/"><em>https://alexgude.com</em></a><em> on August 5, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35be0882f11b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Improving Wikipedia’s Hour Record Plot]]></title>
            <link>https://medium.com/@Alex.Gude/improving-wikipedias-hour-record-plot-6f2f5b86b97f?source=rss-a6ad23d03f88------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f2f5b86b97f</guid>
            <category><![CDATA[wikipedia]]></category>
            <category><![CDATA[hour-record]]></category>
            <category><![CDATA[cycling]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Alex Gude]]></dc:creator>
            <pubDate>Tue, 09 Jul 2019 00:00:00 GMT</pubDate>
            <atom:updated>2019-07-11T17:23:21.442Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="A chromolithograph showing six men in colorful clothing racing bikes on a dirt track." src="https://cdn-images-1.medium.com/max/1024/1*aPCy2rjrv9jMPz97uKVtWA.jpeg" /></figure><p>The <a href="https://en.wikipedia.org/wiki/Hour_record">cycling hour record</a> is a grueling experience: the would-be record setter rides as far as they can in one hour. The record was first set in the modern era by the great <a href="https://en.wikipedia.org/wiki/Eddy_Merckx">Eddy Merckx</a>, and it has traded hands multiple times since. Wikipedia has this plot showing the progression:</p><figure><img alt="The original plot." src="https://cdn-images-1.medium.com/max/1024/0*50YBPQx3lvSe72yN.png" /></figure><p>This plot gets the message across-twice, the distance went up quickly in a short amount of time-but could be much more effective. Here are some problems:</p><ul><li>It is missing a legend and title, which are both necessary to understand it.</li><li>It has too much precision in the date labels, which are down to the day but do not align with when the records were set.</li><li>The label text is too small to read easily.</li><li>It has a lot of unused space.</li></ul><p>I love cycling, and I love plots, so I tried my hand at improving the plot.</p><h3>Improvements</h3><p>Here is my version:</p><figure><img alt="My updated plot." src="https://cdn-images-1.medium.com/max/1024/1*CdESzAFNCfV6DxHenIxTDQ.png" /></figure><p>I also made the <a href="https://alexgude.com/files/hour-record//womens_hour_records_progression.svg">same type of plot for the Women’s Hour Record progression</a>.</p><p>The code that generated the improved plots can be found <a href="https://alexgude.com/files/hour-record//Hour%20Record%20Replot.ipynb">here</a> ( <a href="https://github.com/agude/agude.github.io/blob/master/files/hour-record//Hour%20Record%20Replot.ipynb">rendered on Github</a>). The data <a href="https://alexgude.com/files/hour-record//hour_record_dataframe.json">is here</a>.</p><p>I added a title and legend. The title makes the subject clear: the progression of the men’s hour record. The legend is pretty minimal, but conveys that there are three different types of record, and they are each plotted in a different color.</p><p>The tick labels are now much larger and easier to read. I have changed the date ticks to every decade because we do not really care about an exact date, just a rough time and the ordering. I have added a light shading for each decade to make them easier to tell apart. I have also removed the x-axis label because it is clear that it shows “years”.</p><p>Using the extra white space, I have added <strong>a lot</strong> more information to the plot: I have added the name of the rider who set each record, and the distance they rode. I have also added a line indicating the status of each record at each point in time, making it easy to see where the record is at any point, and helping to highlight the instances when the record stood for a long time.</p><p>This plot took a lot of work to make-matplotlib is not the most forgiving library-but I think it was worth it. Of course, as a good <a href="https://en.wikipedia.org/wiki/Wikipedia:WikiFairy">WikiFairy</a>, I <a href="https://en.wikipedia.org/w/index.php?title=Hour_record&amp;oldid=903869466#Statistics">contributed the plots back to Wikipedia</a> so that everyone can benefit from the improvements!</p><p><em>Originally published at </em><a href="https://alexgude.com/blog/hour-record-plot-improvements/"><em>https://alexgude.com</em></a><em> on July 9, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f2f5b86b97f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Wayback Machine Archiver: Backup Pages with Python]]></title>
            <link>https://medium.com/@Alex.Gude/wayback-machine-archiver-backup-pages-with-python-ab45d1e21ba2?source=rss-a6ad23d03f88------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab45d1e21ba2</guid>
            <category><![CDATA[software]]></category>
            <category><![CDATA[backup-software]]></category>
            <category><![CDATA[wayback-machine]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[internet-archive]]></category>
            <dc:creator><![CDATA[Alex Gude]]></dc:creator>
            <pubDate>Tue, 04 Jun 2019 00:00:00 GMT</pubDate>
            <atom:updated>2019-06-30T19:06:42.385Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ais0AsO4QA-r7I3j.jpg" /></figure><p>The <a href="https://archive.org/">Internet Archive</a> runs a service called the <a href="https://archive.org/web/">Wayback Machine</a> to create a digital archive of the entire internet. It contains the <a href="https://web.archive.org/web/20130518151312/http://alexgude.com/">first snapshot of my website</a>, as well as many others. I love the ability to go back and see how my site has evolved, and know that even if I stop hosting it, the archive will live on. That’s why I want the Wayback Machine to archive every change my site goes through.</p><p>The Internet Archive makes it easy to submit a site for archival, but doing this manually is time consuming. So I built <a href="https://github.com/agude/wayback-machine-archiver"><strong>Wayback Machine Archiver</strong></a> to automate it.</p><h3>Wayback Machine Archiver</h3><p>The Archiver runs on either <a href="https://www.python.org/">Python</a> 2.7 or 3.4+. It can be installed with pip:</p><pre>pip install wayback-machine-archive</pre><p>After that, submitting pages for archival is as easy as:</p><p>archiver https://alexgude.com https://alexgude.com/blog/ # etc.</p><p>This is not much of an improvement over doing it manually, since we still have to find each URL by hand. Luckily, most sites already have a list of all their pages in a <a href="https://en.wikipedia.org/wiki/Sitemaps">sitemap.xml</a>.</p><p>For example, my sitemap is at https://alexgude.com/sitemap.xml. It is automatically generated by <a href="https://en.wikipedia.org/wiki/Jekyll_(software)">Jekyll</a> when I update my site. Archiver can read a sitemap and submit all of the pages listed in it, making submitting my blog for archiving is as easy as:</p><pre>pip install wayback-machine-archive</pre><p>Archiver has additional options like using multiple threads, logging, and archiving the sitemap as well as the pages they link to. Checkout the <a href="https://github.com/agude/wayback-machine-archiver">README</a> on the Github site, or use the --help flag.</p><h3>Scheduling Archiver</h3><p>Archiver follows the <a href="https://en.wikipedia.org/wiki/Unix_philosophy">Unix Philosophy</a> of “Make each program do one thing well”, so it leaves the scheduling to another program. I recommend . Here is how I backup my site, and a few others, each day:</p><pre># Backup three websites weekly<br>@weekly archiver --sitemaps https://alexgude.com/sitemap.xml --archive-sitemap-also --log INFO<br>@weekly archiver --sitemaps http://charles.uno/sitemap.xml --archive-sitemap-also --log INFO<br>@weekly archiver https://www.radiokeysmusic.com --sitemaps https://www.radiokeysmusic.com/sitemap.xml --archive-sitemap-also --log INFO</pre><p>If you find my Archiver useful, please consider <a href="https://archive.org/donate/"><strong>donating to the Internet Archive</strong></a>; none of this would be possible without them! Your company may even match your donation like mine does!</p><p><em>Originally published at </em><a href="https://alexgude.com/blog/wayback-machine-archiver/"><em>https://alexgude.com</em></a><em> on June 4, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab45d1e21ba2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Matching Cars with Siamese Networks]]></title>
            <link>https://medium.com/@Alex.Gude/matching-cars-with-siamese-networks-83646122ad9c?source=rss-a6ad23d03f88------2</link>
            <guid isPermaLink="false">https://medium.com/p/83646122ad9c</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Alex Gude]]></dc:creator>
            <pubDate>Wed, 09 Aug 2017 14:31:24 GMT</pubDate>
            <atom:updated>2018-01-17T18:22:01.232Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Az8gzDiHNswx2jN5cNf27w.jpeg" /></figure><p>Lab41 just finished <a href="https://github.com/Lab41/pelops">Pelops</a>, a vehicle re-identification project using data from fixed video cameras. Last time I talked about “chipping”, that is extracting an image of a vehicle from a frame of video automatically. We found that background subtraction worked OK based on the small amount of labeled data we had.</p><p>In this post I’ll go over the rest of the pipeline: <strong>feature extraction</strong> and <strong>vehicle matching</strong>.</p><h3>Feature Extraction</h3><p>Machine learning algorithms operate on a vector of numbers. An image can be thought of as a vector of numbers — three numbers to define the color of each pixel — but it turns out that taking these numbers and transforming them gives a more <a href="https://en.wikipedia.org/wiki/Visual_descriptor">useful representation</a>. This step of taking an image and creating a vector of useful numbers is called feature extraction. We performed feature extraction using several different algorithms.</p><p>Our first method of feature extraction was an old one: Histogram of Oriented Gradients or HOG. HOG was first proposed in the 80s, but has since found uses in identifying pedestrians and was used by our sister lab <a href="https://medium.com/the-downlinq">CosmiQ Works</a> to <a href="https://medium.com/the-downlinq/histogram-of-oriented-gradients-hog-heading-classification-a92d1cf5b3cc">identify boat headings</a>. HOG effectively counts the number and direction of edges it finds in an image, and as such is useful for finding specific objects. HOG lacks color information, so in addition to the output from HOG, we appended a histogram of each color channel.</p><p>Our second method of feature extraction was based on deep learning. We took <a href="https://arxiv.org/abs/1512.03385">ResNet50</a> trained on <a href="http://www.image-net.org/">ImageNet</a>, removed the fully connected layers, and treated the 2048-dimension output of the convolutional layers as our feature vector. <a href="https://cs231n.github.io/transfer-learning/">It is well known that networks trained on ImageNet, despite being exceptionally good at identifying dogs and cats, are also very good for general image problems.</a> It turns out the edges, shapes, and colors learned for dogs are also, in different configurations, useful for cars. For more details on the ResNet architecture, see my <a href="https://gab41.lab41.org/lab41-reading-group-deep-residual-learning-for-image-recognition-ffeb94745a1f">reading group blog post</a>.</p><p>Our third method of feature extraction was a <a href="https://cs231n.github.io/transfer-learning/">fine-tuned</a> ResNet50. Pretrained networks are good at general image tasks, but they can be “fine-tuned” to perform better on specific tasks. For Pelops that specific task was make, model, and color identification of cars in a labeled dataset. It is hoped that making the model better at make, model, and color detection will generate features that are more useful for matching cars. This makes intuitive sense: any human matching cars would use make, model, and color as primary features.</p><h3>Matching</h3><p>Once all of the vehicles have feature vectors associated with them, those vectors can be used to match vehicles to each other. There are a few ways to do this, starting with the simplest, which is to calculate a distance between the vectors. This works great if the feature extractors are designed to make the distance meaningful, but this is not generally the case. Neural networks can have cost functions based on distance, but ResNet50 does not. So this method, while attractive in simplicity, is not a good solution.</p><p>The second possible way of matching is to train a traditional (that is, non-deep learning based) classifier. We trained a logistic regression model, a random forest, and a support vector machine on top of each of the types of feature vectors. Each model was given two feature vectors and asked to classify them as coming from the same vehicle, or not. The training data was balanced so that there were as many positive as negative examples. The best accuracy these models achieved was 80%, although most struggled to pass 70%. Accuracy is the number of true results divided by the number of total items tested.</p><p>The third method of matching was to use a neural network as a classifier. Once we added a deep learning classifier on top of our deep learning feature extractor, we had a <a href="http://papers.nips.cc/paper/769-signature-verification-using-a-siamese-time-delay-neural-network.pdf">Siamese neural network</a>. For details about how we trained such a network, and for an overview of its architecture, see <a href="https://gab41.lab41.org/tl-dr-turn-static-portions-of-your-network-into-a-lookup-table-numerically-rank-your-architectures-46cc7750cad6">our blog post here</a>. The Siamese network performs the feature extraction and matching in one step, and so allows optimizing both portions at the same time. This arrangement achieved the best results by far, hitting nearly 93% accuracy on our test set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1kNAXq4oQrvBWa9XDimdiw.png" /><figcaption>A cartoon of our Siamese network architecture. The two convolutional blocks (CNN) output vectors which are joined together and then passed through a set of fully connected (FC) layers for classification.</figcaption></figure><h3>Results</h3><h4>Dataset</h4><p>In order to determine how well our various feature extraction and matching algorithms did, we needed a labeled dataset. We used the <a href="http://ieeexplore.ieee.org/document/7553002/">VeRi dataset</a>, which contains pictures of 776 uniquely identified vehicles. There are multiple pictures of each vehicle taken from 20 different traffic cameras in China. An example of two VeRi images is show below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/152/1*nEYWKtFwWkgUDq0h7RqB8w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*UVE84RHoASpZb41Aw5jaLg.jpeg" /><figcaption>Two example images from VeRi showing the same truck passing two different cameras. From Liu X., Liu W., Mei T., Ma H. A Deep Learning-Based Approach to Progressive Vehicle Re-identification for Urban Surveillance. In: European Conference on Computer Vision. Springer International Publishing, 2016: 869–884.</figcaption></figure><p>This dataset allowed us to test our performance on essentially the exact task we were hoping to solve: re-identifying the same vehicle if it passed another camera.</p><h4>Metric</h4><p>The final metric we used is a cumulative matching curve (CMC). A CMC is constructed as follows: 10 vehicles are selected in one set, and 10 in another. These two sets have one car in common that is the correct match. The algorithms then rank all 100 pairwise comparisons by confidence that they are the same vehicles. The rank of the correct pair on this list of 100 pairs is recorded. This trial is repeated for many randomly selected sets. The curve is generated by recording what fraction of trials have the correct pair ranked at a certain position or better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*au_jmSpPeNP2Ta-fut50Ag.png" /><figcaption>Comparison of three matching methods with a random baseline using a cumulative matching curve.</figcaption></figure><p>The CMC plot shows the final Siamese network compared to HOG + Color Histogram using euclidean distance, ResNet50 with euclidean distance, and a purely random selection of matches. The sharp rise in the Siamese CMC is because it is very good at matching on color, so all matches where the cars share the same color appear near the top of the rankings. The slow rise after about rank 10 is due to cases where color was not very helpful in making the match, either because the car was a very common color, or because it was a color easily mistaken for another (for example, yellow and white are hard for the network to tell apart).</p><h4>Lab41 is a Silicon Valley challenge lab where experts from the U.S. Intelligence Community (IC), academia, industry, and In-Q-Tel come together to gain a better understanding of how to work with — and ultimately use — big data.</h4><h4>Learn more at <a href="http://www.lab41.org/">lab41.org</a> and follow us on Twitter: <a href="https://twitter.com/_lab41">@_lab41</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83646122ad9c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object Localization without Deep Learning]]></title>
            <link>https://medium.com/@Alex.Gude/object-localization-without-deep-learning-1cf234b4780a?source=rss-a6ad23d03f88------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cf234b4780a</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Alex Gude]]></dc:creator>
            <pubDate>Mon, 07 Aug 2017 13:57:54 GMT</pubDate>
            <atom:updated>2018-01-17T18:22:22.129Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DwbOBuDy5wRkd5ZmYEzvtQ.jpeg" /></figure><p>Lab41 is just wrapping up a vehicle re-identification project named <a href="https://github.com/Lab41/pelops">Pelops</a>. The goal was to be able to identify if the same car drove past a fixed set of video cameras without reading the license plate.</p><p>We broke the project down into three parts:</p><ul><li><strong>Chipping</strong>: localizing vehicles within an image or frame from a video and extract and image (chip) containing the vehicle</li><li><strong>Feature extraction</strong>: producing a compact representation of a vehicle’s chip suitable for machine learning</li><li><strong>Matching</strong>: grouping chips of the same vehicle based on their feature representations</li></ul><p>Today I’ll show you our approach to chipping; feature extraction and matching will follow in a later post.</p><h3>Chipping</h3><p>There has been a lot of work done on using deep learning for object localization in the past few years. Deep learning based methods currently achieves state of the art results for many localization problems. In fact, our sister lab, <a href="https://medium.com/the-downlinq">CosmiQ Works</a>, explored using these techniques, and even developed a modified version of YOLO called <a href="https://medium.com/the-downlinq/you-only-look-twice-multi-scale-object-detection-in-satellite-imagery-with-convolutional-neural-38dad1cf7571">You Only Look Twice</a> (YOLT) to do ship and plane localization in satellite images.</p><p>Deep learning seems like the best option for finding cars as well! But we don’t use deep learning, for two reasons:</p><ol><li>An “off-the-shelf” network, <a href="https://arxiv.org/abs/1512.02325">SSD</a>, performed poorly.</li><li>We did not have much labeled data, so retraining wasn’t an option.</li></ol><p>We were able to hand label about 200 frames of the traffic camera data in order to test our algorithms, but did not have enough time (or, critically, patience) to label enough vehicles to train or fine-tune a deep learning model. Therefore, we chose an old standard in computer vision: <a href="https://en.wikipedia.org/wiki/Background_subtraction">background subtraction</a>.</p><h4>Background Subtraction</h4><p>What background subtraction tries to do, at its simplest, is to classify every pixel in an image as either background or foreground. Background pixels are ignored while foreground pixels are taken to be part of an object of interest. To do this classification the algorithms develop background models. We used two different algorithms with the only difference being the method in which they model the background pixels.</p><p>The first method used a very simple background model and was mainly intended as a benchmark. For each pixel it takes the median luminosity of the last ten frames. This gives a crude estimation of what objects are “permanent” and which are transient.</p><p>The second method was based on <a href="http://www.zoranz.net/Publications/zivkovicPRL2006.pdf">a paper by Zivkovic and van der Heijden</a>. It uses a Gaussian mixture model to estimate the distribution of background pixels in RGB space. It learns the distributions based on the previous frames and updates as new frames are processed. We used the implementation in OpenCV called MOG2, <a href="http://docs.opencv.org/3.1.0/d7/d7b/classcv_1_1BackgroundSubtractorMOG2.html">cv::BackgroundSubtractorMOG2</a>, which also includes a model for shadow rejection. Shadows are otherwise a tough problem to solve because shadows are real changes in the image, but are generally not ones that are interesting.</p><p>After the background models are computed, the two algorithms perform the same steps. They subtract their background model from the image leaving black pixels where there was no change and pixels with some luminosity in areas where there was a moving object. We then run a Gaussian blur over the image in order to join incorrectly separated regions (e.g., where the model splits an object in half). After the blur is applied, all pixels below a threshold value are set to black and bounding boxes are drawn around the remaining pixels. For both of our models, the size of the Gaussian kernel and the threshold value are free parameters which we optimize over. The best values for these parameters are discussed in the results section.</p><h4>Data and Labeling</h4><p>The data we used to test our chipping algorithms was from two sets of traffic cameras. The first set was from San Antonio, Texas, and the second set was from New Orleans, Louisiana. These two datasets cover a wide range of vehicle sizes in terms of number of pixels. The Texas data is low resolution and the cameras are mounted high above the highway giving very small chips, with the largest being roughly 50 pixels on a side. The Louisiana data is taken with higher resolution cameras that are mounted closer to the roadway and so the chips are much larger. Some of the chips are up to 300 pixels on a side. An example of the Texas data and Louisiana data follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*WkP3K8oxzbjgEmw9EQlBsA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*nUKPpQMlLv_WdrLftPRD7g.png" /><figcaption>An example of the Texas traffic camera data (Left) and Louisiana traffic camera data (Right). The axes indicate pixel count.</figcaption></figure><p>We hand labeled the images by drawing bounding boxes around the vehicles in a series of frames. This process was tedious and so we were only able to label about 200 frames and just under 1000 vehicles. The labeled data covered two cameras from Texas and one from Louisiana. All the frames were captured during the day time and good weather.</p><h4>Metric</h4><p>We use two metrics to assess the quality of the chipping. The first is average intersect over union (IOU) and the second is the box-wise average F1 score. These are similar (but not identical) to the metric CosmiQ Works uses for <a href="https://medium.com/the-downlinq/the-spacenet-metric-612183cc2ddb">SpaceNet</a>.</p><p>The average IOU is computed as follows: each predicted box is matched to a ground truth box such that the combination has the highest IOU score, and no other combination with that truth box has a higher score. Predicted boxes without a matching truth box are given a score of 0, and truth boxes without a matched predicted box are also given a score of 0. These IOU scores are computed across all frames for a particular camera and the mean is computed.</p><p>The average F1 score uses the IOU scores computed for each matched pair above, but with a threshold assigned. Pairs that have a higher IOU than the threshold count as “good matches” while all others count as bad matches. Truth boxes without matched predicted boxes are false negatives, and predicted boxes without matched truth boxes are false positives.</p><p>Mean IOU gives a more fine-grained metric where high overlap is better, low overlap is worse, and partial overlap is scored depending on how much is matched. The F1 score, on the other hand is binary. Overlaps are either above threshold and good, or below threshold and bad.</p><h4>Results</h4><p>The MOG2 algorithm provided by OpenCV performed best on the three different cameras we tested, two from Texas and one from Louisiana. For the Texas data, the optimal kernel size was around 10 pixels (although only odd sizes are allowed), while it was nearly 100 pixels for the Louisiana data. This puts the kernels at roughly the same scale as the size of the objects we are trying to detect, which makes sense as smaller kernels will not suppress the noise enough while larger ones will merge nearby objects together.</p><p>The optimal pixel intensity threshold value was also different between the two datasets: about 10 for Texas and about 50 for Louisiana (where 0 is black, and 255 is white). Unlike the kernel size, we do not have a good explanation for this.</p><p>The top three results for each camera in the test set are shown below, along with example images. In the example images the truth boxes are marked in green and the predicted boxes are in red.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*ZNsvD_i7_7fH6qJ-mtEfwA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*McACnWBbj8XNLSaJUVTqXQ.png" /><figcaption>Example results from the two Texas traffic cameras. The red boxes are the predicted regions, and the green boxes are the hand-labeled truth.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*ZXWd8taHTXVl92vWN8F0qg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*7vg0rG57ZTZND644_NVy-g.png" /><figcaption>The three best chipping methods for Texas IH-37 at 9th St. camera.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*wrYqnyxRZsNm6RFA-1oJOg.png" /><figcaption>An example result from the Louisiana traffic camera. The red boxes are the predicted regions, and the green boxes are the hand-labeled truth.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*tElK3rBv1pVHkCsDvyP_CQ.png" /><figcaption>The three best chipping methods for the Louisiana camera.</figcaption></figure><h4>Conclusion</h4><p>The results are adequate, but not great. There are a few major issues with the MOG2 algorithm:</p><ol><li>Shadows still present a major problem, as seen in the image from the camera positioned at IH-37 at Jones Ave.</li><li>Getting the correct size for the bounding box is tough, as seen in the Louisiana frame.</li><li>Nearby vehicles are often merged together.</li></ol><p>Despite these issues, background subtraction based localization is good enough for our purpose, and easy to implement with a small amount of data. In the future, we would focus on labeling more data so that training a deep learning system was feasible, and focus on classifying pixels within the chips as vehicle or background to help the down-stream algorithms focus on the important parts of the chip.</p><h4>Lab41 is a Silicon Valley challenge lab where experts from the U.S. Intelligence Community (IC), academia, industry, and <a href="https://www.iqt.org/">In-Q-Tel</a> come together to gain a better understanding of how to work with — and ultimately use — big data.</h4><h4>Learn more at <a href="http://www.lab41.org/">lab41.org</a> and follow us on Twitter: <a href="https://twitter.com/_lab41">@_lab41</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cf234b4780a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lab41 Reading Group: Swapout: Learning an Ensemble of Deep Architectures]]></title>
            <link>https://medium.com/@Alex.Gude/lab41-reading-group-swapout-learning-an-ensemble-of-deep-architectures-e67d2b822f8a?source=rss-a6ad23d03f88------2</link>
            <guid isPermaLink="false">https://medium.com/p/e67d2b822f8a</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[lab41-reading-group]]></category>
            <dc:creator><![CDATA[Alex Gude]]></dc:creator>
            <pubDate>Mon, 12 Dec 2016 17:01:02 GMT</pubDate>
            <atom:updated>2016-12-12T17:01:02.686Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ov-jo4TgJZIj8kmiWwGqNQ.jpeg" /></figure><p>Next up for the reading group is <a href="https://arxiv.org/abs/1605.06465">a paper about a new stochastic training method</a> written by Saurabh Singh, Derek Hoiem, and David Forsyth of the University of Illinois at Urbana–Champaign. Their new training method is like <a href="https://arxiv.org/abs/1207.0580">dropout</a>, <a href="https://arxiv.org/abs/1603.09382">stochastic depth</a>, and <a href="https://arxiv.org/abs/1512.03385">ResNets</a> but with its own special twist. I recommend picking up the paper after going through this post, it is very readable and includes an excellent section on performing inference with a stochastically trained network that I will only touch on.</p><p>As you may recall, dropout works by randomly setting individual neuron outputs in a network to zero, essentially dropping those neurons from training and hence forcing the network to use a variety of signals instead of over-training on one. Stochastic depth (<a href="https://gab41.lab41.org/lab41-reading-group-deep-networks-with-stochastic-depth-564321956729#.7x90kpg35">covered in a previous post</a>) is similar, but instead of dropping neurons it bypasses whole layers! We can think of these operations a little more mathematically, but first I’ll have to define some notation.</p><p>I’ll use block to mean a set of layers in some specific configuration (for example, a convolution followed by a ReLU), and a unit to be one of the computational nodes within the block (basically a neuron). <strong>X</strong> will be the input from the previous block, and <strong>F(X)</strong> will be the output from a unit within the current block.</p><p>Using this notation then, we can think about ResNets as consisting of blocks where ever unit in the block always reports <strong>X + F(X)</strong>. A standard, feed-forward layer can be viewed in this framework as well, with each unit always reporting <strong>F(X)</strong>. The paper includes a figure, which I’ve edited and included below, showing feed-forward and ResNets in this scheme:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SqCm8PCctAV6HmssZ_XDQQ.png" /><figcaption>Each box represents a block, and each circle is a unit from the block.</figcaption></figure><p>Things become more interesting when we start thinking about stochastic training methods in this manner. Dropout can be thought of as randomly selecting the output for each unit from the following set of possible outcomes: <strong>{Zero, F(X)}</strong>. Likewise, stochastic depth can be thought of as randomly selecting between the outcomes <strong>{X, F(X)}</strong> for each block, so that every unit in the block returns <strong>X</strong> or <strong>F(X)</strong> together. Both of these training methods are shown in the figure below, which is again has been modified from the paper:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gAinV8cS9VmpUeo2hLdfpg.png" /><figcaption>Each box represents a block, and each circle is a unit from the block. Circles with two colors represent a block choosing all units to be one or the other.</figcaption></figure><p>So now that I’ve laid the groundwork, what does swapout add? Well, add isn’t really the right word, swapout combines! It randomly selects from the four possible outcomes mentioned above: feed-forward, ResNet, dropout, and stochastic depth. They do this by allowing each unit to randomly select from the following outcomes: <strong>{Zero, X, F(X), X + F(X)}</strong>. Therefore, swapout samples from every possible stochastic depth and ResNet architecture, both including and not include dropout!</p><p>In addition to swapout, the authors define a simpler version called skipforward. Skipforward only allows units to select from the outcomes <strong>{X, F(X)}</strong>, that is limiting the choice to only stochastic depth and feed-forward. Both of these architectures are shown in the figure below, which is again from the paper with modification:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kJCQGG8QpmL5felmTPouYg.png" /><figcaption>Each box represents a block, and each circle is a unit from the block.</figcaption></figure><p>One of the dilemmas when using stochastic training methods is: how do I use the network at inference time? When training the network is constantly mutating as units pick different ways of behaving, but at inference time that network needs to be roughly static so that the same input will always yield the same prediction. We can make the network static in two ways:</p><ol><li><strong>Deterministic inference</strong>: All values are replaced by their expectation value. That is, the unit that was dropped half the time is set to 50% weight.</li><li><strong>Stochastic inference</strong>: Several versions of the network are randomly generated at the end of training and their results averaged. A unit that is dropped half the time would (by chance) appear in half randomly generated versions of the network.</li></ol><p>Although it seems like deterministic inference should be faster (because it does not require running multiple networks) it has several drawbacks. The first drawback is that you can not actually calculate the true expectation value for a swapout network, only approximate it. The second is the the fact that <a href="http://jmlr.org/proceedings/papers/v37/ioffe15.pdf">batch normalization</a> — one of the most powerful training methodologies, see our <a href="https://gab41.lab41.org/batch-normalization-what-the-hey-d480039a9e3b#.ydbv20tjo">previous post</a> for a summary — does not work with deterministic inference. The authors conclude (through testing) that stochastic inference works best.</p><p>The authors test swapout and skipforward networks against networks trained with stochastic depth, dropout, and various ResNet architectures. They conclude:</p><ul><li>Swapout improves results as compared with ResNet</li><li>Stochastic inference beats deterministic, even with only a few averaged results</li><li>Increasing the width of a network greatly improves performance</li></ul><p>One final note on the paper: the way they define the various operations as random selections from a set of possible outcomes is, for me, a very intuitive way to think about them. I would love to see other papers use a similar framework for describing their network modifications!</p><h4>Lab41 is a Silicon Valley challenge lab where experts from the U.S. Intelligence Community (IC), academia, industry, and In-Q-Tel come together to gain a better understanding of how to work with — and ultimately use — big data.</h4><h4>Learn more at <a href="http://www.lab41.org/">lab41.org</a> and follow us on Twitter: <a href="https://twitter.com/_lab41">@_lab41</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e67d2b822f8a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lab41 Reading Group: Skip-Thought Vectors]]></title>
            <link>https://medium.com/@Alex.Gude/lab41-reading-group-skip-thought-vectors-fec68c05aa92?source=rss-a6ad23d03f88------2</link>
            <guid isPermaLink="false">https://medium.com/p/fec68c05aa92</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[lab41-reading-group]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Alex Gude]]></dc:creator>
            <pubDate>Mon, 31 Oct 2016 15:01:01 GMT</pubDate>
            <atom:updated>2016-10-31T15:59:16.412Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GrPMDu7Yd2v3buWyQhbP3A.jpeg" /></figure><p>Continuing the tour of older papers that started with our <a href="https://gab41.lab41.org/lab41-reading-group-deep-residual-learning-for-image-recognition-ffeb94745a1f#.bc3hiquop">ResNet blog post</a>, we now take on <a href="https://arxiv.org/abs/1506.06726"><strong>Skip-Thought Vectors</strong></a> by <a href="http://www.cs.toronto.edu/~rkiros/">Kiros</a> <em>et al</em>. Their goal was to come up with a useful embedding for sentences that was not tuned for a single task and did not require labeled data to train. They took inspiration from Word2Vec skip-gram (you can find <a href="https://gab41.lab41.org/python2vec-word-embeddings-for-source-code-3d14d030fe8f#.e301tsg77">my explanation of that algorithm here</a>) and attempt to extend it to sentences.</p><p>Skip-thought vectors are created using an encoder-decoder model. The encoder takes in the training sentence and outputs a vector. There are two decoders both of which take the vector as input. The first attempts to predict the previous sentence and the second attempts to predict the next sentence. Both the encoder and decoder are constructed from recurrent neural networks (RNN). Multiple encoder types are tried including <strong>uni-skip</strong>, <strong>bi-skip</strong>, and <strong>combine-skip</strong>. Uni-skip<strong> </strong>reads the sentence in the forward direction. Bi-skip reads the sentence forwards and backwards and concatenates the results. Combined-skip concatenates the vectors from uni- and bi-skip. Only minimal tokenization is done to the input sentences. A diagram indicating the input sentence and the two predicted sentences is shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MQXaRQ3BsTHpn0cfOXcbag.png" /><figcaption>Given a sentence (the grey dots), skip-thought attempts to predict the preceding sentence (red dots) and the next sentence (green dots). Figure from the paper.</figcaption></figure><p>Their model requires groups of sentences in order to train, and so trained on the <strong>BookCorpus Dataset</strong>. The dataset consists of novels by unpublished authors and is (unsurprisingly) dominated by romance and fantasy novels. This “bias” in the dataset will become apparent later when discussing some of the sentences used to test the skip-thought model; some of the retrieved sentences are quite exciting!</p><p>Building a model that accounts for the meaning of an entire sentence is tough because language is remarkably flexible. Changing a single word can either completely change the meaning of a sentence or leave it unaltered. The same is true for moving words around. As an example:</p><blockquote><em>One </em><strong><em>difficulty</em></strong><em> in building a model to handle sentences is that a single word can be changed and yet the meaning of the sentence is the same.</em></blockquote><p>Put a different way:</p><blockquote><em>One </em><strong><em>challenge</em></strong><em> in building a model to handle sentences is that a single word can be changed and yet the meaning of the sentence is the same.</em></blockquote><p>Changing a single word has had almost no effect on the meaning of that sentence. To account for these word level changes, the skip-thought model needs to be able to handle a large variety of words, some of which were not present in the training sentences. The authors solve this by using a pre-trained continuous bag-of-words (CBOW) Word2Vec model and learning a translation from the Word2Vec vectors to the word vectors in their sentences. Below are shown the nearest neighbor words after the vocabulary expansion using query words that do not appear in the training vocabulary:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uhD6xdEZTdGcwUITMB96Hg.png" /><figcaption>Nearest neighbor words for various words that were not included in the training vocabulary. Table from the paper.</figcaption></figure><p>So how well does the model work? One way to probe it is to retrieve the closest sentence to a query sentence; here are some examples:</p><blockquote><strong><em>Query:</em></strong> <em>“I’m sure you’ll have a glamorous evening,” she said, giving an exaggerated wink.</em></blockquote><blockquote><strong><em>Retrieved:</em></strong><em> “I’m really glad you came to the party tonight,” he said, turning to her.</em></blockquote><p>And:</p><blockquote><strong><em>Query:</em></strong><em> Although she could tell he hadn’t been too interested in any of their other chitchat, he seemed genuinely curious about this.</em></blockquote><blockquote><strong><em>Retrieved</em>:</strong> <em>Although he hadn’t been following her career with a microscope, he’d definitely taken notice of her appearance.</em></blockquote><p>The sentences are in fact very similar in both structure and meaning (and a bit salacious, as I warned earlier) so the model appears to be doing a good job.</p><p>To perform more rigorous experimentation, and to test the value of skip-thought vectors as a generic sentence feature extractor, the authors run the model through a series of tasks using the encoded vectors with simple, linear classifiers trained on top of them.</p><p>They find that their generic skip-thought representation performs very well for detecting the semantic relatedness of two sentences and for detecting where a sentence is paraphrasing another one. Skip-thought vectors perform relatively well for image retrieval and captioning (where they use <a href="https://arxiv.org/pdf/1409.1556.pdf">VGG</a> to extract image feature vectors). Skip-thought performs poorly for sentiment analysis, producing equivalent results to various bag of word models but at a much higher computational cost.</p><p>We have used skip-thought vectors a little bit at the Lab, most recently for the <a href="https://gab41.lab41.org/tell-me-something-i-dont-know-detecting-novelty-and-redundancy-with-natural-language-processing-818124e4013c#.6xf8nejr9">Pythia challenge</a>. We found them to be useful for novelty detection, but incredibly slow. Running skip-thought vectors on a corpus of about 20,000 documents took many hours, where as simpler (and as effective) methods took seconds or minutes. I will update with a link to their blog post when it comes online.</p><h4>Lab41 is a Silicon Valley challenge lab where experts from the U.S. Intelligence Community (IC), academia, industry, and In-Q-Tel come together to gain a better understanding of how to work with — and ultimately use — big data.</h4><h4>Learn more at <a href="http://www.lab41.org/">lab41.org</a> and follow us on Twitter: <a href="https://twitter.com/_lab41">@_lab41</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fec68c05aa92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lab41 Reading Group: Deep Residual Learning for Image Recognition]]></title>
            <link>https://medium.com/@Alex.Gude/lab41-reading-group-deep-residual-learning-for-image-recognition-ffeb94745a1f?source=rss-a6ad23d03f88------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffeb94745a1f</guid>
            <category><![CDATA[lab41-reading-group]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Alex Gude]]></dc:creator>
            <pubDate>Thu, 08 Sep 2016 15:46:40 GMT</pubDate>
            <atom:updated>2016-10-27T16:45:01.590Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6eJ5jtgyyBTuv4XlJGqEig.jpeg" /></figure><p>Today’s <a href="https://arxiv.org/abs/1512.03385">paper offers a new architecture for Convolution Networks</a>. It was written by He, Zhang, Ren, and Sun from Microsoft Research. I’ll warn you before we start: this paper is ancient. It was published in the dark ages of deep learning sometime at the end of 2015, which I’m pretty sure means its original format was papyrus; thankfully someone scanned it so that future generations could read it. But it is still worth blowing off the dust and flipping through it because the architecture it proposes has been used time and time again, including in <a href="https://gab41.lab41.org/lab41-reading-group-deep-networks-with-stochastic-depth-564321956729">some of the papers we have previously read</a>: <a href="https://arxiv.org/abs/1603.09382">Deep Networks with Stochastic Depth</a>.</p><p>He <em>et al.</em> begin by noting a seemingly paradoxical situation: very deep networks perform more poorly than moderately deep networks, that is, that while adding layers to a network generally improves the performance, after some point the new layers begin to hinder the network. They refer to this effect as network <strong>degradation</strong>.</p><p>If you have been following our <a href="https://gab41.lab41.org/lab41-reading-group-deep-networks-with-stochastic-depth-564321956729">previous posts</a> this won’t surprise you; training issues like vanishing gradients become worse as networks get deeper so you would expect more layers to make the network worse after some point. But the authors anticipate this line of reasoning and state that several other deep learning methods, like <a href="https://arxiv.org/abs/1502.03167">batch normalization</a> (see <a href="https://gab41.lab41.org/batch-normalization-what-the-hey-d480039a9e3b">our post</a> for a summary), essentially have solved these training issues, and yet the networks still perform increasingly poorly as their depth increases. For example, they compare 20- and 56-layer networks and find the 56-layer network performs far worse; see the image below from their paper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UbNuXfVNVfTq1WkMZyJ1QA.png" /><figcaption>Comparison of 20- and 56-layer networks on CIFAR-10. Note that the 56-layer network performs more poorly in both training and testing.</figcaption></figure><p>The authors then set up a thought experiment (or <a href="https://en.wiktionary.org/wiki/gedankenexperiment">gedankenexperiment</a> if you’re a recovering physicist like me) to demonstrate that deeper networks should always perform better. Their argument is as follows:</p><ol><li>Start with a network that performs well;</li><li>Add additional layers that are forced to be the identity function, that is, they simply pass along whatever information arrives at them without change;</li><li>This network is deeper, but must have the same performance as the original network by construction since the new layers do not do anything;</li><li>Layers in a network can learn the identity function, so they should be able to exactly replicate the performance of this deep network if it is optimal.</li></ol><p>This thought experiment leads them to propose their <strong>deep residual learning</strong> architecture. They construct their network of what they call residual building blocks. The image below shows one such block. These blocks have become known as <strong>ResBlocks</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4sO3vjCdUlYQZcRq-GNqyw.png" /><figcaption>A ResBlock; a residual function <em>f(x)</em> is learned on the top and information is passed along the bottom unchanged. Image modified from <a href="https://arxiv.org/abs/1603.09382">Huang et al.’s Stochastic Depth paper</a>.</figcaption></figure><p>The ResBlock is constructed out of normal network layers connected with <a href="https://en.wikipedia.org/wiki/Rectifier_(neural_networks)">rectified linear units</a> (ReLUs) and a pass-through below that feeds through the information from previous layers unchanged. The network part of the ResBlock can consist of an arbitrary number of layers, but the simplest is two.</p><p>To get a little into the math behind the ResBlock: let us assume that a set of layers would perform best if they learned a specific function, <em>h(x)</em>. The authors note that the residual, <em>f(x) = h(x)</em>−<em>x</em>, can be learned instead and combined with the original input such that we recover <em>h(x)</em> as follows: <em>h(x) = f(x) + x.</em> This can be accomplished by adding a <em>+x</em> component to the network, which, thinking back to our thought experiment, is simply the identity function. The authors hope that adding this “pass-through” to their layers will aid in training. As with most deep learning, there is only this intuition backing up the method and not any deeper understanding. However, as the authors show, it works, and in that end that’s the only thing many of us practitioners care about.</p><p>The paper also explores a few modifications to the ResBlock. The first is creating bottleneck blocks with three layers where the middle layer constricts the information flow by using fewer inputs and outputs. The second is testing different types of pass-through connections including learning a full projection matrix. Although the more complicated pass-throughs perform better, they do so only slightly and at the cost of training time.</p><p>The rest of the paper tests the performance of the network. The authors find that their networks perform better than identical networks without the pass-through; see the image below for their plot showing this. They also find that they can train far deeper networks and still show improved performance, culminating in training a 152-layer ResNet that outperforms shallower networks. They even train a 1202-layer network to prove that it is feasible, but find that its performance is worse than the other networks examined in the paper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f8TRIszXY6xGqtcMBWvD3g.png" /><figcaption>A comparison of the performance of two networks: the ones on the left do not use ResBlocks, while the ones on the right do. Notice the the 34-layer network performs better than the 18-layer network, but only when using ResBlocks.</figcaption></figure><p>So that’s it! He <em>et al.</em> proposed a new architecture motivated by thought experiments and the hope that it will work better than previous ones. They construct several networks, including a few very deep ones, and find that their new architecture does indeed improve performance of the networks. Although we don’t gain any further understanding of the underlying principles of deep learning, we do get a new method of making our networks work better, and in the end maybe that’s good enough.</p><h4>Lab41 is a Silicon Valley challenge lab where experts from the U.S. Intelligence Community (IC), academia, industry, and In-Q-Tel come together to gain a better understanding of how to work with — and ultimately use — big data.</h4><h4>Learn more at <a href="http://www.lab41.org/">lab41.org</a> and follow us on Twitter: <a href="https://twitter.com/_lab41">@_lab41</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffeb94745a1f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lab41 Reading Group: Deep Compression]]></title>
            <link>https://medium.com/@Alex.Gude/lab41-reading-group-deep-compression-9c36064fb209?source=rss-a6ad23d03f88------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c36064fb209</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[compression]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[lab41-reading-group]]></category>
            <dc:creator><![CDATA[Alex Gude]]></dc:creator>
            <pubDate>Tue, 09 Aug 2016 16:46:39 GMT</pubDate>
            <atom:updated>2016-10-27T16:45:51.503Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0D44qU_d2R5JFGm1p0t4FA.jpeg" /></figure><p><a href="https://arxiv.org/abs/1510.00149">The next paper from our reading group</a> is by Song Han, Huizi Mao, and William J. Dally. It won the best paper award at ICLR 2016. It details three methods of compressing a neural network in order to reduce the size of the network on disk, improve performance, and decrease run time.</p><p>Pre-trained convolutional neural networks are too large for mobile devices: <a href="http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks">AlexNet</a> is 240 MB and <a href="https://arxiv.org/abs/1409.1556">VGG-16</a> is over 552 MB. This seems small when compared to a music library or large video, but the difference is that the networks reside in memory when running. On mobile devices SRAM is scarce and DRAM is expensive to access in terms of energy used. For reference, the authors estimate that a 1 billion node network running at 20 FPS on your phone would draw nearly 13 Watts from just the DRAM access alone. If these networks are going to run on a mobile device (where they could, for example, automatically tag pictures as they are taken) they must be compressed in some manner. In this paper the authors apply three compression methods to the weights of various networks and measure the results. A diagram of the three methods and their results are below; I’ll walk you through them in more depth in the next few paragraphs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GEG4DH-Nx_hqXIcUWLw3NA.png" /><figcaption>A summary of the three stages in the compression pipeline proposed by Han, Mao, and Dally. Note that the size reduction is cumulative. Image from their paper.</figcaption></figure><p>The first compression method is <strong>Network Pruning</strong>. In this method a network is fully trained and then any connections with a weight below a certain threshold are removed leaving a sparse network. The sparse network is then retrained to ensure the remaining connections are used optimally. This form of compression reduced the size of AlexNet by a factor of 9, and VGG-16 by a factor of 13. The authors also use a clever data structure that makes use of variably sized integers to store the network after this compression.</p><p>The second compression method is <strong>Trained Quantization and Weight Sharing</strong>. Here the weights in a network are clustered together with other weights of similar magnitude, and all these weights are then represented by a single shared value. The authors use k-means clustering to group weights for sharing. They explore multiple methods of setting the k centroids and find that a simple linear spacing of the centroids along the full distribution of weight values performs best. This compression method reduces the size of the networks by a factor of 3 or 4. A diagram with an example of this compression technique is shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BhdGZ-QK1LKWYZMN_hRrwQ.png" /><figcaption>A toy example of trained quantization and weight sharing. On the top row, weights of the same color have been clustered and will be replaced by a centroid value. On the bottom row, gradients are calculated and used to update the centroids. From Han, Mao, and Dally’s paper.</figcaption></figure><p>The third and final compression method is <strong>Huffman Coding</strong>. Huffman coding is a standard lossless compression technique. The general idea is that it uses fewer bits to represent data that appears frequently and more bits to represent data that appears infrequently. For more details see the <a href="https://en.wikipedia.org/wiki/Huffman_coding">Wikipedia Article</a>. Huffman coding reduces network size by 20% to 30%.</p><p>Using all three compression methods leads to a compression factor of 35 times for AlexNet, and 49 times for VGG-16! This reduces AlexNet to 6.9 MB, and VGG-16 to under 11.3 MB! Unsurprisingly it is the fully connected layers that are the largest (90% of the model size), but they also compress the best (96% of weights pruned in VGG-16). The new, smaller convolutional layers run faster than their old versions (4 times faster on mobile GPU) and use less energy (4 times less). These results are achieved with no loss in performance! A plot showing the energy efficiency and speedups due to compression are shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9-wuWX72LKKQ0CeaYfKXag.png" /><figcaption>The energy efficiency and speedups due to compression for various layers in the neural networks. The <strong>dense</strong> bars are the results before compression, and the <strong>pruned</strong> bars are the results after. Note the Y axis is log10! From Han, Mao, and Dally’s paper.</figcaption></figure><p>Han, Mao, and Dally’s compression techniques achieve an almost perfect result: the in memory size of a network is reduced, the run speed is increased, and the energy used to perform the calculation is decreased. Although designed with mobile in mind, their compression is so successful I would not be surprised to see it widely supported by the various deep learning frameworks in the near future.</p><h4>Lab41 is a Silicon Valley challenge lab where experts from the U.S. Intelligence Community (IC), academia, industry, and In-Q-Tel come together to gain a better understanding of how to work with — and ultimately use — big data.</h4><h4>Learn more at <a href="http://www.lab41.org/">lab41.org</a> and follow us on Twitter: <a href="https://twitter.com/_lab41">@_lab41</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c36064fb209" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lab41 Reading Group: Deep Networks with Stochastic Depth]]></title>
            <link>https://medium.com/@Alex.Gude/lab41-reading-group-deep-networks-with-stochastic-depth-564321956729?source=rss-a6ad23d03f88------2</link>
            <guid isPermaLink="false">https://medium.com/p/564321956729</guid>
            <category><![CDATA[lab41-reading-group]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Alex Gude]]></dc:creator>
            <pubDate>Mon, 11 Jul 2016 21:46:13 GMT</pubDate>
            <atom:updated>2016-10-27T16:46:05.609Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDOHVWFjIB9_C4iiNAFF1Q.jpeg" /></figure><p><a href="https://arxiv.org/abs/1603.09382">Today’s paper</a> is by Gao Huang, Yu Sun, <em>et al</em>. It introduces a new way to perturb networks during training in order to improve their performance. Before I continue, let me first state that this paper is a <strong>real pleasure to read</strong>; it is concise and extremely well written. It gives an excellent overview of the motivating problems, previous solutions, and Huang and Sun’s new approach. I highly recommended giving it a read!</p><p>The authors begin by pointing out that deep neural networks have greater expressive power as compared to shallow networks, that is they can learn more details and better separate similar classes of objects. For example, a shallow network might be able to tell cats from dogs, but a deep network has a better chance of learning to tell Husky from a Malamute. However, deep networks are more difficult to train. Huang and Sun list the following issues that appear when training very deep networks:</p><ol><li><strong>Vanishing Gradients</strong>: As the gradient information is backpropagated through the network, it is multiplied by the weights. In a deep network this multiplication is repeated several times with small weights and so the information that reaches the earliest layers is often too little to effectively train the network.</li><li><strong>Diminishing Feature Reuse</strong>: This is the same problem as the vanishing gradient, but in the forward direction. Features computed by early layers are washed out by the time they reach the final layers by the many weight multiplications in between.</li><li><strong>Long Training Times</strong>: Deeper networks require a longer time to train than shallow networks. Training time scales linearly with the size of the network.</li></ol><p>There are many solutions to these problems and the authors propose a new one: <strong>Stochastic Depth</strong>. In essence what stochastic depth does is randomly bypass layers in the network while training. They construct their network of ResBlocks (see image below, and <a href="https://gab41.lab41.org/lab41-reading-group-deep-residual-learning-for-image-recognition-ffeb94745a1f#.7bl1myhho">our post for more information</a>) which are a set of convolution layers and a bypass that passes the information from the previous layer through without any change. With stochastic depth, the convolution block is sometimes switched off allowing the information to flow through the layer without being changed, effectively removing the layer from the network. During testing, all layers are left in and the weights are modified by their survival probability. This is very similar to how dropout works, except instead of dropping a single node in a layer the entire layer is dropped!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2u0do-MwkV_cbJRaPalmfA.png" /><figcaption>A ResBlock. The top path is a convolution layer, while the bottom path is a pass through. From Gao Huang, Yu Sun, <em>et al</em>.</figcaption></figure><p>Stochastic depth adds a new hyper-parameter, <em>p(l)</em>, the probability of dropping a layer as a function of its depth. They take <em>p(l)</em> to be linear with it equal to 0.0 for the first layer and 0.5 for the last, although other functions (include a constant) are possible. With this model the expected depth of a network is effectively reduced by 25% with corresponding reductions in training time. The authors also show that it reduces the problems associated with vanishing gradients and diminishing feature use, as expected for a shallower network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*Pny3rCtqvf9xC8RRffhMew.png" /><figcaption>An example training run on a network with stochastic depth. The red and blue bars indicate the probability of dropping a layer, p(l). In this example layer 3 and layer 5 have been dropped. From Gao Huang, Yu Sun, <em>et al</em>.</figcaption></figure><p>In addition to aiding in training, the trained networks actually <strong>perform better</strong> than networks trained without stochastic depth! This is because stochastic depth, like dropout, acts as a form of regularization, preventing the network from over training. However, unlike dropout, stochastic depth works with <a href="https://gab41.lab41.org/batch-normalization-what-the-hey-d480039a9e3b">batch normalization</a> making it a very powerful combination.</p><p>The authors demonstrate the new architecture on <a href="https://www.cs.toronto.edu/~kriz/learning-features-2009-TR.pdf">CIFAR-10</a>, <a href="https://www.cs.toronto.edu/~kriz/learning-features-2009-TR.pdf">CIFAR-100</a>, and the <a href="http://ufldl.stanford.edu/housenumbers/nips2011_housenumbers.pdf">Street View House Number dataset (SVHN)</a>. They achieve the lowest published error on CIFAR-10 and CIFAR-100, and second lowest for SVHN. They also test using a very deep network (1202 layers) on CIFAR-10 and find that it produces an even better result, the first time a 1000+ layer network has been shown to further reduce the error on CIFAR-10.</p><p>The main idea behind stochastic depth is relatively simple, remove some layers when training to make the network train is if it were shallow, but the results are surprisingly good. The new networks not only train faster, but they perform better as well. Further, the idea is compatible with other methods of improving network training like batch normalization. All in all, stochastic depth is an essentially free improvement when training a deep network. I look forward to giving it a shot in my next model!</p><h4>Lab41 is a place where experts from the U.S. Intelligence Community (IC), academia, industry, and In-Q-Tel come together to gain a better understanding of how to work with — and ultimately use — big data.</h4><h4>Learn more at <a href="http://www.lab41.org/">lab41.org</a> and follow us on Twitter: <a href="https://twitter.com/_lab41">@_lab41</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=564321956729" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>