<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://mehmandarov.com/tag/machine-learning/feed.xml" rel="self" type="application/atom+xml"/><link href="https://mehmandarov.com/tag/machine-learning/" rel="alternate" type="text/html"/><updated>2017-05-07T20:46:00+02:00</updated><id>https://mehmandarov.com/tag/machine-learning/feed.xml</id><title type="html">Rustam Mehmandarov - tag: machine learning</title><subtitle type="text">Posts tagged &quot;machine learning&quot; on Rustam Mehmandarov.</subtitle><author><name>Rustam Mehmandarov</name></author><entry><title type="html">Hvordan l&#230;re opp ditt eget kamera</title><link href="https://mehmandarov.com/hvordan-laere-opp-ditt-eget-kamera/" rel="alternate" type="text/html" title="Hvordan l&#230;re opp ditt eget kamera"/><published>2017-05-07T20:46:00+02:00</published><updated>2017-05-07T20:46:00+02:00</updated><id>https://mehmandarov.com/hvordan-laere-opp-ditt-eget-kamera</id><content type="html" xml:base="https://mehmandarov.com/hvordan-laere-opp-ditt-eget-kamera/"><![CDATA[<p><a href="/how-to-train-your-camera/">[English version &#8211; Engelsk versjon]</a></p>

<p><em>Bildegjenkjenning gjort enkelt. Slik gjenkjenner du en bestemt gjenstand ved hjelp av et kamera.</em></p>

<ul>
  <li><a href="#utfordringen">Utfordringen</a></li>
  <li><a href="#litt-teori">Litt teori</a></li>
  <li><a href="#hvor-starter-jeg">Hvor starter jeg?</a></li>
  <li><a href="#la-oss-kj&#248;re-bildegjenkjenning">La oss kj&#248;re bildegjenkjenning</a></li>
  <li><a href="#bonus-video">Bonus: Video</a></li>
</ul>

<hr />

<h2 id="utfordringen">Utfordringen</h2>

<p>Denne uken har jeg f&#229;tt utfordringen &#229; foresl&#229; en l&#248;sning p&#229; f&#248;lgende problem:</p>

<blockquote>
  <p><em>&#8220;Med en enkel datamaskin, som en Raspberry Pi, et kamera og et fuglebrett, lag et program som kan artsbestemme hvilke fugler som er innom brettet og spiser i l&#248;pet av en dag.&#8221;</em></p>
</blockquote>

<p>Siden sp&#248;rsm&#229;let var av mer teoretisk art, bestemte jeg meg for &#229; begrense dette innlegget til &#229; introdusere byggeblokkene og gi en forklaring p&#229; hvordan du typisk kan bygge et slikt system.</p>

<p>&#197; gjenkjenne gjenstander er en ganske vanlig oppgave n&#229; for tiden, og den har blitt l&#248;st p&#229; flere forskjellige m&#229;ter, og med forskjellige tiln&#230;rminger. La oss se p&#229; hvordan dette virker.</p>

<blockquote>
  <p><em><strong>TL;DR</strong></em> Det fins noen tradisjonelle m&#229;ter &#229; lage bilde- og gjenstandsgjenkjenning p&#229;, som i OpenCV, og det fins noen teknikker basert p&#229; Deep Learning, som i TensorFlow. Vil du vite mer? Fortsett &#229; lese.</p>
</blockquote>

<hr />

<h2 id="litt-teori">Litt teori</h2>
<p>De mer tradisjonelle prinsippene bak OpenCV for &#229; oppdage er godt beskrevet i <a href="http://www.learnopencv.com/image-recognition-and-object-detection-part1/" target="_blank">dette blogginnlegget</a>, s&#229; vel som i denne veiledningen for &#229; gjenkjenne (hold dere fast!) <a href="http://www.pyimagesearch.com/2016/06/20/detecting-cats-in-images-with-opencv/" target="_blank">katter p&#229; bilder</a>.</p>

<p>Mens <a href="https://www.tensorflow.org/tutorials/keras/basic_classification" target="_blank">dette innlegget</a> forklarer hvordan bildegjenkjenning virker i TensorFlow, som bruker en modell kalt dypt konvolverende nevrale nettverk, vil det ogs&#229; la deg <a href="https://research.googleblog.com/2016/03/train-your-own-image-classifier-with.html" target="_blank">trene opp din egen bildeklassifiserer</a>, slik som OpenCV.</p>

