| China has been an agricultural country since ancient times,and the development of agriculture is the cornerstone of the development of other fields.The saying "people regard food as their prime want" reflects the crucial role of food in people’s lives.With the rapid development of modern society,people no longer satisfy with just filling their stomachs but also pursue high-quality delicacies.Fruits become people’s first choice after meals.The whole process from fruit tree planting to food processing involves multiple links,and a good production process can ensure the quality of the fruits.Currently,harvesting and sorting became one of the more complicated steps in the cultivation process,while the combination of deep learning and computer technology with agriculture provides a research direction for the role of object detection in agricultural production.In practical application scenarios,due to factors such as embedded device configuration and natural environment,high accuracy and lightweight models remain one of the difficulties in the field of object detection.Based on the natural environment of apple fruit,this paper puts forward an apple fruit detection model based on a lightweight improved Yolo v5 algorithm.The first experiment in this paper is to use a lightweight network structure Mobile Net V3 in the main network to reduce the complexity of the network and reduce the number of network parameters.Secondly,the attention module CBAM is introduced to enhance the feature extraction ability of the network.Finally,the Varifocal Loss loss function is introduced to reduce the contribution of negative samples to the prediction through scaling factors,thus increasing the contribution of positive samples to the prediction.The experiments showed that the improved Yolo v5 model has an average precision of 90.8%,a size of 6.8MB,a parameter of 3.2M,and a FPS of82.2Hz.Compared with the baseline model,the average precision decreased by 0.2%,the model size compressed by 54.9%,the parameter amount compressed by 54.3%,and the FPS increased by 4.7Hz.It achieved a balance between model lightweightness and precision.The experimental results of Yolo v3,PPYolo,Retina Net,and Faster RCNN models have also been improved to some extent.This model can provide technical support for fruit detection devices and also provide ideas for maintaining the accuracy of lightweight models.The second experiment in this paper is apple fruit ripeness detection.The experiment used Yolo v5 s as the baseline model,first introduced the attention mechanism to enhance the model’s feature extraction ability and increase detection accuracy.Secondly,the K-means++ algorithm was used to generate prior boxes that are more suitable for the dataset,which improved the detection accuracy and effectiveness.Finally,the Bi FPN structure was used in the feature fusion layer to enhance the network’s feature fusion ability and improve detection accuracy.The experiments showed that the improved Yolo v5 s model has an average precision of91.3% and an F1 value of 89.0,which is a 4.3% increase in average precision over the baseline model.The model has a parameter amount of 8.3M.The improvement enhances the feature extraction ability of Yolo v5 s and increases its feature fusion ability,resulting in more accurate apple fruit ripeness detection.This model can provide technical support for apple fruit sorting devices.Through the above two experiments,this paper has completed the improvement and optimization of the Yolo v5 algorithm model,apple fruit detection,and apple fruit ripeness detection.This provides powerful tools for applying computer deep learning algorithms in the field of agricultural production. |