# JANNet: A U-Shape Network with Jump Attention for Semantic Segmentation of Road Scenes
## 3 Results
### Loss Function  
The basic loss function used in this paper is the NLLLoss loss function provided by Pytorch, which can be used with the Softmax function to achieve the need for fast descent in the case of high error and close to the optimal solution. The optimal solution of the model turns to be better and faster. Since the experimental dataset belongs to the complex scene segmentation dataset, the samples have the characteristics of containing many target categories and an unbalanced number, which leads to the fact that the model cannot learn the features of each category equally and guarantee the segmentation accuracy of each category. In this paper, the category balance method is used to calculate the occurrence frequency \(fq_{i}\) of each category, which is the number of pixels in that category divided by the total number of pixels in the data, where \(i\) represents the \(i\)-th category. In addition, the median value of the occurrence frequency \(fq_{s}\) of all categories is found and divided by the corresponding frequency of that category to obtain the weight of that category, which is calculated as in Equation (11).  
\[weight_{i}=median(fq_{s})/fq_{i} \tag{11}\]  
The generated category weights are used to act on the loss function to make it more sensitive to the categories that occur less frequently, and the formula of the loss function after increasing the weights is shown in Equation (12).  
\[Loss=-\sum_{i=1}^{N}w_{i}NLLoss(y_{i},p_{i}) \tag{12}\]  
The \(w_{i}\) in the formula is the weight of class \(i\); \(y_{i}\) and \(p_{i}\) are the label values and predicted values of all class \(i\) in the image respectively.  
Also, this paper introduces the Dice Loss function as an auxiliary loss function, which is a loss value calculated from the Dice coefficient, an ensemble similarity measure function usually used to calculate the similarity of two sample points with the formula in Equation (13).  
\[S=\frac{2|X\cap Y|}{|X|+|Y|} \tag{13}\]  
where \(|X\cap Y|\) denotes the intersection between \(X\) and \(Y\); \(|X|\) and \(|Y|\) denote the number of elements of \(X\) and \(Y\), respectively. The factor 2 in the numerator is due to the existence of double counting the common elements between \(X\) and \(Y\) in the denominator. If the Dice coefficient is larger, it indicates that the more similar the set is, the smaller the Loss is; and vice versa. Therefore, the Dice Loss is calculated as in Equation (14).  
\[DiceLoss=1-\frac{2|X\cap Y|}{|X|+|Y|} \tag{14}\]  
\(|X\cap Y|\) denotes the dot product of the corresponding elements of two sets and then sums the results of the element-by-element multiplication.  
Dice Loss and NLLLoss are often used together and in this paper, they are weighted as the overall Loss, calculated as in Equation (15).  
\[Final\ Loss=\alpha\times NLLLoss+\beta\times DiceLoss \tag{15}\]  
FCN-ResNet18 was used in advance as the base model to test both weights on the CamVid dataset, and each combination of weights was trained with 100 epochs. Finally, the test set mIoU was calculated to evaluate the training effect of each weight. The test results are shown in Table 3. Since it is unfavorable to small samples when using DiceLoss completely, the cases of \(\alpha=0\) and \(\beta=1\) are not considered.  
It can be seen that the test set performs best when \(\alpha\) is taken as 0.6 and \(\beta\) is taken as 0.4, so this combination of weights is chosen as the weights for subsequent experiments.  
The gradient descent algorithm used in this paper is stochastic gradient descent (SGD). This gradient descent algorithm can sample a portion of the training set data, which is a mini-batch. This parameter can be set by itself. After the forward propagation of the network is completed, SGD gradient descent then uses the loss function calculated from this batch of the training set to calculate the optimal value of the weights until the model converges or the algorithm is stopped manually. SGD has been shown to have better performance in various experiments [30].