[Irene] Servo Setbacks

I ran into servo problems this week. I started by trying to get the servo to turn using an Arduino, but it kept jittering. I tried replacing Vin and GND with a power supply from the 220 lab, but still no luck. I thought it was an issue with the PWM from the Arduino, but when Ronit lent me a mini servo from 18-349, the Arduino handled it fine. I’m also confused because the servo would draw close to 1A when it was jittering. I’m not sure if it’s a problem with the way I’m wiring or controlling the motor or if it’s a faulty motor. I asked around and someone suggested looking into stepper motors. The advantage of this is the continuous rotation. I don’t need to worry about the wheel diameter. However, stepper motors are power drains, especially when doing no work at all.

contour

con⋅ tour | /ˈkänˌto͝or/

(noun) A curve joining all the continuous points (along the boundary), having same color or intensity.

I did achieve my goal to implement image cropping. The current frame is smoothed and converted into grayscale, and then the absolute difference is taken between this and the reference frame. A binary threshold is applied to the frame delta such that if a pixel’s intensity is above a set threshold, the pixel is set to maximum intensity.

For each contour in the frame delta, if the contour area is greater than the minimum contour area parameter, the contour is considered to be actual motion. The image is cropped around all significant contours. In order to track where to crop, a bounding rectangle is drawn around each contours and the outermost corners out of all the contours set the cropping region. The original and cropped frames are written to a file and the smoothed grayscale current frame is saved as the new reference frame.

This week was high in discouragement and low in progress made. Next week, I will ask Sam and Cyrus for advice in the beginning of the week, and have new parts picked and an order in by Tuesday. I will also have the parameters for the motion detection script tuned and tested as it is integrated with Jing’s ML.

[Philip] Jetson Breakthroughs

This week I worked a lot with the Jetson. First, I wanted to be able to read and write from the GPIO pins. I looked through the datasheet of the Jetson TX2 development board to figure out what pins are available to use. Then I found a python library which would enable me to more easily communicate to the GPIO pins. Finally, I wrote simple code to show that I could in fact use the GPIO pins. I did this by reading values from the PIR sensor.

Second, I was able to download the MQTT library onto the Jetson board. I created a Python script that subscribed to messages from the simulated iPhone app on my laptop. These messages were successfully received! I now have an established protocol to communicate between both devices.

My progress is slightly behind. I was hoping to also get OpenCV downloaded and running on the Jetson board. However, I need access to an Ubuntu machine which I did not have. Luckily, my research lab has one that I am able to use. Therefore, I am expecting to catch up soon.

In the next week I hope to get OpenCV running on the Jetson board. I would like Irene to be able to test her OpenCV code on the Jetson using the USB camera. I also wish to get the timer page up and running for the iPhone app.

[Jing] Refining Tensorflow

This past week I retrained the model several times (15+ times) to optimize our neural network and improve the accuracy the inference. I initially hit an accuracy of 65% and tried several things to improve the accuracy.

First, I added another convolution layer, and it improved the accuracy of our model to 75%. However, adding a second convolution layer made our model overfit. In other words, our model hit a 90% training accuracy, but remained at a 75% validation accuracy. Adding a third convolution layer actually lowered the overall accuracy, likely because our data set is not large enough.

Afterwards, I looked into adding regularization functions to improve our validation accuracy. Regularization functions are supposed to improve overfit models by making the model less responsive to noise. These were already built in to the Tensorflow library, so utilizing them was not difficult. I tried three different regularization functions (the sum of absolute values, sum of squared values, and the sum of both), and applied them to various parameters of the neural network – the bias, kernal, and activity variables. After training several times, I discovered that accuracy was significantly worse for some models, and approximately the same for others.

The only other solution I could think of was to enlarge our data set. From what I’ve looked up online, accuracy performance peaks using a data set of 1000-2000 images per class. Our data set currently only has 500 images each for raccoons, squirrels, and the lower body of humans. Over the next week I’ll scrape some images off of Google to enlarge our data set. Enlarging the data set also means that we can increase the number of parameters our neural network can program. This means we can expand our neural network to work with more layers, which may improve the accuracy.

