## 2 The Proposed Theory
### Image Cross-Domain Conversion: Data Enhancement Based on Cycle GAN  
Due to the significant differences of images in different production lines, it is difficult to directly apply the sample defects collected by the existing production lines to other production lines, resulting in the poor universality of defect samples and difficulties in  
Figure 1: (**a**) Model deployment process. (**b**) The framework of the proposed method. deploying them in other production lines. To solve the above problems, this paper proposes a sample migration method based on Cycle GAN for generating adversarial networks. The existing defective samples are migrated, applied to the new production line, and combined with non-defective samples. Many surface defect sample data suitable for the new production line are obtained. The basis of defect sample data migration comes from the similarity of the underlying features of different images, including lines, colors, textures, and other features. The CNN can thoroughly learn these image underlying features in source domain A and migrate them to target domain B. A schematic diagram of defect sample migration algorithms is shown in Figure 2.  
Figure 2 connects the defect samples obtained from production line 1 with the defect-free samples from production line 2 to obtain new defect samples. The generative antagonistic network was proposed by [PERSON] in 2014 [PERSON] _et al._ (2014) through confrontation training between a generative model (generator) and a discriminator model (discriminator) to generate images that are false and genuine. The generator \(G\) and the discriminator \(D\) are continuously optimized to obtain the optimal solution. In this process, the authenticity of false samples generated by the generated model increases, and the discrimination ability of the discriminant model becomes stronger. Unlike the classical GAN algorithms, Cycle GAN has an obvious effect in solving the problem of unlabeled and unpaired image cross-domain conversion, and its model includes double mapping \(G\): \(X\)\(\rightarrow\)\(Y\) and \(F\): \(Y\)\(\rightarrow\)\(X\). The loss function of Cycle \(GAN\) is the adversarial loss function [PERSON] _et al._ (2014), which is defined based on generator function \(G\) and discriminator \(D_{Y}\). \[L_{GAN}(G,D_{Y},X,Y)=E_{y\sim P_{data}(y)}[logD_{Y}(y)]+E_{x\sim P_{data}(x)}[ log(1-D_{Y}(g(x))]. \tag{1}\]  
where \(D_{Y}\) is used to distinguish whether the data come from the generated sample \(G(x)\) or the true sample \(y\), \(E\) is the expectation, \(G\) is used to minimize the adversarial loss function \(L_{GAN}(\ )\), and the function of \(D\) is opposite to that of \(G\). The goal of the adversarial loss function is to learn the interdomain mapping of \(X\)\(\rightarrow\)\(Y\), where \(\{x_{i}\}_{i=1}^{N},x_{i}\in X,\{y_{i}\}_{i=1}^{N},y_{i}\in Y\). The data distribution is \(x\sim p_{data}(x)\), and \(y\sim p_{data}(y)\), and \(X\)\(\rightarrow\)\(Y\). The role of the adversarial loss function is to match the distribution of the generated image with the target domain, but the confrontation loss cannot completely map the input to the output \(y_{i}^{\prime}\), so we define the cycle consistency loss [PERSON] _et al._ (2014) to further reduce the space of the mapping function, and the cycle consistency loss function is:  
\[L_{cyc}(G,F)=E_{x\sim p_{data}(x)}[||F(x)-x||_{1}]+E_{y\sim p_{data}(x)}[||G(y )-y||_{1}]. \tag{2}\]  
The total loss function is:  
\[ \begin{split}& L(G,F,D_{X},D_{Y})=L_{GAN}(G,D_{Y},X,Y)+L_{GAN}(F,D_{ X},Y,X)\\ &+\lambda_{1}L_{cyc}(G,F)+\lambda_{2}L_{id}(G,F).\end{split}  \tag{3}\]  
Figure 2: Defect sample migration algorithms.