## 2 Data Preparation
### Data Pre-Processing  
The dataset in this research has the problems of the data being sparse and the image scale of the four labels being uneven. Most of the rail defects are concentrated in the rail head area, with 96 and 79 images of crescent-shaped fatigue cracks and scaling, respectively. This paper uses data enhancement to expand the image set of the web and base area. The category of target defect in B-scan images is related to the position of the whole image, which limits the enhancement way. So, data enhancement mainly uses random mirror transformation (only left and right) and random miscut transformation to change each image while randomly maintaining the same pixel size. In this way, the sizes of the original image set of fishbol hole cracks, rail web cracks, and rail base transverse crack expand three times, reaching a balance of all defect categories. It is conducive for the network to learn image feature information fully.  
The last problem of the dataset is always noisy. Unlike the Gaussian white noise in ordinary images, the noise in ultrasonic B-scan images is influenced by complicated factors during the ultrasonic wave propagation process, including the state of the rail surface, water coupling, electronic noise, and impacts of detection parameters. A B-scan image is a two-dimensional image created by superimposing the pixel values on the corresponding position of the three-primary-color two-dimensional matrix. The pixel (echo) points of the same reflector are closely connected. This paper adopts the pixel subtraction method and eight-directional point finding denoising method, that is, starting from one-pixel point, using it as the starting point to find consecutive non-background color pixel points from each of the eight directions and add up these pixel points, and if the number of consecutive pixel points is less than or equal to 3, it will be regarded as a spurious wave, that is noise. This paper eliminates noise by setting the threshold of the echo points number as 3 to build a cleaner and clearer dataset. Figure 5a shows the schematic diagram eight-point direction finding denoising method. Figure 5b shows the comparison of B-scan images before and after denoising.  
Finally, 20 images (containing 16 labels) were taken as the test set and 282 images (containing 336 labels) as the training set. Table 5 shows the labels and quantity of the pre-processed B-scan image dataset.  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Image Category** & **Label** & **Training Set** & **Test Set** & **Total** \\ \hline crescent-shaped fatigue cracks & head & 96 & 2 & 98 \\ fishbol hole cracks & bolt hole & 22 & 5 & 27 \\ rail web cracks & web & 30 & 7 & 37 \\ rail base transverse cracks & base & 28 & 2 & 30 \\ total & & 176 & 16 & 192 \\ \hline \hline \end{tabular}
\end{table}
Table 4: Labels and quantity of B-scan images dataset.  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Image Category** & **Label** & **Training Set** & **Test Set** & **Total** \\ \hline crescent-shaped fatigue cracks & head & 96 & 2 & 98 \\ fishbol hole cracks & web1 & 66 & 5 & 71 \\ rail web cracks & web2 & 90 & 7 & 97 \\ rail base transverse cracks & base & 84 & 2 & 86 \\ total & & 336 & 16 & 352 \\ \hline \hline \end{tabular}
\end{table}
Table 5: Labels and quantity of pre-processed B-scan images dataset.