<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Deep Learning | Data Science Portfolio</title>
    <link>http://mreevesdsba.hopto.org/tag/deep-learning/</link>
      <atom:link href="http://mreevesdsba.hopto.org/tag/deep-learning/index.xml" rel="self" type="application/rss+xml" />
    <description>Deep Learning</description>
    <generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><lastBuildDate>Sun, 15 Sep 2019 00:00:00 +0000</lastBuildDate>
    <image>
      <url>http://mreevesdsba.hopto.org/images/icon_hua2ec155b4296a9c9791d015323e16eb5_11927_512x512_fill_lanczos_center_2.png</url>
      <title>Deep Learning</title>
      <link>http://mreevesdsba.hopto.org/tag/deep-learning/</link>
    </image>
    
    <item>
      <title>What is a GAN?</title>
      <link>http://mreevesdsba.hopto.org/post/what-is-a-gan/</link>
      <pubDate>Sun, 15 Sep 2019 00:00:00 +0000</pubDate>
      <guid>http://mreevesdsba.hopto.org/post/what-is-a-gan/</guid>
      <description>&lt;p&gt;Before reading this post, it is helpful to understand what a neural Network is. Please see the following if you need a refresher:&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://mreevesdsba.hopto.org/post/what-is-a-neural-network/&#34;&gt;What is a Neural Network?&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Before describing how a Generative Adversarial Network (GAN) works, let us start with the goal, which is to create a network that can generate outputs that are indistinguishable from the given set of real objects. We will call the network that produces these outputs the generator network. However, we also need something that can distinguish between the actual objects and the generated objects, which we will call the discriminator network. This network provides feedback to the generator to let it know which outputs are closest to the actual.&lt;/p&gt;
&lt;p&gt;Imagine we have a set of keys and we want a lock that can be opened by as many of those keys as possible and as few keys as possible that are not in that original set. A locksmith starts working on making that lock. At the same time, we have a key-maker creating keys to attempt to open the lock made by the locksmith. As the key-maker gets better, the locksmith will also have to get better at distinguishing between the real and fake keys. As they continue to improve, what started off as the key-maker making random keys will eventually become keys that are similar to the original set of keys. In this example the locksmith is the discriminator, trying to reduce the number of errors, both positive and negative and the key-maker is the generator, creating keys that will try to open the lock.&lt;/p&gt;
&lt;p&gt;The important thing to keep in mind, as with any network, is what the input looks like and what the output looks like. These two networks must work in tandem with the generator creating an output that is able to be consumed by the discriminator; this would be the key-maker making a key in the previous analogy. The discriminator, on the other hand, must be able to accept the initial set of objects and the output of the generator (the lock accepting the key) and output a binary, True/False result based on the given input (whether the key opens the lock). This only leaves the input for the generator, which is generally just a random vector to allow for variety within the generator network, the shape of which is not all that important.&lt;/p&gt;
&lt;p&gt;GANs can be used to recreate any type of matrix, but in general they are used to create images. Images can easily be represented in matrix form by seperating each color layer into a seperate, equally sized matrix, with the intensity of that color represented by a numeric value.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>What is a Neural Network?</title>
      <link>http://mreevesdsba.hopto.org/post/what-is-a-neural-network/</link>
      <pubDate>Sun, 15 Sep 2019 00:00:00 +0000</pubDate>
      <guid>http://mreevesdsba.hopto.org/post/what-is-a-neural-network/</guid>
      <description>&lt;p&gt;A neural network, at its most basic level, can be thought of as a function that consists of an input, a transformation process, and an output. One helpful analogy for this is the Plinko game in The Price is Right. The game consists of a contestant dropping a chip at the top of a board which then bounces, seemingly randomly, through a field of pegs before landing in one of several slots.&lt;/p&gt;