<p><img src="/assets/images/posts-images/2017-04-29-cartoon_image_processing_1.png" alt="Training your own model" class="bigger-image" /></p>
<figcaption class="caption">Noen m&#229; l&#230;re opp modellen som du skal bruke til bildeklassifisering (-gjenkjenning).</figcaption>

<hr />

<h2 id="hvor-starter-jeg">Hvor starter jeg?</h2>

<p>I utgangspunktet har du to valg &#8211; du b&#248;r enten l&#230;re opp din egen modell eller finne en modell som har blitt l&#230;rt opp av noen andre, og du vil kanskje alltid starte med &#229; se etter en forh&#229;ndsoppl&#230;rt modell. Men jo mer spesifiserte bildeklassifiseringskravene dine er, jo h&#248;yere er sjansen for at du m&#229; l&#230;re opp din egen modell. Dette vil v&#230;re det samme enten du velger OpenCV eller TensorFlow.</p>

<p>Siden vi vil kj&#248;re modellen p&#229; en relativt enkel datamaskin, kan du vurdere &#229; gj&#248;re prosesseringen i skyen. Det b&#248;r imidlertid ogs&#229; v&#230;re mulig &#229; kj&#248;re <a href="http://www.pyimagesearch.com/2016/04/18/install-guide-raspberry-pi-3-raspbian-jessie-opencv-3/" target="_blank">OpenCV</a> og <a href="https://svds.com/tensorflow-image-recognition-raspberry-pi/" target="_blank">TensorFlow</a> p&#229; den nyeste Raspberry Pi.</p>

<hr />

<h2 id="la-oss-kj&#248;re-bildegjenkjenning">La oss kj&#248;re bildegjenkjenning</h2>

<p>N&#229; vet du litt om teorien. La oss s&#229; ta en rask titt p&#229; hvordan vi kan l&#230;re opp modellene i v&#229;re behov.</p>

<blockquote>
  <p><em><strong>TL;DR</strong></em> M&#229;ten dette virker p&#229;, er at du viser modellen ganske mange bilder av en gjenstand, og en tilsvarende mengde bilder uten gjenstanden p&#229;.</p>
</blockquote>

<p>La oss si at du vil bruke modellen til &#229; gjenkjenne fugler utenfor huset ditt i Norge. Et godt utgangspunkt vil da v&#230;re &#229; f&#229; en liste over de typiske artene som du mest sannsynlig ser i hagen din, og samle s&#229; mange bilder av hver art som mulig.</p>

<p><img src="/assets/images/posts-images/2017-04-29-cartoon_image_processing_2.png" alt="Your own model in action" class="bigger-image" /></p>
<figcaption class="caption">Din oppl&#230;rte modell i aksjon.</figcaption>

<p>Her er hva du kan gj&#248;re:</p>

<ol>
  <li>Start med &#229; finne en liste over norske fugler p&#229; <a href="https://en.wikipedia.org/wiki/List_of_birds_of_Norway" target="_blank">Wikipedia</a>, eller <a href="https://snl.no/Fugler_i_Norge" target="_blank">Store Norske Leksikon</a>.</li>
  <li>S&#248;k p&#229; nettet etter bilder av hver fugleart. Det kan v&#230;re du vil automatisere dette arbeidet, og s&#248;rg for at du plukker ut bilder med de riktige opphavsrettstillatelsene.</li>
  <li>Bruk disse bildene i oppl&#230;ringen av din modell.</li>
  <li>Sett opp din Raspberry Pi med et kamera og fuglebrett, og gj&#248;r deg klar til &#229; identifisere fuglearter. Du b&#248;r optimalisere programvaren slik at bildeklassifiseringen ikke skjer hele tiden, men kun n&#229;r man ser en bevegelse.</li>
</ol>

<p><em>Pro tip:</em> Det kan ogs&#229; v&#230;re litt utfordrende &#229; ta gode bilder av v&#229;re fj&#230;rkledde venner, s&#229; s&#248;rg for at kameraet ditt er godt plassert, og materen er p&#229; et godt opplyst sted. Uten &#229; forstyrre dyrelivet, s&#229; klart.</p>

<p>Lurer du p&#229; om lignende systemer har blitt implementert eller om det er mulig? Svaret er ja. Her er det noen lenker til inspirasjon for videre lesning:</p>

