Tips for implementing SSD Object Detection (with TensorFlow code)
Tips for implementing SSD Object Detection (with TensorFlow code)
Object Detection using Single Shot MultiBox Detector
The problem
The task of object detection is to identify " what" objects are inside of an image and " where" they are. Given an input image, the algorithm outputs a list of objects, each associated with a class label and location (usually in the form of bounding box coordinates). In practice, only limited types of objects of interests are considered and the rest of the image should be recognized as object-less background.
Object detection has been a central problem in computer vision and pattern recognition. It does not only inherit the major challenges from image classification, such as robustness to noise, transformations, occlusions etc but also introduces new challenges, for example, detecting multiple instances, identifying their precise locations in the image etc.
Before the renaissance of neural networks, the best detection methods combined robust low-level features (SIFT, HOG etc) and compositional model that is elastic to object deformation. A classic example is " Deformable Parts Model (DPM) ", which represents the state of the art object detection around 2010. However, its performance is still distanced from what is applicable in real-world applications in term of both speed and accuracy. Moreover, these handcrafted features and models are difficult to generalize – for example, DPM may use different compositional templates for different object classes.
Since the 2010s, the field of object detection has also made significant progress with the help of deep neural networks. In this tutorial we demonstrate one of the landmark modern object detectors – the " Single Shot Detector (SSD)" invented by Wei Liu et al.
| Network | SSD300 | SSD512 |
|---|---|---|
| Training Speed (images/sec) | 145 | 65 |
| (AP) IoU=0.50:0.95, area=all, maxDets=100 | 21.9 | 25.7 |
| Total training time (100 epochs) | 23.5 hours | 42.5 hours |
- Hardware: Lambda Quad i7-7820X CPU + 4 x GeForce 1080 Ti
- OS: Ubuntu 18.04 LTS with Lambda Stack
Single-Shot Detector
Let's first remind ourselves about the two main tasks in object detection: identify what objects in the image (classification) and where they are (localization). In essence, SSD is a multi-scale sliding window detector that leverages deep CNNs for both these tasks.
A sliding window detection, as its name suggests, slides a local window across the image and identifies at each location whether the window contains any object of interests or not. Multi-scale increases the robustness of the detection by considering windows of different sizes. Such a brute force strategy can be unreliable and expensive: successful detection requests the right information being sampled from the image, which usually means a fine-grained resolution to slide the window and testing a large cardinality of local windows at each location.
SSD makes the detection drastically more robust to how information is sampled from the underlying image. Let's first summarize the rationale with a few high-level observations:
- Deep convolutional neural networks can classify object very robustly against spatial transformation, due to the cascade of pooling operations and non-linear activation. This is something well-known to image classification literature and also what SSD is heavily leveraged on.
- Deep convolutional neural networks can predict not only an object's class but also its precise location.
- Last but not least, SSD allows feature sharing between the classification task and the localization task.
While the concept of SSD is easy to grasp, the realization comes with a lot of details and decisions. Next, let's discuss the implementation details we found crucial to SSD's performance.
Implementation Details
Input and Output: The input of SSD is an image of fixed size, for example, 512x512 for SSD512. The fixed size constraint is mainly for efficient training with batched data.
The output of SSD is a prediction map. Each location in this map stores classes confidence and bounding box information as if there is indeed an object of interests at every location.
Multi-scale Detection: The resolution of the detection equals the size of its prediction map. Multi-scale detection is achieved by generating prediction maps of different resolutions.
Priorbox: Heads up – this is important!
We know the ground truth for object detection comes in as a list of objects, whereas the output of SSD is a prediction map.
- There can be multiple objects in the image.
- Intuitively, object detection is a local task: what is in the top left corner of an image is usually unrelated to predict an object in the bottom right corner of the image.
This is where priorbox comes into play.
Hard negative mining: To address this problem, SSD uses hard negative mining: all background samples are sorted by their predicted background scores in the ascending order.
Data augmentation: SSD uses a number of augmentation strategies.
Pre-trained Feature Extractor and L2 normalization: Although it is possible to use other pre-trained feature extractors, the original SSD paper reported their results with VGG_16.
Post-processing: The prediction map cannot be directly used as detection results.
Demo
You can download the demo from this repo.
git clone https://github.com/lambdal/lambda-deep-learning-demo.git
Follow the instructions in this document to reproduce the results.
https://lambdalabs.com/lambda-stack-deep-learning-software
Once you have TensorFlow with GPU support, simply run the following the guidance on this page to reproduce the results.