# Vehicle Detection with Self-Training for Adaptative Video Processing Embedded Platform
## 3 Methods
### Vehicle Detection  
In this work, SqueezeDet was applied for vehicle detection. In this section, the main components of the architecture and loss function are briefly described. SqueezeDet is a lightweight, single-shot, fully convolutional object detection architecture developed recently for applications in autonomous vehicles. The design objectives (efficiency and accuracy) make it perfect for the traffic monitoring system on an embedded platform. As SqueezeDet processes an image, the first step is the extraction of a high dimensional, low-resolution feature map (as in other CNN architectures). Having obtained feature map representation, the goal is to predict the bounding boxes of the vehicles in the input image. SqueezeDet falls into the category of one-stage detectors. A \(W\)\({}^{*}H\) grid is defined over an image, where \(W\) and \(H\) are the number of grid cells along the horizontal and vertical axes. At each element of the grid, there are \(K\) bounding boxes with predefined size, which are called anchor boxes. Each anchor is defined by four scalars: \(\hat{x}_{i}\), \(\hat{y}_{j}\), \(\hat{w}_{k}\), \(\hat{h}_{k}\), where \(i\in[1,W]\), \(j\in[1,H]\) and \(k\in[1,K]\). \(\hat{x}_{i}\), \(\hat{y}_{j}\), stand for spatial coordinates of \((i,j)\) grid center, and \(\hat{w}_{k}\), \(\hat{h}_{k}\) are the width and height of \(k\)-th bounding box. The anchors define the a priori distribution of the size of bounding-boxes. In total, there are \(W\)\({}^{*}H\)\({}^{*}K\) anchors that are responsible for detecting objects. One-stage detectors further learn how to refine the initial window to match the true location of the object. Hence, for each \(i\),\(j\),\(k\)-anchor four relative coordinates \(\delta x_{ijk}\), \(\delta y_{ijk}\), \(\delta w_{ijk}\), \(\delta h_{ijk}\) are computed that transform the anchor into final bounding box prediction [11]:  
\[ \begin{split} x_{i}^{p}&=\hat{x}_{i}+\hat{w}_{k} \delta x_{ijk}\\ y_{j}^{p}&=\hat{y}_{j}+\hat{h}_{k}\delta y_{ijk}\\ w_{k}^{p}&=\hat{w}_{k}+\exp(\delta w_{ijk})\\ h_{k}^{p}&=\hat{h}_{k}+\exp(\delta h_{ijk})\end{split}  \tag{1}\]  
Figure 2: Schematic overview of the presented model. The deployed system is responsible for traffic monitoring as well as for collecting new samples for model fine-tuning. The server collects the data and fine-tunes the model, which is then sent to the deployed systems. where \(x_{i}^{p}\), \(y_{j}^{p}\), \(w_{p}^{k}\), and \(h_{p}^{k}\) are the final coordinates predictions of the detected object. Each anchor also returns \(C+1\) values where the first value is a confidence score which determines how likely it is that the given bounding box contains an object. The other \(C\) scalars represent the conditional probability distribution for each of \(C\) predefined classes. Consequently, SqueezeDet returns \(W*H*K\) predictions in total. Then, as a post-processing step, the top \(N\) predictions with the highest confidence score are used for further processing with the Non-Maximum Suppression (NMS) algorithm, which removes the redundant boxes. This is a procedure that looks for pairs of boxes for which the intersection-over-union (IOU) is bigger than a selected threshold, and it removes boxes with a lower confidence score. During training, the SqueezeDet is supervised with training samples where, for each image, a list of ground truth bounding boxes (\(x,y,w,h\)), and its corresponding class \(c\), is given. The objective of the training phase is to update the weights of the neural network, so that the output from the detector matches the ground truth as closely as possible. This is achieved by defining a loss function that is optimised through backpropagation. The loss function is defined, as follows [11]:  
\[