# Hybrid-Supervised-Learning-Based Automatic Image Segmentation for Water Leakage in Subway Tunnels
## 2 Approach
### Automatic Generation of Water Leakage Labels for Subway Tunnels  
The automatic generation of water leakage labels for subway tunnels adopts the WL-CAM based on weakly supervised learning. Image-level labels are generated through ASP, which is divided into the following steps:  
1. Calculate the gray value of the image to find \(K\). Suppose an image \(I_{gray}\) consists of \(N\) water basin characteristic areas, \(I_{gray}=\left\{\gamma_{n}\middle|\gamma_{n}\in R^{d},n=1,2,3,\ldots,N\right\}\), where \(\gamma_{n}\) consists of \(M\) data that provide its characteristics. \(\gamma_{n}=\left\{\gamma_{m}\middle|\gamma_{m}\in\gamma_{n},m=1,2,3,\ldots,M\right\}\), and \(\gamma_{m}\) is the gray value of \(M\) pixels in the feature area. Calculate the grayscale histogram. In the grayscale histogram, \(U_{u}^{max}=\left\{U_{v}^{max}\in I_{gray},v=1,2,3,\ldots,V\right\}\), \(U_{v}^{max}\) is the peak value of the gray value, and \(v\) is the peak value number. 2. To further determine the number of clusters \(K\), find the \(\gamma_{n}\) mean \(\overline{\gamma_{n}}\), and the number of types of \(K\) is: \[K=\left\{ \begin{array}{c}n\ \overline{\gamma_{n}}<a\\ v\ a<\ \overline{\gamma_{n}}<b\ and\ a<U_{v}^{max}<b\\ K=n+v\end{array} \right.\] (1) \[K=n+v\] (2)
3. To process the RGB of the image, let \(I_{rgb}\) consist of \(N\) data, \(I_{rgb}=\left\{S_{n}\middle|S_{n}\in R^{d},n=1,2,3,\ldots,N\right\}\). A binary variable \(P_{nk}\in\left\{0,1\right\}\) is introduced to indicate which \(k\) cluster \(S_{k}\) (\(k=1,2,\ldots,K\)) any point \(S_{n}\) belongs to. When \(P_{nk}=1\)  
Figure 3: The overall framework of the HSL. it means that the data belong to class \(k\); otherwise it is 0. The loss function is thus defined as:  
\[\Psi=\sum_{n=1}^{N}\sum_{k=1}^{K}P_{nk}\|S_{n}-S_{k}\|^{2} \tag{3}\]  
\[\|S_{n}-S_{k}\|=\sqrt{D_{1}^{2}+D_{2}^{2}} \tag{4}\]  
\[D_{1}=\sqrt{\left(R_{n}-R_{k}\right)^{2}+\left(G_{n}-G_{k}\right)^{2}+\left(B_ {n}-B_{k}\right)^{2}} \tag{5}\]  
\[D_{2}=\sqrt{\left(X_{n}-X_{k}\right)^{2}+\left(Y_{n}-Y_{k}\right)^{2}} \tag{6}\]  
\(D_{1}\) is the color distance, \(D_{2}\) is the Euclidean space distance, \(\|S_{n}-S_{k}\|\) is the absolute value of the clustering distance. The APS converges the cluster centers through continuous iteration, and \(S_{n}\) and \(S_{k}\) can be optimized alternately during the iterative process. When \(K=2\), calculate the pixel area and keep the largest pixel area. 4. During clustering, the calculation of spatial distance will affect the classification of pixel points, resulting in the existence of independent pixels within the cluster. The Canny edge extraction algorithm obtains the closed cluster edge to determine the closed cluster. Calculate the color distance between the independent pixels inside the closed cluster and the \(K\) cluster centers, and assign it to the cluster area with the smallest color distance, as shown in Figure 4.  
After the image-level labels are obtained, deep learning training is performed on the dataset to generate Mask Data and the segmentation performance is mainly affected by the classifier. Compared with Res2 Net (as shown in Figure 5), WRes2 Net adds atrous convolution, which can obtain more characteristic information about water leakage without changing the scale and can connect more residual blocks to make water leakage. Feature information is more abundant. After each convolution, the feature maps go through activation layers and normalization [32; 33]. To make the network have better accuracy and stability, the activation function ReLU is replaced by the Mish function [34]. The non-negative effect of the activation function can make the weight layer update less ideal, placing the activation layer before the normalization layer [33]. Figure 4: Classification of independent pixels within the cluster. (**a**) Obtaining the color distance for independent pixels. (**b**) The classification of independent pixels.