# A Raisin Foreign Object Target Detection Method Based on Improved YOLOv8
## 1 Introduction
The integration of a visual transformer equipped with a deformable attention mechanism into the C2f module aims to bolster the network's feature extraction process and improve detection precision. The model demonstrated an average detection accuracy of 77.6% in scenarios with seed aggregation and occlusion, an inference time of 2.86 ms, and improved seed detection accuracy under conditions of stacking, adhesion, and occlusion. Presently, deep learning-based detection techniques are primarily categorized into two-stage object detection methods, exemplified by Faster R-CNN, and single-stage object detection methods, typified by YOLO [16]. Two-stage methods boast higher accuracy but compromise on real-time capabilities. Conversely, single-stage methods, albeit with marginally lower accuracy, excel in real-time performance and are extensively applied in industrial settings. The main goal of this research is to create and deploy a system for detecting and identifying foreign objects in raisins, utilizing an enhanced version of the YOLOv8 algorithm. By deeply analyzing the shortcomings of the YOLOv8 algorithm in handling small target detection and complex background recognition, we propose an enhanced real-time detection approach leveraging an improved YOLOv8 model. Our major contributions are as follows:  
* Incorporated the multi-head self-attention mechanism (MHSA) from BoTNet into the backbone network of the YOLOv8 model, strengthening the model backbone's global information capture capability to enhance the richness and completeness of feature extraction. * The Conv module of the neck layer was changed to the RFAConv module, and the feature extraction process of different regions was fine-adjusted, so that the model could dynamically generate acceptance fields and improve the detection ability of foreign bodies of different sizes. * The original network's CIoU loss is substituted with EIoU, enhancing the efficiency and accuracy of raisin foreign body detection. Through such algorithm optimization and model adjustments, the detection system's accuracy and real-time performance have been improved without increasing the number of parameters, making it more suitable for the raisin processing production environment. The subsequent sections of this paper are structured as follows: Section 2 primarily introduces the dataset construction process used for raisin foreign matter detection, demonstrating the model employed in this paper's detection method and the significance of each module in the improved model for raisin detection. Section 3 outlines the experimental setup and parameter settings, detailing the model performance metrics for evaluation. It further presents the training outcomes and detection visualizations and underscores the model's performance and the efficacy of the refined model through comparative studies with other models, ablation analyses, and experiments on various foreign matter compositions. Section 4 discusses and analyzes the research in conjunction with other researchers and the research presented in this paper. Section 5 renders a thorough encapsulation of the entire research undertaking.