Here we state the problem of using a pretrained SSD model. We then suggest two methods to detect such unusual animals: 1 – fine-tune the pretrained SSD for the animal type; 2 – develop our own lightweight DNN (not SSD) model and use it together with a motion detector. Finally we use the second approach and detect the moose.
Unruly wildlife can be a pain for businesses and homeowners alike. Animals like deer, moose, and even cats can cause damage to gardens, crops, and property.
In this article series, we’ll demonstrate how to detect pests (such as a moose) in real time (or near-real time) on a Raspberry Pi and then take action to get rid of the pest. Since we don’t want to cause any harm, we’ll focus on scaring the pest away by playing a loud noise.
You are welcome to download the source code of the project. We are assuming that you are familiar with Python and have a basic understanding of how neural networks work.
In the previous article, we described how to detect animals with the MobileNet SSD model pre-trained on the Pascal VOC 2012 dataset. This model can detect twenty types of objects, including potential domestic pests like cats and dogs. Unfortunately, it can’t detect wildlife. In this article, we’ll explore our options for detecting wildlife pests like deer, moose, and armadillos.
Use Another Model?
We’ve found an object detector network that seems to work well — except it can’t detect all of the pests we’d like to recognize.
Should we use an alternative DNN detector model that includes the deer, moose, and armadillo classes? That might work, but remember that our choice is restricted to those models that can run on a device without much computing power.
Models that work well on such devices are usually trained on datasets with less than 100 classes. For example, the popular COCO dataset contains 80 object categories. So we’re in a situation where no suitable pre-trained DNN model has a class for every animal we want to detect. For instance, the COCO dataset does not have a class for moose.
Perhaps Another Dataset Instead?
Here’s another idea: What if we train our MobileNet model on a new dataset that contains our pest of choice? This approach is called transfer learning. It has proven effective in many areas of computer vision. But how does transfer learning work, and how could we use it?
First, we’ll need to acquire a data set containing images of the new pests the network should recognize.
Then, while training the base DNN model on the new dataset, some of the network’s convolutional layers can be frozen to prevent their kernels (convolutional filters) from changing during the training process. Other layers get trained on the new dataset in such a way that the model becomes "tuned" for detecting new classes.
One advantage of this approach is that it uses a proven and reliable DNN model, which gives us a good chance of getting accurate results for detecting our "exotic" pest. On the other hand, fine-tuning an SSD model is not a trivial task. It requires a large dataset containing the new pest, as well as a lot of experience and effort to tune the model to a high degree of accuracy.
Nope, Use Another Model — a Simpler One
Yet another approach is to create our own lightweight model, which can be more effective on edge devices. In this case, we should probably sacrifice the versatility of an SSD model for the simplicity of a classifier. Our aim is to create an AI system that can recognize a specific type of animal, and we can develop a classification DNN appropriate for this task. This model can be very simple compared to the SSD model we used earlier in this series. On the other hand, we can expect this model to be more effective when running on an edgedevice.
As we’ve mentioned before, the capabilities of classifier DNNs for pest detection are limited. With classifiers, the detection object must be seen as a whole in an image, so we need to design an algorithm for selecting the part of the image containing the object.
This can be achieved with the use of a simple motion detector. Because our final goal is to detect pests in video streams (not in separate frames), we can use a motion detection algorithm to select segments of interest and then apply the classifier to check whether the selected segments contain a pest.
We’ll choose the last approach — the development of a lightweight, simple classifier model — for our pest elimination system. In the next article, we’ll create the training dataset for our pest of choice: The moose.