## 3 The Proposed Model
### Loss Function
We set \(\lambda_{1}\) to 10, \(\lambda_{2}\) to 0.5, \(\lambda_{3}\) to 0.02, \(m^{+}\) in the capsule network to 0.9, \(m^{-}\) to 0.1, and \(\lambda\) to 0.5, respectively, and used the Adam optimizer with default parameters for gradient computation. The comparison plots of defects generated by the three generative models are shown in Figure 4.

Visually, compared to the other two models, the PreCaCycleGAN model with DenseNet incorporated into the U-Net network exhibits more diverse defect sample generation in four datasets: (b), (h), (i), (j). Moreover, in three datasets: (a), (e), (f), and (g), our model with a two-branch discriminator demonstrates a more refined feature representation. However, in the remaining dataset, our defect generation performance is not clearly superior to that of the other models. Although our model appears to improve defect generation diversity and feature quality compared to the existing models from visual inspection, the generated defect samples need to be tested on actual industrial inspection models to verify their effectiveness. Therefore, we need further quantitative data to support the current superiority of our model. Figure 4: **(a–e)** represent the datasets of Class 1–Class 5, respectively. Comparison of generation defects of PreCaCycleGAN with different generative models on different datasets. Red boxes identify the defects in the images and are shown zoomed in adjacent positions. In (**a,b,e**), it can be clearly found that PreCaCycleGAN is able to generate more realistic and diverse defects, while the other models suffer from blurring and distortion. (**f–j**) represent Class 5–Class 10 datasets, respectively. In (**h–j**), it can be clearly found that PreCaCycleGAN is able to generate a wider variety and a larger number of defects, while the other models can only generate a single defect. ### Detection Model Training Validation

To validate the effectiveness of our model-generated defect samples in real industrial manufacturing, we selected three models YOLOv5 [48], SSD [49], and Faster-RCNN [50], which are currently widely used in industrial inspection, for generating images for generalization enhancement of the detection model. In the training set, we designed three types of training sets De-Train A, De-Train B, and De-Train C, for different datasets, where De-Train A consists of 700 defect-free samples and 100 real defect samples, De-Train B consists of 700 defect-free real samples and 100 synthetic defect samples generated by different models, De



Out of the 60 results from De-Train B training and De-Train C training, PreCayCeleGAN achieved 51 top scores, and the results in the items that did not achieve top scores were very close to the top scores. In general, the detection accuracy was improved by 3-5% using De-Train B to train the dataset than using De-Train A to train the dataset, while the detection accuracy was improved by 8-10% using De-Train C to train the dataset than using De-Train A to train the dataset, which proves that the defect samples generated by different models all have a significant impact on the generalization and accuracy of the detection model. The improvement is evident, especially when the mixture of generated defect samples and real defect samples is used to train the detection model, which is consistent with the current actual industrial manufacturing situation. We further compared the defect samples generated by PreCayCeleGAN with those generated by Tree-CycleGAN and CycleGAN-TSS and found that PreCayCeleGAN-generated defect samples exhibited better detail features for detection model learning in different datasets. Taking the YOLOv5 detection model as an example, we observed that PreCaCycleGAN-generated defect samples improved the detection accuracy by about 4% in (a), (b), (f), (g), and by 1-2% in the remaining datasets, compared to the other two generative models. This proves that our model can generate images with more detailed defect features and defect diversity.