A citrus fruit rapid identification and positioning method, system and application based on improved YOLOv5m
Patent Information
- Application Number
- CN202611146197.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-30
- Publication Date
- 2026-10-30
AI Technical Summary
传统基于颜色、纹理的手工特征提取方法(如OTSU、SVM、HOG等)泛化能力与鲁棒性不足,易出现误检与漏检
[0019]采用以上结构后,本发明具有如下优点:1、模型轻量化程度高,便于嵌入式部署:通过GhostConv替换常规卷积,模型参数量由原始YOLOv5m的2.39×107降至1.83×107,权重文件大小由45.2MB压缩至44.1MB,显著降低了存储开销与计算开销,具备在采摘机器人嵌入式GPU设备上实时运行的潜力。
Smart Images

Figure CN123016155A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer vision and intelligent detection technology for agricultural and sideline products, specifically to a method, system, and application for rapid identification and localization of citrus fruits based on an improved YOLOv5m. Background Technology
[0002] Citrus is my country's largest fruit crop and the world's third largest traded agricultural product. As of 2022, my country's annual citrus production reached 55.956 million tons, with a planting area of nearly 45 million mu (approximately 3.67 million hectares). The citrus industry plays an irreplaceable pillar role in my country's rural revitalization and regional economic development. With the rapid development of artificial intelligence technology, the modern citrus industry is accelerating its transformation towards intelligence and automation. Precise identification and positioning of fruit targets are core supporting technologies for achieving intelligent operations such as automated harvesting, growth status monitoring, and variable-rate spraying.
[0003] However, in the natural environment of citrus orchards, machine vision inspection technology still faces many technical bottlenecks: 1. Severe fruit occlusion and overlap: Citrus fruits often grow densely in clusters on branches, with fruits occluding each other or being obscured by branches and leaves. Traditional target detection algorithms struggle to accurately identify occluded fruits, easily leading to collisions and damage to the end effector of harvesting robots due to positioning errors.
[0004] 2. High similarity between fruit and background color: The color of citrus fruit is visually highly similar to the background of leaves and branches. Furthermore, the shadows and colors on the fruit surface vary significantly under different lighting conditions, such as direct light, backlight, sidelight, and cloudy conditions. Traditional manual feature extraction methods based on color and texture (such as OTSU, SVM, HOG, etc.) lack generalization ability and robustness, making them prone to false positives and false negatives.
[0005] 3. Existing deep learning models struggle to balance accuracy and speed: Deep learning models such as YOLOv3, YOLOv4, and Faster R-CNN have been applied to the field of fruit detection, but in complex orchard scenarios, these models lack sufficient accuracy in detecting dense small targets and overlapping targets; at the same time, the models have a large number of parameters and high computational cost, making it difficult to deploy them directly on the embedded hardware of harvesting robots and failing to meet the operational requirements of real-time detection.
[0006] 4. Insufficient ability to fuse global and local features: Existing detection models based on convolutional neural networks are good at extracting local detailed features, but lack the ability to model global contextual information. In scenarios where the fruit and leaves are similar in color and there is severe occlusion, false detections and false negatives are easily generated due to the lack of global semantic support.
[0007] Therefore, there is an urgent need to develop a lightweight, high-precision, and robust method for detecting citrus fruits that can achieve real-time and accurate identification and positioning of citrus fruits in complex natural orchard environments, providing reliable visual technology support for harvesting robots. Summary of the Invention
[0008] The purpose of this invention is to overcome the aforementioned shortcomings of existing technologies and provide a rapid identification and localization method for citrus fruits based on an improved YOLOv5m network. This invention optimizes the backbone and feature fusion structures of the YOLOv5m network, introduces VisionTransformer to enhance global feature modeling capabilities, introduces convolutional block attention modules to strengthen key feature representation, and employs GhostConv lightweight convolutions to reduce the number of model parameters and computational load. Ultimately, this achieves high-precision, real-time detection of citrus fruits in complex orchard environments, providing stable and reliable technical support for the automated operation of harvesting robots.
[0009] To solve the above-mentioned technical problems, the technical solution provided by this invention is: a method for rapid identification and localization of citrus fruits based on an improved YOLOv5m, comprising the following steps: (1) Collect images of citrus fruits under different lighting and shading conditions in the natural environment of the citrus orchard, perform data augmentation and manual annotation on the images, and construct a citrus fruit detection dataset containing training set, validation set and test set. (2) Construct an improved YOLOv5m detection model: Replace the regular convolutions in the CBS module of the original YOLOv5m backbone network and neck network with GhostConv lightweight convolutions to reduce the number of model parameters and computation while maintaining feature extraction capabilities; (3) VisionTransformer encoder modules are embedded at the ends of the backbone network and the neck network respectively. The long-distance dependency between global pixels of the feature map is established through the multi-head self-attention mechanism, which enhances the model's ability to model the global semantic features of citrus fruits. (4) Embed the CBAM convolutional block attention module in the PANet structure of the neck network, and perform adaptive feature weighting through channel attention and spatial attention in sequence to enhance the feature expression of key channels and spatial regions of citrus fruit, while suppressing background interference information; (5) Input the citrus fruit detection dataset constructed in step (1) into the improved YOLOv5m detection model for training. Use the K-means clustering algorithm to generate prior anchor boxes that fit the size distribution of citrus fruits. Use CIoULoss as the bounding box regression loss function. Combine confidence loss and classification loss for end-to-end optimization. After training, select the weight with the best average precision on the validation set as the final detection model. (6) Input the image of the citrus orchard to be detected into the final detection model. After multi-scale feature extraction of the backbone network and feature fusion of the neck network, the detection head outputs the predicted bounding box, confidence and class probability. Then, redundant detection boxes are removed by non-maximum suppression. Finally, the location coordinates and class information of the citrus fruit are output to complete the identification and localization of the fruit.
[0010] Furthermore, the data augmentation process described in step (1) includes brightness adjustment, saturation adjustment, contrast enhancement, mirror flip, Gaussian blur, image rotation, and addition of Gaussian noise.
[0011] Furthermore, the GhostConv lightweight convolution described in step (2) is implemented as follows: first, a basic feature map is generated by a small number of regular convolutions, then a redundant feature map is generated based on the basic feature map by a cheap depth convolution operation, and finally the basic feature map and the redundant feature map are spliced and fused together for output.
[0012] Furthermore, the VisionTransformer encoder module in step (3) includes, in sequence, a PatchEmbedding layer, a position encoding layer, a multi-head self-attention layer, a layer normalization layer, and a feedforward network layer; wherein the PatchEmbedding layer maps the input feature map into a vector sequence, the position encoding layer superimposes spatial position information, and the multi-head self-attention layer realizes global long-distance feature dependency modeling.
[0013] Furthermore, in step (4), the CBAM convolutional block attention module performs attention weighting sequentially along the channel dimension and the spatial dimension; the channel attention submodule generates channel weights through global average pooling and global max pooling, and the spatial attention submodule generates spatial weights through average pooling and max pooling followed by convolution operation.
[0014] Furthermore, in step (5), the model training process employs a warm-up strategy and a cosine annealing learning rate scheduling strategy to dynamically adjust the learning rate.
[0015] Furthermore, in step (5), the bounding box regression loss in the training process adopts CIoULoss, and the confidence loss and classification loss are combined to form the total loss function, thereby achieving end-to-end joint optimization of the model.
[0016] A citrus fruit detection system based on an improved YOLOv5m includes: an image acquisition module for acquiring original images of citrus fruits under different lighting and occlusion conditions in a natural environment of a citrus orchard; an image preprocessing module for performing data augmentation and annotation on the acquired original images to construct a citrus fruit detection dataset; an improved YOLOv5m detection model, including replacing the conventional convolutional CBS module with GhostConv, embedding a backbone network and a neck network with a VisionTransformer encoder, and embedding a neck network with a CBAM convolutional block attention module; a model training module for training and optimizing the improved YOLOv5m detection model using the citrus fruit detection dataset and outputting the optimal detection weights; and an object detection and localization module for inputting the image to be detected into the trained model and outputting the location bounding box and category information of the citrus fruit.
[0017] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described method for rapid identification and localization of citrus fruits based on the improved YOLOv5m.
[0018] A harvesting robot, equipped with the aforementioned citrus fruit detection system based on the improved YOLOv5m, is used to perform automated harvesting operations based on the citrus fruit location information output by the system.
[0019] With the above structure, this invention has the following advantages: 1. High model lightweighting, facilitating embedded deployment: By replacing conventional convolution with GhostConv, the number of model parameters is reduced from 2.39 × 10⁻⁶ in the original YOLOv5m. 7 Reduced to 1.83×10 7 The weight file size was compressed from 45.2MB to 44.1MB, significantly reducing storage and computational overhead, and has the potential to run in real time on the embedded GPU device of the harvesting robot.
[0020] 2. Significantly improved detection accuracy: After introducing VisionTransformer and CBAM attention mechanism, the model’s ability to express global semantic features and key local features of citrus fruits is greatly enhanced. The mean accuracy (mAP) on the self-built citrus dataset reaches 95.1%, and it can still maintain a high recognition accuracy in complex scenarios such as fruit occlusion, overlap, and similar fruit and leaf colors.
[0021] 3. Robustness in complex environments: This method has good adaptability to various complex orchard environments such as strong sunlight on sunny days, weak light on cloudy days, front light, back light, side light, and shading from branches and leaves. The false positive rate and false negative rate are lower than those of YOLOv3, YOLOv4 and the original YOLOv5m model.
[0022] 4. The detection speed meets the requirements of real-time operation: the average detection speed of a single image reaches 0.016s (about 62.5fps), which fully meets the real-time requirements of the picking robot for target detection and can provide fast and accurate target positioning information for the end effector.
[0023] 5. Reduce the risk of damage to harvesting equipment: By improving the accuracy of identifying obscured and overlapping fruits, the risk of end effector collision damage caused by positioning errors is reduced, thereby improving the reliability and safety of harvesting operations. Attached Figure Description
[0024] Figure 1 A schematic diagram illustrating image acquisition under different shooting conditions in the natural environment of a citrus orchard; Figure 2 This is a schematic diagram of the basic network framework of YOLOv5m; Figure 3 This is a schematic diagram of the GhostConv feature extraction process; Figure 4 This is a schematic diagram of the Transformer encoder structure; Figure 5 This is a schematic diagram of the CBAM attention module structure; Figure 6 This is a schematic diagram of the overall architecture of the improved YOLOv5m model of this invention; Figure 7 This is a comparison chart of the training loss curves of the method of this invention and the original YOLOv5m; Figure 8 This is a comparison chart of the training mAP curves of the method of the present invention with those of YOLOv3, YOLOv4, and YOLOv5m; Figure 9 The PR accuracy curves for each comparison method are shown. Detailed Implementation
[0025] The present invention will now be described in further detail with reference to the accompanying drawings.
[0026] Combined with appendix Figure 1-9To achieve the aforementioned objectives, this invention employs the following technical solution, specifically including the following steps: Step 1: Construction and Preprocessing of Citrus Fruit Image Dataset. In the natural environment of a citrus orchard, industrial cameras are used to capture original images from different angles within a shooting distance of 0.5–1.5m. The captured scenes cover various complex conditions, including citrus fruits being obscured by leaves or branches, overlapping fruits, front lighting, backlighting, side lighting, sunny days, cloudy days, and morning dew. Data augmentation processing is performed on the acquired original images, specifically including brightness adjustment, saturation adjustment, contrast enhancement, mirror flipping, Gaussian blur, image rotation, and adding Gaussian noise. Data augmentation expands the number of training samples and improves the model's generalization ability. Annotation tools are used to manually annotate the citrus fruits in the images, marking each citrus fruit with a minimum bounding rectangle, generating corresponding label files. Finally, all images and labels are divided into training, testing, and validation sets to construct a complete citrus fruit detection dataset.
[0027] Step 2: Constructing an Improved YOLOv5m Detection Model. Based on the original YOLOv5m model, structural improvements are made in three dimensions: lightweight design, global feature enhancement, and attention weighting. Specific improvements are as follows: Lightweight Improvement of the CBS Module: The regular convolutions within the CBS module of the original YOLOv5m backbone and neck network are replaced with lightweight GhostConv convolutions. GhostConv first generates basic feature maps through a small number of regular convolutions, and then generates more redundant feature maps based on the basic feature maps through inexpensive depthwise convolution operations. The basic and redundant feature maps are then concatenated and fused before output. This structure significantly reduces the number of model parameters and computational cost while maintaining feature extraction capabilities, thereby improving detection speed.
[0028] To enhance global feature extraction, a VisionTransformer is introduced: Transformer encoder modules are embedded at the ends of the backbone network and the neck network, respectively. This module maps the input feature map into a vector sequence through PatchEmbedding and superimposes positional encoding to preserve spatial location information. A multi-head self-attention mechanism is used to establish long-distance dependencies between global pixels in the feature map, enabling the model to focus more on the global semantic information of the citrus fruit target region, effectively improving the feature extraction capability for occluded and overlapping fruits.
[0029] CBAM is introduced to enhance feature representation: CBAM convolutional block attention modules are embedded in the PANet structure of the neck network. CBAM performs adaptive feature optimization sequentially along the channel and spatial dimensions: the channel attention module generates channel weights through global average pooling and global max pooling, highlighting key channel features for citrus fruit identification; the spatial attention module generates spatial weights through pooling and convolution operations, suppressing background interference information and accurately focusing on the target fruit region.
[0030] Step 3: Model Training and Hyperparameter Optimization. The preprocessed citrus fruit dataset is input into the improved YOLOv5m model for training. K-means clustering is used to cluster the bounding boxes in the training set, generating prior anchor boxes suitable for the size distribution of citrus fruits. During training, CIoULoss is used as the bounding box regression loss function, combined with confidence loss and classification loss to form the total loss function, and end-to-end joint optimization is performed. Initial learning rate, momentum coefficient, weight decay rate, and batch size are set. A warm-up strategy and cosine annealing learning rate scheduling strategy are used during training to dynamically adjust the learning rate to improve training stability and convergence. The model can be trained from scratch or fine-tuned based on publicly available pre-trained weights. The weight file is saved after each iteration, and the weight file with the best mean average precision (mAP) on the validation set is selected as the final detection model after training.
[0031] Step 4: Citrus Fruit Detection and Localization. The image of the citrus orchard to be detected is input into the trained improved YOLOv5m model. The model first extracts multi-scale features through the backbone network, and then performs multi-scale feature fusion through the neck network. The detection head outputs the predicted bounding box, target confidence, and class probability. Subsequently, redundant detection boxes are removed through non-maximum suppression, and finally the location coordinates and class information of all citrus fruits in the image are output, providing accurate target localization data for the harvesting robot.
[0032] In a specific implementation of this invention, Example 1: Citrus fruit image acquisition and dataset construction In citrus orchards, mature citrus trees approximately 1.5m tall, spaced 2m apart, and with a crown width of approximately 1.2m were selected as the subjects for data collection. Using a Canon EOS 700D industrial camera, images were captured from multiple angles (eye level, upward, and downward) within a shooting distance of 0.5–1.5m, resulting in a total of 1120 original images. The captured scenes comprehensively covered complex orchard environments, including typical scenarios such as sunny days with direct sunlight, backlighting, sidelighting, cloudy days with low light, branches and leaves obscuring fruit, overlapping fruits, and fruit with dew in the morning. All original images were saved in JPEG format with a resolution of 4000×3000 pixels.
[0033] The 1120 collected images were randomly divided into a training set of 784 images, a test set of 224 images, and a validation set of 112 images, in a 7:2:1 ratio. Data augmentation was performed on the training set images using OpenCV, specifically including: random ±20% adjustment of brightness, random ±15% adjustment of saturation, random ±15% enhancement of contrast, horizontal and vertical mirroring, Gaussian blur, random angle rotation, and addition of Gaussian noise. This data augmentation expanded the training set to 13440 images, improving the model's generalization ability and robustness.
[0034] All images were manually labeled using the LabelImg annotation tool, with each citrus fruit marked with a minimum bounding rectangle. The annotation information was saved as a YOLO format TXT label file, ultimately forming a complete citrus fruit detection dataset.
[0035] Example 2: Construction of an improved YOLOv5m detection model An improved YOLOv5m detection model was built based on the PyTorch deep learning framework. The model takes a 640×640×3 RGB image as input and outputs the predicted bounding box of the citrus fruit, the target confidence score, and the class probability. The specific structural improvements are as follows: GhostConv Lightweight Replacement: This approach iterates through all CBS modules in the backbone and neck network, replacing the standard 3×3 convolutions within each module with GhostConv. The number of channels in the basic convolution is set to half the original number. A corresponding number of redundant feature maps are generated through depthwise convolution. Finally, the basic and redundant features are concatenated along the channel dimension to output a feature map with the same number of channels as the original convolution, thus reducing the number of parameters while maintaining the same feature dimension.
[0036] VisionTransformer embedding: Three cascaded Transformer encoder blocks are embedded in the last output node of the backbone network and the last output node of the neck network, respectively. The embedding dimension of PatchEmbedding is set to match the number of input feature channels, the number of heads in the multi-head self-attention is set to 8, and the hidden layer dimension of the feedforward network is 4 times the embedding dimension. Each encoder block adopts a residual connection structure, combined with layer normalization and Dropout layers to avoid model overfitting.
[0037] CBAM Attention Module Embedding: CBAM attention modules are embedded in the upsampling and downsampling branches of the PANet neck network structure, respectively. The front end of each module connects to a channel attention submodule, which generates channel weights through global average pooling and global max pooling, thus weighting the input features by channel. The channel-weighted features are then connected to a spatial attention submodule, which compresses the channel dimension through average pooling and max pooling, and then generates spatial weights through a 7×7 convolution, completing the spatial dimension feature weighting.
[0038] The final improved YOLOv5m model architecture is as follows: Figure 6 As shown, it combines lightweight characteristics, global feature modeling capabilities, and key feature focusing capabilities.
[0039] Example 3: Model Training and Performance Evaluation In this embodiment, model training and performance testing are performed on a workstation. The workstation hardware configuration is as follows: GeForce RTX 2080 Ti GPU (11GB VRAM), Intel i9-9900k CPU, and 32GB RAM. The software environment is as follows: Windows 11 operating system, PyTorch 1.8 deep learning framework, CUDA 10.2 and CUDNN 7.6.5 acceleration library.
[0040] Model training settings: The K-means clustering algorithm was used to cluster the labeled boxes in the training set to generate 9 prior anchor boxes that fit the size distribution of citrus fruits. Training hyperparameter settings: initial learning rate 0.001, momentum coefficient 0.937, weight decay coefficient 0.0005, batch size 16, total training epochs 400; Learning rate scheduling: The first 3 rounds use a warm-up strategy to linearly increase the learning rate, and the subsequent rounds use a cosine annealing strategy to dynamically decrease the learning rate; Loss function: CIoULoss is used as the bounding box regression loss, combined with binary cross-entropy confidence loss and binary cross-entropy classification loss to form the total loss function, and end-to-end joint optimization is performed.
[0041] During training, a weight file is saved for each iteration. After training, the weight file with the highest mAP on the validation set is selected as the final detection model. The model performance is evaluated on the test set, and the evaluation metrics include precision, recall, F1 score, mean precision (mAP), number of parameters, weight file size, and average detection speed.
[0042] To verify the synergistic effect of each improved module, an ablation experiment was conducted using the controlled variable method. Under the same dataset and training parameters, GhostConv, Transformer, and CBAM modules were added in sequence. The experimental results are shown in Table 1.
[0043] Table 1. Impact of different improvement methods on the detection performance of the YOLOv5m model.
[0044] The ablation experiment results show that after GhostConv, Transformer and CBAM are fused, the model mAP reaches 95.1%, which is better than the single improvement scheme and any pairwise combination scheme, verifying the synergistic effect of each module in feature extraction enhancement and model lightweighting.
[0045] The method of the present invention was further compared with mainstream object detection models such as YOLOv3, YOLOv4, and the original YOLOv5m on the same test set, and the results are shown in Table 2.
[0046] Table 2 Performance comparison of different detection models on the citrus dataset
[0047] The comparison results show that the mAP of the method of this invention is improved by 1.9% compared with the original YOLOv5m, 2.3% compared with YOLOv4, and 4.3% compared with YOLOv3. At the same time, the number of model parameters and the size of the weight file are reduced, and the detection speed is slightly improved, achieving a dual optimization of detection accuracy and model lightweighting.
[0048] Furthermore, the method of this invention was compared with advanced YOLO series models such as YOLOX-S, YOLOv5s, YOLOv7, and YOLOv8m, and the results are shown in Table 3.
[0049] Table 3 Performance Comparison of Different YOLO Series Detection Models
[0050] The comparative results show that the method of the present invention achieves the best accuracy and mAP while maintaining a high detection speed, and the number of parameters is significantly lower than that of YOLOv7 and YOLOv8m, making it more suitable for deployment in embedded vision systems of picking robots.
[0051] Example 4: Verification of Citrus Fruit Detection under Complex Environments To verify the robustness of this method under different environmental conditions, 112 typical scene images were selected from the test set for specific testing, including 54 images of sunny, bright light (with 284 citrus fruits labeled) and 58 images of cloudy, low-light light (with 272 citrus fruits labeled). YOLOv3, YOLOv4, the original YOLOv5m, and the method of this invention were used for detection, and the number of correct detections, false positives, and false negatives were counted. The results are shown in Table 4.
[0052] Table 4. Detection results of each model under different weather conditions.
[0053] Experimental results show that the method of the present invention achieved the lowest number of false positives and the number of correct detections was at the optimal level under both sunny and cloudy lighting conditions. Even in complex situations where the fruit and leaves are similar in color, the fruit is partially obscured by branches and leaves, and the fruits overlap, the method can still accurately locate the fruit position. The false negative rate and the missed detection rate are significantly lower than those of the comparison model, demonstrating good adaptability and robustness to complex orchard environments.
[0054] The present invention and its embodiments have been described above. This description is not restrictive, and the actual structure is not limited thereto. In conclusion, if those skilled in the art, inspired by this description, design similar structures and embodiments without departing from the spirit of the invention, such designs should fall within the scope of protection of this invention.
Claims
1. A method for rapid identification and localization of citrus fruits based on an improved YOLOv5m, characterized in that, Includes the following steps: (1) Collect images of citrus fruits under different lighting and shading conditions in the natural environment of the citrus orchard, perform data augmentation and manual annotation on the images, and construct a citrus fruit detection dataset containing training set, validation set and test set. (2) Construct an improved YOLOv5m detection model: Replace the regular convolutions in the CBS module of the original YOLOv5m backbone network and neck network with GhostConv lightweight convolutions to reduce the number of model parameters and computation while maintaining feature extraction capabilities; (3) VisionTransformer encoder modules are embedded at the ends of the backbone network and the neck network respectively. The long-distance dependency between global pixels of the feature map is established through the multi-head self-attention mechanism, which enhances the model's ability to model the global semantic features of citrus fruits. (4) Embed the CBAM convolutional block attention module in the PANet structure of the neck network, and perform adaptive feature weighting through channel attention and spatial attention in sequence to enhance the feature expression of key channels and spatial regions of citrus fruit, while suppressing background interference information; (5) Input the citrus fruit detection dataset constructed in step (1) into the improved YOLOv5m detection model for training. Use the K-means clustering algorithm to generate prior anchor boxes that fit the size distribution of citrus fruits. Use CIoULoss as the bounding box regression loss function. Combine confidence loss and classification loss for end-to-end optimization. After training, select the weight with the best average precision on the validation set as the final detection model. (6) Input the image of the citrus orchard to be detected into the final detection model. After multi-scale feature extraction of the backbone network and feature fusion of the neck network, the detection head outputs the predicted bounding box, confidence and class probability. Then, redundant detection boxes are removed by non-maximum suppression. Finally, the location coordinates and class information of the citrus fruit are output to complete the identification and localization of the fruit.
2. The method for rapid identification and localization of citrus fruits based on an improved YOLOv5m according to claim 1, characterized in that, The data augmentation process described in step (1) includes brightness adjustment, saturation adjustment, contrast enhancement, mirror flip, Gaussian blur, image rotation, and addition of Gaussian noise.
3. The method for rapid identification and localization of citrus fruits based on an improved YOLOv5m according to claim 1, characterized in that, The specific implementation of GhostConv lightweight convolution in step (2) is as follows: First, a basic feature map is generated by a small number of regular convolutions. Then, a redundant feature map is generated based on the basic feature map by a cheap depth convolution operation. Finally, the basic feature map and the redundant feature map are spliced and fused together for output.
4. The method for rapid identification and localization of citrus fruits based on an improved YOLOv5m according to claim 1, characterized in that, The VisionTransformer encoder module in step (3) includes, in sequence, a PatchEmbedding layer, a position encoding layer, a multi-head self-attention layer, a layer normalization layer, and a feedforward network layer; wherein the PatchEmbedding layer maps the input feature map into a vector sequence, the position encoding layer superimposes spatial position information, and the multi-head self-attention layer realizes global long-distance feature dependency modeling.
5. The method for rapid identification and localization of citrus fruits based on an improved YOLOv5m according to claim 1, characterized in that, In step (4), the CBAM convolutional block attention module performs attention weighting sequentially along the channel dimension and the spatial dimension; the channel attention submodule generates channel weights through global average pooling and global max pooling, and the spatial attention submodule generates spatial weights through average pooling and max pooling followed by convolution operation.
6. The method for rapid identification and localization of citrus fruits based on an improved YOLOv5m according to claim 1, characterized in that, In step (5), the model training process uses a warm-up strategy and a cosine annealing learning rate scheduling strategy to dynamically adjust the learning rate.
7. The method for rapid identification and localization of citrus fruits based on an improved YOLOv5m according to claim 1, characterized in that, In step (5), the bounding box regression loss in the training process adopts CIoULoss, and the confidence loss and classification loss are combined to form the total loss function, so as to achieve end-to-end joint optimization of the model.
8. A citrus fruit detection system based on an improved YOLOv5m, characterized in that, include: The image acquisition module is used to acquire original images of citrus fruits under different lighting and shading conditions in the natural environment of the citrus orchard; The image preprocessing module is used to perform data augmentation and annotation on the acquired raw images to construct a citrus fruit detection dataset; the YOLOv5m detection model is improved by replacing the conventional convolutional CBS module with GhostConv, embedding a backbone network and neck network with a VisionTransformer encoder, and embedding a neck network with a CBAM convolutional block attention module. The model training module is used to train and optimize the improved YOLOv5m detection model using the citrus fruit detection dataset, and output the optimal detection weights; the object detection and localization module is used to input the image to be detected into the trained model, and output the location bounding box and category information of the citrus fruit.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the rapid identification and localization method for citrus fruits based on the improved YOLOv5m as described in any one of claims 1 to 7.
10. A harvesting robot, characterized in that, The system is equipped with a citrus fruit detection system based on the improved YOLOv5m as described in claim 8, which is used to perform automated harvesting operations based on the citrus fruit location information output by the detection system.
