build details

# Real-time object detection: Project report

Modified 2021-01-01 by Dishank Bansal

Authors :

Dishank BANSAL
Bhavya PATWA
Sophie CHAUDONNERET

## The final result

Modified 2021-01-01 by Dishank Bansal

Let’s start from a teaser.

The instructions and code to get the results mentioned in this report can be found on project github repository.

## Mission, Scope and motivation

Modified 2021-01-01 by Dishank Bansal

Perception is a key component for any autonomous system. State-of-the-art autonomous driving technologies have object detection as part of their perception method. Unfortunately, benefits of object detection were never fully leveraged for Duckietown as this method runs into one big obstacle: real-time performance. Real time performance is crucial for robotics and as object detection is quite computationally expensive, its performance on the duckiebot is limited. The goal of this project is to propose a method for real-time object detection and tracking that can be run on a duckiebot with acceptable performance using a Jetson Nano.

### Existing solution

Modified 2021-01-01 by Dishank Bansal

For this work, and with this difficult context, we were not able to build our own dataset to train our different models. Fortunately, a previous project built a whole dataset for to implement object detection in Duckietown. We also found this project that aimed at implementing an object detector in DuckieTown. Unfortunately, this project seems to be deprecated, so we did not use it. Finally, we used the exercise 3 structure to implement our final object detector.

### Opportunity

Modified 2021-01-01 by Dishank Bansal

As stated before, no object detectors were implemented in the DuckieTown pipeline for one good reason : it could not run on the Raspberry Pi in real time. This year, we were lucky to also have a Jetson Nano that has a more powerful GPU. We therefore decided to try and implement an object detector that : - run faster with Tracking while maintaining a good accuracy, - can run on the Jetson Nano at reasonable speed.

To do this, we compared and used different objection detection methods to find out which offers the best compromise between performance and accuracy in the DuckieTown setting. To increase the speed of the object detection, we also used tracking between two object detections. With the final OD real-time pipeline, we tried to implement a way to avoid detected obstacles.

## Background and Preliminaries

Modified 2021-01-01 by Dishank Bansal

In this report a few preliminary knowledge is needed.

The main mathematical difficulty that the reader can encounter is the Kalman Filter. Kalman filter is used in this project in the Tracking step. The main idea of the Kalman filter is that, given a model of evolution of our state, its noise model and the measurement and noise measurement model of our system, we can firstly predict the next step state then, with our measurement corresponding to this new step, we can update to take into account both the dynamic model and the measurement. A full lecture was given by Dr. Forbes on this subject there.

On another subject, the two neural networks that are presented are compared have two very different architectures. Indeed, there are mainly two types of object detectors. On the one hand, we have the one-stage object detectors, such a Yolo or SSD-MobileNet, which make a fixed number of predictions on grid. On the other hand, the two stages object detectors use a proposal network to find approximately objects and then use a second network to fine-tune these detections and give final predictions, such as FasterRCNN or MaskRCNN. One stage ODs tend to have faster inference time while two stages ODs tend to have higher mean average precision. This article explains quite thoroughly the differences and similarities between the two architectures.

## Object detection models : FasterRCNN vs. YOLOv5

Modified 2021-01-01 by Dishank Bansal

### FasterRCNN architecture and performance

Modified 2021-01-01 by Dishank Bansal

As mentioned above, FasterRCNN is a two stage detector. The first stage is called the RPN (Region Proposal Network), it processes the images by a feature extractor and keep only the topmost feature maps to to predict bounding box proposals. The second stage then crop features from the topmost feature maps using these bounding box proposals. The cropped features are then passed on to the FastRCNN for bounding box regression and classification.

As its name suggests, FastRCNN is a faster version of R-CNN. Its architecture is presented in figure 3.1.

In figure 3,2, you can see the 2 stages mentioned above and the FastRCNN module.

### Yolo architecture and performance

Modified 2021-01-01 by Dishank Bansal

YOLOv5 is a one stage object detector, like any one stage detector, it is made of three main parts :

• model backbone
• model neck

The model backbone is used in object detection to extract the most important features : the richest and most distinctive ones. In YOLOv5, the backbone used is CSPNet which stands for Cross Stage Partial Networks.

Model neck is used in object detectors to build feature pyramids in order to detect an object of different sizes and scales. There are many different feature pyramid techniques available. YOLOv5 uses PANet, which stands for Path Aggregation Network.

The YOLOv5 model head is the same as in the previous version of Yolo.

Figure 3.3 gives an overall representation of YOLOv5 architecture.

## Tracking

Modified 2021-01-01 by Dishank Bansal

### Motivation

Modified 2021-01-01 by Dishank Bansal

Now that we have found the detector that provides the best compromise between performance and accuracy, we wanted to be able to speed up the detection process by tracking the detected bounding boxes between two detections in order to be able to skip frames in our object detector.

Moreover, Tracking can help to recover dropped detection for in-between frames.

