A method for detecting the ripeness of passion fruit in a complex orchard environment based on improved YOLOv8
By improving the feature fusion and bounding box regression methods of YOLOv8, the problems of missed detection and inaccurate positioning in passion fruit detection in complex orchard environments have been solved, achieving high-precision, lightweight and real-time detection results, which are suitable for automated yield measurement and intelligent harvesting in orchards.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HEZHOU UNIV
- Filing Date
- 2026-04-07
- Publication Date
- 2026-07-03
AI Technical Summary
Existing technologies for passion fruit detection in complex orchard environments suffer from issues such as missed detections, false detections, and inaccurate bounding box localization. In particular, when branches and leaves obscure the fruit or leaves and the fruit is camouflaged by its color and shape, lightweight networks struggle to extract deep features, and bounding box regression is prone to distortion, failing to meet the needs of precise harvesting by robotic arms.
An improved YOLOv8 approach was adopted, which introduced progressive feature pyramid (AFPN) for feature fusion, reconstructed the neck network topology, used the Slim-Neck component for lightweight processing, and introduced the WIoUv3 loss function for dynamic non-monotonic bounding box regression, thus solving the problems of feature loss and localization bias.
It significantly improves the recall and accuracy of passion fruit detection, achieves a balance between lightweight design and high real-time inference at the edge, reduces the false detection rate, and enhances the model's generalization ability and the upper limit of scenario expansion.
Smart Images