Before I do that next week, I attempted to make even the number of images per class to see if that would change the results. Because I have over 12000 images each of dogs and cats, I removed 11500 of them from each set, so that each class could have 500 images. After training again, I discovered that the results were approximately the same (75% validation accuracy).

Finally, I played around with the batch size of our neural network. The batch size is a parameter which tells the neural network how many images to process at one step. Initially, this value was set to 32, but the smaller I made it, the more accurate our inference was. When I tuned the batch size down to a size of 8, I was able to get a validation accuracy of 78%. This was the best I could get it up to.

March 30: Weekly Status Report

Because our team decided that we would do integration in April, we have been focusing on individual parts for the in-lab demo on April 1. Irene will demo her Computer Vision algorithm, Jing will demo his Machine Learning inference, Philip will demo his iPhone app, as well as GPIO with the Jetson board.

Unfortunately, there are a few risks which have set us back.

  1. For the cat door, the servo is jittery and doesn’t work, so Irene is planning on using a stepper motor instead. While we’re certain the stepper motor will work, in case that it doesn’t, Irene will consult her robotics friends and order multiple stepper motors to make sure that it can open the cat door.  The only costs here will be the price of two or three stepper motors.
  2. For the Machine Learning inference, we have reached a peak of 75% accuracy on the validation data set. While this is reasonably high for demoing purposes, it doesn’t meet our initial goal of 95%. After trying several different architectures and regularization functions, we decided that the best way to improve accuracy is to enlarge our data set. Over the next few weeks, we will attempt to find more images to add to our data set by scraping them off of Google images.

The schedule is approximately the same as before, with a few extra tasks. Originally, by next Saturday April 6, we planned on doing the following tasks:

Irene: Integrate CV and ML

Philip: Get camera feed on Jetson

Jing: Run Tensorflow on GPU of Jetson

The tasks that we have added are:

Irene: Get stepper motor to work with the door

Jing: Build and test solenoid circuit

[Philip] iPhone App then transition to Jetson

This week I focused on developing the app for our project. Previously I had just done a simple design for the app. Now, I am fully implementing it. Although I have created iPhone apps before, I was definitely rusty and needed to go through a fair share of tutorials to brush up. Afterwards, I was able to code the key function of the app: communicating over Wifi (using the MQTT protocol) to close or open the door. This required implementing the communication mechanism using the cocoaMQTT libraries.

(Note: in the picture there is a connect and disconnect button, but I was able to remove the need for them)

I started working on the Daily Reminder page, although I encountered difficulty with this, as the “list” feature in Xcode is difficult to understand.

On the Jetson side of things, I ordered a USB hub, as there is only one USB port on the developer kit. I also, booted up the board with Ubuntu, connected it to CMU Wifi, and downloaded all necessary libraries for Jing and Irene to use (python and pip). The benefit of this is that they will now be able to test their code on the board.

My schedule has shifted a bit because I am now focusing on the Jetson, because my partners requested I finish that part first so that we can integrate our parts sooner. Therefore the App development is being delayed and the Jetson deliverables are being prioritized.

That being said, this week I want to be able to use the GPIO pins on the Jetson board for input and output. In addition, I want the Jetson to be able to communicate over Wifi using the MQTT protocol to the iPhone App. This will require no further work on the iPhone side of things.

[Jing] Running Tensorflow on AWS

This week I began running my machine learning code on AWS. I first requested an EC2 instance with a GPU, which took about 2 days for AWS to process the request. Then on Wednesday I uploaded my data set and code to the EC2. Fortunately, the EC2 instance I requested was built for using Deep Learning libraries such as Tensorflow, so running the code on the GPU was a piece of cake. I simply had to change some settings on the EC2, and the code ran itself on the GPU (or so that’s what the terminal output said).

