# DeepSOCIAL: Social Distancing Monitoring and Infection Risk Assessment in COVID-19 Pandemic
## 3 Methodology
### People Detection
#### 3.1.4 Head Module  
The head of a DNN is responsible for classifying the objects (e.g., people, bicycles, chairs, etc.) as well as calculating the size of the objects and the coordinates of the correspondent bounding boxes. There are usually two types of head sections: one-stage (dense) and two-stage (sparse). The two-stage detectors use the region proposal before applying the classification. First, the detector extracts a set of object proposals (candidate bounding boxes) by a selective search. Then it resizes them to a fixed size before feeding them to the CNN model. This is similar to R-CNN based detectors [46; 47; 48]. In spite of the accuracy of two-stage detectors, such methods are not suitable for the systems with restricted computational resources [99]. On the other hand, the one-stage detectors perform a unified detection process. They map the image pixels to the enclosed grids and checks the probability of the existence of an object in each cell of the grids. Similar to the work done by [PERSON] et al. \"Single Shot Multibox Detector\" (known as SSD), or other works done by [PERSON] et al. [50; 51; 52], and [PERSON] et al. [53], known as \"You Only Look Once\" or YOLO detectors. Such detectors use regression analysis to calculate the dimensions of bounding boxes and interpret their class probabilities. This approach offers excellent improvements in terms of speed and efficiency. In the head of the model, we use the same configuration as YOLOv3. Similar to many other anchor-based models, YOLO uses predefined boxes to detect multiple objects. Then the object detection model will be trained to predict each generated anchor boxes that belong to a particular class. After that, an offset will be used to adjust the dimensions of the anchor box in order to better match with the ground-truth data, based on the classification and regression loss. Assuming the grid cell reference point \((c_{x},c_{y})\) at the top left corner of the object image and the bounding box prior with the width and height \((p_{w},p_{h})\), the network predicts a bounding box at the centre \((x,y)\) and the size of \((w,h)\) with the corresponding offset and scales of \((b_{x},b_{y},b_{w},b_{h})\) as follows:  
\[ \begin{array}{l}x^{\prime}=\sigma(b_{x})+c_{x}\\ y^{\prime}=\sigma(b_{y})+c_{y}\\ w^{\prime}=p_{w}e^{b_{w}}\\ lt=p_{h}e^{b_{h}}\end{array}  \tag{5}\]  
where \(\sigma\) is the Sigmoid confidence score function within the range of 0 and 1. We represent the class of \"human\" with a 4-tuple \((x,y,w,h)\), where \((x,y)\) is the centre of the bounding box, and \(w,h\) are width and height, respectively. We use three anchor boxes to find a maximum of three people in each grid cell. Therefore, the total number of channels is 18: (1 class + 1 object + 4 coordinates) \(\times\) 3 anchors. Figure 5: The YOLO-based heads applied at different scales  
Since we have multiple anchor boxes for each spatial location, a single object may be associated with more than one anchor boxes. This problem can be resolved by using non-maximal suppression (NMS) technique and by computing intersection over union (IoU) to limit the anchor boxes association. As part of the weight adjustment and loss minimisation operation, we use Complete IoU (CIoU) (in Equation (7)) instead of the basic IoU (Equation (6)). The CIoU not only compares the location and distance of the candidate bounding boxes to the ground-truth bounding box but also it compares the aspect ratio of the size of the generated bounding boxes with the size of the ground-truth bounding box. \[IoU=\frac{|B\bigcap B^{gt}|}{|B\bigcup B^{gt}|} \tag{6}\]  
\(B^{gt}=(x^{gt},y^{gt},w^{gt},h^{gt})\) is the ground-truth box, and \(B=(x,y,w,h)\) is the predicted box. We use CIoU not only as a detection metric but also as a loss function:  
\[\mathcal{L}_{CIoU}=1-IoU+\frac{|\rho^{2}(B,B^{gt})|}{c^{2}}+\alpha v \tag{7}\]  
where \(\rho\) is Euclidean distance between grand-truth \(B^{gt}\), and predicted \(B\) bounding box.