Here, we state the problem of pest elimination in terms of using AI and DNN. We then suggest two possible solutions: 1 – using pretrained SSD models to detect cats, sheep and others; 2 – using MD and train our own DNN to detect ‘nonstandard’ pests such as moose. Finally, we provide a short outline of the series and state the tools for developing: Python, OpenCV, Caffe.
Introduction
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.
This series will guide you through several steps. First, we’ll show you how to apply a pre-trained deep neural network (DNN) detector to find pests on video. We’ll then describe the possible solutions for detecting unusual pests that cannot be detected with most of the existing DNN detectors. Next, we’ll focus on the implementation of the selected approach. We’ll explain how to gather a dataset for DNN training and provide data augmentation methods for extending the dataset. We’ll train a DNN for detecting a rare pest, then we’ll develop the computer code for a simple motion detector and explain how to use it together with the trained DNN. Finally, we’ll adapt the code for Raspberry Pi and show you how to play a scary sound to chase the detected pests away.
The project code will be written in Python 3.7 to run on a PC and then on a Raspberry Pi device. The OpenCV library will provide us with computer vision algorithms, and the Caffe DL framework will be used for DNN training. These software pieces are easy to download and install on your PC.
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.
Selectors vs. Detectors
Our first task is to detect a pest in the video stream from a camera using an edge device like Raspberry Pi. We’ll use AI to solve this problem. The most powerful modern AI approach to image recognition and video processing is to use deep neural networks (DNNs). Various types of DNNs have been successfully applied to the most difficult problems in computer vision, including the detection of various objects: humans, animals, and so on.
To achieve our goal, we can use two main DNN types. The first network type is a simple classifier. This is a DNN trained to define what class an object in an image belongs to.
Image classification was the major success for convolutional neural networks (CNNs). This led to the deep learning (DL) revolution in image processing. One of the advantages of classifiers is their high precision. Modern DNN classifiers can achieve 90% — or higher — classification accuracy for image datasets with hundreds or even thousands of classes.
However, applying classifiers to our task poses some challenges. One problem is that an image submitted to a classifier should only contain one identifiable object. Another issue is that an object — such as a human or an animal — must usually occupy most of the image’s area for a classifier to handle it correctly. Since a pest probably won’t occupy most of a camera frame, we need to find a way to detect objects that only take up part of an image.
We can circumvent the limitations of classifiers by using an alternative DNN type: a detector. Detector networks can determine if an image contains an object of a certain class, and can also identify the location of the object within the image.
Detector DNNs can be used on images containing multiple objects of different classes because they locate the separate objects first, and then classify each located object. The only drawback of Detector DNNs is that they’re less accurate than classifiers.
Overall, a detector network will be a more viable option in our case, so a detector it is!
Detector DNNs can definitely help us solve the first part of our problem — detect a pest in an image. If we can do that, we’ll also be able to detect pests in a video stream. The only question is whether we can do it in real time on an edge device, such as a Raspberry Pi. These devices aren’t very powerful, so we should be very careful when selecting a neural network. We need one that can run in real-time on our edge device. See this article for a deep-dive into choosing object detector neural networks suitable for edge devices.
Next Step
In the next article, we’ll use a pre-trained DNN to detect pests on video.
History
- 15th December, 2020: Initial version