Figure CN122336742A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of agricultural target detection and machine vision technology, specifically relating to a method for detecting the maturity of passion fruit based on an improved YOLOv8 in complex orchard environments. Background Technology
[0002] With the development of agricultural automation, the research and deployment of intelligent harvesting robots to solve the problems of high cost and low efficiency of manual harvesting has become an industry trend. In the visual servoing system of intelligent harvesting robots, deep learning technology, especially the YOLO series algorithms (such as YOLOv8), has become the standard paradigm in the field of agricultural target detection due to its low computational overhead and stable generalization performance. For complex orchard environments, existing technologies usually attempt to introduce attention mechanisms or improve feature networks to lightweightly customize the YOLO model in order to achieve fruit detection and localization.
[0003] While existing technologies have achieved some success in specific scenarios, they still face the following serious technical challenges and shortcomings when applied to real passion fruit trellis cultivation environments:
[0004] 1. Poor adaptability to complex environments, prone to missed detections and misjudgments: Passion fruit is usually cultivated on trellises, and the orchard environment is highly unstructured. The fruit is easily obscured by dense vines and leaves, and immature green fruit also exhibits severe morphological camouflage of "fruit and leaves of the same color." Existing lightweight networks struggle to fully extract deep features when faced with extreme heavy occlusion, failing to provide accurate target identification while ensuring high recall (no missed picking).
[0005] 2. Limitations of conventional feature extraction and fusion: Conventional convolution in existing networks has high parameter and computational redundancy, which is not conducive to deployment on agricultural edge computing platforms with limited computing power; at the same time, when concatenating features across layers, the large semantic gap between non-adjacent feature layers often leads to the loss of fine-grained edge features at the bottom layer.
[0006] 3. Bounding box regression under complex occlusion is prone to generating harmful gradients: Existing bounding box regression loss functions (such as the default CIoU) rely excessively on the relative consistency of aspect ratio. Under drastic changes in natural lighting and severe occlusion, the visible outline of the fruit exhibits extreme distortion. Forcibly zooming in on such low-quality samples can easily generate harmful gradients and mislead the model's optimization direction, resulting in serious deviations in the final bounding box localization, which cannot meet the requirements of precise picking by robotic arms. Summary of the Invention
[0007] The purpose of this invention is to address the problems of missed detection, false detection, and inaccurate bounding box localization of passion fruit in complex orchard environments due to foliage occlusion and morphological camouflage. This invention provides a passion fruit maturity detection method based on an improved YOLOv8 for complex orchard environments. This method overcomes the bottleneck of PANet cross-layer fusion, improves the problem of feature loss and missed detection in complex environments, reconstructs the conventional neck network topology, achieves an extreme balance between lightweight design and high real-time inference at the edge, overcomes interference from extreme CIoU distortion samples, dynamically corrects localization deviations to comprehensively improve bounding box regression accuracy, and possesses strong generalization ability and a high upper limit for scenario expansion.
[0008] The technical solution to achieve the objective of this invention is:
[0009] A method for detecting the maturity of passion fruit based on an improved YOLOv8 in complex orchard environments includes the following steps:
[0010] Step 1: Acquire and preprocess orchard image data;
[0011] Image data of passion fruit in a natural orchard environment was acquired. The image data included complex scenes such as dense clusters, branches occluding, and fruit and leaves of the same color. The image data was labeled and divided into two categories: immature (pf) and mature (rpf). A passion fruit target detection dataset was constructed. The input images in the passion fruit target detection dataset were uniformly scaled to a preset resolution, and the input images were stitched together using the Mosaic data augmentation strategy to enrich the background context and increase the number of small target samples.
[0012] Step 2: Multi-scale feature extraction based on the backbone network;
[0013] The images from the preprocessed passion fruit target detection dataset are input into the YOLOv8 backbone network, where layer-by-layer spatial dimensionality reduction and feature abstraction are performed through a deep convolutional neural network.
[0014] Step 3: Feature fusion based on AFPN progressive feature pyramid;
[0015] An improved YOLOv8 is obtained by introducing an Advanced Feature Pyramid (AFPN) after the YOLOv8 backbone network to reconstruct the feature fusion path. The specific fusion process is as follows:
[0016] (3.1) Preliminary weighted fusion of adjacent features at the bottom layer;
[0017] (3.2) Introduce secondary weighted fusion of deep semantic features;
[0018] Step 4: Lightweight neck feature processing based on the Slim-Neck component;
[0019] A Slim-Neck component is constructed in the neck network that connects the backbone network and the subsequent decoupled detection head. This component performs low-computational-cost deep processing on the fused features output from step 3. The specific tensor transfer and topology reconstruction process within the Slim-Neck component is as follows:
[0020] (4.1) Internal feature recombination of the GSConv operator: The fused features output from step 3 are fed into the GSConv operator as input features. First, the input features are processed by a regular convolution (Conv2d) for channel mapping and information extraction. Then, the output features of the regular convolution are simultaneously split into two branches. One branch is directly passed forward as the retained features, and the other branch is input into a depthwise separable convolution (DWConv2d) for lightweight capture of spatial features. Next, the output features of the two branches are concatenated in the channel dimension. Finally, a channel shuffle operation is performed to forcibly shuffle and recombine the channel order, so that features rich in correlation information are evenly distributed throughout the computation flow.
[0021] (4.2) GSBottleneck bottleneck block residual construction: The features processed by GSConv are input into the GSBottleneck bottleneck block, which is composed of two GSConv operators connected in series. A residual connection (Add) is introduced between the input end and the output end of the second GSConv operator, which effectively avoids gradient vanishing while deepening the number of network layers.
[0022] (4.3) VoV-GSCSP cross-stage global convergence: The GSBottleneck bottleneck block is embedded into the VoV-GSCSP module to replace the original C2f module in the improved YOLOv8 neck network. Inside VoV-GSCSP, the input features first undergo a regular convolution process, and then split into two paths. The main processing branch passes through the continuously stacked GSBottleneck bottleneck block to perform in-depth mining of high-dimensional features, while the side branch acts as a short jumper across stages. Finally, the output of the main processing branch and the output of the side branch are concatenated and integrated by the end regular convolution. This reconstruction completely eliminates redundant floating-point operations (FLOPs), and while being extremely lightweight, it strictly maintains the lossless transmission of the texture of the occluded fruit edges.
[0023] Step 5: Dynamic non-monotonic bounding box regression based on WIoUv3;
[0024] The feature map processed in step 4 is input into the output prediction box of the decoupled detection head of the improved YOLOv8 network. During the backpropagation training stage of the improved YOLOv8 network, the WIoUv3 loss function with dynamic non-monotonic focusing mechanism is used to optimize the network to address the pain point of "low-quality samples" in natural scenes where passion fruit is severely occluded, resulting in extreme distortion of the visible outline.
[0025] Step 6: Analyze the prediction tensor and output the final detection result;
[0026] The improved YOLOv8 network completes iterative training and convergence through steps 1 to 5, and then enters the inference stage for practical application deployment. The actual orchard image to be detected is input into the trained network. After forward propagation, the decoupled detection head outputs the original prediction tensor containing all candidate targets. Subsequently, the original prediction tensor is parsed and post-processed to filter out redundant information and generate the final structured target localization and classification data. The final structured target localization and classification data includes the two-dimensional position coordinates of each target passion fruit, i.e., the center point coordinates and length and width dimensions of the bounding box, the final detection confidence, and the accurately mapped maturity classification label, i.e., immature or mature. Finally, the passion fruit target detection task in a complex orchard environment is completed.
[0027] The specific process of multi-scale feature extraction in step 2 is as follows:
[0028] (2.1) Low-level detail feature extraction: After the image is input into the backbone network, it is processed by the basic convolutional layer and the original cross-stage local network (C2f module) inside the backbone network for shallow feature extraction and spatial downsampling, and outputs the first scale feature layer (P3). This layer has high spatial resolution and contains fine-grained geometric edge and positional detail information of passion fruit.
[0029] (2.2) Intermediate transition feature extraction: The first scale feature layer is passed down, and after convolution dimensionality reduction and downsampling again, the second scale feature layer (P4) is output. This layer serves as a transition layer that connects the upper and lower layers and initially integrates the local context information within the receptive field.
[0030] (2.3) Deep semantic feature extraction and pooling: The second-scale feature layer is spatially downsampled for the last time and sent to the spatial pyramid pooling module (SPPF). Inside the spatial pyramid pooling module, multi-scale receptive fields are fused through multiple pooling kernels of different sizes, and finally the third-scale feature layer (P5) is output. Although this layer has low spatial resolution, it abstracts the global context and high-level semantic information of the orchard environment.
[0031] The preliminary weighted fusion process of the underlying adjacent features in step (3.1) is as follows (fusion of P3 and P4):
[0032] 3.1.1) Channel dimension unification: Extract the first-scale feature layer and the second-scale feature layer from the backbone network output. To address the physical limitation of inconsistent feature channel depth between the first-scale feature layer and the second-scale feature layer, use 1×1 pointwise convolution to perform linear mapping and dimensionality reduction on the first-scale feature layer and the second-scale feature layer respectively. Adjust the feature channels of the first-scale feature layer and the second-scale feature layer to the preset standard dimension to eliminate the channel barrier of cross-layer fusion.
[0033] 3.1.2) Spatial resolution alignment: The first-scale feature layer and the second-scale feature layer after channel unification are input into the first adaptive spatial fusion node (ASFF-2) in the progressive feature pyramid. Interpolation upsampling or stride convolution pooling operations are used to adjust the feature maps of the first-scale feature layer and the second-scale feature layer to have the same spatial resolution.
[0034] 3.1.3) Dynamic weight generation and normalization: The two spatially aligned feature layers are input into the weight learning convolutional layer to dynamically generate the corresponding spatial weight matrix. Then, the Softmax function is used to normalize the weight matrix, forcibly constraining the sum of the weight scalars of each feature layer to be constant at any spatial pixel position.
[0035] 3.1.4) Pixel-wise weighted summation: Using the normalized spatial weight matrix, pixel-wise weighted summation is performed on the feature maps of the first scale feature layer and the second scale feature layer to output the first fusion feature that retains high-frequency details such as the passion fruit edge contour to the maximum extent.
[0036] The process of introducing the secondary weighted fusion of deep semantic features in step (3.2) is (fusion of the first fusion feature and P5):
[0037] 3.2.1) Deep processing and cross-layer channel unification: The first fusion feature output from step 3.1.4) is input into the convolutional module for deep processing. At the same time, the third-scale feature layer of the backbone network is extracted, and the channel dimension of the third-scale feature layer is linearly reduced using 1×1 convolution to ensure that the number of channels in the third-scale feature layer is strictly consistent with the first fusion feature after deep processing.
[0038] 3.2.2) Cross-layer spatial alignment: The first fusion feature of deep processing after channel alignment and the third scale feature layer are input together into the second adaptive spatial fusion node (ASFF-3) in the progressive feature pyramid, and the first fusion feature of deep processing and the third scale deep feature layer are again subjected to an adaptive alignment operation of spatial resolution.
[0039] 3.2.3) Secondary weight generation and final fusion: The network dynamically generates and normalizes the second set of spatial weight matrices, and uses the second set of spatial weight matrices to perform pixel-by-pixel secondary weighted fusion on the first fusion feature and the third scale feature layer. Through this gradual strategy of introducing deep semantic features with a delay, the cross-alignment of multi-scale features is smoothly completed, which alleviates the fine-grained feature decay and semantic distortion caused by the large span of the feature layer from the underlying mechanism.
[0040] The specific mathematical operations and dynamic control process of the dynamic non-monotonic bounding box regression based on WIoUv3 in step 5 are as follows:
[0041] (5.1) Calculate the distance penalty term:
[0042] The attention penalty term R is calculated based on the distance between the center points of the predicted bounding box and the ground truth bounding box. WIoU :
[0043] (1),
[0044] In formula (1):
[0045] x, y — coordinates of the center point of the prediction box;
[0046] xgt, ygt — coordinates of the center point of the actual bounding box;
[0047] Wg, Hg — the width and height of the smallest bounding rectangle of the two;
[0048] * — This indicates that the term should be separated from the computation graph to prevent abnormal gradients from occurring during backpropagation;
[0049] Secondly, the outlier β of the sample is calculated to measure the degree of deviation of the current sample:
[0050] (5.2) Dynamically calculate the outlier β:
[0051] The outlier is calculated in real time, reflecting the degree to which the current sample deviates from the true value. This accurately quantifies the degree of dirty data for each fruit sample. The calculation formula is as follows:
[0052] (2),
[0053] In formula (2):
[0054] L * IoU —Basic intersection-union ratio loss;
[0055] —A moving average with momentum, used to record the average mass level of the current batch of samples;
[0056] (5.3) Calculate the non-monotonic gain factor r:
[0057] Calculate the non-monotonic gradient gain factor r based on the outlier β, and then redistribute the gradient weights accordingly. The formula for calculating the gain factor is:
[0058] (3),
[0059] In formula (3):
[0060] α — An adjustable hyperparameter used to control the reweighting strength of the gradient or loss;
[0061] δ — A hyperparameter that determines the inflection point of the dynamic focusing mechanism and is used to define the quality boundary for the model's gradient assignment.
[0062] (5.4) Dynamic weight allocation and network update:
[0063] Calculate the final total loss In iterative optimization, once this non-monotonic mechanism encounters a low-quality sample whose β value soars due to severe branching, the mechanism actively and forcibly reduces the corresponding gradient gain r, completely blocking the pollution of network weights by harmful gradients. At the same time, the mechanism increases the focusing weight of ordinary occluded samples.
[0064] The post-processing procedure in step 6 is as follows:
[0065] (6.1) Initial screening with confidence threshold: Extract all candidate prediction boxes output by the decoupled detection head and the confidence scores and category probabilities corresponding to the candidate prediction boxes; set the expected confidence filtering threshold, traverse the candidate boxes in the whole image, and directly filter out low-quality background noise and invalid prediction boxes with confidence scores lower than the threshold, and retain the high-confidence candidate set.
[0066] (6.2) Non-maximum suppression (NMS) deduplication: In response to the phenomenon that the same passion fruit entity is easily surrounded by multiple overlapping prediction boxes under dense clustering conditions, the non-maximum suppression (NMS) algorithm is used to remove redundancy. First, the remaining candidate boxes are sorted from high to low confidence scores, and the prediction box with the highest current score is selected as the true target reference box. Then, the spatial intersection-union ratio (IUU) of the remaining prediction boxes and the reference box is calculated. If the IUU of the current prediction box is greater than the set overlap suppression threshold, the current prediction box is determined to be a redundant box pointing to the same target and is removed. The above reference box selection and redundancy removal process is iteratively executed until all candidate boxes are processed, ensuring that each passion fruit target retains only a unique and optimal bounding box.
[0067] (6.3) Structured perception data output: After the non-maximum suppression deduplication process in step (6.2), the final high-precision detection result is output. The result is presented in the form of a structured parameter array. The result includes the two-dimensional position coordinates of each target passion fruit, i.e., the center point coordinates and length and width dimensions of the bounding box, the final detection confidence, and the precise mapping maturity classification label, i.e. immature or mature. Finally, the target detection task of passion fruit in complex orchard environment is completed.
[0068] The beneficial effects of this technical solution are:
[0069] (1) Break through the bottleneck of PANet cross-layer fusion and significantly improve the problem of feature loss and missed detection in complex environments.
[0070] The existing YOLOv8 uses the PANet structure by default for direct linear stitching across layers. In the case of heavy occlusion in orchards, a significant semantic gap exists between non-adjacent feature layers. Direct, brute-force stitching easily leads to extremely subtle edge details at the lower layers being "submerged" by deep global semantics, resulting in missed detections. This technical solution innovatively introduces a Progressive Feature Pyramid (AFPN), reconstructing the one-step cross-layer stitching into a progressive convergence "from near to far, first adjacent then across layers." Relying on the normalized spatial weight matrix generated by the internal ASFF nodes, pixel-level adaptive feature alignment is achieved. This mechanism perfectly bridges the semantic gap, accurately capturing occluded micro-edges when dealing with densely clustered passion fruit and the "green fruit and green leaves of the same color" morphological camouflage.
[0071] (2) Reconstruct the conventional neck network topology to achieve the ultimate balance between lightweight and high real-time inference at the edge.
[0072] Traditional object detection networks, such as the native YOLOv8, use standard convolutions in a coarse manner in their default C2f module, resulting in high parameter redundancy (excessive FLOPs) and making them difficult to deploy on edge devices in agricultural machinery. Simply replacing them with depthwise separable convolutions (DWConv) would severely sever the implicit feature relationships between channels, leading to a precipitous drop in model accuracy. This technical solution designs a Slim-Neck topology based on GSConv and VoV-GSCSP in the neck network. Through a heterogeneous cascade combination of "standard convolution extraction + channel halving + local depthwise separable convolution + channel shuffling," redundant computational nodes in the native network are safely eliminated at the physical level. This design significantly reduces redundant floating-point operations while forcibly preserving the correlation between feature channels, maintaining the lossless transfer of high-dimensional semantic features.
[0073] (3) Overcome the interference of extreme CIoU distorted samples and dynamically correct the positioning deviation to comprehensively improve the accuracy of bounding box regression.
[0074] The native YOLOv8 loss function, such as CIoU, heavily relies on the relative consistency of the aspect ratio between the predicted and ground truth bounding boxes. In a real orchard, occlusion by branches can cause extreme and unpredictable distortions in the visible outline of the fruit (i.e., low-quality samples). The native network forcibly magnifies these poor-quality samples, generating large, harmful gradients that mislead the optimization direction of the entire network. This invention innovatively introduces WIoUv3 in the bounding box regression stage and constructs a "dynamic non-monotonic focusing mechanism" based on its outlier β and gain factor r. This mechanism acts as a "smart circuit breaker" at the network's bottom layer. When a sample is found to have severe distortion and an extremely high outlier β, it actively reduces its gradient gain r, cutting off harmful gradient interference caused by dirty data and instead assigning higher focusing learning weights to ordinary occluded samples. Experiments show that, in parallel comparisons with the native CIoU and other mainstream loss functions, the WIoUv3 used in this invention exhibits the best overall performance balance, resulting in a jump in the model's accuracy (P) to 89.9% (globally optimal). This mechanism fundamentally corrects the persistent problem of detection frame positioning deviation under complex working conditions, and significantly reduces the false detection rate (i.e., prevents the risk of the robotic arm pruning branches incorrectly).
[0075] (4) It has strong generalization ability and upper limit of scenario expansion.
[0076] This technical solution not only performs exceptionally well in real-time detection tasks, but also, by introducing Test-Time Augmentation (TTA) strategies during the offline testing phase, leverages multi-scale image transformations to further unlock the network's potential, pushing the overall model's recall and mean precision (mAP@0.5) to an extreme of 87.6% and 92.3%, respectively. This provides a high-value technical alternative for non-real-time agricultural scenarios with extremely stringent requirements for detection accuracy, such as offline refined yield measurement in orchards and growth monitoring. Attached Figure Description
[0077] Figure 1 Flowchart for an embodiment;
[0078] Figure 2 This is a diagram of the improved target detection network structure in the embodiment;
[0079] Figure 3 This is a schematic diagram of the feature fusion architecture of the progressive feature pyramid in the embodiment;
[0080] Figure 4 This is a schematic diagram of the structure of the GSConv operator and the VoV-GSCSP cross-stage local network in the embodiment;
[0081] Figure 5 This is a schematic diagram illustrating the WIoUv3 bounding box evaluation principle and dynamic non-monotonic focusing mechanism in the embodiment;
[0082] Figure 6 A visual comparison chart of the detection results of the baseline model and the embodiment model under complex working conditions;
[0083] Figure 7 A visualization comparison of feature activation between the baseline model and the embodiment model under complex natural conditions. Detailed Implementation
[0084] The present invention will be further described below with reference to the accompanying drawings and embodiments, but this is not intended to limit the scope of the invention.
[0085] Example:
[0086] Reference Figure 1 A method for detecting the maturity of passion fruit based on an improved YOLOv8 in complex orchard environments includes the following steps:
[0087] Step 1: Acquire and preprocess orchard image data;
[0088] Image data of passion fruit in a natural orchard environment was acquired, including complex scenes such as dense clusters, branch occlusion, and fruit and leaves of the same color. This image data was divided into training, validation, and test sets in a 7:2:1 ratio. The images were labeled and classified into immature (pf) and mature (rpf) categories to construct a passion fruit target detection dataset. During the training phase, the input images in the passion fruit target detection dataset were uniformly adjusted to 640×640 pixels, and a Mosaic data augmentation strategy was used to stitch the images together to enrich the background context and increase the number of small target samples. The overall training iterations (Epochs) of the network were set to 100, the batch size (Batchsize) to 32, and the initial learning rate to 0.01. Mosaic data augmentation was turned off in the last 10 iterations to improve the fitting quality of the bounding boxes in the later stages of the network training.
[0089] Step 2: Multi-scale feature extraction based on the backbone network, such as... Figure 2 As shown;
[0090] The images from the preprocessed passion fruit target detection dataset are input into the YOLOv8 backbone network, and layer-by-layer spatial dimensionality reduction and feature abstraction are performed through a deep convolutional neural network.
[0091] The specific process of multi-scale feature extraction is as follows:
[0092] (2.1) Low-level detail feature extraction: After the image is input into the backbone network, it is processed by the basic convolutional layer and the original cross-stage local network (C2f module) inside the backbone network for shallow feature extraction and spatial downsampling, and outputs the first scale feature layer (P3). This layer has high spatial resolution and contains fine-grained geometric edge and positional detail information of passion fruit.
[0093] (2.2) Intermediate transition feature extraction: The first scale feature layer is passed down, and after convolution dimensionality reduction and downsampling again, the second scale feature layer (P4) is output. This layer serves as a transition layer that connects the upper and lower layers and initially integrates the local context information within the receptive field.
[0094] (2.3) Deep semantic feature extraction and pooling: The second-scale feature layer is spatially downsampled for the last time and sent to the spatial pyramid pooling module (SPPF). Inside the spatial pyramid pooling module, multi-scale receptive fields are fused through multiple pooling kernels of different sizes, and finally the third-scale feature layer (P5) is output. Although this layer has low spatial resolution, it abstracts the global context and high-level semantic information of the orchard environment.
[0095] Step 3: Feature fusion based on AFPN progressive feature pyramid, such as... Figure 3 As shown;
[0096] An improved YOLOv8 is obtained by introducing an Advanced Feature Pyramid (AFPN) after the YOLOv8 backbone network to reconstruct the feature fusion path. The specific fusion process is as follows:
[0097] (3.1) Preliminary weighted fusion of adjacent features at the bottom layer (fusion of P3 and P4);
[0098] 3.1.1) Channel dimension unification: Extract the first-scale feature layer and the second-scale feature layer from the backbone network output. To address the physical limitation of inconsistent feature channel depth between the first-scale feature layer and the second-scale feature layer, use 1×1 pointwise convolution to perform linear mapping and dimensionality reduction on the first-scale feature layer and the second-scale feature layer respectively. Adjust the feature channels of the first-scale feature layer and the second-scale feature layer to the preset standard dimension to eliminate the channel barrier of cross-layer fusion.
[0099] 3.1.2) Spatial resolution alignment: The first-scale feature layer and the second-scale feature layer after channel unification are input into the first adaptive spatial fusion node (ASFF-2) in the progressive feature pyramid. Interpolation upsampling or stride convolution pooling operations are used to adjust the feature maps of the first-scale feature layer and the second-scale feature layer to have the same spatial resolution.
[0100] 3.1.3) Dynamic weight generation and normalization: The two spatially aligned feature layers are input into the weight learning convolutional layer to dynamically generate the corresponding spatial weight matrix. Then, the Softmax function is used to normalize the weight matrix, forcibly constraining the sum of the weight scalars of each feature layer to be constant at any spatial pixel position.
[0101] 3.1.4) Pixel-wise weighted summation: Using the normalized spatial weight matrix, pixel-wise weighted summation is performed on the feature maps of the first-scale feature layer and the second-scale feature layer to output the first fusion feature that retains high-frequency details such as the passion fruit edge contour to the maximum extent.
[0102] (3.2) Introduce a second-weighted fusion of deep semantic features to obtain fused features and output them (fusion of the first fused feature and P5).
[0103] 3.2.1) Deep processing and cross-layer channel unification: The first fusion feature output from step 3.1.4) is input into the convolutional module for deep processing. At the same time, the third-scale feature layer of the backbone network is extracted, and the channel dimension of the third-scale feature layer is linearly reduced using 1×1 convolution to ensure that the number of channels in the third-scale feature layer is strictly consistent with the first fusion feature after deep processing.
[0104] 3.2.2) Cross-layer spatial alignment: The first fusion feature and the third scale feature layer after channel alignment are input into the second adaptive spatial fusion node (ASFF-3) in the progressive feature pyramid, and the first fusion feature and the third scale feature layer are again subjected to the adaptive alignment operation of spatial resolution.
[0105] 3.2.3) Secondary weight generation and final fusion: The network dynamically generates and normalizes the second set of spatial weight matrices, and uses the second set of spatial weight matrices to perform pixel-by-pixel secondary weighted fusion on the first fusion feature and the third scale feature layer. Through this gradual strategy of introducing deep semantic features with a delay, the cross-alignment of multi-scale features is smoothly completed, which alleviates the fine-grained feature decay and semantic distortion caused by the large feature layer span from the underlying mechanism.
[0106] Step 4: Lightweight neck feature processing based on the Slim-Neck component;
[0107] In the neck network that connects the backbone network and the subsequent decoupled detection head, a Slim-Neck component is constructed to perform low-computational-cost deep processing on the fused features output from step 3. The specific tensor transfer and topology reconstruction process within the Slim-Neck component is as follows: Figure 4 As shown:
[0108] (4.1) Reorganization of internal features of the GSConv operator, such as Figure 4 As shown in (a): The fused features output from step 3 are fed into the GSConv operator as input features. First, the input features are processed by a regular convolution (Conv2d) for channel mapping and information extraction. Then, the output features of the regular convolution are simultaneously split into two branches. One branch is directly passed forward as the retained features, and the other branch is input into a depthwise separable convolution (DWConv2d) for lightweight capture of spatial features. Next, the output features of the two branches are concatenated in the channel dimension. Finally, a channel shuffle operation is performed to forcibly shuffle and reorganize the channel order, so that features rich in correlation information are evenly distributed throughout the computation flow.
[0109] (4.2) Construction of GSBottleneck bottleneck block residuals, such as Figure 4 (b) shows that the features processed by GSConv are input into the GSBottleneck bottleneck block, which is composed of two GSConv operators connected in series. A residual connection (Add) is introduced between the input end and the output end of the second GSConv operator, which effectively avoids gradient vanishing while increasing the number of network layers.
[0110] (4.3) VoV-GSCSP cross-stage global convergence, such as Figure 4 As shown in (c): The GSBottleneck bottleneck block is embedded into the VoV-GSCSP module to replace the original C2f module in the improved YOLOv8 neck network. Inside VoV-GSCSP, the input features first undergo a regular convolutional process, and then split into two paths. The main processing branch passes through the continuously stacked GSBottleneck bottleneck block to perform in-depth mining of high-dimensional features, while the side branch acts as a jumper to directly cross the stage. Finally, the output of the main processing branch and the output of the side branch are concatenated and integrated by the end regular convolution. This reconstruction completely eliminates redundant floating-point operations (FLOPs), and while being extremely lightweight, it strictly maintains the lossless transmission of the texture of the occluded fruit edges.
[0111] Step 5: Dynamic non-monotonic bounding box regression based on WIoUv3, such as... Figure 5 As shown;
[0112] The feature map processed in step 4 is input into the decoupled detection head of the improved YOLOv8 network to output the predicted bounding box. During the backpropagation training stage of the improved YOLOv8 network, the network is optimized by using the WIoUv3 loss function with dynamic non-monotonic focusing mechanism to address the pain point of "low-quality samples" in natural scenes where passion fruit is severely occluded and the visible contour is extremely distorted.
[0113] The specific mathematical operations and dynamic control process of dynamic non-monotonic bounding box regression based on WIoUv3 are as follows:
[0114] (5.1) Calculate the distance penalty term, such as Figure 5 As shown in (a):
[0115] The attention penalty term R is calculated based on the distance between the center points of the predicted bounding box and the ground truth bounding box. WIoU :
[0116] (1),
[0117] In formula (1):
[0118] x, y — coordinates of the center point of the prediction box;
[0119] xgt, ygt — coordinates of the center point of the actual bounding box;
[0120] Wg, Hg — the width and height of the smallest bounding rectangle of the two;
[0121] * — This indicates that the term should be separated from the computation graph to prevent abnormal gradients from occurring during backpropagation;
[0122] Secondly, the outlier β of the sample is calculated to measure the degree of deviation of the current sample:
[0123] (5.2) Dynamically calculate the outlier β:
[0124] The outlier is calculated in real time, reflecting the degree to which the current sample deviates from the true value. This accurately quantifies the degree of dirty data for each fruit sample. The calculation formula is as follows:
[0125] (2),
[0126] In formula (2):
[0127] L * IoU —Basic intersection-union ratio loss;
[0128] —A moving average with momentum, used to record the average mass level of the current batch of samples;
[0129] (5.3) Calculate the non-monotonic gain factor r, such as Figure 5 As shown in (b):
[0130] Calculate the non-monotonic gradient gain factor r based on the outlier β, and then redistribute the gradient weights accordingly. The formula for calculating the gain factor is:
[0131] (3),
[0132] In formula (3):
[0133] α — An adjustable hyperparameter used to control the reweighting strength of the gradient or loss;
[0134] δ — A hyperparameter that determines the inflection point of the dynamic focusing mechanism and is used to define the quality boundary for the model's gradient assignment.
[0135] (5.4) Dynamic weight allocation and network update:
[0136] Calculate the final total loss In iterative optimization, this non-monotonic mechanism operates like a smart circuit breaker. Once it encounters a low-quality sample whose β value soars due to severe cutting of branches and leaves, the non-monotonic mechanism actively suppresses the corresponding gradient gain r, completely blocking the pollution of network weights by harmful gradients. At the same time, the non-monotonic mechanism increases the focusing weight of ordinary occluded samples.
[0137] Step 6: Analyze the prediction tensor and output the final detection result;
[0138] After the improved YOLOv8 network completes training and convergence through steps 1 to 5, the network enters the inference stage for practical application deployment with efficient inference at a speed of 86.0f / s. The actual orchard image to be detected is input into the trained network. After forward propagation, the decoupled detection head outputs the original prediction tensor containing all candidate targets. Subsequently, the original prediction tensor is parsed and post-processed to filter out redundant information and generate the final structured target localization and classification data. The final structured target localization and classification data includes the two-dimensional position coordinates of each target passion fruit, i.e., the center point coordinates and length and width dimensions of the bounding box, the final detection confidence, and the accurately mapped maturity classification label, i.e. immature or mature. Finally, the passion fruit target detection task in a complex orchard environment is completed.
[0139] The post-processing procedure is as follows:
[0140] (6.1) Initial screening with confidence threshold: Extract all candidate prediction boxes output by the decoupled detection head and the confidence scores and class probabilities corresponding to the candidate prediction boxes; set the expected confidence filtering threshold, traverse the candidate boxes in the whole image, and directly filter out low-quality background noise and invalid prediction boxes with confidence scores lower than the threshold, and retain the high-confidence candidate set.
[0141] (6.2) Non-maximum suppression (NMS) deduplication: To address the phenomenon that the same passion fruit entity is easily surrounded by multiple overlapping bounding boxes under dense clustering conditions, the non-maximum suppression (NMS) algorithm is used for redundancy removal. First, the remaining candidate boxes are sorted from high to low confidence scores, and the predicted box with the highest current score is selected as the true target reference box. Then, the spatial intersection-union ratio (IUU) of the remaining predicted boxes and the reference box is calculated. If the IUU of the current predicted box is greater than the set overlap suppression threshold, the current predicted box is determined to be a redundant box pointing to the same target and is removed. The redundancy removal process is repeated iteratively until all candidate boxes are processed, ensuring that each passion fruit target retains only a unique and optimal bounding box.
[0142] (6.3) Structured perception data output: After the non-maximum suppression deduplication process in step (6.2), the final high-precision detection result is output. The result is presented in the form of a structured parameter array. The result includes the two-dimensional position coordinates of each target passion fruit, i.e., the center point coordinates and length and width dimensions of the bounding box, the final detection confidence, and the precise mapping maturity classification label, i.e. immature or mature. Finally, the target detection task of passion fruit in complex orchard environment is completed.
[0143] The structured sensing data can be directly output, providing high-precision underlying visual sensing information for downstream agricultural tasks such as automated yield measurement in orchards, maturity inspection, or intelligent harvesting.
[0144] Effect verification and data support:
[0145] To verify the effectiveness of the ASW-YOLOv8 algorithm proposed in this embodiment, ablation experiments and comparison experiments with mainstream algorithms were conducted under the same hardware and software environment and parameter configuration as described above.
[0146] (1) Ablation experiment verification
[0147] To verify the practical effectiveness of the AFPN, Slim-Neck, WIoUv3 modules, and TTA multi-scale inference strategy, this example uses YOLOv8n as the baseline model and conducts six ablation experiments by progressively stacking improved modules. Specific performance evaluation metrics for each scheme are shown in Table 1.
[0148] Table 1 Ablation test results of different improvement methods
[0149]
[0150] As shown in Table 1, the ablation test data demonstrates that all the improved strategies designed in this example have produced substantial gains in fruit feature extraction and final detection. From the verification of specific modules, AFPN (Solution 1) increased the mAP@0.5 of immature fruit (pf) from 87.5% to 89.0%, directly confirming the fine-grained capture advantage of the progressive fusion mechanism in breaking the "green fruit and green leaves of the same color" camouflage. Introducing WIoUv3 separately (Solution 3), without adding additional network parameters, raised the overall mAP to 91.6% while maintaining an extremely high frame rate of 136.0 FPS, highlighting the underlying computational efficiency of this non-monotonic focusing mechanism. After comprehensive reconstruction, the ASW-YOLOv8 model (Solution 5) in this example achieved an overall mAP@0.5 of 91.8% and an accuracy of 89.9% (an improvement of 1.2 and 2.1 percentage points compared to the original baseline). Furthermore, thanks to the lightweight design of Slim-Neck, the model's inference speed remained stable at 86.0 FPS when processing complex features, sufficient to meet the high real-time visual servoing requirements of the harvesting robot. To further explore the perception limits of this architecture, a TTA strategy was added in Solution 6, successfully pushing the overall recall and mAP@0.5 limits to 87.6% and 92.3%, respectively. Although the frame rate dropped to 35.6 FPS due to the heavy image transformation calculations, it still maintained a basic smoothness baseline of 30 FPS. This provides a high-value technical alternative for non-real-time scenarios with extremely stringent accuracy requirements, such as offline yield measurement in orchards.
[0151] (2) Comparison Experiment of Bounding Box Loss Function
[0152] To explore the advantages of the WIoUv3 loss function, a set of replacement tests was specifically conducted on the ASW-YOLOv8 basic network, which already integrates AFPN and Slim-Neck. Specifically, the bounding box regression loss of the network was replaced with the currently mainstream GIoU, DIoU, EIoU, SIoU, and the two earliest versions of WIoU, and then run in parallel. Quantitative comparison data for each loss function are shown in Table 2.
[0153] Table 2. Impact of different bounding box loss functions on the performance of the improved model.
[0154]
[0155] As shown in Table 2, WIoUv3 exhibits the best overall performance balance among various bounding box regression loss functions. Specifically, WIoUv3 achieves the best global performance in terms of accuracy (P) and inference speed (89.9% and 86.0 FPS, respectively). It not only effectively suppresses false detections of orchard backgrounds as fruits and significantly reduces computational latency, but also effectively corrects the localization bias of low-quality samples (pf) by utilizing a non-monotonic focusing mechanism, achieving a detection accuracy of 89.2%, which is tied with SIoU. Although SIoU has a slight data advantage of 0.1 percentage points in overall mAP@0.5 (91.9%) compared to WIoUv3, this gain comes at the cost of severely sacrificing inference speed (reduced to the lowest global value of 80.8 FPS) and some accuracy. Taking into account the high precision requirements of agricultural harvesting operations ("it's better to miss picking than to cut branches incorrectly") and the high real-time requirements of visual servoing, using WIoUv3 as the final bounding box regression loss function is the optimal strategy that balances network perception accuracy and deployment efficiency.
[0156] (3) Comparison and verification with mainstream algorithms
[0157] To further verify the comprehensive performance advantages of the ASW-YOLOv8 model in complex orchard environments, it was compared and evaluated with current mainstream object detection algorithms (including the two-stage Faster R-CNN, and the single-stage YOLOv5, YOLOv7, YOLOv9, YOLOv10, and YOLOv11) on the same validation set. The experimental results are shown in Table 3.
[0158] Table 3 Performance Comparison Results of Mainstream Object Detection Algorithms
[0159]
[0160] Based on the benchmark data in Table 3, the ASW-YOLOv8 model constructed in this example achieves the global best with an overall mAP of 91.8%@0.5. Looking at the specific comparison data, while the traditional two-stage network Faster R-CNN achieves a very high recall rate (91.7%) thanks to the RPN mechanism, its high false positive rate severely drags down the overall mAP (only 88.4%), and its processing speed of 55.9 FPS is completely unable to keep up with the real-time visual servoing pace of the robotic arm. More importantly, even when directly compared to the latest state-of-the-art algorithms (YOLOv10 and YOLOv11) with their extremely strong generalization capabilities, this model still maintains a significant advantage in recognizing the highly challenging immature green fruits (pf), achieving an mAP of 89.2% (0.6 percentage points higher than YOLOv11). This data reflects a real-world scenario: while the latest general-purpose YOLO algorithm boasts strong performance, in orchards, when faced with similar-colored unripe fruit and leaves, and severe foliage occlusion, its original network structure struggles to extract subtle features. In contrast, the model in this example, through the introduction of AFPN and WIoUv3 for specific optimization, effectively addresses this deficiency. Ultimately, this model not only maintains a high detection speed of 86.0 FPS but also surpasses the accuracy of the latest algorithms in this complex field environment, providing a truly practical and applicable visual solution for orchard harvesting.
[0161] Visual verification
[0162] To visually demonstrate the detection capabilities of this model in a real, complex orchard, we selected highly representative challenging scenarios (dense clustering, branch interference, morphological camouflage, dark light occlusion, and boundary adhesion) for a comparative visualization test.
[0163] (1) Visual verification of test results:
[0164] Figure 6 The color of the frame represents different levels of maturity. In this example model (ASW-YOLOv8), mature fruits (rpf) are marked with red frames, and immature fruits (pf) are marked with pink frames. However, the baseline model (YOLOv8n) uses a default monochrome output, so all targets are uniformly represented by blue frames.
[0165] Effect description: Combination Figure 6 The visualization results show that the baseline model faces severe feature loss and obfuscation when dealing with highly similar backgrounds and extreme lighting conditions. Specifically, in Figure 6 In scenarios where targets are concealed, such as (a) dense clustering, (c) morphological camouflage, and (d) low-light occlusion, the original YOLOv8n exhibits significant false negatives due to insufficient high-frequency feature extraction capabilities. Meanwhile, Figure 6(b) Under the conditions of branch interference and (e) boundary adhesion, the model is limited by the representational limitations of the one-way feature pyramid, and is prone to misclassifying similar background structures such as vines and withered leaves as targets, resulting in false positives. To solve the above perception problem, the reconstructed ASW-YOLOv8 model exhibits strong scene adaptability, successfully eliminating visual interference from withered branches and diseased leaves, and accurately recalling hidden and faint targets.
[0166] (2) Visual verification of feature activation heatmap (Grad-CAM):
[0167] Figure 7 From left to right, the images show the original image, the baseline model (YOLOv8n) heatmap, and the example model (ASW-YOLOv8) heatmap. The redder the color, the more attention the network pays to that area during recognition and localization (extremely high activation weights); the darker the blue, the more the network treats that area as background noise and suppresses it.
[0168] Effect description: Combination Figure 7 The heatmap comparison reveals that the baseline model YOLOv8n is prone to feature extraction errors when faced with complex conditions such as dense clusters and branch interference. High-frequency activation regions are largely dispersed to surrounding thick branches and similar green leaves, which is the direct cause of its frequent false positives. In contrast, the reconstructed ASW-YOLOv8 in this example, relying on AFPN and Slim-Neck at the feature fusion layer, successfully focuses attention firmly on the real fruit, significantly suppressing ineffective activations caused by background noise. This demonstrates a substantial leap in its anti-occlusion capabilities from the network's underlying structure.
Claims
1. A method for detecting the ripeness of passion fruit in a complex orchard environment based on improved YOLOv8, characterized in that, Includes the following steps: Step 1: Acquire and preprocess orchard image data; Acquire passion fruit image data in a natural orchard environment. The image data includes complex scenes such as dense clusters, branches and trunks occluding the fruit, and fruits and leaves of the same color. The image data is labeled and divided into two categories: immature and mature. A passion fruit target detection dataset is constructed. Step 2: Multi-scale feature extraction based on the backbone network; The images from the preprocessed passion fruit target detection dataset are input into the YOLOv8 backbone network, and layer-by-layer spatial dimensionality reduction and feature abstraction are performed through a deep convolutional neural network. Step 3: Feature fusion based on AFPN progressive feature pyramid; A progressive feature pyramid is introduced after the YOLOv8 backbone network to reconstruct the feature fusion path, resulting in an improved YOLOv8. The specific fusion process is as follows: (3.1) Preliminary weighted fusion of adjacent features at the bottom layer; (3.2) Introduce a second-order weighted fusion of deep semantic features to obtain fused features and output them; Step 4: Lightweight neck feature processing based on the Slim-Neck component; In the neck network that connects the backbone network and the subsequent decoupled detection head, a Slim-Neck component is constructed to perform low-computational-cost deep processing on the fused features output in step 3. The specific tensor transfer and topology reconstruction process within the Slim-Neck component is as follows: (4.1) Internal feature recombination of the GSConv operator: The fused features output from step 3 are fed into the GSConv operator as input features. First, the input features are processed by a regular convolution for channel mapping and information extraction. Then, the output features of the regular convolution are simultaneously split into two branches. One branch is directly passed forward as the retained features, and the other branch is input into a depthwise separable convolution for lightweight capture of spatial features. Next, the output features of the two branches are concatenated in the channel dimension. Finally, a channel shuffling operation is performed to forcibly shuffle and reorganize the channel order, so that features rich in correlation information are evenly distributed throughout the computation flow. (4.2) GSBottleneck bottleneck block residual construction: The features processed by GSConv are input into the GSBottleneck bottleneck block, which is composed of two GSConv operators connected in series, and a residual connection is introduced between the input end and the output end of the second GSConv operator. (4.3) VoV-GSCSP cross-stage global convergence: The GSBottleneck bottleneck block is embedded into the VoV-GSCSP module to replace the original C2f module in the improved YOLOv8 neck network. Inside VoV-GSCSP, the input features first undergo a regular convolution process, and then split into two paths. The main processing branch passes through the continuously stacked GSBottleneck bottleneck block to perform deep mining of high-dimensional features, while the side branch acts as a jumper to directly cross the stages. Finally, the output of the main processing branch and the output of the side branch are concatenated and integrated by the end regular convolution. Step 5: Dynamic non-monotonic bounding box regression based on WIoUv3; The feature map processed in step 4 is input into the output prediction box of the decoupled detection head of the improved YOLOv8 network. During the backpropagation training stage of the improved YOLOv8 network, in order to address the pain point of extreme distortion of the visible outline caused by severe occlusion of passion fruit in natural scenes, the WIoUv3 loss function with dynamic non-monotonic focusing mechanism is used for network optimization. Step 6: Analyze the prediction tensor and output the final detection result; The improved YOLOv8 network completes iterative training and convergence through steps 1 to 5, and then enters the inference stage for practical application deployment. The actual orchard image to be detected is input into the trained network. After forward propagation, the decoupled detection head outputs the original prediction tensor containing all candidate targets. Subsequently, the original prediction tensor is parsed and post-processed to filter out redundant information and generate the final structured target localization and classification data. The final structured target localization and classification data includes the two-dimensional position coordinates of each target passion fruit, i.e., the center point coordinates and length and width dimensions of the bounding box, the final detection confidence, and the accurately mapped maturity classification label, i.e., immature or mature. Finally, the passion fruit target detection task in a complex orchard environment is completed.
2. The method for detecting the ripeness of passion fruit in a complex orchard environment based on improved YOLOv8 according to claim 1, characterized in that, The specific process of multi-scale feature extraction in step 2 is as follows: (2.1) Low-level detail feature extraction: After the image is input into the backbone network, it is processed by the basic convolutional layer and the original cross-stage local network C2f module inside the backbone network for shallow feature extraction and spatial downsampling, and outputs the first scale feature layer. This layer has high spatial resolution and contains fine-grained geometric edge and positional detail information of passion fruit. (2.2) Intermediate transition feature extraction: The first-scale feature layer is passed down, and after convolutional dimensionality reduction and downsampling, the second-scale feature layer is output. This layer serves as a transition layer that connects the upper and lower layers and initially integrates the local context information within the receptive field. (2.3) Deep semantic feature extraction and pooling: The second-scale feature layer is downsampled for the last time and sent to the spatial pyramid pooling module. Inside the spatial pyramid pooling module, multi-scale receptive field fusion is performed through multiple pooling kernels of different sizes, and finally the third-scale feature layer is output. Although this layer has low spatial resolution, it abstracts the global context and high-level semantic information of the orchard environment.
3. The method for detecting passion fruit maturity based on improved YOLOv8 in complex orchard environments according to claim 1, characterized in that the preliminary weighted fusion process of adjacent features at the bottom layer in step (3.1) is as follows: 3.1.1) Channel dimension unification: Extract the first-scale feature layer and the second-scale feature layer from the backbone network output. To address the physical limitation of inconsistent feature channel depth between the first-scale feature layer and the second-scale feature layer, use 1×1 pointwise convolution to perform linear mapping and dimensionality reduction on the first-scale feature layer and the second-scale feature layer respectively. Adjust the feature channels of the first-scale feature layer and the second-scale feature layer to a preset standard dimension to eliminate the channel barrier of cross-layer fusion. 3.1.2) Spatial resolution alignment: The first-scale feature layer and the second-scale feature layer after channel unification are input into the first adaptive spatial fusion node in the progressive feature pyramid. Interpolation upsampling or stride convolution pooling operations are used to adjust the feature maps of the first-scale feature layer and the second-scale feature layer to have the same spatial resolution. 3.1.3) Dynamic weight generation and normalization: The two spatially aligned feature layers are input into the weight learning convolutional layer to dynamically generate the corresponding spatial weight matrix. Then, the Softmax function is used to normalize the weight matrix, forcibly constraining the sum of the weight scalars of each feature layer to be constant at any spatial pixel position. 3.1.4) Pixel-wise weighted summation: Using the normalized spatial weight matrix, pixel-wise weighted summation is performed on the feature maps of the first scale feature layer and the second scale feature layer to output the first fusion feature that retains high-frequency details such as the passion fruit edge contour to the maximum extent.
4. The method for detecting the ripeness of passion fruit in a complex orchard environment based on improved YOLOv8 according to claim 3, characterized in that, The process of introducing the secondary weighted fusion of deep semantic features in step (3.2) is as follows: 3.2.1) Deep processing and cross-layer channel unification: The first fusion feature output from step 3.1.4) is input into the convolutional module for deep processing. At the same time, the third-scale feature layer of the backbone network is extracted, and the channel dimension of the third-scale feature layer is linearly reduced using 1×1 convolution to ensure that the number of channels in the third-scale feature layer is strictly consistent with the first fusion feature after deep processing. 3.2.2) Cross-layer spatial alignment: The first fusion feature of deep processing after channel alignment and the third scale feature layer are input together into the second adaptive spatial fusion node in the progressive feature pyramid, and the spatial resolution adaptive alignment operation is performed again on the first fusion feature of deep processing and the third scale feature layer. 3.2.3) Secondary weight generation and final fusion: The network dynamically generates and normalizes the second set of spatial weight matrices, and uses the second set of spatial weight matrices to perform pixel-by-pixel secondary weighted fusion on the first fusion feature and the third scale feature layer. Through this gradual strategy of introducing deep semantic features with a delay, the cross-alignment of multi-scale features is smoothly completed, which alleviates the fine-grained feature decay and semantic distortion caused by the large span of the feature layer from the underlying mechanism.
5. The method for detecting passion fruit maturity in complex orchard environments based on improved YOLOv8 according to claim 1, characterized in that, The specific mathematical operations and dynamic control process of the dynamic non-monotonic bounding box regression based on WIoUv3 in step 5 are as follows: (5.1) Calculate the distance penalty term: Based on the distance measurement between the center points of the predicted box and the real box, the attention penalty term R is calculated WIoU : (1), In formula (1): x, y — coordinates of the center point of the prediction box; xgt, ygt — coordinates of the center point of the actual bounding box; Wg, Hg — the width and height of the smallest bounding rectangle of the two; * — This indicates that the term should be separated from the computation graph to prevent abnormal gradients from occurring during backpropagation; Secondly, the outlier β of the sample is calculated to measure the degree of deviation of the current sample: (5.2) Dynamically calculate the outlier β: The outlier is calculated in real time, reflecting the degree to which the current sample deviates from the true value. This accurately quantifies the degree of dirty data for each fruit sample. The calculation formula is as follows: (2), In formula (2): L * IoU — basic intersection over union loss; —A moving average with momentum, used to record the average mass level of the current batch of samples; (5.3) Calculate the non-monotonic gain factor r: Calculate the non-monotonic gradient gain factor r based on the outlier β, and then redistribute the gradient weights accordingly. The formula for calculating the gain factor is: (3), In formula (3): α — An adjustable hyperparameter used to control the reweighting strength of the gradient or loss; δ — A hyperparameter that determines the inflection point of the dynamic focusing mechanism and is used to define the quality boundary for the model's gradient assignment. (5.4) Dynamic weight allocation and network update: Calculate the final total loss In iterative optimization, once the non-monotonic mechanism encounters a low-quality sample whose β value soars due to severe branching, the non-monotonic mechanism actively suppresses the corresponding gradient gain r, completely blocking the pollution of network weights by harmful gradients. At the same time, the non-monotonic mechanism increases the focusing weight of ordinary occluded samples.
6. The method for detecting passion fruit maturity in complex orchard environments based on improved YOLOv8 according to claim 1, characterized in that, The post-processing procedure in step 6 is as follows: (6.1) Initial screening with confidence threshold: Extract all candidate prediction boxes output by the decoupled detection head and the confidence scores and category probabilities corresponding to the candidate prediction boxes; set the expected confidence filtering threshold, traverse the candidate boxes in the whole image, and directly filter out low-quality background noise and invalid prediction boxes with confidence scores lower than the threshold, and retain the high-confidence candidate set. (6.2) Non-maximum suppression (NMS) deduplication: In view of the phenomenon that the same passion fruit entity is easily surrounded by multiple overlapping prediction boxes under the dense clustering condition, the non-maximum suppression algorithm is used to remove redundancy; firstly, the remaining candidate boxes are sorted from high to low according to the confidence score, and the prediction box with the highest current score is selected as the true target reference box. Then, the spatial intersection-union ratio (IUU) of the remaining predicted boxes with the baseline box is calculated. If the IUU of the current predicted box is greater than the set overlap suppression threshold, the current predicted box is determined to be a redundant box pointing to the same target and is removed. The above baseline box selection and redundancy removal process is iteratively executed until all candidate boxes are processed, ensuring that each passion fruit target retains only a unique and optimal bounding box. (6.3) Structured perception data output: After the non-maximum suppression deduplication process in step (6.2), the final high-precision detection result is output. The result is presented in the form of a structured parameter array. The result includes the two-dimensional position coordinates of each target passion fruit, i.e., the center point coordinates and length and width dimensions of the bounding box, the final detection confidence, and the precise mapping maturity classification label, i.e. immature or mature. Finally, the target detection task of passion fruit in complex orchard environment is completed.