<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Python | Data Science Portfolio</title>
    <link>http://mreevesdsba.hopto.org/tag/python/</link>
      <atom:link href="http://mreevesdsba.hopto.org/tag/python/index.xml" rel="self" type="application/rss+xml" />
    <description>Python</description>
    <generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><lastBuildDate>Wed, 26 Jun 2019 00:00:00 +0000</lastBuildDate>
    <image>
      <url>http://mreevesdsba.hopto.org/images/icon_hua2ec155b4296a9c9791d015323e16eb5_11927_512x512_fill_lanczos_center_2.png</url>
      <title>Python</title>
      <link>http://mreevesdsba.hopto.org/tag/python/</link>
    </image>
    
    <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>
    
    <item>
      <title>Vintage Smart Remote</title>
      <link>http://mreevesdsba.hopto.org/project/remote/</link>
      <pubDate>Sat, 27 Apr 2019 00:00:00 -0400</pubDate>
      <guid>http://mreevesdsba.hopto.org/project/remote/</guid>
      <description>&lt;h2 id=&#34;overview&#34;&gt;Overview&lt;/h2&gt;
&lt;hr&gt;
&lt;p&gt;The  Zenith Space Command was the first commercially available remote. It was battery-free and worked by using ultra-sonic clicks in order to communicate with the television. In essence, it was a musical instrument that only the television could hear. The goal of this project was to modernize the remote, maintaining its original form-factor and styling but adding WiFi and IR capabilities.
&lt;br&gt;
There were several goals to the project:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;WiFi-enabled&lt;/li&gt;
&lt;li&gt;Able to control TV, stereo, and lights&lt;/li&gt;
&lt;li&gt;Dependable&lt;/li&gt;
&lt;li&gt;User-friendly
&lt;br&gt;
&lt;br&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;approach&#34;&gt;Approach&lt;/h2&gt;
&lt;hr&gt;
&lt;p&gt;As WiFi is notoriously power-hungry, enabling it in a remote device is a challenge. Another challenge was the limited number of buttons available. The one positive aspect of the project is that the remote is fairly large, by today&amp;rsquo;s standards, which allowed for a lot of room to add components. An ESP8266 chip was selected for its WiFi capabilities. This was combined with a battery and wireless charger. The additional components were the IR transmitter for local devices and a vibration sensor for battery management.
&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h2 id=&#34;hardware&#34;&gt;Hardware&lt;/h2&gt;
&lt;hr&gt;
&lt;h5 id=&#34;build&#34;&gt;Build&lt;/h5&gt;
&lt;p&gt;Many of the original components were removed and the button contacts were wired to the microcontroller. A new support was designed and 3d-printed to house all of the components and hold the battery.
&lt;img src=&#34;http://mreevesdsba.hopto.org/img/remote/remote2.jpg&#34; alt=&#34;3D-printed housing with development board&#34;&gt;&lt;/p&gt;
&lt;h5 id=&#34;microcontroller&#34;&gt;Microcontroller&lt;/h5&gt;
&lt;p&gt;The ESP8266 chip is a common starting point for many similar projects. It has a small footprint and quite capable, in fact overly capable for this project.&lt;/p&gt;
&lt;h5 id=&#34;battery&#34;&gt;Battery&lt;/h5&gt;
&lt;p&gt;An 800mAh battery was used as it was the largest battery that would still fit in the given space. It provides a decent amount of power for the project, but not nearly enough for a reasonable remote control without adjustments.&lt;/p&gt;
&lt;h5 id=&#34;charging&#34;&gt;Charging&lt;/h5&gt;
&lt;p&gt;In order to be more dependable and user-friendly without sacrificing the aesthetics, wireless charging was incorporated to allow it to be charged on any Qi-enabled charge pad.&lt;/p&gt;
&lt;h5 id=&#34;additional-components&#34;&gt;Additional Components&lt;/h5&gt;
&lt;p&gt;IR was added for local components (i.e. TV and stereo). A vibration sensor was also added in order to reduce battery usage. Without modifications, the remote lasted around 4 hours with the WiFi connection. However, by going into deep sleep until the vibration sensor is activated, this has been extended to over a week on a single charge, depending on usage. There is no discernible difference in functionality due to deep sleep.
&lt;img src=&#34;http://mreevesdsba.hopto.org/img/remote/remote1.jpg&#34; alt=&#34;Ensuring buttons and charging work before switching from dev to production board&#34;&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h2 id=&#34;software&#34;&gt;Software&lt;/h2&gt;
&lt;hr&gt;
&lt;p&gt;The microcontroller was programmed with the Arduino IDE. WiFi SSID is set with an WAP if no connection can be established. The WAP allows the user to scan the local WiFi networks, select the desired connection, and add a password.&lt;/p&gt;
&lt;h5 id=&#34;button-configuration&#34;&gt;Button Configuration&lt;/h5&gt;
&lt;p&gt;Due to the lack of inputs, each button has two input methods: short press and long press. In addition to short and long presses, a single press of the yellow button allows for each of 4 lights to be controlled individually. This means there are a total of 11 button functions instead of 4.
&lt;img src=&#34;http://mreevesdsba.hopto.org/img/remote/button.PNG&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;h5 id=&#34;wifi-communication&#34;&gt;WiFi Communication&lt;/h5&gt;
&lt;p&gt;In order to ensure ease of updates, the remote does not communicate directly with each smart device. Instead, an MQTT message is sent to a broker run through FLASK on a cloud server. The server then sends the appropriate command to the specified device.
&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h2 id=&#34;results&#34;&gt;Results&lt;/h2&gt;
&lt;hr&gt;
&lt;p&gt;While the functionality of the remote is not as user-friendly as hoped, the other aspects of the project were quite successful. The styling and innovation from nearly 70 years ago has been modernized to accommodate for current technologies.
&lt;img src=&#34;http://mreevesdsba.hopto.org/img/remote/remote3.gif&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