&lt;img src=&#34;http://mreevesdsba.hopto.org/img/lantern/plinko.gif&#34; alt=&#34;Plinko&#34;&gt;
&lt;p&gt;What makes this analogy especially appropriate is that the relationship between the input (starting position of the chip) and the output (the slot at the bottom of the board) is completely obscured by the complexity of the pathway; there is no way to tell the exact path the chip will take based on the starting position. This is what is typically meant when a neural network is referred to as a black box.&lt;/p&gt;
&lt;p&gt;While a process that produces random outputs is useful in a game of chance, it is less useful when trying to utilize machines for decision-making. The power of neural networks comes through the training process. This consists of minor adjustments to the transformation process based on repeated evaluations of inputs. To continue the Plinko analogy, this could be thought of as allowing the contestants to move the pegs. After dropping chips potentially millions of times and looking at the output distribution, the contestant would be allowed to make slight changes to the location each of the pegs and repeat the process. If the overall total winnings increased then they would move each of the pegs further in the same direction. If the overall total winnings decreased they would move them in the opposite direction. This process, known as back propagation, is repeated over and over until an optimized peg configuration is found. The distance that the pegs are allowed to be moved each iteration is called the learning rate, the number of chips we use each time is called the batch size, and each training iteration is called an epoch.&lt;/p&gt;
&lt;p&gt;While it would be tempting just to create channels with the pegs to force the outcome that you want, this is what is known in the machine-learning world as overfitting. Because the data that we train on (the starting position of the chips that we use to optimize the pegs) is rarely the exact positions that we would see when we are actually playing the game, we want to make sure that the final configuration works universally rather than just for the positions that we use to train. What we sacrifice in perfection with our training accuracy we will make up for with a generalized model that will be more successful over time in different situations.&lt;/p&gt;
&lt;p&gt;Up to this point we have only discussed the transformation process as an abstract concept. What it actually consists of is a specified number of layers (rows of pegs) each with a specified size (numbers of pegs per row). The actual composition of these layers is determined during the training process with only generalized guidelines as to how many or how large they should be.&lt;/p&gt;
&lt;p&gt;Continuing to describe neural networks in more detail is beyond the scope of this overview in part because the technicalities of their implementation extends beyond the Plinko analogy. However, it was a useful tool for describing the process of overall process works.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>No, I Will Not Call This Diogenes GAN-terns</title>
      <link>http://mreevesdsba.hopto.org/project/gan-tern/</link>
      <pubDate>Wed, 26 Jun 2019 00:00:00 +0000</pubDate>
      <guid>http://mreevesdsba.hopto.org/project/gan-tern/</guid>
      <description>&lt;h2 id=&#34;project-overview&#34;&gt;Project Overview&lt;/h2&gt;