### Kalman filter

Modified 2021-01-01 by Dishank Bansal

To track a bounding over frames, we will be working in pixel space. For tracking, we assume here that the bounding boxes moves at constant speed in pixel space.

We will use a Kalman filter to track our bounding boxes. Let be the state vector that represents the bounding boxe coordinates and their velocities.

The motion model of the system that will be used for prediction is quite simple (as velocity is assumed constant):

The bounding box detection by object detector is used as measurement in the update step. The measurement is the bounding box coordinates :

The measurement model of the system is then :

The final Kalman filter equations for bounding box tracking is :

• Prediction step :

• Update step :

### Hungarian filter

Modified 2021-01-01 by Dishank Bansal

In the previous section, we only talk about one bounding box that we track through frames.

In reality it is more complex : when there are multiple detections (i.e multiple bounding boxes), how to know which observation associate with which prediction at the update step ?

A solution is to use the Hungarian algorithm for Data association.

Let there be N predicted bounding boxes and M observations (detected bounding boxes). The Hungarian Algorithm will match the N boxes to N observations among the M possible so that the solution is optimal over a given metric. Here, the metric used is IoU, which stands for Intersection over Union. It is computed using this formula :

## Object avoidance

Modified 2021-01-01 by Dishank Bansal

In this section, we will see how we can use the duckiebot and duckie detector to implement certain behaviours in order to make DuckieTown safe again. We had two main goal behaviours :

• Stopping in front of an obstacle
• Overtaking an obstacle

### Compute obstacle position in lane

Modified 2021-01-01 by Dishank Bansal

First of all, we need to know, from the bounding boxes detected by our detector, the position of the obstacles. This position will be used to pass two information to the lane controller :

• Is there an obstacle close enough in our lane ?
• Is there a close obstacle in the other (left) lane ?

Let’s take a bounding box. The coordinate of this box is given in pixels in the distorted image (due to the camera lens). First, we need to compute the center of the obstacle on the ground. Then, we need to rectify the center coordinates so that it corresponds to the rectified image. Since the point is considered on the ground (low edge of the box), we can use the GroundProjection module (used for line detection) to estimate the real coordinates from the duckiebot’s origin. Then, with the duckiebot’s lane pose, we can compute the obstacle lane pose using this formula :

A diagram given in figure 3.4 illustrates the situation, the grey rectangle being the duckiebot and the yellow cross an obstacle.

In the figure 3.5, the flowchart to make the decision is detailed.

### Stopping in front of an obstacle

Modified 2021-01-01 by Dishank Bansal

The first behaviour is quite straight forward : if an obstacle (duckiebot of duckie) is detected in our lane close enough from the bot, the lane controller passes to the wheel command. Figure 3.6 details the algorithm used to stop in front of an obstacle.

### Overtaking an obstacle

Modified 2021-01-01 by Dishank Bansal

Here the problem is more challenging : avoiding an obstacle. In the literature, obstacle avoidance is well researched and most of the solutions proposed use graphs in which the vehicle must find the shortest path while respecting constraints or path planning.

In DuckieTown, we thought it would be simpler to overtake the obstacle by switching lane.

Our solution is to change the d_off parameter used in the Lane Controller Node to make the duckiebot believe it is not in the right lane.

First, we need to increase the d_off parameter so that the bot moves to the left lane, then keep it increased while it passes the obstacle and finally decrease it to switch back to the right lane.

The decision process to know when to overtake is detailed in figure 3.5. In figure 3.7, the flowchart to overtake the obstacle is explained. The corresponding algorithm is also detailed in figure 3.8.

## Formal performance evaluation / Results

Modified 2021-01-01 by Dishank Bansal

We compared the different detectors using different processors to assess which will perform best on the duckiebot.

Here are some specifications regarding the material used to obtain the metrics provided above :

• CPU : AMD Ryzen Threadripper 1950X 16-Core Processor
• GPU : GeForce RTX 2080 Ti, 11 GB
• RAM : 32 GB
• Jetson Nano : specifications cqn be found here

The metrics used to assess the object detector’s performance are FPS (Frames Per Second) and mAP (mean Average Precision). The first one measures the detector’s speed and the second one its accuracy.

We would like to remind the reader here that the following numbers are without Tracking and that FPS can be easily doubled if we do measurement after every one image and use prediction for in between frames.

Here is the performance of FasterRCNN with two different backbones : Resnet50 and Resnet18. Both were tested using the DuckieTown gym mentioned [above]{#real-time-object-detection-final-literature}.

• Using the Resnet50 backbone :

• Using Resnet18 :

YOLOv5 has been tested on high and low-resolution images.

Hence, we achieve about real-time performance of 20 FPS on Jetson Nano using DL based object detector and combining it with tracking

## Future avenues of development

Modified 2021-01-01 by Dishank Bansal

Making Docker image with Object Detection that can be run on Jetson Nano.