## 3 The Proposed Model
### Loss Function
Overall, the detection models trained with our model-generated defects mixed with real defects, YOLOv5 detection models in ten datasets compared to the original detection models, CycleGAN-TSS generation models and Tree-CycleGAN generation models improved the detection accuracy by 5.75%, 1.16% and 1.26% on average, respectively, and the average improvement in detection rate by an average of 14.94%, 3.60% and 3.55% improvement, and 5.44%, 1.22% and 1.63% decrease in false detection rate; SSD detection model compared to the original detection model, CycleGAN-TSS generation model and Tree-CycleGAN generation model detection accuracy improved by 5.46%, 1.23% and 1.27% on average, respectively, with an average improvement of detection rate by 13.73%, 3.76% and 3.35% on average, and the false detection rate by 6.74%, 1.89% and 2.42%; Faster-RCNN detection model compared \begin{table}
\begin{tabular}{c c c c c c c c c} \hline \hline \multirow{2}{*}{**Model**} & \multirow{2}{*}{**Train Dataset**} & \multirow{2}{*}{**Test Dataset**} & \multicolumn{3}{c}{**De-Test B**} & \multicolumn{3}{c}{**De-Test C**} \\ \cline{3-10}  & & & **DDA** & **DDR** & **FDR** & **DDA** & **DDR** & **FDR** \\ \hline \multirow{4}{*}{YOLOv5} & \multirow{4}{*}{De-Train B} & Tree-CycleGAN [42] & 92.86\% & 80.65\% & 1.96\% & 93.92\% & 83.61\% & 1.92\% \\  & & CycleGAN-TSS [43] & 92.43\% & 80.00\% & 1.89\% & 93.41\% & 82.26\% & 1.92\% \\  & & PreCaCycleGAN & **94.47\%** & **86.08\%** & **0.00\%** & **94.71\%** & **85.51\%** & **0.00\%** \\ \cline{2-10}  & & \multirow{4}{*}{De-Train C} & Tree-CycleGAN [42] & 94.57\% & 84.38\% & 0.00\% & 95.03\% & 85.25\% & 0.00\% \\  & & CycleGAN-TSS [43] & 94.09\% & 83.33\% & 0.00\% & 95.08\% & 85.71\% & 0.00\% \\  & & PreCaCycleGAN & **95.02\%** & **87.65\%** & **0.00\%** & **95.81\%** & **88.73\%** & **0.00\%** \\ \hline \multirow{4}{*}{SSD} & \multirow{4}{*}{De-Train B} & Tree-CycleGAN [42] & 92.86\% & 80.65\% & 1.96\% & 93.37\% & 81.97\% & 1.96\% \\  & & CycleGAN-TSS [43] & 94.05\% & 83.08\% & 0.00\% & 94.51\% & 83.87\% & 0.00\% \\  & & PreCaCycleGAN & **94.47\%** & **86.08\%** & **0.00\%** & **94.71\%** & **85.51\%** & **0.00\%** \\ \cline{2-10}  & & \multirow{4}{*}{De-Train C} & Tree-CycleGAN [42] & 94.57\% & 84.38\% & 0.00\% & 95.58\% & 86.89\% & 0.00\% \\  & & CycleGAN-TSS [43] & 94.62\% & 84.85\% & 0.00\% & 95.63\% & 87.30\% & 0.00\% \\  & & PreCaCycleGAN & **95.52\%** & **88.99\%** & **0.00\%** & **96.34\%** & **90.14\%** & **0.00\%** \\ \hline \multirow{4}{*}{Faster-RCNN} & \multirow{4}{*}{De-Train B} & Tree-CycleGAN [42] & 92.86\% & 80.65\% & 1.96\% & 93.92\% & 83.61\% & 1.92\% \\  & & CycleGAN-TSS [43] & 93.51\% & 83.08\% & 1.82\% & 93.96\% & 83.87\% & 1.89\% \\ \cline{1-1}  & & PreCaCycleGAN & **93.97\%** & **84.81\%** & **0.00\%** & **94.71\%** & **85.51\%** & **0.00\%** \\ \cline{1-1} \cline{2-10}  & & \multirow{4}{*}{De-Train C} & Tree-CycleGAN [42] & 94.57\% & 84.38\% & 0.00\% & 95.03\% & 85.25\% & 0.00\% \\ \cline{1-1}  & & CycleGAN-TSS [43] & 94.62\% & 84.85\% & 0.00\% & 95.08\% & 85.71\% & 0.00\% \\ \cline{1-1}  & & PreCaCycleGAN & **95.02\%** & **87.65\%** & **0.00\%** & **95.29\%** & **87.32\%** & **0.00\%** \\ \hline \hline \end{tabular}
\end{table} 
Table 13: _Cont._to the original detection model, CycleGAN-TSS generation model and Tree-CycleGAN generation model detection accuracy by 5.64%, on average, respectively 0.88% and 1.42%, the average improvement in detection rate is 14.54%, 3.22% and 3.62% on average, and the false detection rate is decreased by 5.64%, 0.89% and 2.26%. The test results show that compared with the two generation models of Tree-CycleGAN and CycleGAN-TSS, our model can extract the local and global features of defects more effectively and improve the fineness of features by adding perceptual functions and capsule discriminators for (d) and (i), which are datasets with complex backgrounds and obscure performance of defective features, Class4 and Class9 detection results are shown in Figures 5 and 6.