Abstract
Ginseng is regarded as the top of traditional Chinese medicine, and its root is widely used as herbal medicine with a long history and multiple medicinal values; thus, monitoring and managing its quality is crucial. This paper introduces a method called CGC-YOLOv8, a lightweight detection system based on YOLOv8n, designed to classify and assess the quality of ginseng based on its appearance. We selected ginseng harvested in Fusong County, Jilin Province, as an experimental sample in the current year and used data enhancement techniques to simulate various typical environments. In the basic network design of the model, we replace the regular convolutional layer with two conditional convolutional layers (CondConv) in the backbone part based on the architecture of YOLOv8 to highlight the appearance features of the input ginseng and enhance the accuracy and efficiency of feature extraction. In addition, we applied a thin neck combination (GSconv+VoVGSCSP) in the neck structure to lighten the model. Before detecting the head of the model, we incorporate the Coordinate Attention mechanism (CA), a design that effectively improves the performance without significantly increasing the computational burden, making the method suitable for resource-limited devices. The CGC-YOLOv8 model optimized by ablation experiments achieved 85.70% in terms of precision, 91.23% in terms of recall, 94.69% in terms of IoU=0.50 mean average precision (mAP50), and 72.43% in terms of IoU=0.95 mean average precision (mAP50-95), respectively. Compared to YOLOv8n, CGC-YOLOv8 improves precision by 2.74, recall by 4.64, mAP50 by 3.71, and mAP50-95 by 4.09. Our model outperforms the original model when detecting photos not involved in training. In addition, the number of CGC-YOLOv8 model parameters is reduced by 6.39% compared to the original model, and the weight size is only 6.0 MB, which meets the lightweight condition and is easy to deploy on mobile devices. In this experiment, we compared the effects of different attention mechanisms (CBAM, EMA, SE, SIMAM, and CA) on the improved YOLOv8n model and explored the application of the CA mechanism in different feature layers (such as before SPPF, after SPPF, upsampling P4 layer, small object detection layers P3, P4, and P5). The results demonstrated that the CA mechanism performed best when applied to the P5 layer, significantly enhancing the model's recall and mean average precision. When compared in comparison experiments, both traditional SSD and EfficientDet and yolo series models, cgcyolov8 performs better overall, in terms of Precision, CGC-YOLOv8 improves 0.43% to 48.6% compared to other models. Secondly, in terms of Recall, CGC-YOLOv8 improves by 5.70% to 35.86%. For mean average precision (mAP50), CGC-YOLOv8 improves by 3.29% to 57.21%. Finally, on the mean average precision at higher thresholds (mAP50-95), CGC-YOLOv8 improves by 13.06% to 60.43%. Extensive experiments demonstrate that the CGC-YOLOv8 model significantly outperforms the original YOLOv8 model and other traditional detection models in terms of precision, recall, and mean average precision (mAP). The results firmly establish the CGC-YOLOv8 model as a highly effective solution for intelligent ginseng quality detection, providing a solid technical foundation for further advancements in the field.