# Vehicle Detection with Self-Training for Adaptative Video Processing Embedded Platform
## 3 Methods
### Automatic Labelling and Fine-Tuning
```
1:\(image\), \(tracks\), \(fg\_mask\)\(\triangleright\)\(fg\_mask\) = foreground mask Output: detections
2:\(is\_candidate\leftarrow false\)
3:\(tracks\leftarrow FilterTracks(tracks,fg\_mask)\)
4:for all \(trk\) in tracksdo\(\triangleright\) For all trackers
5:if\(trk\_conf\) in range (\(C_{min}\), \(C_{max}\)) then\(\triangleright\) If low- confidence detection
6:if\(trk\_length>=L_{min}\) or \(trk\_maxConf>C_{t}\)then\(\triangleright\) confident tracker
7:\(is\_candidate\leftarrow true\)
8:break
9:if\(is\_candidate\) and \(Is\_MotionCovered(track,fg\_mask)\)then
10:return\(tracks\_bboxes\)\(\triangleright\) return filtered bounding boxes
11:elsereturn None
12:procedureFilterTracks(tracks, \(fg\_mask\))\(\triangleright\) Filter out tracks that belong to the background
13:\(ret\_tracks\leftarrow[]\)
14:for all\(trk\) in tracksdo
15:\(x1,y1,x2,y2\gets trk\_bbox\)
16:\(fg\_probe\gets fg\_mask[y1:y2,x1:x2]\)
17:\(fg\_pixels\gets count\_nonzero(fg\_probe)\)
18:\(mov\gets fg\_pixels/((y2-y1)*(x2-x1))\)
19:if\(mov>T_{m}\)then\(\triangleright\) If at least \(T_{m}*100\)\(\%\) pixels are foreground
20:\(ret\_tracks.append(trk)\)
21:return\(ret\_tracks\)
22:
23:procedureIsMotionCovered(tracks, \(fg\_mask\))\(\triangleright\) Return true if foreground objects are detected
24:\(fg\_pixels\gets count\_nonzero(fg\_mask)\)\(\triangleright\) number of \(fg\) pixels
25:for all\(trk\) in trackersdo\(\triangleright\) For all trackers
26:\(fg\_mask[trk\_bbox]\gets 0\)\(3\)\(\triangleright\) not covered pixels
27:\(rem\_pixels\gets count\_nonzero(fg\_mask)\)\(\triangleright\) not covered pixels
28:\(frac\_covered\gets 1-rem\_pixels/fg\_pixels\)
29:return\(frac\_covered>T_{c}\)
```  
**Algorithm 1** Extract Labels  
The model gets fine-tuned after the automatically labelled samples are collected. To prevent catastrophic forgetting, a popular rehearsal technique is used, where the initial data (on which the model was trained) is mixed with new data during the fine-tuning stage [38]. One of the drawbacks of this method is that it requires access to a lot of data storage. However, because in our architecture, the model is fine-tuned on the core server, there are no strict storage constraints in this case. Our labelling procedure works on the assumption that it is possible to train an initial model that will perform sufficiently in the deployment environment so that it can obtain confident tracks of at least some objects. This assumption is met for objects for which a large database is available, i.e., for vehicles. However, the main drawback of the presented method is the use of the one-stage detector in which a whole frame is being employed for neural network training. This means that all of the objects in the scene should be correctly annotated in this case. This stands in contrast to the exemplar-based method [24], where sparse labels (a bounding box only around the single object of interest) are used. Yet, because the goal is real-time performance on embedded systems, and utilising advances in CNNs, the one-stage detector is our choice. To reduce the number of noisy labels, the background subtraction method is employed, which can fail in some dense traffic scenes or during the nighttime. However, automatic labelling can be turned off in such situations. Nonetheless, using a detector that can be trained on sparse labels is an important future research direction.