My first iteration of training resulted in a training accuracy of 76% and a validation accuracy of 74%, and took around 6 hours to run. This was surprisingly good. Although it doesn’t meet our goal of 95%, it seems reliable enough for demoing purposes. In order to bump up the accuracy, I added another convolution and activation (relu) layer. After training for a second time, I achieved a training accuracy of 95%, and a validation accuracy of 76%. What this means is that the model is overfit, and needs a larger data set and a regularization function. I will make the data set larger by flipping all of the images over the y-axis, and add a regularization function, and retrain tonight.

I will also draw a diagram for the solenoid sometime today. Once I finish the diagram, and once I retrain, I will update this post with the results.

March 23: Team Status Update

  • What are the most significant risks that could jeopardize the success of the project? How are these risks being managed? What contingency plans are ready?

Philip not being able to completely finish his individual parts before April 1st. He will be focusing on getting the Jetson working and pause his current work on the app.

Jing not being able to achieve 95% accuracy rate for ML algorithm: look into changing the architecture to improve from the current 80%

  • Were any changes made to the existing design of the system (requirements, block diagram, system spec, etc)? Why was this change necessary, what costs does the change incur, and how will these costs be mitigated going forward?

Added a USB Hub to use with the Jetson. Otherwise, no changes to the design.

  • Provide an updated schedule if changes have occurred.

The current goal is to finish all individual parts by April 1st.

[Irene] Sliding Panel & GIFs

I started the week off by attaching the panel to the drawer slides.

Then, Prof. Nace helped me out with the band saw to create two rectangular prisms for the other side of the drawer slides. I secured the drawer slides to the rectangular prisms and attached them to the indoor side of the door.

It’s a little lopsided, but it works.

Animated GIF - Find & Share on GIPHY

Unfortunately, devices are not mounted on the door because I was waiting on parts. However, I made up for that by spending time getting ahead on the motion detection script. I prepared testing data by downloading videos of raccoons and editing ten clips of raccoons that will be used as input to the system. For the motion detection, when a large enough change is detected between the current frame and the reference frame, the program saves a JPEG file, which is the file type that Jing is working with for the ML model. The current frame is set as the new reference frame. This allows the program to output a series of images spaced out in time. The images are noticeably different from each other such that our ML model is not wasting time computing on redundant images. This script does not do any image cropping. To demonstrate the program functionality, I have strung together the image outputs from the program as GIFs:

Animated GIF - Find & Share on GIPHY

Animated GIF - Find & Share on GIPHY

Deliverables for next week are to have the rotating servo that lifts the panel and image cropping implemented in the motion detection script.

[Jing] Setting up Tensorflow

This week I began learning how to use Tensorflow to build a Convolutional Neural Network and train a machine learning model. I did a tutorial online and found that it was surprisingly easy and intuitive.

Originally, the convolutional neural network was supposed to classify between 6 different types of objects: Cat, Dog, Squirrel, Raccoon, Legs, and Shoes. After taking sample images using a camera that was set up at the cat door height from one meter away, I realized that almost all of the time, the camera would see a human’s entire lower body, from the hip to the feet. Therefore, instead of classifying Legs and Shoes, we will get rid of both of them and classify Lower Body. I had previously found a large image data set of humans which contained annotated human body parts, so I wrote a python script to parse through some 10 gigabytes of images and only keep the ones which contained a human’s lower body. Then, I properly arranged each set of images into a directory for the Tensforflow script to read.

Now that the Tensorflow script has been written, the convolutional neural network built, and the data set prepared, I will test on a small sub-data set to ensure that the script is correct and then deploy the entire thing to AWS. I will slowly get to these two tasks over Spring Break and have them done before school starts again.

March 9: Team Status Update

This week the team finished the design review report and spent most of the time working on individual parts, including the ethics reading assignment. Because it was the week before Spring Break, most of us were busy studying for exams or finishing large assignments due before break, however, we are still on schedule. We forwarded our design review report to Professor Bain for review and had a phone call with him to address some of the worries we had with scheduling. We agreed that everyone should plan on finishing every as early as possible to address unforeseen issues and communicate as soon as a problem arises, especially because certain parts depend on others. Although we weren’t planning on working over Spring Break, we will continue to make progress and keep each other updated during this time.