# Deep Learning Models for Road Passability Detection during Flood Events Using Social Media Data
## 4 Proposed Solutions
### Algorithms Based on Image Only
#### 4.2.3 Compactness Loss  
As previously explained, the problem is divided into two tasks: (i) detecting if the image has evidence of roads and (ii) if the image has been classified as containing a road, determining whether the road is passable or not. The first task could be considered as a _binary classifier_ (\"evidence of road passability\" and \"no evidence of road passability\"), but the concept of \"not having any evidence of road passability\" could also be subsumed by \"anything which is not contained in the first class\". Thus, the problem could also be considered as a _one class classification_ or as an _out of distribution problem_, where \"evidence of road passability\" would be the class to classify (or the in distribution class). The advantage of considering the problem as a one-class classification problem rather than a binary classification problem is that one-class classification algorithms take into account that the out of distribution class is not only defined by the images used for the training, but that it could be anything that has not previously been seen during the training phase. Similarly, the second task could be considered as a _binary classification problem_ (\"passable\" and \"impassable\" roads) or as a _one class classification problem_ \"passable road\". For this solution, we considered both tasks as a one-class classification problem. Taking inspiration from [55], we wanted the features extracted from the first fully connected layer to be as descriptive as possible for the class at hand, meaning that the feature representation of that class' images will be distinctive from the feature representation for images not belonging to the class and, at the same time, we would like a low intra-class distance, meaning that features from the same class should be as close as possible in the feature space. This optimization can be described as \(\hat{g}=\max_{g}D(g(t))+\lambda C(g(t))\), where: \(g\) is the deep feature representation for the training data \(t\), \(\lambda\) is a positive constant and \(\mathcal{D}\) is the _Descriptive loss function_ (within this approach, we used the cross-entropy) and \(\mathcal{C}\) is the _compactness loss function_, which evaluates the batch inter-class deep feature distance to derive objects from the same class. This compactness loss can be applied to either of the two previous models, the ensemble base image architecture or the double-ended architecture. In the first case, we would add the compactness loss to the first fully connected layer. For the double-ended architecture, we would replace the last fully connected layer by a fully connected layer followed by two fully connected layers in parallel--one for each task--and add a compactness loss for each task, as shown on Figure 8. The outputs of both final fully connected layers are two real values in the range (0,1). They represent the percentage of which the evidence is believed to be of roads and of passable roads, respectively. The two outputs are then rounded according to a threshold of 0.5. Therefore, the first output is the classifier for the ER class. On the other hand, to avoid inconsistent classifications (i.e., ER = false and ERP = true), the second output is multiplied by the first one, determining the classifier for the ERP class. Note that the decision of which fully connected layer accomplishes the ER and which the ERP tasks is taken during the network training phase. For the compactness loss, we implemented the same loss as the one proposed in [55], which is given by  
\[l_{c}=\frac{1}{nk}\sum_{i=1}^{n}\mathbf{z_{i}}^{T}\mathbf{z_{i}} \tag{1}\]  
where \(\mathbf{z_{i}}=\mathbf{x_{i}}-\mathbf{m_{i}}\), being \(\mathbf{x_{i}}\in\mathbb{R}^{k}\) the samples of the batch of size \(n\) for all \(1\leq i\leq n\) and \(\mathbf{m_{i}}=\frac{1}{n-1}\sum\limits_{ \begin{subarray}{c}j=1\\ j\
eq i\end{subarray} }^{n}\mathbf{x_{j}}\), the mean of the remaining samples.