Lightweight pitaya counting method based on improved YOLOv11s
By improving the YOLOv11s model and combining wavelet transform with the WDC module of depthwise separable convolution, the SWS-SimAM attention mechanism, and the DySample operator, the problems of high model complexity and insufficient small target detection in dragon fruit detection are solved, and a high-precision, low-computational-cost, and robust dragon fruit counting method is realized.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-04
- Publication Date
- 2026-03-10
AI Technical Summary
Existing technologies for dragon fruit detection suffer from problems such as high model complexity, difficulty in real-time deployment, insufficient ability to detect small targets, and high false positive and false negative rates, especially in complex environments.
An improved YOLOv11s model is adopted, and a WDC module combining wavelet transform and depthwise separable convolution is used for feature extraction. A parameter-independent SWS-SimAM attention mechanism is introduced to optimize the detection head structure, and the DySample operator is used to enhance the small target detection performance.
It achieves high-precision dragon fruit counting, reduces computational overhead, improves the model's robustness and real-time deployment capability, reduces false detection and false negative rates, and meets the accuracy and real-time requirements of intelligent orchard management.
Smart Images

Figure CN121639643A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of yield prediction, in particular to a lightweight pitaya counting method based on improved YOLOv11s. BACKGROUND
[0002] In recent years, the domestic pitaya industry has shown an explosive growth trend, and has become the world's largest pitaya producing country. According to data, as of 2024, China's pitaya planting area exceeded 60,000 mu, and the total output climbed to 1.5 million tons. With the expansion of production scale, the accurate and efficient acquisition of pitaya individual quantity has become the core basis for crop growth state evaluation, yield prediction and orchard precision management, which has great significance for stabilizing market supply and optimizing the industrial chain.
[0003] However, traditional manual field investigation and visual counting mode has inherent defects such as high labor intensity, low efficiency, significant subjective error and poor timeliness, which is difficult to meet the management needs of modern agricultural scale and intensive production. In this context, intelligent agricultural solutions integrating unmanned aerial vehicles (UAV) and computer vision have rapidly developed, providing an effective means for non-destructive and high-throughput acquisition of crop phenotype information. For example, existing technical solutions disclose the realization of pitaya recognition under UAV images based on lightweight convolutional network and attention mechanism, verifying the potential of deep learning in pitaya target detection. However, this method still has high false detection and missed detection rates in complex environments. Existing technical solutions also use YOLOv5 and ByteTrack to propose a fast counting method that can track fruits in video sequences, but the model size is large and the adaptability to embedded platforms is insufficient. Existing technical solutions further propose a lightweight pitaya detection model, which significantly improves the detection speed, but the small target recognition accuracy is still low in high-altitude aerial scenes. As can be seen, although existing research has made progress in speed and lightweight, there are still deficiencies in small target robustness in complex scenes and adaptability to embedded deployment. In the field of fruit detection, the YOLO series algorithm has been widely applied and has shown good performance. Existing technical solutions also combine YOLOv5s and attention mechanisms to realize real-time recognition and counting of multiple types of fruits, significantly improving detection accuracy while maintaining speed. Existing technical solutions also propose a lightweight YOLO model for pomegranate detection, effectively reducing model parameters, but performance decreases in the case of dense and mutually occluded fruits. Existing technical solutions also design an improved YOLO structure for apple detection tasks, achieving automated counting, but its method still relies on large-scale computing resources. Existing technical solutions use UAV images combined with deep learning to realize citrus load estimation, verifying the feasibility of UAV vision in large-scale orchard management, but the false detection rate is still high in complex backgrounds. Overall, existing work has laid a technical foundation for fruit detection and counting, but the general problem is that: ① the model complexity is too high, making it difficult to be deployed in real time on edge devices such as UAVs; ② the small target detection capability is insufficient, especially in high-altitude aerial, dense distribution and strong occlusion environments.
[0004] To solve the above problems, the academic circle has proposed various improvement directions. Lightweight networks such as MobileNet, ShuffleNet and EfficientNet reduce computational overhead through depth separable convolution or network structure search, and show advantages in embedded applications, but their feature expression ability is limited, and the small target detection performance is insufficient in high-density scenes. At the same time, attention mechanisms have gradually become the core means to improve model robustness. For example, SE and CBAM can enhance key feature responses through channel and spatial weighting, Coordinate Attention can achieve more fine feature encoding in complex backgrounds, and SimAM can improve discriminative ability while maintaining lightweight in a parameter-independent manner. These methods provide new ideas for small target recognition and detection in complex scenes. In addition, dynamic operators and new feature reconstruction methods have also attracted attention. DySample realizes lightweight upsampling operation by introducing dynamic sampling offset, which reduces computational cost while maintaining strong feature reconstruction ability, especially suitable for small target detection tasks. The introduction of the Transformer architecture further promotes the development of target detection methods, and its global modeling ability helps to alleviate the problem of target density and occlusion, but the model size is large and the deployment cost is high.
[0005] However, these methods often only optimize a single problem, and lack systematic improvement under the dual challenges of lightweight and small target detection. In summary, although existing research has made some progress in unmanned aerial visual detection of pitaya and other fruits, the detection accuracy in complex environments and embedded real-time deployment are still bottlenecks that need to be broken through. SUMMARY
[0006] To solve the above problems of the prior art, the purpose of the present application is to provide a lightweight pitaya counting method based on improved YOLOv11s, which introduces a WDC module combining wavelet transform and depth separable convolution, constructs a lightweight feature extraction structure to reduce computational overhead and improve feature representation ability; combined with the parameter-independent SWS_SimAM attention mechanism, the discriminative ability of the model in complex backgrounds is enhanced; at the same time, the detection head structure is optimized, and the P2 branch and DySample operator are used to strengthen the small target detection performance. The experimental results show that the present application not only realizes high precision in the pitaya detection task, but also shows advantages in model compression and inference acceleration, providing efficient and reliable technical support for orchard intelligent management and unmanned production.
[0007] To achieve the above purpose, the present application provides the following scheme: A lightweight pitaya counting method based on improved YOLOv11s, comprising: A dragon fruit image is acquired, and the dragon fruit image is input into a counting model to obtain the number of dragon fruits. The counting model is trained using a training set to improve the YOLOv11s model. The training set includes: the original dragon fruit image. The YOLOv11s model is improved by replacing the C3k2 module with the lightweight C3k2-DWT module for efficient and lightweight feature extraction, replacing the SimAM module with the SWS-SimAM attention mechanism to divide the input feature map into local sub-blocks and independently calculate energy weights within each sub-block, mapping the weights to the entire feature map, replacing the P5 layer of the detection head with the P2 small target detection layer, and introducing a dynamic upsampling operator in the neck area to perceive local feature content during upsampling, dynamically adjust the sampling position and weights, and restore spatial detail information.
[0008] Optionally, efficient and lightweight feature extraction based on the C3k2-DWT lightweight module includes: The input features are subjected to channel-wise spatial filtering via depthwise separable convolution, and then... Convolution compresses the number of channels, and the compressed features are fed into depthwise separable convolution, which is then decomposed into low-frequency subbands and high-frequency subbands by discrete wavelet transform, carrying global structural information and multi-directional texture details respectively. Each sub-band is weighted using a channel attention mechanism, and the weighted sub-bands are reconstructed into spatial domain features using inverse wavelet transform. The residual path in the DWT decomposition mode is then used to fuse the depthwise separable convolution output features with the spatial domain features.
[0009] Optionally, weighting each sub-band using the channel attention mechanism includes: ; in, For global average pooling, It is a fully connected layer. For the Sigmoid function, For low-frequency sub-band, For high-frequency sub-band, This is the feature map of the corresponding sub-band after wavelet decomposition.
[0010] Optionally, reconstructing the spatial domain features from the weighted subbands using inverse wavelet transform includes: ; in, Features of the spatial domain The low-frequency subband is reconstructed by inverse wavelet transform after weighting. , , For the reconstructed high-frequency subband, representing horizontal edges and textures, representing vertical edges and textures, representing diagonal details and noise information.
[0011] Optionally, the mapping of the weight to the entire feature map comprises: ; wherein, is the activation value of a spatial position on a channel, representing the response strength of the pitaya feature at the position, is the mean value within the local slice, as a local background reference, is the local variance within the sub-block, is a constant term / regularization factor to avoid a denominator of 0, is a local energy function to measure the pixel saliency difference, is the local attention weight obtained by the energy mapping, is the feature map enhanced by the local attention, as the input of the next upsampling and detection.
[0012] Optionally, the restoring of the spatial detail information comprises: ; wherein, is the upsampled feature map output by the DySample, for use by the detection head, is the sampling position with offset, is a set of pixel grid points adjacent to for bilinear / interpolation; is the interpolation weight, is the input feature value at position , is the dynamic offset for each upsampled position.
[0013] Optionally, the obtaining of the dynamic offset comprises: ; wherein, is a static or dynamic scaling factor, is a linear mapping layer; is pixel rearrangement for constructing an offset tensor.
[0014] Optionally, the obtaining of the pitaya quantity comprises: using the detection head, generating a candidate bounding box, performing confidence screening and non-maximum suppression on the candidate bounding box, and generating a final candidate bounding box set after deduplication; taking the number of detection boxes in the final candidate bounding box set as the pitaya quantity.
[0015] Optionally, the confidence screening and non-maximum suppression on the candidate detection frame comprises: ; ; wherein, is a confidence threshold value, controlling whether low-confidence predictions are discarded, is a confidence-screened candidate set, is the confidence of the frame, is an IoU threshold value, and the overlapping frame greater than the threshold value will be merged / suppressed; is the final candidate frame set after deduplication.
[0016] The beneficial effects of the present application are: The present application has been systematically improved from four aspects of feature extraction, attention modeling, feature reconstruction and detection head design. First, by replacing the C3k2 module in YOLOv11s with the proposed C3k2-DWT lightweight structure, a feature decoupling method combining discrete wavelet transform and depth separable convolution is introduced, which enables the model to capture low-frequency contour information and high-frequency texture details of pitaya fruits at the same time, achieving more efficient feature expression. Under the same computational load, this structure significantly improves the representation ability of small size targets, effectively reduces redundant convolution operations, and improves inference speed.
[0017] Secondly, the present application uses SWS-SimAM attention mechanism instead of traditional SimAM module, which realizes parameter-independent saliency enhancement through local sub-block slicing and energy weight mapping, so that the model can more accurately identify pitaya targets in complex environments such as cluttered background, strong light interference and branch obstruction, thereby reducing the false detection and missed detection rate. Compared with channel-space attention, the present method does not require additional convolution and full connection structure, and is particularly suitable for embedded device deployment.
[0018] Thirdly, the present application introduces a DySample dynamic upsampling operator in the neck feature fusion stage, which learns a local content-adaptive sampling offset to enable the upsampling process to restore edge and contour details in a targeted manner, significantly improving the feature reconstruction quality of dense small target regions and solving the distortion problem of traditional fixed interpolation methods in high-altitude aerial scenes.
[0019] Finally, the present application replaces the P5 layer in the detection head structure with a P2 small target detection layer to improve the detection resolution of small-scale fruits, and combines an efficient NMS strategy to make the counting result more stable and reliable.
[0020] By the technical solution, the following remarkable technical effects are achieved. Detection accuracy is improved: small target recall rate and overall mAP are significantly improved, especially in dense fruit areas and severely occluded areas.
[0021] The model is lightweight: the parameter quantity and FLOPs are greatly reduced, making the model have good edge deployment capability and enabling real-time inference on unmanned aerial vehicles and portable terminals.
[0022] Robustness is enhanced: false detection and missed detection rates are significantly reduced under conditions of light changes, branch and leaf occlusions, and complex backgrounds, making the model more suitable.
[0023] The counting result is more accurate and reliable: based on the optimized detection head and robust post-processing method, the final fruit counting error is significantly reduced, meeting the dual requirements of precision and real-time performance for orchard intelligent management.
[0024] In summary, the present application solves the core problems of insufficient small target detection capability, high model complexity and limited deployment in the prior art, and forms a lightweight dragon fruit counting method with high precision, low computational complexity and strong robustness, providing a reliable technical means for orchard automation and unmanned production. BRIEF DESCRIPTION OF DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed in the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0026] Figure 1 The unmanned aerial vehicle dragon fruit image of the embodiment of the present application; Figure 2 The data set enhancement schematic diagram of the embodiment of the present application; Figure 3 The YOLOv11 network structure diagram of the embodiment of the present application; Figure 4 The simplified three-layer detection head schematic diagram of the embodiment of the present application; Figure 5 The Dysample structure schematic diagram of the embodiment of the present application; (a) dynamic upsampling based on sampling, (b) sampling point generator schematic diagram; Figure 6 The SWS-SimAM structure schematic diagram of the embodiment of the present application; Figure 7 The wave depth convolution structure schematic diagram of the embodiment of the present application; Figure 8A comparison diagram of improved effects of an embodiment of the present application is shown. Figure 9 A comparison diagram of detection effects of an embodiment of the present application is shown.
[0027] Figure 10 A flowchart of a lightweight dragon fruit counting method based on improved YOLOv11s of an embodiment of the present application is shown. DETAILED DESCRIPTION
[0028] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.
[0029] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and easy to understand, the present application will be further described in detail below with reference to the drawings and specific embodiments.
[0030] As shown in the formula: Figure 10 The present embodiment discloses a lightweight dragon fruit counting method based on improved YOLOv11s, which comprises: Step 1, input image: operation: read the original image collected by the unmanned aerial vehicle / ground; symbol / function: input is ( : original RGB image, pixel coordinate system, used for subsequent all detection and counting operations).
[0031] Step 2, wave depth convolution (WDC): feature extraction and high frequency enhancement: formula: ; Wherein, is the WDC output feature map, used for subsequent small target detection and counting; : 1x1 convolution is used for fusing channel information; is the inverse discrete wavelet transform, used for reconstructing the weighted subband into spatial features; : is the wavelet subband , is the subband feature after channel attention weighting of the subband obtained by DWT decomposition, containing high frequency edge / textural information, is the activation, GAP is the global average pooling, FC is the full connection, is the depth separable convolution on , is the input feature of the Backbone for channel-by-channel filtering and channel compression.
[0032] Counting relationship: The edge and texture response of pitaya is enhanced, especially for small fruits, and the missing detection caused by downsampling loss is reduced, thereby improving the recall rate and accuracy of the final count. To achieve efficient and lightweight feature extraction, a wave-depth convolution (WDC) module is proposed. This module combines wavelet transform convolution (WTConv) and depthwise separable convolution (DWConv), and through the cooperative optimization of frequency domain decomposition and spatial compression, it significantly reduces the computational complexity and model parameter amount while ensuring detection accuracy. The basic idea is to replace the C3k2 module with a C3k2-DWT lightweight module. Wavelet transform convolution is used to introduce multi-scale frequency domain analysis in the shallow and key feature extraction stage to enhance global and detailed features. At the same time, depth-separated convolution is used to reduce computational overhead. Combined with residual connection and channel attention mechanism, it effectively alleviates the gradient attenuation in the deep training process and selectively enhances the effective information.
[0033] In the implementation process, the input features are first subjected to spatial filtering in each channel by depthwise separable convolution, and then convolution is used to compress the number of channels to of the original input, thereby reducing the computational burden of subsequent wavelet transform. Subsequently, the compressed features are sent to depthwise separable convolution, which is decomposed into low-frequency subband and high-frequency subband by discrete wavelet transform (DWT), respectively carrying global structure information and multi-directional texture details. To suppress redundancy and noise, each subband is weighted by the channel attention mechanism, and its calculation form is: ; where is the global average pooling, is the fully connected layer, is the Sigmoid function. The weighted subbands are reconstructed into spatial domain features by inverse wavelet transform (IWT): To improve the stability of information transmission, WDC uses a residual path to fuse the depthwise separable convolution output and the wavelet transform convolution reconstructed feature : . Where represents convolution, which is used for channel adjustment and information fusion. This residual mechanism can avoid information loss caused by frequency domain enhancement and ensure effective gradient transmission in deep networks.
[0034] The WDC module is designed around the principle of "shallow details - middle enhancement - deep stability". In the YOLOv11 backbone network, wavelet transform convolution is respectively performed on the 2nd, 5th, 7th, 9th, 14th, 17th, 20th, 23rd and 26th layers to capture multi-scale features such as edges and textures layer by layer; and depth separable convolution is applied to the input layer (0th and 1st layers), part of the shallow layer (3rd layer) and the middle layer (6th and 8th layers), mainly undertaking the tasks of spatial filtering and channel compression.
[0035] Step 3, local slice attention (SWS-SimAM), local saliency amplification: Formula: ; Wherein, is the activation value of a certain spatial position on a certain channel, representing the response strength of the position to the pitaya feature; is the mean value in the local slice (sub-block), serving as a local background reference; is the local variance in the sub-block; is a constant term / regularization factor to avoid a denominator of 0; is a local energy function to measure the saliency difference of pixels; is the local attention weight (the greater the value, the more likely the position is the center or edge of the fruit) obtained by energy mapping; is the feature map enhanced by local attention, serving as the input of the next upsampling and detection.
[0036] Counting relationship: SWS-SimAM amplifies the response of fruits that are weakened by leaves, stems, leaves or background at a local scale, making it easier for the subsequent detector to generate independent detection boxes, reducing missed detection and merging caused by occlusion, so that the counting is closer to the actual number of fruits. SimAM, as a parameter-free attention method, characterizes the difference between feature points and other points through an energy function, achieving weighting on salient regions. However, in complex scenes, the global statistics of SimAM are easily dominated by large targets or backgrounds, resulting in insufficient enhancement of small targets. To solve this problem, the present invention introduces the SWS-SimAM attention mechanism. This method divides the feature map into local sub-blocks and independently calculates the energy weight in the sub-block, so that small targets are more prominent in terms of local mean, thereby obtaining higher attention response. The final weight is mapped to the entire feature map, achieving a balance between large and small targets.
[0037] Step 4, DySample (dynamic upsampling in the neck): preserve spatial details of small targets: Formula (offset generation): ; wherein, Dynamic offset for each up-sampling location, used to locate the optimal sampling point; Static or dynamic scaling factor (e.g. 0.25 or modulated by Sigmoid); Linear mapping layer; Pixel rearrangement for constructing the offset tensor.
[0038] Relation to counting: DySample helps to recover and align small fruit cores and boundaries during up-sampling, enabling the P2 / P3 small-scale detection head to output detection boxes that closely fit the fruit bodies, reducing false positives and bounding box errors, and thus directly reducing counting bias. In traditional feature fusion, bilinear interpolation or transpose convolution are commonly used for up-sampling, both of which are fixed patterns and cannot adaptively adjust the sampling strategy according to the feature content. To enhance the feature recovery capability of the up-sampling process, the present invention introduces the DySample dynamic up-sampling operator. This operator achieves adaptive sampling through learnable offset parameters, can perceive local feature content during up-sampling, and dynamically adjust the sampling location and weight, thus more accurately recovering spatial detail information. For example, for small target regions, DySample will automatically assign higher weights to retain key features and avoid detail blurring caused by fixed interpolation. Compared with traditional bilinear interpolation, the content-aware nature of DySample makes it perform better in shallow feature fusion, providing stronger feature support for small target detection in the P2 layer, and effectively alleviating the problem of missed detection caused by detail loss.
[0039] Step 5, Detection head (multi-scale prediction: P2 / P3 / P4): generate candidate detection boxes: Formula: (Where : detection set, is the pixel coordinates and size of the th detection box; is the confidence of the box; : YOLOv11-style detection head function (including bounding box regression, target existence confidence, and class prediction).) Relation to counting: the candidate boxes generated by the detection head are the basis for counting; the combined effect of WDC, SWS-SimAM, and DySample makes these candidates more accurate and less missed, thereby affecting the accuracy of the final count .
[0040] Step 6, confidence filtering and non-maximum suppression (NMS): de-duplication; Formula (confidence filtering): , where : confidence threshold, controls whether low-confidence predictions are discarded; : candidate set after confidence filtering.
[0041] Formula (NMS): wherein : typical IoU-based non-maximum suppression operator; : IoU threshold, above which overlapping boxes will be merged / suppressed; : final candidate box set after de-duplication.
[0042] Counting relationship: is the direct input set for final counting; reasonable setting and (Combined with the quality improvement of WDC / SWS / DySample) can make closer to the true number of pitaya.
[0043] Step 7, counting output: Formula: ; wherein, is the final output of pitaya number estimation, equal to the number of detection boxes in the de-duplicated candidate set ; this number is the fruit counting result that needs to be reported or warehoused in the target application.
[0044] Counting relationship: due to the combined effect of front-end WDC (enhanced small fruit), SWS-SimAM (amplify local saliency) and DySample (preserve spatial details), the error of counting significantly decreases compared to the unimproved model.
[0045] The embodiment discloses a lightweight pitaya counting method based on improved YOLOv11s, comprising: Materials and methods: cloudy weather on the day avoids the interference of sunlight on data collection. The image acquisition device used is DJI Mavic3 unmanned aerial vehicle, which is equipped with a 20 million pixel Hasselblad camera, the aperture value is f / 2.8-f / 11, under the commonly used shooting parameter setting, the exposure time is set to 1 / 60s, the ISO speed is ISO-100, the maximum endurance time is about 46 minutes, the maximum transmission distance can reach 20km under O4 high-definition image transmission system, the maximum flight speed is 21m / s, the resolution size of the photographed image is 5472 pixels×3648 pixels, the camera is perpendicular to the ground at 90°, the flight height during shooting is 3-50m, and 2602 unmanned aerial vehicle pitaya images are obtained. The obtained pitaya images are shown in Figure 1 .
[0046] The acquired pitaya images are processed according to the following steps: first, due to the influence of leaf shading and light changes in the orchard, the pitaya image data is expanded from 2,602 to 4,148 by rotating, sharpening, cropping and adjusting the contrast of the image data, further increasing the diversity of data in the model and the generalization ability of the model, as shown in Figure 2 Secondly, 4,148 pitaya images are randomly divided into training set, validation set and test set by Python code according to the ratio of 8:1:1, of which 3,318 images are used for training, 415 images are used for validation, and 415 images are used for testing. Finally, the pitaya in the image data is manually labeled using the labeling tool Labelimg, and a bounding box is drawn for each fruit in the image. The label name is "pitaya", and the spatial position information of the pitaya is stored in the corresponding.xml file. By writing a Python format conversion program, it is converted into the.txt format required by YOLOv11.
[0047] YOLOv11 network model: YOLOv11, as the latest version of the YOLO series target detection model promoted by Ultralytic company, has made a number of key improvements in technical architecture compared to the previous generation YOLOv8, significantly improving the model performance and applicability. First, YOLOv11 uses C3k2 module instead of the original C2f module, optimizing the network structure of the feature extraction part, enhancing the feature expression ability and improving the recognition effect of the model on multi-scale targets. Second, a C2PSA (Context-Aware Parallel Self-Attention) module based on the Transformer architecture and fusion of self-attention mechanism is introduced, which effectively enhances the model's feature perception ability in complex background, light change and other challenging scenarios, thereby improving the robustness and overall precision of detection. In addition, in the classification and detection head part, YOLOv11 adds two deep separable convolution layers, which reduces the computational complexity and parameter size of the model, thereby improving the inference efficiency. The above series of technical innovations make YOLOv11 maintain high detection accuracy while achieving faster inference speed, further expanding its application potential in complex environments, making it a solution with significant performance advantages in the current target detection field. The network architecture of YOLOv11 is shown in Figure 3 .
[0048] YOLOv1 1's original detection head has certain limitations in practical applications. It is difficult to balance the detection accuracy of large and small targets at the same time in the processing of multi-scale targets, so its performance in some scales is not ideal. When the scene background is complex or the target is occluded, the target shape often changes, and the position and angle are also prone to instability, which further increases the difficulty of accurate positioning. Target detection essentially relies on diverse feature representations, but the existing detection head structure is relatively simple and lacks sufficient flexibility, making it insufficiently adaptable to different application environments. Since the prediction branch still remains at a single scale design, the model's dynamic learning ability is limited, and the overall performance declines accordingly, especially in the task of small target detection on the unmanned aerial vehicle platform. In the standard YOLO architecture, the detection head usually selects three scales of feature maps, P3, P4, and P5. The shallow feature map is suitable for small target recognition due to its high resolution, while the deep feature map has a larger receptive field and is more conducive to large target detection. Taking the P3 layer as an example, after two times of downsampling, the feature map is about one-fourth of the original image, and small targets larger than 8x8 can still retain details. However, when the target is smaller, the key features are easily lost in the downsampling process, and only a few pixels are occupied on the P3 feature map, often being mistaken for background noise and missed.
[0049] To address this issue, a common improvement approach is to introduce shallower detection heads, such as P2 or even P1, to enhance the perception of low-resolution small targets. Existing research has shown that this method is indeed effective in improving small target detection accuracy, but it also brings significant computational overhead. Taking YOLOv1 1s as an example, the computational complexity of its baseline model is 22.8 GFLOPs; after adding the P2 detection head, it rises to 28.2 GFLOPs, and further introducing the P1 increases it to 44.5 GFLOPs, almost twice the original model. As can be seen, although the shallow detection head improves the detection capability, the additional resource consumption is difficult to accept for edge devices with high real-time requirements.
[0050] In the unmanned aerial vehicle aerial task, the detected objects are mostly small targets that occupy only a few pixels in the image. Although deep convolution can extract abstract semantic information, the details of small targets are often weakened after multiple downsampling, resulting in limited contribution of deep features in small target detection. Taking the P5 detection head as an example, its main role is to represent large targets, and it is not valuable for small target tasks. At the same time, deep convolution layers usually allocate more channels to carry high-level semantics, and if the P5 detection head is discarded, not only can the parameter size and computational complexity be effectively reduced, but also the redundant overhead in small target detection can be avoided. Based on this, the present invention removes the P5 layer in the detection head design and introduces the P2 layer, thereby constructing a simplified three-layer detection head scheme, as shown inFigure 4 As shown in the figure. Experimental results show that this improvement significantly reduces model complexity while maintaining accuracy: the number of parameters is reduced from 10.26M in the standard YOLOv11s to 7.44M, demonstrating a clear advantage in lightweight design, and also showing better performance in small object detection tasks.
[0051] In traditional feature fusion, upsampling operations often employ bilinear interpolation or transposed convolution, both of which are fixed modes and cannot adaptively adjust the sampling strategy based on feature content. To enhance the feature recovery capability of the upsampling process, this invention introduces the DySample dynamic upsampling operator. This operator achieves adaptive sampling through learnable offset parameters, enabling it to perceive local feature content during the upsampling process and dynamically adjust the sampling position and weights, thereby more accurately recovering spatial detail information. For example, for regions containing small targets, DySample automatically assigns higher weights to retain key features, avoiding detail blurring caused by fixed interpolation. Compared to traditional bilinear interpolation, DySample's content-aware characteristics make it superior in shallow feature fusion, providing stronger feature support for small target detection in the P2 layer and effectively mitigating the problem of missed detection of small targets due to loss of detail.
[0052] The key to DySample lies in how to effectively generate offsets. Figure 5 (a)-(b) illustrate two types of sampling point generation mechanisms: 1. Static Scope Factor: Input features Mapped through a linear layer to The feature tensors of the channels are then resized to size (sH, sW, 2g) using a pixel shuffle operation to obtain the offset set. During this process, the offset range is scaled by a fixed factor (e.g., 0.25), that is: (1); This ensures that the sampling points are distributed within the local neighborhood.
[0053] 2. Dynamic Scope Factor: To improve adaptability, DySample introduces a learnable dynamic modulation factor. This is achieved by predicting the scale parameter through an additional linear layer and using a sigmoid function for constraint. (2); in, Using the Sigmoid function ensures that the offset range adapts adaptively to the feature content, thus better adapting to the sampling needs of different regions. Under both mechanisms, the sampling point generator can use group mapping (i.e., dividing the channels into...) Parallel prediction (PRP) can be used to improve expressive power and reduce the number of parameters.
[0054] After obtaining the set of sampling locations Then, DySample performs feature interpolation via grid_sample: (3); in, Indicates the sampling position Four adjacent grid points, These are the weights for bilinear interpolation.
[0055] Based on the above design, DySample maintains the content-aware characteristics of dynamic upsampling while achieving computational complexity close to bilinear interpolation. Compared to traditional dynamic convolution methods, its advantage lies in not relying on high-resolution guiding features or additional convolutional kernel prediction networks, thus significantly reducing the computational burden while ensuring performance.
[0056] The SWS-SimAM attention mechanism addresses this issue. SimAM, a parameter-free attention method, uses an energy function to characterize the differences between feature points and other points, thus weighting salient regions. However, in complex scenes, SimAM's global statistics are easily dominated by large targets or the background, leading to insufficient enhancement of small targets. To solve this problem, this invention introduces the SWS-SimAM attention mechanism. This method divides the feature map into local sub-blocks and independently calculates energy weights within each sub-block, making the differences of small targets more prominent under local means, thereby achieving a higher attention response. The final weights are mapped to the entire feature map, achieving a balance between targets of different sizes.
[0057] The SimAM module measures the importance of feature points using an energy function. For channels... pixels on The energy function is defined as: (4); in, It is the location in the channel. activation value, These are the mean and variance of all positions in the channel, respectively. It is a smooth term. The attention weight is obtained after energy normalization: (5); The higher the energy, the more significant the difference between that point and the overall characteristics, and the greater the corresponding weight. For example... Figure 6As shown, SimAM performs global statistics across the entire feature map, generating attention weights and weighting the features. However, because the global average is dominated by large targets and background regions, the energy differences of small targets are often weakened, resulting in insufficient attention enhancement. To improve SimAM's response to small targets, SWS-SimAM first performs a slicing operation on the input feature map, that is, dividing the feature map into several sub-blocks (slices) in the spatial dimension. Let the input feature map be... Divide it into There are 1 sub-blocks, each sub-block being approximately the size of 1. The slicing method is uniform division (grid partitioning).
[0058] Let the first The sub-blocks are ,in .
[0059] Local SimAM computation, for each sub-block Calculate the local mean for each channel. Local variance and each spatial location in that sub-block Calculate local energy : (6); Then, the local energy is converted into local attention weights through mapping with SimAM: (7); The weights of each sub-block are spatially concatenated to form a complete feature map, which is then applied to the input features. (8); like Figure 6 As shown, the slicing operation makes the differences of small targets more obvious under the reference of local mean, thus obtaining higher attention weights and thus achieving more prominent performance in the fused enhanced feature map.
[0060] As can be seen from the comparison in the figures, SimAM's global modeling excels in enhancing large targets, but its discrimination against small targets is insufficient. SWS-SimAM effectively alleviates this problem through slice modeling: statistical analysis of local sub-block ranges can highlight the differences between small targets and the surrounding background, while maintaining the integrity of large targets during the stitching and integration stages. This mechanism balances global consistency and local saliency, improving the model's adaptability in multi-scale target detection tasks.
[0061] To achieve efficient and lightweight feature extraction, this invention proposes a Wave-Depth Convolution (WDC) module. This module integrates Wavelet Transform Convolution (WTConv) and Depthwise Separable Convolution (DWConv), significantly reducing computational complexity and model parameter count while maintaining detection accuracy through synergistic optimization of frequency domain decomposition and spatial compression. The basic idea is to replace the C3k2 module with a lightweight C3k2_DWT module. Wavelet Transform Convolution introduces multi-scale frequency domain analysis in the shallow and key feature extraction stages to enhance global and detailed features; simultaneously, the lightweight design of Depthwise Separable Convolution reduces computational overhead; and combined with residual connections and channel attention mechanisms, it effectively alleviates gradient decay during deep training and achieves selective enhancement of effective information.
[0062] In terms of implementation process, the input features are first subjected to channel-wise spatial filtering via depthwise separable convolution, and then... Convolution compresses the number of channels to 25% of the original input, thus reducing the computational burden on subsequent wavelet transforms. The compressed features are then fed into depthwise separable convolution, and decomposed into low-frequency subbands via discrete wavelet transform (DWT). With high-frequency subband Each subband carries global structural information and multi-directional texture details, respectively. To suppress redundancy and noise, each subband is weighted using a channel attention mechanism, calculated as follows: (9); Where GAP represents global average pooling, and FC represents a fully connected layer. The sigmoid function is used. The weighted subbands are reconstructed into spatial domain features using inverse wavelet transform (IWT): (10); To improve the stability of information transmission, WDC uses residual paths to output depthwise separable convolutions. Fusion with wavelet transform convolutional reconstruction feature X: (11); in, express Convolution is used for channel adjustment and information fusion. This residual mechanism can avoid information loss caused by frequency domain enhancement and ensure the effective propagation of gradients in deep networks.
[0063] Compared to standard convolution, WDC has a significant advantage in terms of structural lightweighting. If the input is... The kernel size is The number of output channels is The number of parameters in a standard convolution is: (12); The number of parameters for depthwise separable convolution is: (13); Therefore, the number of parameters in WDC is only about 12.5% to 11.1% of that in standard convolution, significantly reducing computational overhead while maintaining feature expressiveness. Structurally, as... Figure 7 As shown, the WDC module revolves around the design principle of "shallow details – mid-level enhancement – deep stability". In the YOLOv11 backbone network, wavelet transform convolutions perform DWT decomposition at layers 2, 5, 7, 9, 14, 17, 20, 23, and 26 to capture multi-scale features such as edges and textures layer by layer; while depthwise separable convolutions are applied to the input layer (layers 0 and 1), some shallow layers (layer 3), and mid-level layers (layers 6 and 8), mainly undertaking spatial filtering and channel compression tasks. In summary, the innovations of WDC are mainly reflected in the following aspects: achieving frequency domain-spatial co-modeling through wavelet transform, taking into account both low-frequency global information and high-frequency detailed features; combining depthwise separable convolutions and channel compression design to significantly reduce the number of parameters and computational complexity; introducing an attention mechanism to filter wavelet subbands, enhancing effective features and suppressing noise; and employing a residual fusion mechanism to improve the stability of deep information transmission. Experimental results show that YOLOv11 with WDC significantly reduces model size and computational cost while maintaining detection accuracy, demonstrating good adaptability to resource-constrained environments.
[0064] Experiment and results: The experimental environment and configuration required are shown in Table 1.
[0065] Table 1 The training parameters are shown in Table 2.
[0066] Table 2 Evaluation Metrics: To comprehensively evaluate the overall performance of the model, this invention uses a multi-dimensional evaluation system covering key performance dimensions such as detection accuracy, localization precision, and model complexity. Specifically, the core metrics selected include: Precision, Recall, Mean Average Precision (mAP), Total Number of Model Parameters (Params), and Floating Point Operations (FLOPs).
[0067] In model performance evaluation, precision quantifies the reliability of predicting positive samples, reflecting the proportion of correctly identified targets. It is defined as: Precision (14); Where TP is the number of true positives and FP is the number of false positives.
[0068] Recall represents the model's ability to cover the true target, measuring the proportion of actual positive samples that are successfully detected. Recall (15); Where FN is the number of false negatives.
[0069] Mean Average Precision (mAP), as a comprehensive evaluation metric, is calculated by averaging the integral precision-recall curve across classes, reflecting the overall detection robustness. (16); Model complexity is characterized by both the number of parameters and the number of floating-point operations (FLOPs): the number of parameters describes the scale of trainable weights, directly affecting the model's storage requirements and lightweight nature; the number of floating-point operations measures the floating-point overhead of the inference process. Together, they determine the feasibility of deploying the model in edge computing scenarios.
[0070] Ablation experiments of the improved model: To analyze the correlation between the performance of the system's analytical model and the design of specific components, and to verify the effectiveness of the improvement scheme, this invention starts with the YOLOv11n baseline architecture, progressively introduces innovative modules, and finally constructs a complete improved model. The ablation experiment results are shown in Table 3.
[0071] Table 3 Ablation experiments using the YOLO11-WDTC model In Table 3, Model A is the original YOLOv11s model. Model B represents the model after removing the P5 detector head. After removing the P5 detector head, the number of parameters and computational cost of the model are reduced, while the parameters of each index remain basically unchanged, and the accuracy, which has the largest change, only decreases by 1.7%. Model C adds a P2 detection layer and detector head after removing the P5 detector head. Since the feature map resolution of the P2 layer is higher, it can retain more features of small targets, thus significantly improving mAP50, but also bringing greater computational cost. Model D adds a Wavelength Convolutional (WDC) module to Model C. WDC combines the lightweight advantages of DWConv with the multi-scale frequency domain analysis capabilities of WTConv: DWConv is used in the input layer and some shallow and middle layers to reduce computational cost, while WTConv is used in key layers to perform DWT decomposition, attention filtering, and IWT reconstruction of features to enhance detail representation and suppress noise. Finally, the two are fused through residual connections and the number of channels is unified. This design significantly reduces model complexity while maintaining feature representation capabilities: the number of parameters decreases from 7.65M to 5.12M, and the computational cost decreases from 28.2 GFLOPs to 19.0 GFLOPs. Simultaneously, detection performance is improved, with mAP50 increasing from 91.4% to 92.5% and mAP50:95 from 49.4% to 51.9%, achieving a balance between accuracy and efficiency. Model E, building upon Model D, further incorporates the SWS-SimAM attention mechanism. This module adaptively allocates weights across feature channels and spatial dimensions, highlighting key information and suppressing redundant information, enabling the model to focus more on the target region. Experimental results show that mAP50 and mAP50:95 continue to improve while maintaining almost the same number of parameters, reaching 92.7% and 52.2% respectively, demonstrating the optimization of detection performance by the attention mechanism. Model F, building upon Model E, employs the DySample dynamic sampling module to replace the traditional fixed upsampling method. DySample can adaptively select sampling positions based on local information in the feature map, thereby improving the accuracy of feature fusion. Experimental results show that model F improves mAP50 to 93.4% with almost no increase in the number of parameters and computational cost, while maintaining a high level of mAP50:95 at 52.2%. This demonstrates that DySample is effective in improving feature upsampling quality and enhancing detection accuracy.
[0072] A comprehensive comparison of the results of each model in Table 3 reveals that by gradually improving the model structure, not only were the number of parameters and computational loads effectively reduced, but the accuracy of target detection was also continuously improved. The final improved model outperformed the original YOLOv11s in both small target detection and overall performance.
[0073] To verify the performance advantages of the proposed model, this section selects representative lightweight models (all with the suffix "S") from the YOLO series for comparison. Under the experimental condition of maintaining consistent network depth and width, a systematic performance comparison is conducted. Table 4 shows the comparison results of the proposed model and the baseline model on various metrics. The changes in each parameter during training are also compared. Figure 8 As shown.
[0074] Table 4 Comparative experiments of the improved model As shown in Table 4, the proposed YOLOv11-WDTC model exhibits significant advantages in both detection accuracy and computational efficiency. Specifically, mAP50 and mAP50:95 reach 93.4% and 52.2%, respectively, representing improvements of 5.6% and 5.9% compared to the baseline YOLOv11s. Simultaneously, the number of parameters and computational complexity are reduced by 50.6% and 16.7%, respectively, indicating a significant enhancement in detection performance while maintaining lightweight characteristics. Further comparison with other recently performing lightweight models reveals that YOLOv11-WDTC leads in both accuracy and efficiency. Compared to YOLOv8s, its mAP50 and mAP50:95 are improved by 5.7% and 4.9% respectively, while the number of parameters and computational cost are reduced by 57.6% and 35.6% respectively, demonstrating a dual advantage in detection accuracy and model complexity. Compared to YOLOv10s, the accuracy is improved by 5.9% and 6.0% respectively, while the number of parameters and computational cost are reduced by 39.6% and 25.2% respectively, demonstrating the ability to maintain high accuracy while reducing computational overhead. Compared to YOLOv13s, YOLOv11-WDTC improves mAP50 and mAP50:95 by 5.9% and 5.7% respectively, while the number of parameters and GFLOPs are reduced by 43.8% and 9.5% respectively, demonstrating its competitiveness in the new generation of lightweight models.
[0075] In summary, YOLOv11-WDTC demonstrates a significant improvement in detection accuracy and an effective reduction in resource consumption in a comprehensive comparison with mainstream lightweight models such as YOLOv8s, YOLOv10s, YOLOv11s, and YOLOv13s. Furthermore, it achieves a better balance between detection accuracy and model complexity, exhibiting superior overall performance compared to existing lightweight YOLO models.
[0076] To visually demonstrate the performance differences in target detection between YOLOv11s and YOLOv11-WDTC at different shooting heights, this invention provides a comparative analysis of the two models' performance through visualization in multi-scale scenes, such as... Figure 9As shown. In close-up scenes at low altitudes (3 meters), although both models were able to detect plant and fruit targets, YOLOv11-WDTC exhibited a denser distribution of detection boxes and more complete confidence annotations, demonstrating stronger ability to capture small targets without significant missed detections. As the shooting altitude increased to 10 meters (medium to low distance), the scene transformed into a row-and-column crop planting area. YOLOv11-WDTC displayed more detection boxes than YOLOv11s, with a higher degree of fit between the target bounding boxes and the actual targets. Background interference was effectively suppressed, and the recall rate also improved. Further scaling up to medium heights (20 meters and 30 meters), with the shooting perspective covering mixed areas of buildings and crops, YOLOv11-WDTC demonstrated stronger global perception capabilities, with a wider detection box coverage and significantly better localization accuracy for distant targets than YOLOv11s. Particularly at a height of 30 meters, YOLOv11-WDTC could reliably identify crop targets around buildings, while YOLOv11s exhibited some missed detections. Finally, in large-scale scenes at macro scales (40 meters and 50 meters), crop rows became the primary observation object. YOLOv11-WDTC's detection boxes were more regularly distributed, completely covering long rows of crops, while YOLOv11s, due to scale expansion, resulted in blurred target features, sparse detection boxes, and localized missed detections.
[0077] In summary, the experimental results show that YOLOv11-WDTC outperforms YOLOv11s in both target detection completeness and positioning accuracy across different scales of the scene. Its performance advantage is particularly prominent in long-distance and large-scale scenarios, which provides strong support for subsequent quantitative index analysis.
[0078] This invention addresses the high cost and low efficiency of traditional manual dragon fruit counting by proposing a lightweight counting method, YOLOv11-WDTC, based on an improved YOLOv11s. This method introduces a WDConv module that fuses wavelet transform convolution (WTConv) and depthwise separable convolution (DWConv), and improves the C3k2 structure to C3k2_DWT. This effectively reduces the number of model parameters and computational complexity while expanding the receptive field, thereby enhancing feature extraction and detection capabilities. Simultaneously, it introduces the SWS_SimAM attention mechanism to enhance feature representation, optimizes the detection head structure, removes the P5 detection layer and adds a P2 small target detection layer, and combines the DySample dynamic upsampling operator to reduce computational overhead, further improving the model's small target detection performance in occluded scenarios. Experimental results show that YOLOv11-WDTC outperforms the baseline model YOLOv11s in accuracy, recall, mAP50, and mAP50:95, reaching 91.1%, 86.3%, 93.4%, and 52.2%, respectively, with improvements of 2.5, 6.2, 5.6, and 5.9 percentage points. Simultaneously, the number of model parameters and computational complexity are reduced by 50.6% and 16.7%, respectively. These results demonstrate that this method achieves significant improvements in detection accuracy and efficiency while reducing resource consumption, providing effective technical support for dragon fruit growth monitoring and yield prediction, and possessing promising application prospects and widespread value. Future work will further investigate the model's generalization ability in real-world production environments with complex lighting and background interference, and explore optimized deployment using edge computing devices to meet the real-time and stability requirements of agricultural production sites.
[0079] The embodiments described above are merely preferred embodiments of the present invention and are not intended to limit the scope of the present invention. Various modifications and improvements made to the technical solutions of the present invention by those skilled in the art without departing from the spirit of the present invention should fall within the protection scope defined by the claims of the present invention.
Claims
1. A lightweight dragon fruit counting method based on improved YOLOv11s, characterized by, The method comprises the following steps: An image of the dragon fruit is acquired, and the image of the dragon fruit is input into a counting model to acquire the number of dragon fruits; The counting model uses a training set to train an improved YOLOv11s model; the training set comprises original images of dragon fruits; The YOLOv11s model is improved: the C3k2 module of the YOLOv11s model is replaced with a C3k2-DWT lightweight module for efficient and lightweight feature extraction, a SWS-SimAM attention mechanism is used to replace a SimAM module for dividing an input feature map into local sub-blocks and independently calculating energy weights in the sub-blocks, the weights are mapped to the entire feature map, a P2 small target detection layer is used to replace a P5 layer of a detection head, and a dynamic upsampling operator is integrated in a neck part for perceiving local feature content in the upsampling process, dynamically adjusting the sampling position and the weight, and restoring spatial detail information.
2. The improved YOLOv11s-based lightweight cactus count method according to claim 1, characterized in that, The efficient and lightweight feature extraction based on the C3k2-DWT lightweight module comprises the following steps: The input features are subjected to deep separable convolution for channel-by-channel spatial filtering, and are subjected to The convolution compresses the number of channels, and the compressed features are sent to deep separable convolution, are decomposed into a low-frequency subband and a high-frequency subband through discrete wavelet transform, and respectively carry global structure information and multi-directional texture details; Each sub-band is weighted through a channel attention mechanism, the weighted sub-band is reconstructed into a spatial domain feature through inverse wavelet transform, and a residual path in a DWT decomposition mode is used to fuse the depth separable convolution output feature and the spatial domain feature.
3. The improved YOLOv11s-based lightweight cactus count method according to claim 2, characterized in that, The weighting of each sub-band through the channel attention mechanism comprises the following steps: ; wherein, is a global average pooling, is a fully connected layer, is a Sigmoid function, is a low frequency subband, is a high frequency subband, is a feature map corresponding to a subband after wavelet decomposition.
4. The improved YOLOv11s-based lightweight cactus count method according to claim 2, characterized in that, The reconstruction of the weighted sub-band into the spatial domain feature through the inverse wavelet transform comprises the following steps: ; wherein, is the spatial domain feature, is the low frequency subband after inverse wavelet transform reconstruction of the weighted subband, , , is the high frequency subband after reconstruction, represents the horizontal direction edge and texture, is the vertical direction edge and texture, represents the diagonal direction detail and noise information.
5. The improved YOLOv11s-based lightweight cactus count method according to claim 1, characterized in that, The mapping of the weight to the entire feature map comprises the following steps: ; wherein, is the activation value of a spatial location on a certain channel, indicating the response intensity of the location to the pitaya feature, is the mean value within the local slice, as a local background reference, is the local variance within the sub-block, is the constant term / regularization factor to avoid the denominator being 0, is the local energy function to measure the pixel saliency difference, is the local attention weight obtained by the energy mapping, is the feature map enhanced by the local attention, as the input of the next upsampling and detection.
6. The improved YOLOv11s-based lightweight cactus count method according to claim 1, characterized in that, The restoration of the spatial detail information comprises the following steps: ; in, This is the upsampled feature map output by DySample, used by the detection head. For the sampling position with offset, To and The set of neighboring pixel grid points is used for bilinear / interpolation; For interpolation weights, For in position The input feature values, The dynamic offset for each upsampling position.
7. The improved YOLOv11s-based lightweight cactus count method according to claim 6, characterized in that, The acquisition of the dynamic offset comprises the following steps: ; wherein, is a static or dynamic scaling factor, is a linear mapping layer; is a pixel rearrangement for constructing the shift tensor.
8. The improved YOLOv11s-based lightweight cactus count method according to claim 1, wherein, The acquisition of the number of dragon fruits comprises the following steps: The detection head is used to generate a candidate detection frame, the candidate detection frame is subjected to confidence screening and non-maximum suppression, and a final candidate frame set after deduplication is generated; The number of detection frames in the final candidate frame set is taken as the number of dragon fruits.
9. The improved YOLOv11s-based lightweight cactus count method of claim 8, wherein, The confidence screening and the non-maximum suppression of the candidate detection frame comprise the following steps: ; ; wherein, is a confidence threshold that controls whether low confidence predictions are discarded, is a set of confidence-filtered candidates, is the confidence of this box, is an IoU threshold, above which overlapping boxes will be merged / suppressed; is the final set of de-duplicated candidate boxes.