&lt;hr&gt;
&lt;p&gt;The goal of the project was to create a Generative Adversarial Network (GAN) that would produce visually interesting images. A unique wildflower native to Northern California, the Diogenes Lantern, was selected for the training set based on the pleasing geometric structures and vibrant yellow color.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;http://mreevesdsba.hopto.org/img/lantern/img_1.jpg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;While reliant on deep-learning techniques, this project differed in several key factors from the normal implementation of these methodologies. The first is that the end goal was not necessarily to create the most convincing replication of the training set, but rather to create something within the artistic realm while capturing the underlying essence of the flower. The second, and related variance, is that because the goal was not to necessarily recreate indistinguishable images, optimization and hyperparameter tuning were not required.&lt;/p&gt;
&lt;br&gt;
&lt;br&gt;
&lt;h2 id=&#34;machine-learning-background&#34;&gt;Machine Learning background&lt;/h2&gt;
&lt;hr&gt;
&lt;p&gt;If you are unfamiliar with the concepts of neural networks or GANs please feel free to read the following articles:&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://mreevesdsba.hopto.org/post/what-is-a-neural-network/&#34;&gt;What is a Nerual Network?&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://mreevesdsba.hopto.org/post/what-is-a-gan/&#34;&gt;What is a GAN?&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;data-collection-and-augmentation&#34;&gt;Data Collection and Augmentation&lt;/h3&gt;
&lt;hr&gt;
&lt;p&gt;A total of 172 unique images were scraped using Google image search. This is far fewer than is traditionally leveraged for these types of implementations, especially given the variety of angles, proximity, and backgrounds within the data set. However, due to the stated goal of only needing to create visually interesting images, this is acceptable.&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;Digital augmentation was implemented in order to supplement the dataset and artificially inject variations into the collected images. Zoom, croping, rotation, stretch/skew, and limited color balance changes were randomly applied to create additional images.&lt;/p&gt;
&lt;br&gt;
&lt;br&gt;
&lt;h3 id=&#34;hardware-and-software&#34;&gt;Hardware and Software&lt;/h3&gt;
&lt;hr&gt;
&lt;p&gt;The networks were trained on a Linux machine-learning server leveraging an NVIDIA GeForce 1060 GPU. The server has an Intel core I5 processor and 16 GB of RAM.&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;The code for the networks was coded in Python utilizing the KERAS library leveraging a Tensor-Flow backend with GPU utilization.&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;An output image size of 256x256 pixels was selected in order to optimize training time while still having a minimum viable output for artistic prints. Training of the networks took several days to complete over 300,000 epochs with a batch size of 16. Again, hyperparameters such as learning rate, batch size, and layer structure were not changed as the initial setup produced the desired results.&lt;/p&gt;
&lt;br&gt;
&lt;br&gt;
&lt;h3 id=&#34;results&#34;&gt;Results&lt;/h3&gt;
&lt;hr&gt;
&lt;p&gt;Since the stated goal of this project was based on artistic subjectivity, traditional measures such as accuracy and error rate do not provide meaningful insights into its success. The model produced acceptable outputs and therefore achieved the intended goal of the work. The images produced were interesting and visually appealing enough and therefore there was no need to continue training or tuning the model.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;http://mreevesdsba.hopto.org/img/lantern/img_2.png&#34; alt=&#34;&#34;&gt;
&lt;img src=&#34;http://mreevesdsba.hopto.org/img/lantern/img_3.png&#34; alt=&#34;&#34;&gt;
&lt;img src=&#34;http://mreevesdsba.hopto.org/img/lantern/img_4.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;It should be stated, however, that a layer of human-selection was still required in order to produce these results. While all the images were produced from an initial  random vector, many of them resulted in less-than-acceptable levels of variety (due to mode collapse) or visual interest.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;http://mreevesdsba.hopto.org/img/lantern/img_5.png&#34; alt=&#34;&#34;&gt;
&lt;img src=&#34;http://mreevesdsba.hopto.org/img/lantern/img_6.png&#34; alt=&#34;&#34;&gt;
&lt;img src=&#34;http://mreevesdsba.hopto.org/img/lantern/img_7.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Perhaps with additional tuning and refining, these issues could be reduced, but it was not necessary under these particular circumstances. This should always be considered when judging the effectiveness of a GAN; it should not be judged on the most realistic images produced but on the complete spectrum of the population. It is easy to gravitate towards the most successful results while ignoring the many results that are clearly unrealistic, but it introduces a level of human-bias to the machine-learning that would not be possible in a fully automated application.&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;These images are now part of an art installation. Twelve of the most pleasing resulting images were selected for prints.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;http://mreevesdsba.hopto.org/img/lantern/img_8.jpg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Additionally, one image was selected as the subject of a 48-inch x 48-inch acrylic painting.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;http://mreevesdsba.hopto.org/img/lantern/img_9.jpg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Image Recognition For Specialty Produce</title>
      <link>http://mreevesdsba.hopto.org/project/specialty-image/</link>
      <pubDate>Sat, 27 Apr 2019 00:00:00 -0400</pubDate>
      <guid>http://mreevesdsba.hopto.org/project/specialty-image/</guid>
      <description>&lt;h2 id=&#34;overview&#34;&gt;Overview&lt;/h2&gt;
