## 3 Methods and Materials
### Application Logic Unit Layer
#### 3.4.1 YOLO Deep Neural Network
In view of that, we decide to choose the YOLOv2 instead to introduce some latency in the movements that would annoy the users. _YOLOv2_ network [23] is a CNN made up by 24 convolutional layers, followed by two fully connected layers. This network is inspired by _GoogLeNet_ but has some differences that make it lighter and more efficient. The architecture of _YOLOv2_ is shown in Figure 5[24]. The first convolutional layer performs a downsampling of the input images; the other convolutional layers are used to perform features extraction. The fully connected layers, instead, make the real decision about the bounding boxes and the found objects. Each frame is divided into a grid of \(S_{x}\cdot S_{y}\); in each grid cell, a maximum number of \(B\) bounding boxes are searched; for every bounding box, a certain confidence score is assigned. The confidence score is the probability that inside a bounding box an object is contained and how accurate the decision is. This confidence is expressed as \(p(Object)\). Thus, each bounding box consists in five values: \(X\), \(Y\), \(W\), \(H\) and, \(Confidence\). Furthermore, for each grid cell, the probability of the \(C\) conditional class is computed. In this way, it is possible to obtain for the entire image N bounding boxes, divided into grids. This leads to:  
\[p(Class_{i}|Object)\cdot p(Object)\cdot IOU_{pred}^{truth}=p(Class_{i})\cdot IOU _{pred}^{truth} \tag{2}\]  
for a total of \(S_{x}\cdot S_{y}\cdot(B\cdot 5+C)\) numbers of tensors for iteration, where:  
* \(p(Class_{i}|Object)\): Given a grid cell with at least one object, it represents the conditional probability for one of them to belong to the \(i\)th class. Figure 5: The YOLO network architecture. * \(p(Object)\cdot IOU_{pred}^{truth}\): It represents the confidence of each bounding box inside a cell grid. In each cell, only the classes with the highest \(Confidence\) are taken. For the training phase, the network exploits a multi part loss function (see Equation (3)). \[Loss=\lambda_{coord}\cdot\sum_{i=0}^{S_{x}\cdot S_{y}}\sum_{j=0}^{B} \mathbb{1}_{ij}^{obj}(x_{i}-\hat{x}_{i})^{2}+(y_{i}-\hat{y}_{i})^{2}\] (3) \[+\lambda_{coord}\cdot\sum_{i=0}^{S_{x}\cdot S_{y}}\sum_{j=0}^{B} \mathbb{1}_{ij}^{obj}(\sqrt{w_{i}}-\sqrt{\hat{w}_{i}})^{2}+(\sqrt{h_{i}}- \sqrt{\hat{h}_{i}})^{2}\] \[+\sum_{i=0}^{S_{x}\cdot S_{y}}\sum_{j=0}^{B}\mathbb{1}_{ij}^{obj} (C_{i}-\hat{C}_{i})^{2}+\lambda_{noobj}\sum_{i=0}^{S_{x}\cdot S_{y}}\sum_{j=0} ^{B}\mathbb{1}_{ij}^{obj}(C_{i}-\hat{C}_{i})^{2}\] \[+\sum_{i=0}^{S_{x}\cdot S_{y}}\mathbb{1}_{i}^{obj}\sum_{c\in classes }(p_{i}(c)-\hat{p}_{i}(c))^{2}\]  
where \(\mathbb{1}_{ij}^{obj}\) denotes the \(j\)th bounding box responsible of the prediction of the object in the \(i\)th cell, \(\mathbb{1}_{i}^{obj}\) indicates if an object appears in the \(i\)th cell, \(\lambda_{coord}\) is a constant used for the cell with some objects in it, and \(\lambda_{noobj}\) is a constant used for the cell without objects in it. For our project, the network was retrained to allow the recognition of buttons of the lifts panels. To reduce the training time, we started with the weights of the _Darknet_ and we executed a _fine-tuning_ on the \(YOLOv2\), by changing the weights of the last two layers. This procedure allows maintaining the same feature extraction layers, retraining only the decision part. In addition, the time required for a fine-tuning is less than the one for a full training. The _training-set_ was composed by 23,000 images; the training was represented by 70% of the images, while the validation and test were represented by 15% each. The dataset was created using, respectively, 57% and 43% of doors and lift buttons images. Such pictures were taken from the _ImageNet_ dataset [25]. Owing to the low number of lift buttons present on the dataset, some additional images were used, which were labeled by using the \(COCO\) annotation [26]. In view of the reduced number of training data and of the noise introduced by the low cost camera, the \(mAP\) was 45% during the working conditions.