# Research on Lightweight Model for Rapid Identification of Chunky Food Based on Machine Vision
## 3 Improved YOLOv5 Algorithm
### Experiment Validation
#### 3.3.2 Comparison Experiment  
Convergence Performance Analysis  
To verify the convergence performance of YOLOv5-GCS, a comparison will be made between YOLOv5-GCS and the original model, and the performance of the models will be analyzed. The loss and mAP (mean average precision) curves of the original model and YOLOv5-GCS on the training set are shown in Figure 10.  
The loss functions of both models start to decrease rapidly in the first 50 rounds of training and level off after 100 rounds. Notably, all three loss functions of the YOLOv5-GCS model are significantly smaller than those of YOLOv5s. A comparison of the mAP curves of YOLOv5-GCS and YOLOv5s is shown in Figure 10d, where the mAP of the YOLOv5-GCS model rapidly increases to 90% in the first 50 rounds of training and reaches around 97% after 100 rounds. The final results for the two models are 97.4% and 95.4%, respectively, proving that YOLOv5-GCS outperforms YOLOv5s in detection performance.  
\begin{table}
\begin{tabular}{c c} \hline \hline
**Parameters** & **Configuration** \\ \hline Operating System & Ubuntu 18.04 \\ CPU & Intel(R) Xeon(R) Platinum 8255C \\ GPU & RTX3080 \\ Programming Languages & Python 3.8 \\ Deep Learning Framework & Pytorch 1.9 \\ Accelerated Environment & CUDA 11.0 \\ \hline \hline \end{tabular}
\end{table}
Table 2: Experimental environment.  
\begin{table}
\begin{tabular}{c c} \hline \hline
**Name** & **Numerical Value** \\ \hline Training image resolution & 640 \(\times\) 640 \(\times\) 3 \\ Epochs & 200 \\ Batch\_size & 16 \\ Optimizer & SGD \\ Initial learning rate & 0.01 \\ Learning rate momentum (momentum) & 0.937 \\ Weight decay factor & 0.0005 \\ \hline \hline \end{tabular}
\end{table}
Table 3: Hyperparameter settings.  
Classification Accuracy Analysis  
After image preprocessing, we expanded the number of images to 12,000 with a large number of samples. Therefore, we divided the images into a training set, testing set, and validation set with the ratio of 8:1:1; we did not use the K-fold cross-validation method because it would increase the computational cost. The confusion matrices generated by YOLOv5s and YOLOv5-GCS are shown in Figure 11.  
Figure 11: Confusion matrices generated by different models: (**a**) YOLOv5s; (**b**) YOLOv5-GCS.  
Figure 10: Loss and mAP curve charts: (**a**) box_loss; (**b**) obj_loss; (**c**) cls_loss; (**d**) mAP.  
From Figure 11a, the classification accuracies of mashu, fantau, and nuomiji in YOLOv5s are 91%, 95%, and 95%, respectively. Among them, mashu has a 1% chance of being misidentified as fantau and a 7% chance of being misidentified as background. Fantuan has a 1% chance of being misidentified as mashu and numiji, and a 3% chance of being identified as background. Nuomiji has a 2% chance of being identified as mashu and a 3% probability of being identified as background. This shows that the YOLOv5s model produces false and missed detections.  
As shown in Figure 11b, the classification accuracies of mashu, fantau, and nuomiji in the YOLOv5-GCS model are 95%, 98%, and 96%, respectively, which are 4%, 3%, and 1% better than YOLOv5s. Mashu and fantau have no false detections, and nuomiji has a 2% chance of being falsely detected as mashu. The chances of several categories being recognized as background are reduced compared to YOLOv5s. In summary, YOLOv5-GCS can effectively improve the classification accuracy, reduce the probability of false detection and missing detection, and significantly improve the model performance.