# Road Crack Detection by Combining Dynamic Snake Convolution and Attention Mechanism
## 3 Dataset Description and Performance Metrics
### Experimental Environment and Performance Metrics  
The algorithm in this study was implemented on a Windows 10 operating system, utilizing an i9-12900H CPU and a NVIDIA RTX 3090 GPU. The programming language used was Python 3.8, and the development was carried out on PyCharm using the PyTorch framework. During the experiments, the Adam optimizer was employed, with the learning rate set to 0.001, the number of epochs set to 300, and a batch size of 4.  
For binary classification problems, the commonly used loss function is the cross-entropy loss function. This function assigns equal attention to each class during each gradient backpropagation, making it highly susceptible to the impact of class imbalance. In the context of road defect detection datasets, cracks (i.e., positive samples) occupy only a small portion of the entire image, with the majority of pixels belonging to the background (i.e., negative samples). The ratio of positive to negative sample pixels is illustrated in Figure 7. In such cases, the trained neural network tends to predict nothing, which is reflected in a low recall value. The formula for the cross-entropy loss function is shown in Equation (1).  
\[L=\frac{1}{N}\sum_{i}L_{i}=\frac{1}{N}\sum_{i}-[y_{i}\cdot\log(p_{i})+(1-y_{i}) \cdot\log(1-p_{i})] \tag{1}\]  
where \(N\) denotes the total number of samples; \(y_{i}\) represents the label of sample \(i\), where the positive class is labeled as 1 and the negative class as 0; and \(p_{i}\) indicates the probability that sample \(i\) is predicted to belong to the positive class.  
Figure 6: Images and ground truth from the dataset.  
This paper evaluates the crack detection algorithm using commonly employed machine learning metrics: precision (\(P\)), recall (\(R\)), and the harmonic mean \(F1\)-score. The \(F1\)-score, which is the harmonic mean of precision and recall, provides a comprehensive assessment of the model's performance. It offers an overall metric that avoids the potential issue of neglecting a model's performance in one aspect by focusing solely on either precision or recall. The formulas are shown in Equations (2) and (3).  
\[R=\frac{\text{TP}}{\text{TP}+\text{FN}} \tag{2}\]  
\[P=\frac{\text{TP}}{\text{TP}+\text{FP}} \tag{3}\]  
\[F1=\frac{2}{\frac{1}{P}+\frac{1}{R}}=\frac{2\times P\times R}{P+R} \tag{4}\]  
where TP denotes true positive, the number of samples correctly predicted as positive by the model; FP denotes false positive, the number of samples incorrectly predicted as positive by the model; TN denotes true negative, the number of samples correctly predicted as negative by the model; and FN denotes false negative, the number of samples incorrectly predicted as negative by the model.  
In crack detection, target pixels constitute only a small portion of the image, with most pixels belonging to the background. Consequently, even if the network predicts the entire image as background, the \(P\) metric can still be relatively high, while the \(R\) metric would be low. Therefore, in road crack detection tasks, a higher \(R\) value indicates a greater likelihood that the network detects cracks and that the detected cracks are more complete.  
\(R\) is defined as the proportion of actual positive samples that are correctly predicted as positive. In crack detection, this metric reflects how many of the target pixels in actual cracks are correctly identified. Therefore, the higher the \(R\) value, the more complete the crack detection.