# Surface Defect Detection of Preform Based on Improved YOLOv5
## 4 Results and Discussion
### Prediction Performance of YOLOv5  
The reason for the small number of samples in the self-collected dataset in this article is that in actual production, there are very few samples that can be collected with surface defects. In order to meet this practical situation, there are fewer samples in the self-collected dataset. This article investigates the impact of sample size on model convergence and recognition accuracy in the sample set; choose approximately 50%, 75%, and 85% of 427, respectively. Corresponding to the proportion of the number of images, the number of marked defects is also basically consistent. A sample set with 203, 306, 352, and 427 images was selected for experimental research, and the proportion of various defects remained consistent with the proportion in Section 3. The smaller YOLOv5s model is selected for training and testing, and the loss function obtained is compared with the prediction accuracy, as shown in Figure 8 and Table 6. It can be found that the prediction performance of 352 image datasets and 427 image data is generally better than that of less samples. The predictive performance of the model on the 427 image dataset is slightly better than that on the 352 sample dataset, but the difference is not significant. So, when the sample size is 427, it can be considered a suitable small sample dataset. According to this trend, if the number of sample sets is further increased significantly, the recognition effect will generally be better. However, this article focuses on the problem of defect recognition under extremely small samples, so the sample size is not suitable for further expansion. \begin{table}
\begin{tabular}{c c} \hline \hline
**Environment** & **Configuration Name (Version)** \\ \hline Operating system & Ubuntu (16.04.7) \\ Deep-learning Framework & PyTorch (1.11) \\ CPU & Intel(R)Core(TM)i9-9900K CPU (3.60 GHz) \\ Memory & 32 GB \\ GPU & NVIDIA GeForce RTX 3080 (10G) \(\times\) 2 \\ Compiler & Python (3.9.0) \\ Acceleration module & CUDA (11.1.1) \\ \hline \hline \end{tabular}
\end{table} 
Table 4: System hardware and software configuration. \begin{table}
\begin{tabular}{c c} \hline \hline
**Parameters** & **Value** \\ \hline lr0 & 0.001 \\ lrf & 0.1 \\ Momentum & 0.937 \\ Weight\_decay & 0.0005 \\ Epochs & 200 \\ Optimizer & Adam \\ Image\_size & 640 \(\times\) 640 \(\times\) 3 \\ \hline \hline \end{tabular}
\end{table} 
Table 5: Setting of some hyperparameters. On this basis, we train the four models of the YOLOv5 series and analyze their performance. After training each model, the total loss function curve of each model is shown in Figure 9. The total loss function values of each model in the training set decreased to below 0.05 after 200 training rounds, all remaining in a relatively low state, and there was no overfitting. Therefore, it is reasonable to use YOLOv5 series models to detect surface defects on preforms. The prediction performance of the four models was evaluated on the test set, and the results obtained are shown in Table 7. Among them, for the larger YOLOv5l model, the prediction indicators in this training set are the best, but the model has a larger scale and a longer inference time. The YOLOv5s model has the smallest scale, the shortest reasoning time, and various indicators are in the middle. In order to balance the prediction performance, reasoning time, and portability of the model, the YOLOv5s model is a better choice. We will take the YOLOv5s model as the research object, and based on this \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Number of Samples** & **P** & **R** & **[EMAIL_ADDRESS]** & **[EMAIL_ADDRESS]:0.95** \\ \hline
203 & 0.715 & 0.834 & 0.801 & 0.536 \\
306 & 0.735 & 0.864 & 0.817 & 0.593 \\
352 & 0.882 & 0.896 & 0.951 & 0.693 \\
427 & 0.915 & 0.912 & 0.952 & 0.704 \\ \hline \hline \end{tabular}
\end{table} 
Table 6: Comparison of prediction performance under different sample numbers. Figure 8: Loss function under different sample numbers. Figure 9: Convergence curve of each model after training.