## 3 Research on an Improved CGAN Ground Grid Imaging Algorithm
### Improved CGAN Structure  
#### 3.1.1 Generator Design  
The generator of this method is mainly composed of four modules: the preprocessing module, encoder module, decoder module and attention module. Its structure is shown in Figure 5. First, the input layer receives the boundary voltage value, and the preliminary feature map of the ground grid electrical impedance imaging is obtained after passing through the preprocessing module. Then, the high-level features are extracted for imaging through a U-shaped structure network with a depth of 5 layers. The encoder module of U-Net consists of multiple down-sampling layers, each of which contains two convolutional layers with a convolution kernel size of \(4\times 4\). The stride of the first convolutional layer is 1, which is used for fine feature extraction; the stride of the second convolutional layer is 2, which replaces the traditional pooling layer to better preserve the detail information in image reconstruction. In order to speed up network training and prevent overfitting, batch normalization, a dropout layer and a leaky-ReLU activation function are introduced in the encoder. Its batch normalization is as shown in Equation (4):  
\[y=\gamma\bigg{(}\frac{x-\mu}{\sqrt{\sigma^{2}+\varepsilon}}\bigg{)}+\beta \tag{4}\]  
Figure 4: Improved CGAN algorithm flow chart. Figure 5: Generator structure diagram. The decoder module gradually restores the spatial size of the feature map through multiple up-sampling layers and deconvolutional layers. The structure of the deconvolutional network is similar to that of the encoder, using the same convolution kernel size and stride to gradually enlarge the resolution of the feature map and finally generate a ground grid corrosion image. The size of the generated image is consistent with the input to ensure the spatial consistency of the image. The preprocessing module is responsible for learning the nonlinear mapping relationship between the boundary voltage and the target impedance image to form a preliminary grounding grid impedance image. As shown in Figure 6, the input layer accepts 208 boundary voltage values, and the boundary voltage data sequence is converted into a \(13\times 16\) matrix through the fully connected layer and the deformation layer for further two-dimensional feature extraction. Its expression is given in Equation (5). \[Z=\textit{reshape}(\sigma(W_{1}\cdot x+b_{1}))\in R^{16\times 13} \tag{5}\]  
Then, the network extracts high-order features through a four-level convolutional network, and it finally outputs the conductivity imaging topology of the grounding grid through a deformation and fully connected network. In the first layer of the convolution structure, 32 convolution kernels of size \(3\times 3\) and step size 1 are used. The second, third, and fourth convolutional layers are basically the same, containing 64, 128, and 256 convolution kernels of \(3\times 3\) size, respectively, gradually obtaining higher-level feature information. The activation function after the convolution operation uses Leaky ReLU. After each convolutional layer, a pooling layer is used to reduce the feature size, and the pooling kernel size is \(2\times 2\). The activation function is Equation (6):  
\[f(x)= \begin{cases}x&,\;if\;x>0\\ 0.01x&,\;if\;x\leq 0\end{cases}  \tag{6}\]  
Then, the two-dimensional information features extracted by the convolutional neural network are converted into one-dimensional information through the deformation layer, further information features are learned through two layers of fully connected layers and the Tanh function is used for normalization to generate preliminary feature information of the grounding grid. The Tanh function is Equation (7). \[f(x)=\tanh(x)=\frac{e^{x}-e^{-x}}{e^{x}+e^{-x}} \tag{7}\]  
Figure 6: Preprocessing module diagram. The attention module fuses the features extracted by the encoder with the features in the decoder to better preserve details and important information.