| In recent years,deep learning has made significant progress in the fields of image recognition,speech recognition,and natural language processing,but there are many problems in applying deep learning models on mobile devices,and the limited memory and computational resources affect its practicality and real-time performance on mobile.Deep learning models have also been widely used in the field of target detection,but similarly,there are still difficulties and limitations in their deployment on mobile devices.To address these issues,scholars have proposed many improvement strategies,such as model acceleration,compression,algorithm optimization,and hardware acceleration schemes.To address the problems of current deep learning-based tomato target detection algorithms with high number of parameters,high computational effort,long time consumption,and reliance on high computing power devices such as GPUs,this study proposes a lightweight-based improved YOLOv5 algorithm to achieve real-time localization and ripeness detection of tomato fruits,as follows:(1)Based on network lightweight design and model pruning techniques,YOLOv5 s is lightened and improved with the following four main tasks:firstly,a single downsampling layer is used instead of the original Focus layer,which effectively improves the detection speed;secondly,the bneck module of the lightweight network Mobile Net V3 is used to reconstruct the backbone network of YOLOv5,which accelerates the feature extraction,compared with the Compared with the benchmark model YOLOv5 s,the number and volume of parameters are significantly reduced by 49.71% and61.58%,and the amount of computation is also reduced by 48.61%;next,channel pruning is performed for the Neck layer,and the model volume is further reduced by 56% with a pruning factor of 0.5;finally,a genetic algorithm is used for hyperparameter optimization to improve the detection accuracy.In this study,the improved algorithm was evaluated on a homemade dataset containing 1700 tomatoes of different maturity levels.Experimental results show that the improved model THYOLO has 78%and 84.15% compression in number of parameters(params)and operations(FLOPs)compared to the original YOLOv5 s,while the m AP reaches 0.969 and the detection speed on the CPU platform is 42.5ms,a significant improvement of 64.88%.(2)In order to obtain low-latency,high-throughput deployment inference to achieve the goal of real-time detection,this study further utilizes the NCNN(Nihui Convolutional Neural Networks)framework to quantize the improved model.The experimental data analysis and visualization results show that the quantized algorithm has a better detection effect,especially In particular,the 16 bit quantized model achieves an average detection frame rate of 26.5FPS on the mobile side,which is 268% higher than the original YOLOv5 s.This result can meet the real-time requirements of most scenes on the mobile platform,while the model size is reduced by 51.1% and achieves 93% detection accuracy similar to the original YOLOv5 s.(3)To address the problem that current deep learning-based target detection algorithms rely on expensive equipment such as servers and are inconvenient to deploy in agricultural production environments,this study develops a real-time tomato detection APP based on Android,equipped with the lightly improved and quantified THYOLO model,which can achieve tomato fruit The app can locate and determine the ripeness of tomato fruits locally by calling the mobile phone camera,and it meets the real-time requirement(more than 24 frames).The app is easy to use and the small size and low price of the cell phone as a portable device make it more suitable for the actual agricultural production environment. |