<ul>
  <li><a href="https://www.oreilly.com/learning/dive-into-tensorflow-with-linux" target="_blank">En fugleklassifiserer med tensorflow</a></li>
  <li><a href="https://web.archive.org/web/20161205073600/http://www.bitfusion.io:80/2016/08/31/training-a-bird-classifier-with-tensorflow-and-tflearn/" target="_blank">Trene opp en fugleklassifiserer med Tensorflow og TFLearn</a></li>
  <li><a href="https://www.youtube.com/watch?v=S-W9tMZu8PU" target="_blank">Kj&#248;ret&#248;yklassifisering og -telling med OpenCV</a></li>
  <li><a href="https://web.archive.org/web/20170925210229/http://www.fyens.dk/article/3141726" target="_blank">Blomstergjenkjenning i naturen</a> (p&#229; dansk)</li>
  <li><a href="https://medium.com/@ageitgey/machine-learning-is-fun-part-3-deep-learning-and-convolutional-neural-networks-f40359318721" target="_blank">Maskinl&#230;ring er morsomt! Del 3: Dypt konvolverende nevrale nettverk</a>. (Ta ogs&#229; gjerne en titt p&#229; de andre delene i denne artikkelserien.)</li>
</ul>

<p>Pr&#248;v n&#229; &#229; sette alt dette sammen, og fortell meg gjerne hvordan det g&#229;r!</p>

<p><em>Lykke til!</em></p>

<hr />

<h2 id="bonus-video">Bonus: Video</h2>

<p>En video vi har laget av mine tegninger og en kort forklaring p&#229; hvordan dette virker.</p>

<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/kOXBCWvmtD4?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen=""></iframe>

<hr />]]></content><author><name>Rustam Mehmandarov</name></author><summary type="html">Bildegjenkjenning gjort enkelt. Slik gjenkjenner du en bestemt gjenstand ved hjelp av et kamera og OpenCV eller TensorFlow</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mehmandarov.com/assets/images/posts-images/bird_small.jpg"/><category term="blog"/><category term="iot"/><category term="machine learning"/><category term="norwegian"/></entry><entry><title type="html">How to Train Your Camera</title><link href="https://mehmandarov.com/how-to-train-your-camera/" rel="alternate" type="text/html" title="How to Train Your Camera"/><published>2017-04-29T20:46:00+02:00</published><updated>2017-04-29T20:46:00+02:00</updated><id>https://mehmandarov.com/how-to-train-your-camera</id><content type="html" xml:base="https://mehmandarov.com/how-to-train-your-camera/"><![CDATA[<p><a href="/hvordan-laere-opp-ditt-eget-kamera/">[Norwegian version - Norsk versjon]</a></p>

<p><em>Image recognition made simple. How to recognise a specific object from a camera feed?</em></p>

<ul>
  <li><a href="#the-challenge">The Challenge</a></li>
  <li><a href="#a-tiny-bit-of-theory">A Tiny Bit of Theory</a></li>
  <li><a href="#where-to-start">Where to Start?</a></li>
  <li><a href="#doing-image-recognition">Doing Image Recognition</a></li>
</ul>

<hr />

<h2 id="the-challenge">The Challenge</h2>

<p>This week I have been given the challenge to suggest a solution to the following problem:</p>

<blockquote>
  <p><em>&#8220;Given a simple computer, like a Raspberry Pi, a camera and a bird feeder, create a system that can identify the birds feeding there throughout the day.&#8221;</em></p>
</blockquote>

<p>Since the question was more of a theoretical kind, I decided to limit this post to introducing the building blocks and giving an explanation of how you would typically build a system like that.</p>

<p>Recognising objects is a pretty common task these days, and it has been solved in quite a few ways by different approaches. Let&#8217;s have a look at how this works.</p>

<blockquote>
  <p><em><strong>TL;DR</strong></em> There are some traditional ways of doing image recognition and object detection, like in OpenCV, and there are some techniques based on Deep Learning object detection, like in TensorFlow. Want to know more? Keep on reading.</p>
</blockquote>

<hr />

<h2 id="a-tiny-bit-of-theory">A Tiny Bit of Theory</h2>

<p>The more traditional principles behind OpenCV are well described in this <a href="http://www.learnopencv.com/image-recognition-and-object-detection-part1/" target="_blank">blog post</a>, as well as in this tutorial for detecting (<em>brace yourselves!</em>) <a href="http://www.pyimagesearch.com/2016/06/20/detecting-cats-in-images-with-opencv/" target="_blank">cats in images</a>.</p>

<p>While <a href="https://www.tensorflow.org/tutorials/keras/basic_classification" target="_blank">this post</a> explains how image recognition works in TensorFlow that is using a model called a deep convolutional neural network. Like OpenCV, it will also let you <a href="https://research.googleblog.com/2016/03/train-your-own-image-classifier-with.html" target="_blank">train your own image classifier</a>.</p>

