Problem: Cats do not respect countertop cleanliness or personal boundaries such as shut doors.
Goal: Develop a device that will automatically detect cats and squirt them with water when they enter a certain space.
So how do we detect a cat? or a dog, but not myself while I make dinner?
Google has released some amazing tools recently for the use of object detection, or in this case, just cat detection. These are neural networks that are "trained" on thousands of pictures, such that they can identify common objects. For this application, we are using the MobileNet architecture that excels at object detection and is computationally simple enough to run on "edge" devices like a Raspberry Pi.
I should clarify that there are two big parts to this. The first is called training, where the neural network is exposed to a large dataset. The second part is when the model is implemented, and performs what is called inference. Inference is comparatively much less computationally intense, allowing us to do this on a Raspberry Pi.
We can also take Google's generic model and perform what is called "transfer learning" to get the network to identify s specific object that we have data on, like our own cat, or just to improve the model with a more diverse dataset.
I wanted to do this on my own dataset, so I snapped lots of pictures of my cats( just kidding, I already had plenty) and set out to learn Google's training package, Tensorflow. This is a seriously computationally intense process, so I used Amazon's EC2 GPU enabled instances to do the training on. These will perform the same tasks at least an order of magnitude more quickly than your average laptop.
In order to run the object detection on the Raspberry Pi, you must install all the required software, including OpenCV and it's dependencies. This take a few hours and there are several optimization that are helpful for pulling every last bit of performance out of the Raspberry Pi. For example compiling OpenCV with NEON, FVPV3 will increase the frames per second a noticeable amount. Some have gone to the effort of getting Intel's TBB (Thread building blocks) compiled as well, which should improve the Raspberry Pi's ability to parallelize the tasks.
Initial results from testing are highly effective, as can be seen below! The cat's give it about two tries and don't come back.