# Surface Defect Detection of Preform Based on Improved YOLOv5
## 3 YOLOv5 Network and Improvement
### Improved Methods
#### 3.2.4 Evaluation Indicators  
There are many indicators commonly used to measure algorithm performance in target detection. In order to facilitate comparison, this article uses indicators such as accuracy precision, recall, mean average precision (mAP), and inference time to measure prediction performance.  
Figure 7: Network structure of YOLOv5s-GC.  
Precision is an indicator used to evaluate the performance of a classification model, which refers to the ability of a classifier to accurately identify positive examples during prediction. The formula is as follows:  
\[\text{Precision}=\frac{\text{TP}}{\text{TP}+\text{FP}} \tag{6}\]  
where TP represents true positive, i.e., the number of samples that are positive and are predicted to be positive; FP represents a false positive example, which is the number of samples that are negative examples that are incorrectly predicted as positive examples.  
Recall is used to evaluate the ability of the model to find all positive samples, reflecting the ratio of all actual positive samples found by the model. Its calculation formula is:  
\[\text{Recall}=\frac{\text{TP}}{\text{TP}+\text{FN}} \tag{7}\]  
where FN represents a false negative, which is the number of samples that are positive and incorrectly predicted to be negative.  
AP is an important performance indicator in classification tasks. When measuring model performance, precision and recall are two mutually constraining performance indicators. These two indicators have the limitations of single point values and cannot fully evaluate the overall performance of the model. Therefore, the introduction of AP enables a full trade-off between precision and recall to comprehensively evaluate the performance of the model. Using precision as the ordinate and recall as the abscissa, we can obtain a P-R curve. The area between the P-R curve and the coordinate axis is the value of AP. The expression is:  
\[\text{AP}=\frac{1}{n}\sum_{k=1}^{n}\ P(k)\cdot\textit{rel}(k) \tag{8}\]  
where \(P(k)\) represents the accuracy of the first \(k\) prediction results, while \(\textit{rel}(k)\) is a function that represents the correlation of the \(k\)-th prediction results, where \(k\) ranges from 1 to \(n\); and \(n\) is the total number of prediction results.  
mAP is used to measure the accuracy of the system. In a multi-classification task, each category can calculate its own AP value, and averaging these values can obtain the mAP value of the entire dataset. Typically, mAP values calculated at a threshold of 0.5 are often used to evaluate the performance of a model, also known as [EMAIL_ADDRESS] refers to calculating the mAP values under each threshold by changing the threshold value from 0.5 to 0.95 in steps of 0.05 and averaging all the mAP values to comprehensively evaluate the performance of the model under different IoU thresholds. The calculation formula is:  
\[\text{mAP}=\frac{1}{N_{c}}\sum_{i=1}^{N_{c}}\text{AP}_{i} \tag{9}\]  
where \(N_{c}\) indicates the number of categories, and \(\text{AP}_{i}\) represents the average precision of the ith category. Add up the AP values for all categories and divide by the number of categories; \(N_{c}\) gives the value of mAP.  
In order to evaluate the performance of the model more comprehensively, inference time is introduced, which refers to the time required to recognize the target and output the results after inputting the image into the algorithm. Inference time is one of the important indicators to measure the practicality and real-time performance of defect recognition based on the YOLO model.