<p><img src="/assets/images/posts-images/2017-04-29-cartoon_image_processing_1.png" alt="Training your own model" class="bigger-image" /></p>
<figcaption class="caption">Someone has to train the model that you will be using for image classification (recognition).</figcaption>

<hr />

<h2 id="where-to-start">Where to Start?</h2>

<p>Basically, you have two choices &#8211; you should either train your own model, or find a model that has been trained by someone else, and you might always want to start by looking for a pre-trained model. However, the more specific your image classification requirements are, the higher are chances that you will need to train your own model. This will be the same whether you go for OpenCV or TensorFlow.</p>

<p>Since we want to run the model on a relatively low-end computer, you might consider doing the processing in the Cloud. However, it should also be possible to run <a href="http://www.pyimagesearch.com/2016/04/18/install-guide-raspberry-pi-3-raspbian-jessie-opencv-3/" target="_blank">OpenCV</a> and <a href="https://svds.com/tensorflow-image-recognition-raspberry-pi/" target="_blank">TensorFlow</a> on the latest Raspberry Pis.</p>

<hr />

<h2 id="doing-image-recognition">Doing Image Recognition</h2>

<p>By now, you should know a bit about the theory. So, let&#8217;s have a quick look into how we can train the models for our needs.</p>

<blockquote>
  <p><em><strong>TL;DR</strong></em> The way this works, is that you feed the model with quite a few pictures of an object, and the similar amount of images without that object.</p>
</blockquote>

<p>Say you want to use the model to recognize birds outside your house in Norway. A good starting point would be to get a list of the typical species you are most likely to see in your backyard and collect as many pictures of each type as possible.</p>

<p><img src="/assets/images/posts-images/2017-04-29-cartoon_image_processing_2.png" alt="Your own model in action" class="bigger-image" /></p>
<figcaption class="caption">Your trained model in action.</figcaption>

<p>Here is what you can do:</p>

<ol>
  <li>Start by looking at <a href="https://en.wikipedia.org/wiki/List_of_birds_of_Norway" target="_blank">Wikipedia</a> for a list of the Norwegian birds, or <a href="https://snl.no/Fugler_i_Norge" target="_blank">Norwegian Encyclopaedia</a> (<em>in Norwegian</em>).</li>
  <li>Search the web for the images of each bird type. You might want to automate that task and make sure you are picking images with the right copyright permissions.</li>
  <li>Use those images to train your model.</li>
  <li>Set up your Raspberry Pi with a camera and the bird feeder, and get ready to identify. You might want to optimise the software not to do the image classification all the time, but only when movement is detected.</li>
</ol>

<p><em>Pro tip:</em> It might also be a bit challenging to take a good picture of our feathered friends, so make sure your camera is well-placed, and the feeder is in a well-lit location. Obviously, without disturbing the wildlife.</p>

<p>In case you wonder if similar systems have been implemented, or if it is even possible. The answer is yes. I will provide you with some links to inspire for further reading:</p>

<ul>
  <li><a href="https://www.oreilly.com/learning/dive-into-tensorflow-with-linux" target="_blank">A Bird Classifier with Tensorflow</a></li>
  <li><a href="https://web.archive.org/web/20161205073600/http://www.bitfusion.io:80/2016/08/31/training-a-bird-classifier-with-tensorflow-and-tflearn/" target="_blank">Training a Bird Classifier with Tensorflow and TFLearn</a></li>
  <li><a href="https://www.youtube.com/watch?v=S-W9tMZu8PU" target="_blank">Vehicle classification and Counting with OpenCV</a></li>
  <li><a href="https://web.archive.org/web/20170925210229/http://www.fyens.dk/article/3141726" target="_blank">Wild Flower Detection</a> (<em>in Danish</em>)</li>
  <li><a href="https://medium.com/@ageitgey/machine-learning-is-fun-part-3-deep-learning-and-convolutional-neural-networks-f40359318721" target="_blank">Machine Learning is Fun! Part 3: Deep Learning and Convolutional Neural Networks</a>. (<em>Also, check out the other parts of the article series.</em>)</li>
</ul>

<p>Now, try putting it all together, and let me know how it goes!</p>

<p><em>Good luck!</em></p>

<hr />]]></content><author><name>Rustam Mehmandarov</name></author><summary type="html">Training your camera to recognize objects using OpenCV or TensorFlow</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mehmandarov.com/assets/images/posts-images/bird_small.jpg"/><category term="blog"/><category term="iot"/><category term="machine learning"/><category term="english"/></entry></feed>
