# A Defect Detection Method Based on YOLOv7 for Automated Remanufacturing
## 3 Training and Results
### Training Results
#### 3.5.1 Neu-Det  
In this study, each model variant was trained and tested on this dataset to observe a wider behavior of the model. The validation and inference results are shown in Table 4. There are three main evaluation metrics presented in the table. APtest, APval, and AP50 test are mAP_0.5:0.95 for the testing set, mAP_0.5:0.95 for the validating set, and mAP_0.5 for the testing set, respectively. Those parameters are selected for better visualization of the model's performance. As shown in the table, the main difference between each variant is the model size, increasing as going down the table. The larger the model size, the more training parameters it has, which increases the learning knowledge and training time. Furthermore, the smallest variant of the YOLOv7 model took about 84 min to complete 150 epochs of training, whereas the largest version took four times the smallest one. The table shows that the YOLOv7 achieved about 73.9% mAP with a 0.5 threshold on the testing set. However, as expected, a lower accuracy was observed with an interval threshold of (0.5-0.95). Although each variant was trained in slightly different parameters, the reported results are all for 150 training epochs. In Figure 5, the training process curve of each variant is plotted to represent the mAP_0.5. As shown in this figure, the small-sized models tend to converge faster compared to the larger ones due to the number of parameters that require optimization. It is also worth noticing that smaller models have a smoother learning curve, which might be due to the loss of some information in the images when resizing, especially for the small objects. In addition, a smaller batch size might reduce the sharp fluctuation in the learning curve. Figure 6 shows the mAP_0.5 of the testing set with its trend. The performance trend of the YOLOv7 model variants represents a parabolic trend where the performance decreases in the middle. This could be due to the increase in the image size and the model, which led to more knowledge gained. This dataset is public and has been used in serval studies. Furthermore, comparing the YOLOv7 results with other previously reported results is valuable. [PERSON] et al. [51] reported a 72.2% in mAP_0.5 on their proposed method based on EDDN. Their model performed slightly better in the pitted surface and scratches classes but worse in detecting cracks. Furthermore, [PERSON] et al. [33] reported better results with 75.2% of mAP_0.5 of their proposed model based on an improved YOLOv5 an increase of about 1.3%. Moreover, a recent model proposed by [PERSON] et al. [26], based on Transformers, has achieved higher results in the \begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**YOLOv7** & **\#Params** & **Image Size** & **FPSRTX 3090** & **APtest/APval** & **AP50 test** \\ \hline Tiny & 6 M & 224 & 103 & 37.0\%/35.6\% & 73.9\% \\ Base & 37 M & 224 & 78 & 37.1\%/35.4\% & 73.9\% \\ X & 70.8 M & 224 & 63 & 30.2\%/30.3\% & 65.8\% \\ W6 & 81 M & 448 & 61 & 31.7\%/30.5\% & 69.3\% \\ E6 & 110 M & 448 & 45 & 31.1\%/29.8\% & 67.2\% \\ D6 & 153 M & 448 & 40 & 33.8\%/32.6\% & 70.9\% \\ E6E & 164 M & 704 & 30 & 36.0\%/31.7\% & 73.3\% \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Performance of each variant of YOLOv7 on NEU-DET metal defect datasets. NEU-DET dataset with 80.5% mAP_0.5. It is worth noting that integrating YOLO models with Transformer networks enhances the model performance, as shown; thus, it is worth exploring this approach to further increase detection accuracy. Lastly, the base variant of the YOLOv7 model provides the right balance between accuracy and speed for real-time defect detection. Looking further into the base variant results, the model struggles to detect cracks and rolled-in scale defects with about 19% of mAP, as reported in Table 5 and shown in Figure 7. This might be due to the nature of those types of defects existing with minimal features and are less distinguishable with the metal surface compared to other types of defects.