## 3 Proposed Methods
### Architecture of the Model and Training Pipeline  
As shown in Figure 2a, the proposed model is composed of four basic CNN components, among which \(En_{1}\)\(En_{2}\) and \(D\) are similar in structure to an encoder and \(De\) is a decoder. These encoder-like or decoder-like networks are altogether a series of convolutional blocks. Specifically, for encoder-like \(En_{1}\) and \(En_{2}\), every block consists of a convolutional layer, a batch normalization layer, and a leaky rectified linear unit (ReLU) layer, except that the first block removes the intermediate batch normalization layer and the last block has only a convolutional layer. The decoder-like \(De\) is merely a symmetric version of the above two encoders; however, the convolutional layer in each block is replaced by a transposed convolutional layer and the leaky-ReLU layer is substituted by a ReLU layer, except that the last block is a tanh layer. The discriminator \(D\) is essentially the same as the encoder, but there is a slight variation on the number of channels in the last block, where the discriminator has just one output channel and subsequently attaches a sigmoid layer. As mentioned above, the proposed model is trained on defect-free image samples. In practice, a training dataset is composed of many multiscale image patches which are randomly sampled from the different levels of an image pyramid, as shown in Figure 3. Image pyramid is able to adjust the image scale, and here Gaussian pyramid is used to downsample on a whole image. It is based on the fact that defects always take on different sizes, e.g., small dots, thin lines, and even larger areas. Therefore, to completely detect and locate these defects, the model should be trained on multiscale samples. Specifically, a whole image passes through the Gaussian pyramid to generate multiple images whose sizes decrease with the power of two; then, a fixed-size extraction is carried out on these whole images to form ultimate training samples. Figure 2: Overall architecture of the proposed model in the training and testing phases. (**a**) In the training phase, parameters of the whole network are learned by adversarial learning; (**b**) In the testing phase, pixel-level and regional-level differences between \(I_{org}\) and \(I_{rec}\) are evaluated after image reconstruction to obtain the final segmentaion result. The object function in the training phase plays an essential role in the final defect detection result, which comprises three optimized objects--\(L_{rec}\), \(L_{feat}\) and \(L_{adv}\), respectively--in the proposed model, as shown in Figure 2a. \(L_{rec}\) is designed to improve the quality of image reconstruction through each iteration a, which can be written as:  
\[L_{rec}\ =\left\|I-I^{\prime}\right\|_{1} \tag{1}\]  
where \(I\) and \(I^{\prime}\) represent the input and reconstructed images and \(\left\|\cdot\right\|_{1}\) denotes the 1-norm. \(L_{feat}\) is defined as the difference between the extracted features of \(I\) and \(I^{\prime}\), respectively, which can be expressed as:  
\[L_{feat}=\left\|f_{i}-f_{o}\right\|_{2} \tag{2}\]  
The introduction of this optimized object is meant to assist in the promotion of image reconstruction quality. Additionally, it is utilized to accomplish the LDA task in the testing phase. \(L_{adv}\) is introduced to guarantee that the reconstructed image be more realistic, which is the primary original goal of the GAN. But unlike DCGAN, the proposed model uses the output of the penultimate CNN block to compare the degree of realism of the input image of the discriminator. The third optimized object can thus be defined as:  
\[L_{adv}=\left\|f(I)-f\big{(}I^{\prime}\big{)}\right\|_{2} \tag{3}\]  
where \(f(\cdot)\) denotes the mapping from the input to the output of penultimate block in the discriminator.