&lt;hr&gt;
&lt;p&gt;Specialty Produce has one of the most extensive &lt;a href=&#34;https://www.specialtyproduce.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;databases&lt;/a&gt; of information surrounding produce. In order to fully leverage all of this information in the most advanced way possible, a project was started to perform image classification based on each of their products. The most prohibitive portion of most image recognition is not computation power, but labeled data collection. Specialty Produce is in the unique circumstance to have ready access to thousands of products. This is a highly valuable asset that is difficult with which to compete. The largest hurdle is simply collecting the variety of images and have them properly labelled. Through hardware development and digital data augmentation this hurdle was overcome.&lt;/p&gt;
&lt;br&gt;
&lt;br&gt;
&lt;h2 id=&#34;approach&#34;&gt;Approach&lt;/h2&gt;
&lt;hr&gt;
&lt;p&gt;Image recognition requires labeled images of &amp;ldquo;real-world&amp;rdquo; examples for each class. If the image recognition is in a restricted environment like a laboratory or machine line, the image surrounding the object is less important to introduce maximum variance. However, given that the end-state of this product will be user-submitted images, the images need to be as diverse as possible. Rather than attempting to recreate these settings in real-world environments, data is collected in as uniform of environments as possible and then introduce this variation digitally. Currently, the PoC is only classifying bananas by ripeness (i.e. days to being overripe)&lt;/p&gt;
&lt;br&gt;
&lt;br&gt;
&lt;h2 id=&#34;hardware&#34;&gt;Hardware&lt;/h2&gt;
&lt;hr&gt;
&lt;p&gt;There are 5 main components to the hardware:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Computer (Raspberry Pi)&lt;/li&gt;
&lt;li&gt;Camera module&lt;/li&gt;
&lt;li&gt;Spinning platform&lt;/li&gt;
&lt;li&gt;Photo box&lt;/li&gt;
&lt;li&gt;RFID chip reader&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&#34;http://mreevesdsba.hopto.org/img/imagerecog/hardware1.jpg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The computer is connected to a camera and spinning platform that capture numerous images of the product from different angles. This not only ensures maximum information gain, but also naturally balances the variation within each class. The photo box provides a uniform background which makes it easy to remove during pre-processing. In order to fully streamline the process and ensure as few misclassifications as possible, RFID tags are assigned to each product. After the item is placed on the platform, the corresponding card is tapped. The product ID is captured from the card, the photos are taken, and each image is stored in a database. A single product can be scanned in as little as 15 seconds with essentially no input from the user other than the card tap.&lt;/p&gt;
&lt;br&gt;
&lt;br&gt;
&lt;h2 id=&#34;software&#34;&gt;Software&lt;/h2&gt;
&lt;hr&gt;
&lt;p&gt;The data capture code, image processing, and the neural network are written in Python.&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;data-capture&#34;&gt;Data Capture&lt;/h4&gt;
&lt;p&gt;The code relies on several python hardware libraries to interface with the camera, stepper motor, and RFID tag, in addition to file system and SQL database packages to store the information. The number of images per full-rotation can be selected; however, there are diminishing returns as the images might not have enough variation if more are selected and the capture time will increase. Encoding of the RFID tags is handled separately.&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;image-processing&#34;&gt;Image Processing&lt;/h4&gt;
&lt;p&gt;There are 3 steps to the pre-processing before they can be consumed by the model:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;b&gt;Remove Background&lt;/b&gt;: the background of the image must be removed otherwise when the model sees a real-world image, it will be confused because it does not look like the photo box&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Digital Augmentation&lt;/b&gt;: by stretching, skewing, and otherwise altering the original, we can produce multiple images from one. This step accomplishes two things. The first is that it allows for various real-world variances to be introduced. Images will not have the same lighting conditions, angles, item placement, or color balance as the captured data so this is all introduced artificially. The second is that it allows for multiple training images to be produced from a single image.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Random Backgrounds&lt;/b&gt;: the images are added on top of random backgrounds to simulate the variety of real-world images that will eventually be processed by the production model. This helps train the model to ignore everything but the original item. This is also where the image is resized to fit the model&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&#34;http://mreevesdsba.hopto.org/img/imagerecog/process.PNG&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;neural-network&#34;&gt;Neural Network&lt;/h4&gt;
&lt;p&gt;The network was coded directly in TensorFlow. Transfer learning pretrained on ImageNet was utilized in order to expedite learning. Currently, the PoC is only classifying bananas by ripeness (i.e. days to being overripe) and has not been properly tuned. Once a larger set of the final data set has been collected, hyperparameter tuning will be performed more thoroughly.&lt;/p&gt;
&lt;br&gt;
&lt;br&gt;
&lt;h2 id=&#34;end-state&#34;&gt;End-State&lt;/h2&gt;
&lt;hr&gt;
&lt;p&gt;A twitter app has already been developed, allowing the model to run on an image tweeted to a specific account. After the model has run, it retweets with a model score. Eventually, this project will be incorporated into the Specialty Produce mobile app.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;http://mreevesdsba.hopto.org/img/imagerecog/twitter.PNG&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
