<?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 Nick Bourdakos on Medium]]></title>
        <description><![CDATA[Stories by Nick Bourdakos on Medium]]></description>
        <link>https://medium.com/@bourdakos1?source=rss-154a0d2814f0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Ad3pty9Qgh3SHcF2Dkv4eg.jpeg</url>
            <title>Stories by Nick Bourdakos on Medium</title>
            <link>https://medium.com/@bourdakos1?source=rss-154a0d2814f0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 12 Nov 2026 08:32:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bourdakos1/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[How to Label Data — Create ML for Object Detection]]></title>
            <link>https://medium.com/hackernoon/how-to-label-data-create-ml-for-object-detection-82043957b5cb?source=rss-154a0d2814f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/82043957b5cb</guid>
            <category><![CDATA[hackernoon-top-story]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[how-to-label-data]]></category>
            <category><![CDATA[object-detection]]></category>
            <dc:creator><![CDATA[Nick Bourdakos]]></dc:creator>
            <pubDate>Fri, 07 Jun 2019 12:41:01 GMT</pubDate>
            <atom:updated>2019-06-07T12:41:01.020Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Label Data — Create ML for Object Detection</h3><p>The new Create ML app just announced at WWDC 2019, is an incredibly easy way to train your own personalized machine learning models. All that’s required is dragging a folder containing your training data into the tool and Create ML does the rest of the heavy lifting.</p><p>So how do we prepare our data?</p><p>When doing image or sound classification we just need to organize the data into folders, but if we want to do object detection the task becomes a bit more complicated. With object detection, we need to specify some additional information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ee7JthqyAxguNmWzHTiAw.png" /></figure><p>In addition to our images, we need an annotations.json with the coordinates of where the objects are. The annotations need to match the following format:</p><pre>[<br>    {<br>        &quot;image&quot;: &quot;image1.jpg&quot;,<br>        &quot;annotations&quot;: [<br>            {<br>                &quot;label&quot;: &quot;carrots&quot;,<br>                &quot;coordinates&quot;: {<br>                    &quot;x&quot;: 120<br>                    &quot;y&quot;: 164<br>                    &quot;width&quot;: 230<br>                    &quot;height&quot;: 119<br>                }<br>            },<br>            {<br>                &quot;label&quot;: &quot;orange&quot;,<br>                &quot;coordinates&quot;: {<br>                    &quot;x&quot;: 230<br>                    &quot;y&quot;: 321<br>                    &quot;width&quot;: 50<br>                    &quot;height&quot;: 50<br>                }<br>            }<br>        ]<br>    },<br>    ...<br>]</pre><blockquote><strong>Note:</strong> The x and y coordinates are the centers of the bounding rectangles and all coordinates are in pixels</blockquote><p>How do we generate this json? (I definitely don’t want to do it all by hand)</p><p>Apple tells us</p><blockquote>“You can download tools from the web to help you build these [annotations]”</blockquote><p>So what tool should we use? Cloud Annotations!</p><p>Cloud Annotations is a tool that I built exactly for this purpose. It lets us quickly draw boxes on our images and gives us an annotations.json in the format required by Apple.</p><h3>Creating an object storage instance</h3><p>To use Cloud Annotations we need to create a cloud object storage instance. Creating a Cloud Object Storage instance gives us a reliable place to keep our training data. It also opens up the potential for data collection and collaboration, letting us collect user data and allowing a team of specialists to easily label it.</p><p>IBM Cloud offers a lite tier of object storage, which includes 25 GB of storage for free. (this is what we will be using throughout the tutorial)</p><p>To create an instance we first need to <strong>log in</strong> or <strong>sign up</strong> for <a href="https://ibm.biz/cloud-annotations-sign-up">IBM Cloud</a>.</p><p>Once logged in you should find your IBM Cloud dashboard. This is where we can create and manage IBM Cloud resources.</p><p>We want to create a new Cloud Object Storage instance so click the <strong>Create resource</strong> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ovU7_8k6lZRdBxsv.png" /></figure><p>Locate and choose the <strong>Object Storage</strong> option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u3DRmpnPp_thKGAE.png" /></figure><p>Choose a pricing plan and click <strong>Create</strong>, then <strong>Confirm</strong> on the following popup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eg0Kbb8RWGWBp8iu.png" /></figure><h3>Credentials</h3><p>Once we have an object storage instance we need a way to access our data from outside of IBM Cloud. To do be able to do this we need to create a set credentials for our resource.</p><p>We can do this by navigating to the <strong>Service credentials</strong> tab and clicking the <strong>New credential</strong> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DoZa6QkooYUIHD0V.png" /></figure><p>You can leave most of the options blank, but make sure the credential has the role of <strong>Writer</strong> and add the following inline configuration parameters:</p><pre>{&quot;HMAC&quot;: true}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*woeDzwo8wquFjoCU.png" /></figure><p>Once added, click the <strong>View credentials ▾</strong> dropdown and take note of your <strong>apikey</strong>, <strong>access_key_id</strong>, <strong>secret_access_key</strong> and <strong>resource_instance_id</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cgzg0bgFtS-aMQzM.png" /></figure><pre>{<br>  <strong>&quot;apikey&quot;: &quot;...&quot;,</strong><br>  &quot;cos_hmac_keys&quot;: {<br>    <strong>&quot;access_key_id&quot;: &quot;...&quot;,</strong><br>    <strong>&quot;secret_access_key&quot;: &quot;...&quot;</strong><br>  },<br>  &quot;endpoints&quot;: &quot;...&quot;,<br>  &quot;iam_apikey_description&quot;: &quot;...&quot;,<br>  &quot;iam_apikey_name&quot;: &quot;...&quot;,<br>  &quot;iam_role_crn&quot;: &quot;...&quot;,<br>  &quot;iam_serviceid_crn&quot;: &quot;...&quot;,<br>  <strong>&quot;resource_instance_id&quot;: &quot;...&quot;</strong><br>}</pre><h3>Cloud Annotations</h3><p>To use the tool just navigate to the <a href="https://cloud.annotations.ai/">Cloud Annotations Tool</a> and add your object storage credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GT8BmSWKHHlcltmA.png" /></figure><p>We will be storing our files and annotations in something called a <strong>bucket</strong>, we can create one by clicking <strong>Create bucket</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9V78tApOet0LdU3G.png" /></figure><p>After we create and name our bucket, it will prompt us to choose an annotation type. We need to choose <strong>Localization</strong>. This allows us to draw bounding box rectangles on our images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZhyzkWn9KeCwJzU0.png" /></figure><h4>Training data best practices</h4><ul><li>The model we will be training is optimized for photographs of objects in the real world. They are unlikely to work well for x-rays, hand drawings, scanned documents, receipts, etc.</li><li>The training data should be as close as possible to the data on which predictions are to be made. For example, if your use case involves blurry and low-resolution images (such as from a security camera), your training data should be composed of blurry, low-resolution images. In general, you should also consider providing multiple angles, resolutions, and backgrounds for your training images.</li><li>The model we will be training can’t generally predict labels that humans can’t assign. So, if a human can’t be trained to assign labels by looking at the image for 1–2 seconds, the model likely can’t be trained to do it either.</li><li>We recommend at least 50 training images per label for a usable model, but using 100s or 1000s would provide better results.</li><li>The model we will be training resizes the image to 300x300 pixels, so keep that is mind when training the model with images where one dimension is much longer than the other.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4OJprMsvgqpvB-8I.png" /></figure><h4>Labeling the data</h4><p>To label images:</p><ol><li>Upload a video or many images</li><li>Create the desired labels</li><li>Start drawing bounding boxes</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5u6BxZDXThuockUO.png" /></figure><h3>Getting the annotations</h3><p>After we have collected and labeled our first round of images, we are ready to start training our model!</p><h4>Installation</h4><p>To access our annotations we need to install the Cloud Annotation CLI:</p><pre>npm install -g cloud-annotations</pre><blockquote><strong><em>Note: You’ll need to have Node 10.13.0 or later installed.</em></strong><em> You can use </em><a href="https://github.com/creationix/nvm#installation"><em>nvm</em></a><em> (macOS/Linux) or </em><a href="https://github.com/coreybutler/nvm-windows#node-version-manager-nvm-for-windows"><em>nvm-windows</em></a><em> to easily switch Node versions between different projects.</em></blockquote><h4>Download the annotations</h4><p>To download the annotations all we need to do is run the following command</p><pre>cacli export --create-ml</pre><p>Once finished there should be a folder named exported_buckets with your bucket inside. All you need to do is drag this folder into the Create ML app and you’re good to go!</p><p>Thanks for reading! If you have any questions, feel free to reach out atbourdakos1@gmail.com, connect with me on <a href="https://www.linkedin.com/in/nicholasbourdakos">LinkedIn</a>, or follow me on <a href="https://medium.com/@bourdakos1">Medium</a> and <a href="https://twitter.com/bourdakos1">Twitter</a>.</p><p>If you found this article helpful, it would mean a lot if you gave it some applause👏 and shared to help others find it! And feel free to leave a comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82043957b5cb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/how-to-label-data-create-ml-for-object-detection-82043957b5cb">How to Label Data — Create ML for Object Detection</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TensorFlow.js — Real-Time Object Detection in 10 Lines of Code]]></title>
            <link>https://medium.com/hackernoon/tensorflow-js-real-time-object-detection-in-10-lines-of-code-baf15dfb95b2?source=rss-154a0d2814f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/baf15dfb95b2</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Nick Bourdakos]]></dc:creator>
            <pubDate>Mon, 10 Dec 2018 15:31:00 GMT</pubDate>
            <atom:updated>2018-12-11T01:09:17.955Z</atom:updated>
            <content:encoded><![CDATA[<h3>TensorFlow.js — Real-Time Object Detection in 10 Lines of Code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_ptBWjaV6FgVPgOYd5UZVg.png" /></figure><p>In my <a href="https://hackernoon.com/start-using-tensorflow-js-without-leaving-this-article-fb683ac509ed">last article</a> I showed you how to do image classification in the browser.</p><p>Image classification can be a very useful tool, it can give us an idea of what’s in an image. However, sometimes we want more. It can be a little counterintuitive, but just because a machine learning model can tell what’s in an image, doesn’t mean it can tell us where it is in the image. We need a different architecture for that.</p><p>That’s where object detection comes into play.</p><p>Object detection opens up the capability of counting how many objects are in a scene, tracking motion and simply just locating an object’s position.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y40V8ZZ9T_XI-eGQulwIRQ.png" /></figure><p>By the end of this tutorial we’ll have a fully functional real-time object detection web app that will track objects via our webcam.</p><h3>Detecting Objects</h3><p>To make object detection predictions, all we need to do is import the TensorFlow model, <a href="https://github.com/tensorflow/tfjs-models/tree/master/coco-ssd">coco-ssd</a>, which can be installed with a package manager like NPM or simply imported in a &lt;script&gt; tag. We can then load the model, and make a prediction.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74f4eeb10084bf2ad7119016abe84f77/href">https://medium.com/media/74f4eeb10084bf2ad7119016abe84f77/href</a></iframe><blockquote><strong>Note:</strong> Loading the model can take several seconds. It is best to load the model once and save a reference to it.</blockquote><p>The image we pass into the detection function is just a reference to the html &lt;img&gt; tag:</p><pre>&lt;img id=&quot;image&quot; src=&quot;image_url&quot;&gt;</pre><p>After we get our prediction, we need a way to display it to the screen. Our prediction response will be a list of bounding boxes and their confidence scores. It should look something like this:</p><pre>[{<br>  bbox: [x, y, width, height],<br>  class: &quot;cat&quot;,<br>  score: 0.8380282521247864<br>}]</pre><p>To draw the bounding boxes we are going to take advantage of a &lt;canvas&gt; element:</p><pre>&lt;canvas id=&quot;canvas&quot;&gt;</pre><p>The canvas element allows us to use the strokeRect function, which maps perfectly with our prediction results:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/372ce702b11ab2b701a191715e559252/href">https://medium.com/media/372ce702b11ab2b701a191715e559252/href</a></iframe><h3>Simple Detection Demo</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2F1rk9k7lmmq%3Fautoresize%3D1%26hidenavigation%3D1%26view%3Dpreview&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F1rk9k7lmmq%3Fautoresize%3D1%26hidenavigation%3D1%26view%3Dpreview&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F1rk9k7lmmq%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/afaa13d13a00efd09364c9b88e9ab905/href">https://medium.com/media/afaa13d13a00efd09364c9b88e9ab905/href</a></iframe><h3>Streaming from the Webcam</h3><p>To run real-time detection on a webcam stream is almost as easy as changing from an &lt;img&gt; tag, to a &lt;video&gt; tag …with the simple exception of this giant blob of code to start up the webcam:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da37cde5890682dbbf6f6727c82b9466/href">https://medium.com/media/da37cde5890682dbbf6f6727c82b9466/href</a></iframe><p>We can then just pass our video element to our model for detection. However, this time we are going to call requestAnimationFrame which will call our detection function over and over in an infinite loop as fast as it can, skipping frames when it can’t keep up.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/911716da8bacbf6a88faf9945d9ea231/href">https://medium.com/media/911716da8bacbf6a88faf9945d9ea231/href</a></iframe><h3>Real-Time Detection Demo</h3><p><a href="https://z364noozrm.codesandbox.io/">React App</a></p><blockquote><strong>Note:</strong> You must use Google Chrome or a browser that supports webcam streaming (not Safari).</blockquote><p>Link to the full code: <a href="https://codesandbox.io/s/z364noozrm">https://codesandbox.io/s/z364noozrm</a>.</p><h3>Final Thoughts</h3><p>I’ve been having a lot of fun using TensorFlow.js. They have made it extremely easy to play with machine learning with minimal headache. A similar project would have taken me days, but this only took hours. I think my next project will be to experiment with training some of my own models 🎉</p><p>Thanks for reading! If you have any questions, feel free to reach out at bourdakos1@gmail.com, connect with me on <a href="https://www.linkedin.com/in/nicholasbourdakos">LinkedIn</a>, or follow me on <a href="https://medium.com/@bourdakos1">Medium</a> and <a href="https://twitter.com/bourdakos1">Twitter</a>.</p><p>If you found this article helpful, it would mean a lot if you gave it some applause👏 and shared to help others find it! And feel free to leave a comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=baf15dfb95b2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/tensorflow-js-real-time-object-detection-in-10-lines-of-code-baf15dfb95b2">TensorFlow.js — Real-Time Object Detection in 10 Lines of Code</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Start Using TensorFlow.js — Without Leaving This Article]]></title>
            <link>https://medium.com/hackernoon/start-using-tensorflow-js-without-leaving-this-article-fb683ac509ed?source=rss-154a0d2814f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb683ac509ed</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tensorflowjs]]></category>
            <category><![CDATA[tensorflow]]></category>
            <dc:creator><![CDATA[Nick Bourdakos]]></dc:creator>
            <pubDate>Fri, 07 Dec 2018 11:51:00 GMT</pubDate>
            <atom:updated>2018-12-07T17:33:43.362Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Start Using TensorFlow.js — Without Leaving This Article</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e-SJrzFHC_JzlqpVe0zrWA.png" /></figure><p>One of the largest obstacles for beginners getting experience with artificial intelligence and machine learning can honestly be the setup.</p><p>I’m not going to lie, there are still plenty of days that completely slip away, just trying to get Python, TensorFlow and my GPU to cooperate. Does this make me question my abilities as a competent software engineer? Yes, yes it does.</p><p>I digress.</p><p>So what is TensorFlow.js and how can it help us? From the <a href="https://js.tensorflow.org/">official page</a>, TensorFlow.js is, “A JavaScript library for training and deploying ML models in the browser and on Node.js.”</p><p>What does that mean for us? We can try it out right from this Medium article!</p><h3>The Demo</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fo4l6pnlkzz%3Fautoresize%3D1%26hidenavigation%3D1%26view%3Dpreview&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fo4l6pnlkzz%3Fautoresize%3D1%26hidenavigation%3D1%26view%3Dpreview&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fo4l6pnlkzz%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/da56293a024508102e9c1b92fa4b7de5/href">https://medium.com/media/da56293a024508102e9c1b92fa4b7de5/href</a></iframe><p>In this demo we are using a deep learning model called “MobileNet”. MobileNet is a type of Convolution Neural Network, a model architecture that is good at image classification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y40V8ZZ9T_XI-eGQulwIRQ.png" /></figure><blockquote><strong>Note:</strong> To learn more about what artificial intelligence actually sees, check out my <a href="https://hackernoon.com/understanding-what-artificial-intelligence-actually-sees-7d4e5b9e648e">other article</a>.</blockquote><h3>The Code</h3><p>Using TensorFlow.js to classify an image with MobileNet is as easy as 3 lines of code:</p><pre>mobilenet.load()<br>  .then(model =&gt; model.classify(myImage))<br>  .then(predictions =&gt; // Use predictions)</pre><h3>Final Thoughts</h3><p>At the time of writing this post TensorFlow provides 5 official models, that are just as easy to use:</p><ul><li><a href="https://github.com/tensorflow/tfjs-models/tree/master/mobilenet">mobilenet</a>: Classify images with labels from the <a href="http://www.image-net.org/">ImageNet database</a>.</li><li><a href="https://github.com/tensorflow/tfjs-models/tree/master/posenet">posenet</a>: Realtime pose detection. Blog post <a href="https://medium.com/tensorflow/real-time-human-pose-estimation-in-the-browser-with-tensorflow-js-7dd0bc881cd5">here</a>.</li><li><a href="https://github.com/tensorflow/tfjs-models/tree/master/coco-ssd">coco-ssd</a>: Object detection based on the <a href="https://github.com/tensorflow/models/blob/master/research/object_detection/README.md">TensorFlow object detection API</a>.</li><li>s<a href="https://github.com/tensorflow/tfjs-models/tree/master/speech-commands">peech-commands</a>: Classify 1 second audio snippets from the <a href="https://www.tensorflow.org/tutorials/sequences/audio_recognition">speech commands dataset</a>.</li><li><a href="https://github.com/tensorflow/tfjs-models/tree/master/knn-classifier">knn-classifier</a>: Create a custom k-nearest neighbors classifier. Can be used for transfer learning.</li></ul><p>However, if none of these models suffice, you can also create/train your own, but that’s for another article.</p><p>For fun, I challenge you to look at the PoseNet documentation and try to match the results of the cover photo. But, if you get stuck here’s the code and demo:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fkkjxyq9q8v%3Fautoresize%3D1%26hidenavigation%3D1&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fkkjxyq9q8v%3Fautoresize%3D1%26hidenavigation%3D1&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fkkjxyq9q8v%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/64c8906489f1d95be230b67ee725f8e7/href">https://medium.com/media/64c8906489f1d95be230b67ee725f8e7/href</a></iframe><p>Thanks for reading! If you have any questions, feel free to reach out at bourdakos1@gmail.com, connect with me on <a href="https://www.linkedin.com/in/nicholasbourdakos">LinkedIn</a>, or follow me on <a href="https://medium.com/@bourdakos1">Medium</a> and <a href="https://twitter.com/bourdakos1">Twitter</a>.</p><p>If you found this article helpful, it would mean a lot if you gave it some applause👏 and shared to help others find it! And feel free to leave a comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb683ac509ed" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/start-using-tensorflow-js-without-leaving-this-article-fb683ac509ed">Start Using TensorFlow.js — Without Leaving This Article</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding What Artificial Intelligence Actually Sees]]></title>
            <link>https://medium.com/hackernoon/understanding-what-artificial-intelligence-actually-sees-7d4e5b9e648e?source=rss-154a0d2814f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d4e5b9e648e</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[what-ai-sees]]></category>
            <category><![CDATA[ai-comprehension]]></category>
            <category><![CDATA[understanding-ai]]></category>
            <category><![CDATA[ai-sees]]></category>
            <dc:creator><![CDATA[Nick Bourdakos]]></dc:creator>
            <pubDate>Thu, 23 Aug 2018 12:41:01 GMT</pubDate>
            <atom:updated>2018-08-23T16:28:35.782Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OWAn3Bc4zLjiqA1Txydzow.png" /></figure><p>Many call artificial intelligence (AI) a “black box”, and it kinda is. One of the biggest problems of AI is that it’s incredibly difficult to understand how the data is being interpreted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/371/1*UKIHA2AHtB9WPG-KrfwSZg.png" /></figure><p>Before we get our hands dirty and dive deeper, let’s play a little game.</p><p>I’m going to show you a series of abstract images that are either in category <strong>A</strong> or <strong>B</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Do9IeSmv13KwrLOqcE7bgA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pUy5FyYeKrCfhi0MWDhesQ.png" /></figure><h4>Do you think the following image belongs to category A or B?</h4><blockquote><strong>Hint:</strong> There’s no <strong>C</strong>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LRj2uBTUDjoBtp1BqyWEBA.png" /></figure><p>We’ll get back to this later.</p><h4>Let’s look at some more examples first.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CvOwaj30g4-0yuX_Q1quHw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7eqS3UJDjveUi6MBgq_vmw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Ssj7OpH6ayqo2DKKN-psQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*458aebaCIpOrVP1qa8QMdA.png" /></figure><h4>Now can you tell if it belongs to A or B?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3f4S7ykfM5k1o53Y4c-kjg.png" /></figure><h3>⚠️ Spoiler Alert</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LjVo6ZQLPfd49c8kqt_MSg.png" /></figure><h3>The answer is… A!</h3><p>If you choose <strong>B</strong>, don’t be embarassed,<strong> </strong>you’re not alone. When asked to a room full of engineers and developers, the split is always 50/50. So… why is the answer <strong>A</strong>…?</p><p>Because I said so.</p><p>The answer is <strong>A</strong>, there’s no debating it, but if you don’t agree with me, then it was my fault as the trainer.</p><p>As the trainer, I know that <strong>A</strong> is a red circle. So anything with a red circle in it is <strong>A</strong>. I also know that <strong>B</strong> is an orange circle. The rest of the image is irrelevant. It’s all about trying to find a pattern between the set of images.</p><p>But it’s hard.</p><p>In an AI system, I can’t explain with words what makes the image <strong>A</strong>. All I can do is show you more pictures and hope it starts to click.</p><p>And you, the AI, can’t tell me why you think it’s <strong>B</strong>. It’s up to me to blindly feed you data until you get the answer right.</p><p>Here’s the same set of images, but less abstract. If I were to ask you the same question, everyone would know right away that <strong>A</strong> is an apple and <strong>B</strong> is an orange. This is almost so easy that many people think it’s a trick question. We all know that the hand and background are all irrelevant information, because we’re humans and grew up learning these things, but for AI it’s not a given. It sees images as more abstract and doesn’t know what you want it to focus on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZYPGUk6uNm4osNlCIN24tg.png" /></figure><h3>A Miscommunication</h3><p>Let’s take a look at another toy scenario that shows how we might accidentally communicate the wrong signals to the AI system.</p><p>We have a few samples of oak trees. <em>(It’s a bit cloudy where I live)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YEtPZqRtRJHgdnks9DNnZQ.png" /></figure><p>Here are some palm trees. <em>(It was really sunny on the beach)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h4Av0iMebTiyOoS8icmKHA.png" /></figure><p>This next example is a palm tree, but the lighting is much closer to the oak trees. Which pattern should we focus on? The lighting? Or the shape of the tree? It might be difficult for the model to tell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sy9_UT98ulQd3Pm0eZ3j_A.png" /></figure><pre><strong>Confidence:<br></strong> - Palm 0.75<br> - Oak 0.60</pre><p>With this example, it might be pretty obvious that we left behind an unintended pattern for the AI to pick up. However, in reality, it’s normally something much more inconspicuous.</p><h3>Peeking Under the Curtain</h3><p>So how can we get more insight into what the AI is focussing on?</p><p>What if we passed a rectangle over the image and recorded the changes in confidence? If the confidence drops, then that’s probably an important part of the image.</p><p>Which picture makes it easier to tell that this cable is a USB?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pYc1nKWwmR4LIsKklquCEg.png" /></figure><p>The first image completely obscures the connector, making it nearly impossible to guess, so we can denote the region the rectangle covers as important. However, the rectangle in the second image doesn’t hinder our ability to determine the cable type. We can safely mark the location as insignificant.</p><p>We can continue to pass the rectangle over image to establish a heat map of importance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0iGac83E3GDXgnrZl5RiDA.png" /></figure><p>We can see that the model’s focus is on the tip of the connector, which is great. It’s looking where we want it to.</p><p>Let’s look at a model that wasn’t trained well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*trq2OQDjVGnYQIGEPqDSlQ.png" /></figure><pre><strong>Confidence:<br></strong> - USB 0.76</pre><p>The model correctly predicted that the cable was a USB with a confidence of 0.76. We might say that’s acceptable, especially since the photo is far away and isn’t great quality.</p><p>However, upon closer inspection, the model seems to be focusing on the wrong area, not the ends of the cable like we would expect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4SdDDB-_qq0L2Jdsy2S5WQ.png" /></figure><p>What does this tell us?</p><p>The model appears to rely too heavily on the wire and fingers. To improve accuracy and clear up the confusion, we can include more examples of wire and hands in a negative training set.</p><p>We don’t need to train on piles and piles of generic data until our model starts performing better. We can tactfully use this information as an aid in retraining the model, saving us time and money.</p><h3>Using the Tool</h3><blockquote>Wow! This is great, but I don’t want to put in the effort to actually implement this</blockquote><p>Good news! You can find the fully functional iOS app on my <a href="https://github.com/bourdakos1/visual-recognition-with-coreml">GitHub</a> 😘</p><h3>Final Thoughts</h3><p>Creating your own model is easy, but that doesn’t mean the work stops there. The hardest part of machine learning is always producing good data.</p><p>We can use the basic guidelines of having similar pose, lighting and a consistent mix of stock and natural photos across our training images to gain a foothold in our quest toward a good model. After that, we are left using tools and our intuition to try and gain insight into the thought process of AI.</p><p>Thanks for reading! If you have any questions, feel free to reach out at bourdakos1@gmail.com, connect with me on <a href="https://www.linkedin.com/in/nicholasbourdakos">LinkedIn</a>, or follow me on <a href="https://medium.com/@bourdakos1">Medium</a> and <a href="https://twitter.com/bourdakos1">Twitter</a>.</p><p>If you found this article helpful, it would mean a lot if you gave it some applause👏 and shared to help others find it! And feel free to leave a comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d4e5b9e648e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/understanding-what-artificial-intelligence-actually-sees-7d4e5b9e648e">Understanding What Artificial Intelligence Actually Sees</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simplify Adding AI to Your Apps — Core ML Say Hello to Watson]]></title>
            <link>https://medium.com/hackernoon/simplify-adding-ai-to-your-apps-core-ml-say-hello-to-watson-c4dfebf66802?source=rss-154a0d2814f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4dfebf66802</guid>
            <category><![CDATA[watson]]></category>
            <category><![CDATA[add-watson-to-apps]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[adding-ai-to-your-apps]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Nick Bourdakos]]></dc:creator>
            <pubDate>Thu, 22 Mar 2018 19:57:52 GMT</pubDate>
            <atom:updated>2018-06-25T11:35:15.399Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t6EqUdfaRTlJdUp43YHV8w.gif" /></figure><p>IBM Watson just announced the ability to run Visual Recognition models locally on iOS as Core ML models. I’m very excited.</p><p>Before now, it was fairly easy to integrate a visual recognition system into your iOS app by just downloading a model from Apple. However, the models you can use are very cookie cutter and specific to a standard set of items that it can recognize (cars, people, animals, fruit, etc).</p><p>But what if you wanted to have a model that could recognize items for a use case specific to you?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UYly-jwkRNRZzXcPTraEbg.png" /></figure><p>Before now, if you wanted to do this and you weren’t familiar with the ins and outs of AI, this could be a fairly difficult task. You would need to familiarize yourself with a machine learning framework such as TensorFlow, Caffe, or Keras. However, with Watson we can train our own custom model without having to touch any code.</p><h4><strong>Before</strong>, if you trained a model with Watson</h4><ul><li>It was stuck in the cloud</li><li>You needed an internet connection to access it</li><li>You were charged to use it</li></ul><h4><strong>Now</strong></h4><ul><li>You can download your model as a Core ML model</li><li>You can use it locally like any other Core ML model</li><li>No strings attached</li></ul><h3>Collecting Data</h3><p>To build a custom model we need to collect data to train it on. If we want to train our model on different brands of shoes we need to collect a bunch of pictures of each brand.</p><p>I went ahead and downloaded from Google:</p><ul><li>100 pictures of Nike shoes</li><li>100 pictures of Adidas shoes</li><li>100 pictures of New Balance shoes</li></ul><p>This is a very lazy approach to collecting data. It won’t produce great results unless our use case happens to be classifying Google image search results. A much better approach (given this is for an iOS app) is to take pictures of the different shoes with your iPhone camera. However, I only happen to own 2 pairs of shoes and they both fall into the category of “Nike”.</p><p>We do what we can 🤷‍♂️</p><blockquote><strong>Note:</strong> As expected the model didn’t work as well as I wanted, so I ended up just using 10 pictures of my Nikes, 10 pics of my dad’s New Balances and 10 pics of my friend’s Adidas shoes (instead of the Google photos).</blockquote><p>After you collect your image data, we need each category to be zipped up in its own .zip file.</p><h3>Getting Started with Watson</h3><p>To use Watson we need to create an <a href="https://datascience.ibm.com/">IBM Watson Studio</a> account. Sign in or sign up and then make your way to the main page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YMNHylkMHGV9DzEXxP-3AQ.png" /></figure><blockquote><strong>Note:</strong> If you don’t see New project, Refine data, New notebook, etc... Click the Get started dropdown in the top right corner.</blockquote><p>Click on New project and then select Visual Recognition:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fsFoDEc6eQE5DzUfd3PSfg.png" /></figure><p>Give your project a name and continue:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6cYOiTOm-O-2f27cshvhdA.png" /></figure><p>Browse for your .zip files that you created:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*slDWw2WXlAphA6aS9SaUUw.png" /></figure><p>Then add them to the model by clicking the 3-dot menu and choosing Add to model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PHIZybdhedhpGs-WteDn4A.png" /></figure><p>Then click to train the model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3f1IGpF_a9v3wyDt3K79HA.png" /></figure><h3>Downloading the Core ML Model</h3><p>Once the model finishes training you will be greeted with a small notification. Click to view and test the model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r-ReFkHWe5Df7aSvN3jGdw.png" /></figure><p>That will bring you to the page that will allow you to download the model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7B7ZfY7NHnPykTlHtiNMbQ.png" /></figure><p>Choose Implementation followed by Core ML. Then download the model file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GvgTgz2QZ5So0j68-PM-AQ.png" /></figure><blockquote><strong>Important Note:</strong> Safari downloads the file with a.dms extension. Just rename it to have a .mlmodel extension.</blockquote><h3>Running the App</h3><p>For the simplicity of this post I’m going to assume that you have a working knownledge of Xcode 😬</p><p>I built a sample app that you can <a href="https://github.com/bourdakos1/Watson-CoreML">clone from my GitHub</a>.</p><p>All you need to do is open up the project. Import your Core ML model file that you downloaded. Followed by changing the name of the model to match yours in the CameraViewController file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CSenOZvaTntUkkPgF7p6OA.png" /></figure><blockquote><strong>Update:</strong> After writing this, I found out about the <a href="https://github.com/watson-developer-cloud/swift-sdk">Watson Swift SDK</a>. It makes it extremely easy to make classifications as well as download any updates to your model after retraining.</blockquote><h4>Classify</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13263730b7e9a1ff04b7d854113852bb/href">https://medium.com/media/13263730b7e9a1ff04b7d854113852bb/href</a></iframe><h4>Update Local Model</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8baf5f473d0670001fdee3e5c030bd53/href">https://medium.com/media/8baf5f473d0670001fdee3e5c030bd53/href</a></iframe><p>That’s all! You should be able to run the app, take pictures and get classifications back (please excuse my extremely dirty shoes):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dZnMUREkOF_lF63Xkq6SlQ.png" /></figure><h3>Final Thoughts</h3><p>I know I work for IBM, but hopefully I’m not the only one excited about this 😝 I’ve been waiting for the ability to run my custom Watson models locally for a while now. No more need for an internet connection and the models run fast no matter where you are.</p><p>Thanks for reading! If you have any questions, feel free to reach out at bourdakos1@gmail.com, connect with me on <a href="https://www.linkedin.com/in/nicholasbourdakos">LinkedIn</a>, or follow me on <a href="https://medium.com/@bourdakos1">Medium</a> and <a href="https://twitter.com/bourdakos1">Twitter</a>.</p><p>If you found this article helpful, it would mean a lot if you gave it some applause👏 and shared to help others find it! And feel free to leave a comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4dfebf66802" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/simplify-adding-ai-to-your-apps-core-ml-say-hello-to-watson-c4dfebf66802">Simplify Adding AI to Your Apps — Core ML Say Hello to Watson</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Train Your Machine Learning Models on Google’s GPUs for Free — Forever]]></title>
            <link>https://medium.com/hackernoon/train-your-machine-learning-models-on-googles-gpus-for-free-forever-a41bd309d6ad?source=rss-154a0d2814f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/a41bd309d6ad</guid>
            <category><![CDATA[machine-learning-models]]></category>
            <category><![CDATA[google-gpus]]></category>
            <category><![CDATA[mls]]></category>
            <category><![CDATA[gpu]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Nick Bourdakos]]></dc:creator>
            <pubDate>Mon, 05 Mar 2018 16:56:31 GMT</pubDate>
            <atom:updated>2018-06-25T11:36:42.306Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TPbqOiq2kgue8tw6aDfbyg.png" /></figure><p>Training your model is hands down the most time consuming and expensive part of machine learning. Training your model on a GPU can give you speed gains close to 40x, taking 2 days and turning it into a few hours. However, this normally comes at a cost to your wallet.</p><p>The other day I stumbled upon a great tool called Google Colab. I would describe Colab as the google docs equivalent of Jupyter notebooks. Colab is aimed at being an education and research tool for collaborating on machine learning projects. The great part is, that it’s completely <strong>free forever</strong>.</p><p>There is no setup to use it. I didn’t even need to log in. <em>(I was already logged into my google account)</em></p><p>The best part is that you get an unlimited supply of 12 hours of continuous access to a k80 GPU, which is pretty powerful stuff. <em>(You get disconnected after 12 hours, but you can use it as many times as you want)</em></p><p>I want our focus to be training on a GPU and Colab specific so the notebook is extremely bare bones.</p><p>The first step is to download <a href="https://gist.github.com/bourdakos1/817611ebfe0d72a027ced9b072ec5c87">the notebook</a> <em>(or another notebook of your choice)</em></p><p>Then, head over to <a href="http://g.co/colab">Google Colab</a>, sign into your google account <em>(or create one if you somehow made it this far through life without one)</em></p><p>Choose File &gt; Upload notebook...:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uF7gN3uSyv2TvnzKSxs7fg.png" /></figure><p>Upload the notebook you downloaded:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YbXpDHYZzzpm_bsMCxBeJg.png" /></figure><p>Choose Runtime &gt; Change runtime type:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G3DCACq2yyL_0Snmb8-2-Q.png" /></figure><p>Then choose GPU:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wVFF1CR3Ep53vVpW04zw4Q.png" /></figure><p>Now you should be able to run your notebooks how you normally would. The only difference is the very last part at the end. If you want to download your model or any other files via the browser, you can use their python library:</p><pre>from google.colab import files<br>files.download(&quot;PATH/TO/FILE&quot;)</pre><h3>Final Thoughts</h3><p>This was a pretty short post, but hopefully it ends the painful days of training your models on your poor little old laptop for days at a time or dropping a ton of 💰 on AWS bills.</p><p>Thanks for reading! If you have any questions, feel free to reach out at bourdakos1@gmail.com, connect with me on <a href="https://www.linkedin.com/in/nicholasbourdakos">LinkedIn</a>, or follow me on <a href="https://medium.com/@bourdakos1">Medium</a> and <a href="https://twitter.com/bourdakos1">Twitter</a>.</p><p>If you found this article helpful, it would mean a lot if you gave it some applause👏 and shared to help others find it! And feel free to leave a comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a41bd309d6ad" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/train-your-machine-learning-models-on-googles-gpus-for-free-forever-a41bd309d6ad">Train Your Machine Learning Models on Google’s GPUs for Free — Forever</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Capsule Networks — AI’s Alluring New Architecture]]></title>
            <link>https://medium.com/free-code-camp/understanding-capsule-networks-ais-alluring-new-architecture-bdb228173ddc?source=rss-154a0d2814f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdb228173ddc</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Nick Bourdakos]]></dc:creator>
            <pubDate>Mon, 12 Feb 2018 09:22:41 GMT</pubDate>
            <atom:updated>2018-06-25T11:37:27.877Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*e2Y2V1vCy6oo5Of7x0guUA.jpeg" /><figcaption>“<a href="https://www.instagram.com/p/BaIocBQl-H_/?taken-by=areynolds_illo">Science</a>” by <a href="https://alex-reynolds-art.squarespace.com/">Alex Reynolds</a></figcaption></figure><p>Convolutional neural networks have done an amazing job, but are rooted in problems. It’s time we started thinking about new solutions or improvements — and now, enter capsules.</p><p>Previously, I briefly discussed how <a href="https://hackernoon.com/capsule-networks-are-shaking-up-ai-heres-how-to-use-them-c233a0971952">capsule networks</a> combat some of these traditional problems. For the past for few months, I’ve been submerging myself in all things capsules. I think it’s time we all try to get a deeper understanding of how capsules actually work.</p><p>In order to make it easier to follow along, I have built a visualization tool that allows you to see what is happening at each layer. This is paired with a simple implementation of the network. All of it can be found on GitHub <a href="https://github.com/bourdakos1/CapsNet-Visualization">here</a>.</p><p>This is the CapsNet architecture. Don’t worry if you don’t understand what any of it means yet. I’ll be going through it layer by layer, with as much detail as I can possibly conjure up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aJhYGZZPYF44UZMfFpKkfw.png" /></figure><h3>Part 0: The Input</h3><p>The input into CapsNet is the actual image supplied to the neural net. In this example the input image is 28 pixels high and 28 pixels wide. But images are actually 3 dimensions, and the 3rd dimension contains the color channels.</p><p>The image in our example only has one color channel, because it’s black and white. Most images you are familiar with have 3 or 4 channels, for Red-Green-Blue and possibly an additional channel for Alpha, or transparency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T3vqz3rtDe7IPK8wR4WyeA.png" /></figure><p>Each one of these pixels is represented as a value from 0 to 255 and stored in a 28x28x1 matrix [28, 28, 1]. The brighter the pixel, the larger the value.</p><h3>Part 1a: Convolutions</h3><p>The first part of CapsNet is a traditional convolutional layer. What is a convolutional layer, how does it work, and what is its purpose?</p><p>The goal is to extract some extremely basic features from the input image, like edges or curves.</p><p>How can we do this?</p><p>Let’s think about an edge:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DYDazXcJlCLSxhSTzq4srA.png" /></figure><p>If we look at a few points on the image, we can start to pick up a pattern. Focus on the colors to the left and right of the point we are looking at:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n41sCJbM5iCq2kRCDGnt7A.png" /></figure><p>You might notice that they have a larger difference if the point is an edge:</p><pre>255 - 114 = 141<br>114 - 153 = -39<br>153 - 153 = 0<br>255 - 255 = 0</pre><p>What if we went through each pixel in the image and replaced its value with the value of the difference of the pixels to the left and right of it? In theory, the image should become all black except for the edges.</p><p>We could do this by looping through every pixel in the image:</p><pre>for pixel in image {<br>  result[pixel] = image[pixel - 1] - image[pixel + 1]<br>}</pre><p>But this isn’t very efficient. We can instead use something called a “convolution.” Technically speaking, it’s a “cross-correlation,” but everyone likes to call them convolutions.</p><p>A convolution is essentially doing the same thing as our loop, but it takes advantage of matrix math.</p><p>A convolution is done by lining up a small “window” in the corner of the image that only lets us see the pixels in that area. We then slide the window across all the pixels in the image, multiplying each pixel by a set of weights and then adding up all the values that are in that window.</p><p>This window is a matrix of weights, called a “kernel.”</p><p>We only care about 2 pixels, but when we wrap the window around them it will encapsulate the pixel between them.</p><pre>Window:<br>┌─────────────────────────────────────┐<br>│ left_pixel middle_pixel right_pixel │<br>└─────────────────────────────────────┘</pre><p>Can you think of a set of weights that we can multiply these pixels by so that their sum adds up to the value we are looking for?</p><pre>Window:<br>┌─────────────────────────────────────┐<br>│ left_pixel middle_pixel right_pixel │<br>└─────────────────────────────────────┘</pre><pre>(w1 * 255) + (w2 * 255) + (w3 * 114) = 141</pre><p><strong>Spoilers below!</strong></p><pre> │            │            │<br> │            │            │<br> │            │            │<br> │            │            │<br> │            │            │<br>\│/          \│/          \│/<br> V            V            V</pre><p>We can do something like this:</p><pre>Window:<br>┌─────────────────────────────────────┐<br>│ left_pixel middle_pixel right_pixel │<br>└─────────────────────────────────────┘</pre><pre>(1 * 255) + (0 * 255) + (-1 * 114) = 141</pre><p>With these weights, our kernel will look like this:</p><pre>kernel = [1  0 -1]</pre><p>However, kernels are generally square — so we can pad it with more zeros to look like this:</p><pre>kernel = [<br>  [0  0  0]<br>  [1  0 -1]<br>  [0  0  0]<br>]</pre><p>Here’s a nice gif to see a convolution in action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ss2pdokfkcyi2UWliwABdg.gif" /></figure><p><strong>Note:</strong> The dimension of the output is reduced by the size of the kernel plus 1. For example:(7 — 3) + 1 = 5 (more on this in the next section)</p><p>Here’s what the original image looks like after doing a convolution with the kernel we crafted:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A44IfEqTIDxO1AS-T8tYLg.png" /></figure><p>You might notice that a couple edges are missing. Specifically, the horizontal ones. In order to highlight those, we would need another kernel that looks at pixels above and below. Like this:</p><pre>kernel = [<br>  [0  1  0]<br>  [0  0  0]<br>  [0 -1  0]<br>]</pre><p>Also, both of these kernels won’t work well with edges of other angles or edges that are blurred. For that reason, we use many kernels (in our CapsNet implementation, we use 256 kernels). And the kernels are normally larger to allow for more wiggle room (our kernels will be 9x9).</p><p>This is what one of the kernels looked like after training the model. It’s not very obvious, but this is just a larger version of our edge detector that is more robust and only finds edges that go from bright to dark.</p><pre>kernel = [<br>  [ 0.02 -0.01  0.01 -0.05 -0.08 -0.14 -0.16 -0.22 -0.02]<br>  [ 0.01  0.02  0.03  0.02  0.00 -0.06 -0.14 -0.28  0.03]<br>  [ 0.03  0.01  0.02  0.01  0.03  0.01 -0.11 -0.22 -0.08]<br>  [ 0.03 -0.01 -0.02  0.01  0.04  0.07 -0.11 -0.24 -0.05]<br>  [-0.01 -0.02 -0.02  0.01  0.06  0.12 -0.13 -0.31  0.04]<br>  [-0.05 -0.02  0.00  0.05  0.08  0.14 -0.17 -0.29  0.08]<br>  [-0.06  0.02  0.00  0.07  0.07  0.04 -0.18 -0.10  0.05]<br>  [-0.06  0.01  0.04  0.05  0.03 -0.01 -0.10 -0.07  0.00]<br>  [-0.04  0.00  0.04  0.05  0.02 -0.04 -0.02 -0.05  0.04]<br>]</pre><p><strong>Note:</strong> I’ve rounded the values because they are quite large, for example 0.01783941</p><p>Luckily, we don’t have to hand-pick this collection of kernels. That is what training does. The kernels all start off empty (or in a random state) and keep getting tweaked in the direction that makes the output closer to what we want.</p><p>This is what the 256 kernels ended up looking like (I colored them as pixels so it’s easier to digest). The more negative the numbers, the bluer they are. 0 is green and positive is yellow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ulHrj-TQ2WnlJUckRvwU2A.png" /><figcaption>256 kernels (9x9)</figcaption></figure><p>After we filter the image with all of these kernels, we end up with a fat stack of 256 output images.</p><h3>Part 1b: ReLU</h3><p>ReLU (formally known as Rectified Linear Unit) may sound complicated, but it’s actually quite simple. ReLU is an activation function that takes in a value. If it’s negative it becomes zero, and if it’s positive it stays the same.</p><p>In code:</p><pre>x = max(0, x)</pre><p>And as a graph:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mCZ45vgOYz9cMpucLNfLqw.png" /></figure><p>We apply this function to all of the outputs of our convolutions.</p><p>Why do we do this? If we don’t apply some sort of activation function to the output of our layers, then the entire neural net could be described as a linear function. This would mean that all this stuff we are doing is kind of pointless.</p><p>Adding a non-linearity allows us to describe all kinds of functions. There are many different types of function we could apply, but ReLU is the most popular because it’s very cheap to perform.</p><p>Here are the outputs of ReLU Conv1 layer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OtJFxSNxJnA4aN5o4nPAfQ.png" /><figcaption>256 outputs (20x20 pixels)</figcaption></figure><h3>Part 2a: PrimaryCaps</h3><p>The PrimaryCaps layer starts off as a normal convolution layer, but this time we are convolving over the stack of 256 outputs from the previous convolutions. So instead of having a 9x9 kernel, we have a 9x9x256 kernel.</p><p>So what exactly are we looking for?</p><p>In the first layer of convolutions we were looking for simple edges and curves. Now we are looking for slightly more complex shapes from the edges we found earlier.</p><p>This time our “stride” is 2. That means instead of moving 1 pixel at a time, we take steps of 2. A larger stride is chosen so that we can reduce the size of our input more rapidly:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x30MdjS0wvNSfHj1FiwzHw.gif" /></figure><p><strong>Note:</strong> The dimension of the output would normally be 12, but we divide it by 2, because of the stride. For example: <em>((20 — 9) + 1) / 2 = 6</em></p><p>We will convolve over the outputs another 256 times. So we will end up with a stack of 256 6x6 outputs.</p><p>But this time we aren’t satisfied with just some lousy plain old numbers.</p><p>We’re going to cut the stack up into 32 decks with 8 cards each deck.</p><p>We can call this deck a “capsule layer.”</p><p>Each capsule layer has 36 “capsules.”</p><p>If you’re keeping up (and are a math wiz), that means each capsule has an array of 8 values. This is what we can call a “vector.”</p><p>Here’s what I’m talking about:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M-QjswVLOTkiJEWd2Z1jug.png" /></figure><p>These “capsules” are our new pixel.</p><p>With a single pixel, we could only store the confidence of whether or not we found an edge in that spot. The higher the number, the higher the confidence.</p><p>With a capsule we can store 8 values per location! That gives us the opportunity to store more information than just whether or not we found a shape in that spot. But what other kinds of information would we want to store?</p><p>When looking at the shape below, what can you tell me about it? If you had to tell someone else how to redraw it, and they couldn’t look at it, what would you say?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WBPjVxIPZYogcHpHp-gm-A.png" /></figure><p>This image is extremely basic, so there are only a few details we need to describe the shape:</p><ul><li>Type of shape</li><li>Position</li><li>Rotation</li><li>Color</li><li>Size</li></ul><p>We can call these “instantiation parameters.” With more complex images we will end up needing more details. They can include pose (position, size, orientation), deformation, velocity, albedo, hue, texture, and so on.</p><p>You might remember that when we made a kernel for edge detection, it only worked on a specific angle. We needed a kernel for each angle. We could get away with it when dealing with edges because there are very few ways to describe an edge. Once we get up to the level of shapes, we don’t want to have a kernel for every angle of rectangles, ovals, triangles, and so on. It would get unwieldy, and would become even worse when dealing with more complicated shapes that have 3 dimensional rotations and features like lighting.</p><p>That’s one of the reasons why traditional neural nets don’t handle unseen rotations very well:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9vaI2xlYUsJ4hs-kbVUzIg.png" /></figure><p>As we go from edges to shapes and from shapes to objects, it would be nice if we had more room to store this extra useful information.</p><p>Here is a simplified comparison of 2 capsule layers (one for rectangles and the other for triangles) vs 2 traditional pixel outputs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_cihxGGVPmn7G_hFH9ZNvQ.png" /></figure><p>Like a traditional 2D or 3D vector, this vector has an angle and a length. The length describes the probability, and the angle describes the instantiation parameters. In the example above, the angle actually matches the angle of the shape, but that’s not normally the case.</p><p>In reality it’s not really feasible (or at least easy) to visualize the vectors like above, because these vectors are 8 dimensional.</p><p>Since we have all this extra information in a capsule, the idea is that we should be able to recreate the image from them.</p><p>Sounds great, but how do we coax the network into actually wanting to learn these things?</p><p>When training a traditional CNN, we only care about whether or not the model predicts the right classification. With a capsule network, we have something called a “reconstruction.” A reconstruction takes the vector we created and tries to recreate the original input image, given only this vector. We then grade the model based on how close the reconstruction matches the original image.</p><p>I will go into more detail on this in the coming sections, but here is a simple example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZhjaKUlfUc2PxciU2PoarA.png" /></figure><h3>Part 2b: Squashing</h3><p>After we have our capsules, we are going to perform another non-linearity function on it (like ReLU), but this time the equation is a bit more involved. The function scales the values of the vector so that only the length of the vector changes, not the angle. This way we can make the vector between 0 and 1 so it’s an actual probability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fRARVY1y1Ih9YKCscBve_g.png" /></figure><p>This is what <strong>lengths</strong> of the capsule vectors look like after squashing. At this point it’s almost impossible to guess what each capsule is looking for.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*APRF1OGeWdTTaV9bJsW4bg.png" /><figcaption>Keep in mind that each pixel is actually a vector of length 8</figcaption></figure><h3>Part 3: Routing by Agreement</h3><p>The next step is to decide what information to send to the next level. In traditional networks, we would probably do something like “max pooling.” Max pooling is a way to reduce size by only passing on the highest activated pixel in the region to the next layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vTHAax_6RB9goxBDFjvb1A.png" /></figure><p>However, with capsule networks we are going to do something called routing by agreement. The best example of this is the boat and house example illustrated by Aurélien Géron in <a href="https://www.youtube.com/watch?v=pPN8d0E3900">this excellent video</a>. Each capsule tries to predict the next layer’s activations based on itself:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KhwYeh3Zlj5ionBuZbBM_A.png" /></figure><p>Looking at these predictions, which object would you choose to pass on to the next layer (not knowing the input)? Probably the boat, right? both the rectangle capsule and the triangle capsule agree on what the boat would look like. But they don’t agree on how the house would look, so it’s not very likely that the object is a house.</p><p>With routing by agreement, we only pass on the useful information and throw away the data that would just add noise to the results. This gives us a much smarter selection than just choosing the largest number, like in max pooling.</p><p>With traditional networks, misplaced features don’t faze it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h-Be4Uj-a7N6_Qx-K03KkQ.png" /></figure><p>With capsule networks, the features wouldn’t agree with each other:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jCK173LT9oddZcNPbJMGxQ.png" /></figure><p>Hopefully, that works intuitively. However, how does the math work?</p><p>We have 10 different digit classes that we are predicting:</p><pre>0, 1, 2, 3, 4, 5, 6, 7, 8, 9</pre><p><strong>Note:</strong> In the boat and house example we were predicting 2 objects, but now we are predicting 10.</p><p>Unlike in the boat and the house example, the predictions aren’t actually images. Instead, we are trying to predict the vector that describes the image.</p><p>The capsule’s predictions for each class are made by multiplying it’s vector by a matrix of weights for each class that we are trying to predict.</p><p>Remember that we have 32 capsule layers, and each capsule layer has 36 capsules. That means we have a total of 1,152 capsules.</p><pre>cap_1 * weight_for_0 = prediction<br>cap_1 * weight_for_1 = prediction<br>cap_1 * weight_for_2 = prediction<br>cap_1 * ...<br>cap_1 * weight_for_9 = prediction</pre><pre>cap_2 * weight_for_0 = prediction<br>cap_2 * weight_for_1 = prediction<br>cap_2 * weight_for_2 = prediction<br>cap_2 * ...<br>cap_2 * weight_for_9 = prediction</pre><pre>...</pre><pre>cap_1152 * weight_for_0 = prediction<br>cap_1152 * weight_for_1 = prediction<br>cap_1152 * weight_for_2 = prediction<br>cap_1152 * ...<br>cap_1152 * weight_for_9 = prediction</pre><p>You will end up with a list of 11,520 predictions.</p><p>Each weight is actually a 16x8 matrix, so each prediction is a matrix multiplication between the capsule vector and this weight matrix:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wnSn7KBxRTbf06niLyyTOw.png" /></figure><p>As you can see, our prediction is a 16 degree vector.</p><p>Where does the 16 come from? It’s an arbitrary choice, just like 8 was for our original capsules.</p><p>But it should be noted that we want to increase the number of dimensions of our capsules the deeper we get into the network. This should make sense intuitively, because the deeper we go the more complex our features become and the more parameters we need to recreate them. For example, you will need more information to describe an entire face than just a person’s eye.</p><p>The next step is to figure out which of these 11,520 predictions agree with each other the most.</p><p>It can be difficult to visualize a solution to this when we think in terms of high dimensional vectors. For the sake of sanity, let’s start off by pretending our vectors are just points in 2 dimensional space:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UcOyTC3gSRjvd2VdqYTv_A.png" /></figure><p>We start off by calculating the mean of all of the points. Each point starts out with equal importance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kq5cJSN5d6XLFhpeBYiDeg.png" /></figure><p>We then can measure the distance between every point from the mean. The further the point is away from the mean, the less important that point becomes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0CCoCPIfVk6gQRA3BEku2g.png" /></figure><p>We then recalculate the mean, this time taking into account the point’s importance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LLll4gxxacai5Ad5c5exEA.png" /></figure><p>We end up going through this cycle 3 times:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xWqit5ktjZhDJiHYGc1kHA.gif" /></figure><p>As you can see, as we go through this cycle, the points that don’t agree with the others start to disappear. The highest agreeing points end up getting passed on to the next layer with the highest activations.</p><h3>Part 4: DigitCaps</h3><p>After agreement, we end up with ten 16 dimensional vectors, one vector for each digit. This matrix is our final prediction. The length of the vector is the confidence of the digit being found — the longer the better. The vector can also be used to generate a reconstruction of the input image.</p><p>This is what the lengths of the vectors look like with the input of 4:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BJ5Wkhl3EDkrHP-zzeJW0A.png" /></figure><p>The fifth block is the brightest, which means high confidence. Remember that 0 is the first class, meaning 4 is our predicted class.</p><h3>Part 5: Reconstruction</h3><p>The reconstruction portion of the implementation isn’t very interesting. It’s just a few fully connected layers. But the reconstruction itself is very cool and fun to play around with.</p><p>If we reconstruct our 4 input from its vector, this is what we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kI3SyoGj-NqGUbvg_lcdlg.png" /></figure><p>If we manipulate the sliders (the vector), we can see how each dimension affects the 4:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t_6wAWja2-9A07g1T22AtA.gif" /></figure><p>I recommend cloning the visualization repo to play around with different inputs and see how the sliders affect the reconstruction:</p><pre>git clone <a href="https://github.com/bourdakos1/CapsNet-Visualization.git">https://github.com/bourdakos1/CapsNet-Visualization.git</a><br>cd CapsNet-Visualization<br>pip install -r requirements.txt</pre><p>Run the tool:</p><pre>python run_visualization.py</pre><p>Then point your browser to: <a href="http://localhost:5000/">http://localhost:5000</a></p><h3>Final Thoughts</h3><p>I think that the reconstructions from capsule networks are stunning. Even though the current model is only trained on simple digits, it makes my mind run with the possibilities that a matured architecture trained on a larger dataset could achieve.</p><p>I’m very curious to see how manipulating the reconstruction vectors of a more complicated image would affect it. For that reason, my next project is to get capsule networks to work with the CIFAR and smallNORB datasets.</p><p>Thanks for reading! If you have any questions, feel free to reach out at bourdakos1@gmail.com, connect with me on <a href="https://www.linkedin.com/in/nicholasbourdakos">LinkedIn</a>, or follow me on <a href="https://medium.com/@bourdakos1">Medium</a> and <a href="https://twitter.com/bourdakos1">Twitter</a>.</p><p>If you found this article helpful, it would mean a lot if you gave it some applause👏 and shared to help others find it! And feel free to leave a comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdb228173ddc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/understanding-capsule-networks-ais-alluring-new-architecture-bdb228173ddc">Understanding Capsule Networks — AI’s Alluring New Architecture</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Detectron — Facebook’s Free Platform for Object Detection]]></title>
            <link>https://medium.com/hackernoon/how-to-use-detectron-facebooks-free-platform-for-object-detection-9d41e170bbcb?source=rss-154a0d2814f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d41e170bbcb</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[detectron]]></category>
            <category><![CDATA[facebook]]></category>
            <category><![CDATA[object-detection]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Nick Bourdakos]]></dc:creator>
            <pubDate>Wed, 24 Jan 2018 21:05:37 GMT</pubDate>
            <atom:updated>2018-06-25T11:38:20.108Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WyTv5S6b8fmOG6aBrZyiHw.jpeg" /></figure><blockquote>“How can I draw a more detailed outline around an object?”</blockquote><p>This is probably one of the most frequently asked questions I get after someone reads my <a href="https://medium.freecodecamp.org/tracking-the-millenium-falcon-with-tensorflow-c8c86419225e">previous article</a> on how to do object detection using TensorFlow. There is good news, I finally have the answer.</p><p>Facebook AI Research (FAIR) just open sourced their <a href="https://github.com/facebookresearch/Detectron">Detectron</a> platform. This means that the software that FAIR uses for object detection research is now available to all of us developers. One of the many things that this new platform can do is object masking. Object masking takes objected detection a step further and instead of just drawing a bounding box around the image, it can actually draw a complex polygon.</p><p>Detectron makes it incredibly simple to get object masking running out of the box. Here’s how:</p><h3>Install Caffe2</h3><p>The first step is to install <a href="https://caffe2.ai/">Caffe2</a>:</p><pre>git clone --recursive https://github.com/caffe2/caffe2.git &amp;&amp; cd caffe2<br>make &amp;&amp; cd build &amp;&amp; sudo make install<br>python -c &#39;from caffe2.python import core&#39; 2&gt;/dev/null &amp;&amp; echo &quot;Success&quot; || echo &quot;Failure&quot;</pre><blockquote><strong>Note:</strong> Currently, you <strong>MUST</strong> have an NVIDIA GPU with CUDA in order to use Detectron.</blockquote><h3>Install the COCO API</h3><pre>git clone <a href="https://github.com/cocodataset/cocoapi.git">https://github.com/cocodataset/cocoapi.git</a><br>cd cocoapi/PythonAPI<br>make install</pre><h3>Clone the Repo</h3><p>After we successfully install Caffe2 all we need to do is clone the <a href="https://github.com/facebookresearch/Detectron">Detectron repo</a>:</p><pre>git clone <a href="https://github.com/facebookresearch/Detectron.git">https://github.com/facebookresearch/Detectron.git</a> &amp;&amp; cd Detectron</pre><p>Install the requirements:</p><pre>pip install \<br>numpy \<br>pyyaml \<br>matplotlib \<br>opencv-python&gt;=3.0 \<br>setuptools \<br>Cython \<br>mock \<br>scipy</pre><p>And build the python modules:</p><pre>cd lib &amp;&amp; make &amp;&amp; cd ..</pre><h3>Making Inferences</h3><p>Now all we have to do is run the following command to run object masking on the demo images:</p><pre>python tools/infer_simple.py \<br>--cfg configs/12_2017_baselines/e2e_mask_rcnn_R-101-FPN_2x.yaml \<br>--output-dir demo/output \<br>--image-ext jpg \<br>--wts \<br>https://s3-us-west-2.amazonaws.com/detectron/35861858/12_2017_baselines/e2e_mask_rcnn_R-101-FPN_2x.yaml.02_32_51.SgT4y1cO/output/train/coco_2014_train:coco_2014_valminusminival/generalized_rcnn/model_final.pkl \<br>demo</pre><p>You’ll be able to find the output as PDFs in the Detectron/demo/output directory.</p><p>Here are some of my own test examples, most of them worked pretty well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iz0oY3GiXM2FE3gbMrezjA.png" /></figure><p>But as always, <a href="https://hackernoon.com/capsule-networks-are-shaking-up-ai-heres-how-to-use-them-c233a0971952">the Kardashians continue to stump AI</a>, because are they real?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*sv-Gbf-X9mJbh2FheTCXPQ.png" /></figure><blockquote><strong>Note:</strong> If you want to test your own images just add JPG files to the Detectron/demo directory. For best results keep the images around 600–800px.</blockquote><h3>Final Thoughts</h3><p>This model does a great job at masking very general objects, however a lot of us need something more specific to our use case. For that, keep a look out for my next tutorial on how to build your own custom object masking model!</p><p>Thanks for reading! If you have any questions, feel free to reach out at bourdakos1@gmail.com, connect with me on <a href="https://www.linkedin.com/in/nicholasbourdakos">LinkedIn</a>, or follow me on <a href="https://medium.com/@bourdakos1">Medium</a> and <a href="https://twitter.com/bourdakos1">Twitter</a>.</p><p>If you found this article helpful, it would mean a lot if you gave it some applause👏 and shared to help others find it! And feel free to leave a comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d41e170bbcb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/how-to-use-detectron-facebooks-free-platform-for-object-detection-9d41e170bbcb">How to use Detectron — Facebook’s Free Platform for Object Detection</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Capsule Networks Are Shaking up AI — Here’s How to Use Them]]></title>
            <link>https://medium.com/hackernoon/capsule-networks-are-shaking-up-ai-heres-how-to-use-them-c233a0971952?source=rss-154a0d2814f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/c233a0971952</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[capsule-networks]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[capsule]]></category>
            <dc:creator><![CDATA[Nick Bourdakos]]></dc:creator>
            <pubDate>Fri, 10 Nov 2017 17:04:16 GMT</pubDate>
            <atom:updated>2018-06-25T11:39:55.414Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*HALSN5yfXwLFAObz2szi9g.jpeg" /><figcaption>Geoffrey Hinton [<a href="https://www.technologyreview.com/s/608911/is-ai-riding-a-one-trick-pony/">Source</a>]</figcaption></figure><p>If you follow AI you might have heard about the advent of the potentially revolutionary Capsule Networks. I will show you how you can start using them today.</p><p>Geoffrey Hinton is known as the father of “deep learning.” Back in the 50s the idea of deep neural networks began to surface and, in theory, could solve a vast amount of problems. However, nobody was able to figure out how to train them and people started to give up. Hinton didn’t give up and in 1986 showed that the idea of backpropagation could train these deep nets. However, it wasn’t until 5 years ago in 2012 that Hinton was able to demostrate his breakthrough, because of the lack of computational power of the time. This breakthrough set the stage for this decade’s progress in AI.</p><p>And now, on October 26, 2017, he has released a paper on a new groundbreaking concept, Capsule Networks.</p><blockquote><strong>Note:</strong> For a deeper explanation on how capsules work check out <a href="https://medium.freecodecamp.org/understanding-capsule-networks-ais-alluring-new-architecture-bdb228173ddc">part 2</a>. Also, the research papers can be found <a href="https://arxiv.org/pdf/1710.09829v1.pdf">here</a> and <a href="https://openreview.net/pdf?id=HJWLfGWRb">here</a>.</blockquote><h3>Problems with Traditional Neural Networks</h3><p>Up until now Convolutional Neural Networks (CNNs) have been the state-of-the-art approach to classifying images.</p><p>CNNs work by accumulating sets of features at each layer. It starts of by finding edges, then shapes, then actual objects. However, the spatial relationship information of all these features is lost.</p><p>This is a gross oversimplification, but you can think of a CNN like this:</p><pre>if (2 eyes &amp;&amp; 1 nose &amp;&amp; 1 mouth) {<br>  It&#39;s a face!<br>}</pre><p>You might be thinking that this sounds pretty good, it makes sense, and it does. Although, we might run into a few problems, take this picture of Kim Kardashian for example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iX1qcKeLHEKtSZuzafrgjg.png" /></figure><p>Yikes! There’s definitely two eyes, a nose and a mouth, but something is wrong, can you spot it? We can easily tell that an eye and her mouth are in the wrong place and that this isn’t what a person is supposed to look like. However, a well trained CNN has difficulty with this concept:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h-Be4Uj-a7N6_Qx-K03KkQ.png" /></figure><p>In addition to being easily fooled by images with features in the wrong place a CNN is also easily confused when viewing an image in a different orientation. One way to combat this is with excessive training of all possible angles, but this takes a lot of time and seems counter intuitive. We can see here the massive drop in performance by simply flipping Kim upside down:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RS9iLmj0r9i9zUeBVzo8Kg.png" /></figure><p>Finally, convolutional neural networks can be susceptible to white box adversarial attacks. Which is essentially embedding a secret pattern into an object to make it look like something else.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FqPxlhGSG0tc%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DqPxlhGSG0tc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FqPxlhGSG0tc%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/15cacfe2974dea13c4aa41eebfb7900f/href">https://medium.com/media/15cacfe2974dea13c4aa41eebfb7900f/href</a></iframe><blockquote>“Convolutional neural networks are doomed” — Geoffrey Hinton</blockquote><h3>Capsule Networks to the Rescue!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aJhYGZZPYF44UZMfFpKkfw.png" /><figcaption>Architecture of CapsNet</figcaption></figure><p>The introduction of Capsule Networks gives us the ability to take full advantage of spatial relationship, so we can start to see things more like:</p><pre>if (2 adjacent eyes &amp;&amp; nose under eyes &amp;&amp; mouth under nose) {<br>  It&#39;s a face!<br>}</pre><p>You should be able to see that with this definition our neural net shouldn’t be as easily fooled by our misshapen Kardashian.</p><p>This new architecture also achieves significantly better accuracy on the following data set. This data set was carefully designed to be a pure shape recognition task that shows the ability to recognize the objects even from different points of view. It beat out the state-of-the-art CNN, reducing the number of errors by 45%.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*gHnUO-A3vYj0qtqHXSkGPw.png" /><figcaption>CapsNet was able to identify the bottom images were within the same category (animals, humans, airplanes, cars, trucks) as the correspoding top image far better than CNNs.</figcaption></figure><p>Further more, in their most recent paper, they found that Capsules show far more resistance to white box adversarial attack than a baseline convolutional neural network.</p><h3>Training CapsNet</h3><p>I have pieced together a repo that is an implementation of Hinton’s paper (many thanks to <a href="https://github.com/naturomics/CapsNet-Tensorflow">naturomics</a>). In order to use the Capsule Network model you first need to train it.</p><p>The following guide will get you a model trained on the MNIST data set. For those of you who don’t know, MNIST is a data set of handwritten digits and is a good baseline for testing out machine learning algorithms.</p><p>Start by cloning the <a href="https://github.com/bourdakos1/capsule-networks">repo</a>:</p><pre>git clone <a href="https://github.com/bourdakos1/capsule-networks.git">https://github.com/bourdakos1/capsule-networks.git</a></pre><p>Then install the requirements and download the dataset:</p><pre>pip install -r requirements.txt<br>python download_data.py</pre><p>Start training!</p><pre>python main.py</pre><p>The MNIST data set is 60,000 training images. By default the model will be trained for 50 epochs at a batch size of 128. An epoch is one full run through the training set. Since the batch size is 128 it will do about 468 batches per epoch.</p><p><strong>Note:</strong> Training might take a very long time if you don’t have a GPU. You can read <a href="https://medium.freecodecamp.org/tracking-the-millenium-falcon-with-tensorflow-c8c86419225e#6415">this article</a> on how to speed up training time.</p><h3>Making Inferences</h3><p>Once our model is fully trained we can test it by running the following command:</p><pre>python main.py --is_training False</pre><h3>Final Thoughts</h3><p>Capsule Networks seem awesome, but they are still babies. We could see problems in the future when training huge datasets, but I have faith.</p><p>If you enjoyed reading this and want more, there’s a <a href="https://medium.freecodecamp.org/understanding-capsule-networks-ais-alluring-new-architecture-bdb228173ddc">part 2</a>!</p><p>P.S. Here is a great video that I recommend taking the time to watch.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FTFIMqt0yT2I%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DTFIMqt0yT2I&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FTFIMqt0yT2I%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/662bec19fcc0dc506f910756d66ae79d/href">https://medium.com/media/662bec19fcc0dc506f910756d66ae79d/href</a></iframe><p>Thanks for reading! If you have any questions, feel free to reach out at bourdakos1@gmail.com, connect with me on <a href="https://www.linkedin.com/in/nicholasbourdakos">LinkedIn</a>, or follow me on <a href="https://medium.com/@bourdakos1">Medium</a> and <a href="https://twitter.com/bourdakos1">Twitter</a>.</p><p>If you found this article helpful, it would mean a lot if you gave it some applause👏 and shared to help others find it! And feel free to leave a comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c233a0971952" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/capsule-networks-are-shaking-up-ai-heres-how-to-use-them-c233a0971952">Capsule Networks Are Shaking up AI — Here’s How to Use Them</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tracking the Millennium Falcon with TensorFlow]]></title>
            <link>https://medium.com/free-code-camp/tracking-the-millenium-falcon-with-tensorflow-c8c86419225e?source=rss-154a0d2814f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8c86419225e</guid>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Nick Bourdakos]]></dc:creator>
            <pubDate>Thu, 02 Nov 2017 17:04:17 GMT</pubDate>
            <atom:updated>2019-03-29T14:53:10.059Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2FQuickFortunateBlackandtancoonhound&amp;url=https%3A%2F%2Fgfycat.com%2Fgifs%2Fdetail%2FQuickFortunateBlackandtancoonhound&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FQuickFortunateBlackandtancoonhound-size_restricted.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=gfycat" width="800" height="450" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f35dc44fd9c2d00f3a51e9dc835bef3/href">https://medium.com/media/2f35dc44fd9c2d00f3a51e9dc835bef3/href</a></iframe><p>At the time of writing this post, most of the big tech companies (such as IBM, Google, Microsoft, and Amazon) have easy-to-use visual recognition APIs. Some smaller companies also provide similar offerings, such as <a href="https://www.clarifai.com/">Clarifai</a>. But none of them offer object detection.</p><blockquote><strong>Update:</strong> IBM and Microsoft now have customizable object detection APIs.</blockquote><p>The following images were both tagged using the same <a href="https://www.ibm.com/watson/services/visual-recognition/">Watson Visual Recognition</a> default classifier. The first one, though, has been run through an object detection model first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uCdxGFAuHpEwCmZ3iOIUaw.png" /><figcaption><a href="https://ibm.biz/Bdjh2m">Get started with Watson</a></figcaption></figure><p>Object detection can be far superior to visual recognition on its own. But if you want object detection, you’re going to have to get your hands a little dirty.</p><p>Depending on your use case, you may not need a custom object detection model. <a href="https://www.tensorflow.org/">TensorFlow</a>’s object detection API provides a few models of varying speed and accuracy, that are based on the <a href="http://cocodataset.org/#home">COCO dataset</a>.</p><p>For your convenience, I have put together a complete list of objects that are detectable with the COCO models:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ka9VwFe4x7fGQ61WNGX8fQ.png" /></figure><p>If you wanted to detect logos or something not on this list, you’d have to build your own custom object detector. I wanted to be able to detect the Millennium Falcon and some Tie Fighters. This is obviously an extremely important use case, because you never know…</p><h3>Annotate your images</h3><p>Training your own model is a lot of work. At this point, you may be thinking, “Whoa, whoa, whoa! I don’t want to do a lot of work!” If so, you can check out <a href="https://medium.com/unsupervised-coding/dont-miss-your-target-object-detection-with-tensorflow-and-watson-488e24226ef3">my other article</a> about using the provided model. It’s a much smoother ride.</p><p>You need to collect a lot of images and annotate them all. Annotations include specifying the object coordinates and a corresponding label. For an image with two Tie Fighters, an annotation might look something like this:</p><pre>&lt;annotation&gt;<br>    &lt;folder&gt;images&lt;/folder&gt;<br>    &lt;filename&gt;image1.jpg&lt;/filename&gt;<br>    &lt;size&gt;<br>        &lt;width&gt;1000&lt;/width&gt;<br>        &lt;height&gt;563&lt;/height&gt;<br>    &lt;/size&gt;<br>    &lt;segmented&gt;0&lt;/segmented&gt;<br>    &lt;object&gt;<br>        &lt;name&gt;Tie Fighter&lt;/name&gt;<br>        &lt;bndbox&gt;<br>            &lt;xmin&gt;112&lt;/xmin&gt;<br>            &lt;ymin&gt;281&lt;/ymin&gt;<br>            &lt;xmax&gt;122&lt;/xmax&gt;<br>            &lt;ymax&gt;291&lt;/ymax&gt;<br>        &lt;/bndbox&gt;<br>    &lt;/object&gt;<br>    &lt;object&gt;<br>        &lt;name&gt;Tie Fighter&lt;/name&gt;<br>        &lt;bndbox&gt;<br>            &lt;xmin&gt;87&lt;/xmin&gt;<br>            &lt;ymin&gt;260&lt;/ymin&gt;<br>            &lt;xmax&gt;95&lt;/xmax&gt;<br>            &lt;ymax&gt;268&lt;/ymax&gt;<br>        &lt;/bndbox&gt;<br>    &lt;/object&gt;<br>&lt;/annotation&gt;</pre><p>For my Star Wars model, I collected 308 images including two or three objects in each. I’d recommend trying to find 200–300 examples of each object.</p><p>“Wow,” you might be thinking, “I have to go through hundreds of images and write a bunch of XML for each one?”</p><p>Of course not! There are plenty of annotation tools out there, such as <a href="https://github.com/tzutalin/labelImg">labelImg</a> and <a href="https://rectlabel.com/">RectLabel</a>. I used <a href="https://medium.com/u/5bfb37ff96a8">RectLabel</a>, but it’s only for macOS. It’s still a lot of work, trust me. It took me about three or four hours of nonstop work to annotate my entire dataset.</p><blockquote><strong>Update:</strong> I ended up building my own tool to annotate images and video frames. It’s a free online tool called Cloud Annotations that you can check out <a href="https://github.com/cloud-annotations/training">here</a>.</blockquote><p>If you have the money, you can pay somebody else, like an intern, to do it. Or you can use something like <a href="https://www.mturk.com/mturk/welcome">Mechanical Turk</a>. If you are a broke college student like me and/or find doing hours of monotonous work fun, you’re on your own.</p><p>We will need to do a little setup before we can run the script to prepare the data for TensorFlow.</p><h3>Clone the repo</h3><p>Start by cloning my repo <a href="https://github.com/bourdakos1/Custom-Object-Detection">here</a>.</p><blockquote><strong>Update:</strong> This repo is a bit out of date, I recommend checking out <a href="https://github.com/cloud-annotations/training">this one</a> for a much better time :)</blockquote><blockquote><strong>Note:</strong> The following instructions are also out of date, I urge you to check out <a href="https://cloud-annotations.github.io/training/object-detection/cli/">the new walkthrough</a>.</blockquote><p>The directory structure will need to look like this:</p><pre>models<br>|-- annotations<br>|   |-- label_map.pbtxt<br>|   |-- trainval.txt<br>|   `-- xmls<br>|       |-- 1.xml<br>|       |-- 2.xml<br>|       |-- 3.xml<br>|       `-- ...<br>|-- images<br>|   |-- 1.jpg<br>|   |-- 2.jpg<br>|   |-- 3.jpg<br>|   `-- ...<br>|-- object_detection<br>|   `-- ...<br>`-- ...</pre><p>I’ve included my training data, so you should be able to run this out of the box. But if you want to create a model with your own data, you’ll need to add your training images to images, add your XML annotations to annotations/xmls, update trainval.txt, and label_map.pbtxt.</p><p>trainval.txt is a list of file names that allows us to find and correlate the JPG and XML files. The following trainval.txt list would let us to find abc.jpg, abc.xml, 123.jpg, 123.xml, xyz.jpg and xyz.xml:</p><pre>abc<br>123<br>xyz</pre><p><strong>Note:</strong> Make sure your JPG and XML file names match, minus the extension.</p><p>label_map.pbtxt is our list of objects that we are trying to detect. It should look something like this:</p><pre>item {<br>  id: 1<br>  name: &#39;Millennium Falcon&#39;<br>}</pre><pre>item {<br>  id: 2<br>  name: &#39;Tie Fighter&#39;<br>}</pre><h3>Running the script</h3><p>First, with Python and pip installed, install the scripts requirements:</p><pre>pip install -r requirements.txt</pre><p>Add models and models/slim to your PYTHONPATH:</p><pre>export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim</pre><p><strong>Important Note:</strong> This must be run every time you open the terminal, or added to your ~/.bashrc file.</p><p>Run the script:</p><pre>python object_detection/create_tf_record.py</pre><p>Once the script finishes running, you will end up with a train.record and a val.record file. This is what we will use to train the model.</p><h3>Downloading a base model</h3><p>Training an object detector from scratch can take days, even when using multiple <a href="http://www.nvidia.com/object/what-is-gpu-computing.html">GPUs</a>. To speed up training, we’ll take an object detector trained on a different dataset and reuse some of it’s parameters to initialize our new model.</p><p>You can download a model from this <a href="https://github.com/bourdakos1/Custom-Object-Detection/blob/master/object_detection/g3doc/detection_model_zoo.md">model zoo</a>. Each model varies in accuracy and speed. I used faster_rcnn_resnet101_coco.</p><p>Extract and move all the model.ckpt files to our repo’s root directory.</p><p>You should see a file named faster_rcnn_resnet101.config. It’s set to work with the faster_rcnn_resnet101_coco model. If you used another model, you can find a corresponding config file <a href="https://github.com/bourdakos1/Custom-Object-Detection/tree/master/object_detection/samples/configs">here</a>.</p><h3>Ready to train</h3><p>Run the following script, and it should start to train!</p><pre>python object_detection/train.py \<br>        --logtostderr \<br>        --train_dir=train \<br>        --pipeline_config_path=faster_rcnn_resnet101.config</pre><p><strong>Note:</strong> Replace pipeline_config_path with the location of your config file.</p><pre>global step 1:<br>global step 2:<br>global step 3:<br>global step 4:<br>...</pre><p>Yay! It’s working!</p><p><em>10 minutes later.</em></p><pre>global step 41:<br>global step 42:<br>global step 43:<br>global step 44:<br>...</pre><p><em>Computer starts smoking.</em></p><pre>global step 71:<br>global step 72:<br>global step 73:<br>global step 74:<br>...</pre><p>How long is this thing supposed to run?</p><p>The model that I used in the video ran for about 22,000 steps.</p><p>Wait, what?!</p><p>I use a specked-out MacBook Pro. If you’re running this on something similar, I’ll assume you’re getting about one step every 15 seconds or so. At that rate it will take about three to four days of nonstop running to get a decent model.</p><p>Well, this is dumb. I don’t have time for this 😵</p><p><a href="https://developer.ibm.com/linuxonpower/deep-learning-powerai/">PowerAI</a> to the rescue!</p><h3>PowerAI</h3><p>PowerAI lets us train our model on IBM Power Systems with P100 GPUs fast!</p><p>It only took about an hour to train for 10,000 steps. However, this was just with one GPU. The real power in PowerAI comes from the the ability to do distributed deep learning across hundreds of GPUs with up to 95% efficiency.</p><p>With the help of PowerAI, IBM just set a new image recognition record of 33.8% accuracy in 7 hours. It surpassed the previous industry record set by Microsoft — 29.9% accuracy in 10 days.</p><p>WAYYY fast!</p><p>Since I’m not training on millions of images, I definitely didn’t need those kind of resources. One GPU will do.</p><h4>Creating a Nimbix account</h4><p>Nimbix provides developers a trial account with ten hours of free processing time on the PowerAI platform. You can register <a href="https://www.nimbix.net/cognitive-journey/">here</a>.</p><p><strong>Note:</strong> This process is not automated, so it may take up to 24 hours to be reviewed and approved.</p><p>Once approved, you should receive an email with instructions on confirming and creating your account. It will ask you for a promotional code, but leave it blank.</p><p>You should now be able to log in <a href="https://mc.jarvice.com/">here</a>.</p><h4>Deploy the PowerAI Notebooks application</h4><p>Start by searching for PowerAI Notebooks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X41PZafFtX055NnbwBacEg.png" /></figure><p>Click on it, and then choose TensorFlow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rFh7QVFGs_QzELReRFyAxQ.png" /></figure><p>Choose the machine type of 32 thread POWER8, 128GB RAM, 1x P100 GPU w/NVLink (np8g1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I0ycKwK54z2MdSbuma05vg.png" /></figure><p>Once started, the following dashboard panel will be displayed. When the server Status turns to Processing, the server is ready to be accessed.</p><p>Get the password by clicking on (click to show).</p><p>Then, click Click here to connect to launch the Notebook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JLWTTJT4rUmxLN69lKdFaA.png" /></figure><p>Log-in using the user name nimbix and the previously supplied password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wXLlUuNvo_qPO-_p4kfjKA.png" /></figure><h4>Start training</h4><p>Get a new terminal window by clicking on the New pull-down and selecting Terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j8z6DLJgjyvH13-KXfMajQ.png" /></figure><p>You should be greeted with a familiar face:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XoGutc6f2nEC4lxexRO1Rw.png" /></figure><p><strong>Note:</strong> Terminal may not work in Safari.</p><p>The steps for training are the same as they were when we ran this locally. If you’re using my training data then you can just clone my repo by running (if not, just clone your own repo):</p><pre>git clone <a href="https://github.com/bourdakos1/Custom-Object-Detection.git">https://github.com/bourdakos1/Custom-Object-Detection.git</a></pre><p>Then cd into the root directory:</p><pre>cd Custom-Object-Detection</pre><p>Run this snippet, which will download the pre-trained faster_rcnn_resnet101_coco model we downloaded earlier.</p><pre>wget <a href="http://storage.googleapis.com/download.tensorflow.org/models/object_detection/faster_rcnn_resnet101_coco_11_06_2017.tar.gz">http://storage.googleapis.com/download.tensorflow.org/models/object_detection/faster_rcnn_resnet101_coco_11_06_2017.tar.gz</a><br>tar -xvf faster_rcnn_resnet101_coco_11_06_2017.tar.gz<br>mv faster_rcnn_resnet101_coco_11_06_2017/model.ckpt.* .</pre><p>Then we need to update our PYTHONPATH again, because this in a new terminal:</p><pre>export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim</pre><p>Then we can finally run the training command again:</p><pre>python object_detection/train.py \<br>        --logtostderr \<br>        --train_dir=train \<br>        --pipeline_config_path=faster_rcnn_resnet101.config</pre><h4>Downloading your model</h4><p>When is my model ready? It depends on your training data. The more data, the more steps you’ll need. My model was pretty solid at nearly 4,500 steps. Then, at about 20,000 steps, it peaked. I even went on and trained it for 200,000 steps, but it didn’t get any better.</p><p>I recommend downloading your model every 5,000 steps or so and evaluating it to make sure you’re on the right path.</p><p>Click on the Jupyter logo in the top left corner. Then, navigate the file tree to Custom-Object-Detection/train.</p><p>Download all the model.ckpt files with the highest number.</p><ul><li>model.ckpt-STEP_NUMBER.data-00000-of-00001</li><li>model.ckpt-STEP_NUMBER.index</li><li>model.ckpt-STEP_NUMBER.meta</li></ul><p><strong>Note:</strong> You can only download one at a time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2NUyMsF4SoVv1Jm0zMwc8Q.png" /></figure><p><strong>Note:</strong> Be sure to click the red power button on your machine when finished. Otherwise, the clock will keep on ticking indefinitely.</p><h4>Export the inference graph</h4><p>To use the model in our code, we need to convert the checkpoint files (model.ckpt-STEP_NUMBER.*) into a frozen <a href="http://deepdive.stanford.edu/inference">inference graph</a>.</p><p>Move the checkpoint files you just downloaded into the root folder of the repo you’ve been using.</p><p>Then run this command:</p><pre>python object_detection/export_inference_graph.py \<br>        --input_type image_tensor \<br>        --pipeline_config_path faster_rcnn_resnet101.config \<br>        --trained_checkpoint_prefix model.ckpt-STEP_NUMBER \<br>        --output_directory output_inference_graph</pre><p>Remember<em> </em><em>export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim .</em></p><p>You should see a new output_inference_graph directory with a frozen_inference_graph.pb file. This is the file we need.</p><h4>Test the model</h4><p>Now, run the following command:</p><pre>python object_detection/object_detection_runner.py</pre><p>It will run your object detection model found at output_inference_graph/frozen_inference_graph.pb on all the images in the test_images directory and output the results in the output/test_images directory.</p><h3>The results</h3><p>Here’s what we get when we run our model over all the frames in this clip from Star Wars: The Force Awakens.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FxW2hpkoaIiM&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DxW2hpkoaIiM&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FxW2hpkoaIiM%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/83d34cd0e66f62ba42bafe28f888678e/href">https://medium.com/media/83d34cd0e66f62ba42bafe28f888678e/href</a></iframe><p>Thanks for reading! If you have any questions, feel free to reach out at bourdakos1@gmail.com, connect with me on <a href="https://www.linkedin.com/in/nicholasbourdakos">LinkedIn</a>, or follow me on <a href="https://medium.com/@bourdakos1">Medium</a> and <a href="https://twitter.com/bourdakos1">Twitter</a>.</p><p>If you found this article helpful, it would mean a lot if you gave it some applause👏 and shared to help others find it! And feel free to leave a comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8c86419225e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/tracking-the-millenium-falcon-with-tensorflow-c8c86419225e">Tracking the Millennium Falcon with TensorFlow</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>