Method and device for detecting weeds in corn field based on improved YOLOv11
By improving the YOLOv11 network and combining the SimAM, AC_C3k2 modules and the DySample upsampling operator, a lightweight target detection network CW-YOLO was constructed, which solved the problems of low efficiency and high resource consumption in complex field weed detection, and achieved efficient and robust weed identification and detection.
Patent Information
- Application Number
- CN202511023513.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-24
- Publication Date
- 2025-10-31
AI Technical Summary
Existing weed detection algorithms are inefficient and resource-intensive in complex field environments, making them difficult to deploy on edge computing hardware. They also suffer from issues such as missed detections, inaccurate bounding box regression, and category confusion.
The YOLOv11 network is improved by compressing its width and depth, introducing the parameterless spatial attention mechanism SimAM, designing the AC_C3k2 module, and introducing the DySample upsampling operator to construct a lightweight object detection network CW-YOLO, thereby enhancing the model's robustness and detection capabilities in complex environments.
While maintaining detection accuracy, the model significantly reduces complexity and computational resource requirements, improving detection efficiency and robustness in complex farmland scenarios, and is suitable for intelligent detection of agricultural weeds under low-resource equipment conditions.
Smart Images

Figure CN120877066A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of weed detection, and more particularly to a method and apparatus for detecting weeds in corn fields based on an improved YOLOv11. Background Technology
[0002] Weed control has always been a significant factor affecting modern agricultural production. While early methods of manual weeding and pesticide application were efficient, they still suffered from low efficiency, high costs, and environmental pollution. To address this, high-precision weed control has emerged, especially in the context of intelligent agriculture, where accurate and efficient weed identification is urgently needed. However, with the evolution of real-world applications, the high computational resource consumption caused by high-precision models makes it difficult to meet the real-time and edge deployment requirements of practical applications. Nevertheless, some model studies have proposed a lightweight model design concept to balance accuracy and efficiency for practical applications. These studies indicate that lightweight design in high-precision models ensures higher accuracy, real-time performance, and edge deployment while simultaneously advancing the depth and sophistication of high-precision weed control technology, thus meeting the fundamental technological needs of intelligent agriculture development.
[0003] Although existing detection algorithms have made significant contributions to solving complex field backgrounds and improving weed detection performance, especially in terms of robustness against weeds with similar appearances and unclear boundaries, the model still suffers from drawbacks such as model complexity and high resource consumption. In practical applications, it also has high hardware requirements, making it difficult to deploy on edge computing hardware.
[0004] Therefore, while maintaining high detection performance, further reducing the burden of field weed detection and improving the efficiency of field weed detection have become key points in the process of practical application and deployment of weed detection. Summary of the Invention
[0005] This invention provides a method and device for weed detection in cornfields based on an improved YOLOv11. The invention optimizes and improves the YOLOv11 network, aiming to achieve efficient weed identification in complex and ever-changing cornfield environments using computer vision and deep learning technologies, thus providing reliable technical support for intelligent weeding equipment. This invention proposes an improved lightweight target detection network, CW-YOLO, which significantly reduces model complexity and computational resource requirements while maintaining detection accuracy. Furthermore, it demonstrates stronger robustness and generalization ability in handling typical farmland scenarios such as dense weed occlusion and background mixing. This invention provides a feasible path for realizing intelligent weeding in agricultural fields and provides technical support for promoting the automation, efficiency, and green development of agricultural production. See the description below for details:
[0006] Firstly, a method for detecting weeds in corn fields based on an improved YOLOv11, the method comprising:
[0007] Collect images of weeds, label them using the LabelImg tool, and construct a dataset with multiple types of weeds.
[0008] Based on the weed dataset, the structure of the YOLOv11 object detection network is optimized to obtain the first optimized network; the parameterless spatial attention mechanism SimAM module is integrated into the first optimized network to obtain the second optimized network.
[0009] Based on the second optimized network, the AC_C3k2 module is designed to obtain the third optimized network and construct the feature enhancement network;
[0010] Based on the third optimized network, the DySample upsampling operator is introduced to obtain the fourth optimized network; the fourth optimized network is used as the final lightweight weed detection network, and weeds in cornfields are detected based on the lightweight weed detection network.
[0011] The structural optimization of the YOLOv11 target detection network involves compressing the width and depth of the network and removing redundant modules.
[0012] The SimAM module, which integrates the parameterless spatial attention mechanism in the first optimized network, is as follows:
[0013] For each feature map, a single channel is processed, and the mean and variance of the response of all pixels in that channel are calculated. Based on this, the response difference value of each pixel relative to the whole is calculated, and this difference value is used as its significance index. The significance index is normalized using an activation function and used as a spatial attention weight. This weight is then multiplied by the original feature map to increase the extraction of useful information, thereby enhancing key regions and suppressing invalid backgrounds.
[0014] The AC_C3k2 module is as follows:
[0015] The input weed features are fed into the CAS part for additive self-attention operation. The output global weighted feature map is then fed into the CGLU module. The CGLU module calculates the main features and the gating signal through two convolutional branches, and uses the gating mechanism to fuse the feature map output from the CAS part and the feature map processed by the CGLU module, finally generating the enhanced feature map.
[0016] The introduced DySample upsampling operator is:
[0017] Based on the local information of the input feature map, a sampling offset is dynamically generated. The sampling offset is used to determine the sampling position of each pixel during the upsampling process. Using grid sampling technology, the low-resolution feature map is resampled according to the generated sampling position, thereby recovering the high-resolution feature map.
[0018] In a second aspect, a cornfield weed detection device based on an improved YOLOv11 is provided, the device comprising: a processor and a memory, the memory storing program instructions, the processor calling the program instructions stored in the memory to cause the device to perform the method described in any of the first aspects.
[0019] Third aspect, a computer-readable storage medium storing a computer program, the computer program including program instructions that, when executed by a processor, cause the processor to perform the method described in any one of the first aspects.
[0020] The beneficial effects of the technical solution provided by this invention are:
[0021] 1. This invention uses a method of compressing the width and depth of the network. By simplifying the backbone feature extraction network and feature fusion module in the YOLOv11 network, adjusting the number of channels and stacking depth of each layer, and eliminating redundant structures, the number of model parameters and computational overhead are effectively reduced, thereby improving inference speed and edge deployment efficiency while ensuring detection accuracy.
[0022] 2. This invention uses the SimAM attention mechanism to assign weights to each spatial location of the feature map without adding trainable parameters, thereby enhancing the feature representation of key regions. This mechanism is lightweight and adaptive, dynamically adjusting the attention distribution based on neuron response and information entropy, effectively improving detection and classification performance.
[0023] 3. This invention uses a redesigned AC_C3k2 module, which integrates convolutional additive self-attention and convolutional gated linear units in CAS-ViT to construct a lightweight attention enhancement module AB_CGLU, which replaces the bottleneck module in the original C3k structure. This module reduces computational complexity while enhancing the modeling ability of global context and weed features, has a lower parameter count and stronger robustness, and improves the detection efficiency and accuracy of the model in complex environments.
[0024] 4. This invention uses the DySample upsampling operator, which effectively improves image details and resolution through dynamic sampling position generation and grid sample resampling. Compared with traditional dynamic convolution, the DySample structure is simpler and more efficient, achieving a balance between speed and accuracy. This method adopts the "pl" style, which enhances channel information interaction through pixel shuffle and then performs local perceptual upsampling to effectively extract the contextual features of weeds and improve the detection effect.
[0025] 5. The model training and evaluation method used in this invention involves supervised training of the improved model on the CornWeed8 dataset and testing its generalization ability on heterogeneous datasets such as CottonWeedDet12 and 4WEED DATASET. By comparing the detection accuracy, inference speed and model size in different scenarios, the adaptability and stability of the model are systematically evaluated. At the same time, by combining heatmaps and attention region visualization, the model's attention to and feature response to weed areas are analyzed to verify its recognition effect and practicality in actual agricultural environments.
[0026] 6. This invention demonstrates significant detection effects and application potential in actual cornfield scenarios. It can realize real-time detection and precise control of field operations, significantly improve farming efficiency, reduce weeding error rate and pesticide usage, and provide practical technical support for intelligent farmland management. Attached Figure Description
[0027] Figure 1 This is an overall flowchart of a method for detecting weeds in corn fields based on an improved YOLOv11.
[0028] Figure 2 Example images of eight weed species from the self-made dataset CornWeed8;
[0029] Figure 3 A graph showing the number of each weed instance in the self-made dataset CornWeed8;
[0030] Figure 4 This is a structural diagram of the CW-YOLO network;
[0031] Figure 5 Network structure diagrams for different attention mechanisms;
[0032] Figure 6 Here is the network structure diagram for the AC_C3k2 module;
[0033] Figure 7 Here is the network structure diagram of the DySample module;
[0034] Figure 8 A comparison chart showing the inference performance of different algorithms;
[0035] Figure 9 This is a comparison chart of heatmaps for YOLOv11 and CW-YOLO. Detailed Implementation
[0036] To make the objectives, technical solutions, and advantages of the present invention clearer, the embodiments of the present invention will be described in further detail below.
[0037] YOLOv11, a next-generation real-time object detection model from Ultralytics, offers significant improvements in accuracy, speed, and efficiency. Its optimized trunk and neck structures enhance feature extraction capabilities and improve detection accuracy. Simultaneously, it reduces the number of parameters by 22% compared to YOLOv8, significantly lowering model complexity and supporting efficient deployment on edge devices and multiple platforms. A high-quality weed image dataset, CornWeed8, covering the entire growth cycle of corn, was constructed to provide diverse training samples for the model. Furthermore, by compressing the network width and depth, introducing a parameter-free SimAM attention mechanism, designing a lightweight AC_C3k2 attention module, and integrating the efficient DySample upsampling operator, the model's feature extraction and contextual understanding capabilities for weed regions are comprehensively improved, while significantly reducing computational resource consumption.
[0038] Given the current limitations of existing technologies in inference performance under low-resource conditions, particularly in cases where weeds and crops are occluded, overlapped, or have similar appearances, leading to missed detections, inaccurate bounding box regression, and category confusion, this invention proposes an improved weed detection model, CW-YOLO. Built on a lightweight version of YOLOv11n, CW-YOLO incorporates various structural optimizations and attention mechanisms to enhance the model's perception and discrimination capabilities in complex field environments. To verify the model's effectiveness, systematic ablation experiments and comparative tests were conducted on the self-built CornWeed8 dataset. Furthermore, the algorithm's generalization performance was evaluated on the large-scale CottonWeedDet12 dataset and the small-sample 4WEED DATASET dataset. Experimental results and inference visualization analysis demonstrate that CW-YOLO outperforms existing mainstream algorithms in target recognition accuracy, bounding box regression quality, and the ability to distinguish similar weed categories. It exhibits stronger robustness and cross-scenario adaptability, making it suitable for intelligent weed detection applications in agriculture under low-resource conditions.
[0039] Example 1
[0040] like Figure 1As shown, this embodiment of the invention provides an overall flowchart of a cornfield weed detection method based on an improved YOLOv11. Through a series of optimization steps and module designs, the performance and applicability of the model are significantly improved. In particular, the introduction of the SimAM module and the AC_C3k2 module effectively enhances the model's ability to perceive key areas and complex scenes, while the DySample upsampling operator improves the reconstruction quality of image details. These innovations not only maintain the model's lightweight nature and efficient inference speed but also improve its reliability and robustness in real agricultural environments. The method includes the following steps:
[0041] Step 101: Collect weed images, label them using the LabelImg tool, and construct a dataset with 8 types of weeds;
[0042] The labeling tool is used to assign labels for model training, and these labels are used to judge the model's performance.
[0043] Step 102: Based on the dataset characteristic analysis constructed in Step 101, optimize the structure of the YOLOv11 object detection network to obtain the first optimized network;
[0044] In this method, by compressing the width and depth of the network and removing redundant modules, the number of model parameters and computational complexity are reduced.
[0045] Step 103: Integrate the parameterless spatial attention mechanism SimAM module into the first optimized network to obtain the second optimized network;
[0046] The second optimization network requires no additional parameters. It dynamically adjusts the weights at different spatial locations by statistically analyzing the pixel response intensity within each feature map channel. This second optimization network enhances the neural network's ability to focus on key regions (e.g., weed areas) in an image.
[0047] The specific implementation process is as follows: First, each channel of the feature map is processed, and the mean and variance of the response of all pixels in that channel are calculated. Then, based on this, the response difference value of each pixel relative to the whole is calculated, and this difference value is used as its significance index. Finally, the significance is normalized using an activation function and used as a spatial attention weight, which is then multiplied by the original feature map to enhance key regions and suppress invalid backgrounds. The SimAM module has the characteristics of simple structure, no training required, and easy integration. It does not increase the model complexity, but can effectively improve the model's ability to represent weed features and the detection accuracy, making it particularly suitable for deployment in agricultural scenarios with limited computing resources.
[0048] Step 104: Based on the second optimized network, design the AC_C3k2 module to obtain the third optimized network, and then construct the feature enhancement network;
[0049] The AC_C3k2 module is a lightweight attention enhancement module that combines convolutional additive self-attention blocks and convolutional gated linear units. The AC_C3k2 module mainly consists of two parts: first, a CAS block, used to capture global contextual information in the input feature map. The CAS block strengthens long-range dependencies by calculating additive attention weights between features, improving sensitivity to details like weeds in complex scenes; second, a CGLU structure, serving as a feature gating mechanism. By performing linear transformations and gating on the input features, it effectively suppresses irrelevant information and enhances the expression of useful features.
[0050] The specific process is as follows: the input features first enter the CAS (Computational Self-Attention) part for additive self-attention operations, and the output globally weighted feature map is then fed into the CGLU (Global Convolutional Language Allocation) module. The CGLU module calculates the main features and the gating signal through two convolutional branches, and uses a gating mechanism to fuse the features, finally generating an enhanced feature map. This design, while maintaining low computational complexity, significantly improves the model's ability to capture global semantics and key features, enhances its ability to identify complex and diverse weed morphologies, and effectively improves detection accuracy and model robustness.
[0051] Step 105: Based on the third optimized network, introduce the DySample upsampling operator to obtain the fourth optimized network;
[0052] The DySample upsampling operator is an ultra-lightweight dynamic upsampling module that combines dynamic sampling position generation with a grid-sample-based resampling method. This operator mainly includes two core steps:
[0053] First, sampling offsets are dynamically generated based on the local information of the input feature map. These offsets are used to determine the sampling position of each pixel during the upsampling process, thereby improving the ability to adapt to image details. Second, grid sampling technology is used to resample the low-resolution feature map according to the generated sampling position, thereby restoring a higher-resolution feature map.
[0054] Compared to traditional fixed-rule interpolation methods, the DySample upsampling operator effectively captures local contextual relationships by dynamically adjusting the sampling position, enhancing the detailed representation of feature maps. Furthermore, this module introduces a pixel shuffle operation to improve information exchange between channels, subsequently combining it with a local perception mechanism to achieve fine-grained spatial feature reconstruction. The entire process is structurally simple, requiring no additional parameters, significantly reducing computational burden, improving upsampling efficiency and quality, and enhancing the model's ability to identify fine weed features in complex farmland environments.
[0055] Step 106: Use the fourth optimized network as the final lightweight weed detection network CW-YOLO, and use the lightweight weed detection network CW-YOLO to detect weeds in the cornfield.
[0056] The fourth optimized network is a lightweight weed detection network designed based on the YOLOv11 framework. Its overall structure mainly consists of a backbone feature extraction network, a feature fusion module, an attention enhancement module, and an upsampling module. In the backbone network, by simplifying the network width and depth, rationally adjusting the number of channels and stacked layers in each convolutional layer, and eliminating redundant computational units, the number of model parameters and computational complexity are significantly reduced, while maintaining effective extraction of key weed features. The feature fusion module incorporates a multi-scale information fusion strategy to improve the perception of weed targets of different sizes. The network integrates the SimAM parameterless spatial attention mechanism to enhance the model's feature response to important regions, strengthen the focus on weed detail features, and improve detection accuracy. Furthermore, the DySample dynamic upsampling operator is introduced to effectively improve the image detail reconstruction quality when restoring feature map resolution, enhancing the ability to recognize weed edges and textures in complex environments. Through the above structural optimization and module integration, CW-YOLO significantly enhances the detection accuracy and robustness of diverse weed targets in cornfields while maintaining lightweight and efficient inference speed. It can adapt to the challenges of real agricultural scenarios such as light changes, weed obstruction, and complex backgrounds.
[0057] Step 107: Using the CornWeed8 dataset constructed in Step 101, perform ablation and comparison experiments on the CW-YOLO network;
[0058] Step 108: Based on the model trained in Step 107, conduct a comparative experiment on the generalization ability of the CottonWeedDet12 dataset with a larger number of publicly available samples and the 4WEED DATASET dataset with a smaller number of samples.
[0059] Step 109: Perform model detection performance and visualization analysis on the cross-dataset test results from Step 108.
[0060] Experimental results and visualization analysis demonstrate that, compared with existing comparative algorithms, the algorithm proposed in this embodiment of the invention achieves superior performance while maintaining a lightweight model. It demonstrates more accurate prediction results when handling complex backgrounds and occluded scenes, more refined bounding box regression, and higher output confidence. Furthermore, it exhibits stronger generalization ability and environmental robustness across multiple datasets, validating the algorithm's practical value and stability in real-world applications.
[0061] The proposed AC_C3k2 module is a redesigned version combining a Convolutional Additive Self-Attention Block (CAS) and a Convolutional Gated Linear Unit (GLU), which not only better captures contextual information but also significantly reduces model complexity. The introduction of a Simple Parameter-Free Attention Module (SimAM) and an Ultra-Lightweight and Effective Dynamic Upsampler (DySample) effectively enhances the focus on weed features. CW-YOLO's misclassification and missed detection rates under complex conditions such as occlusion are further improved, while the model becomes more lightweight and performs better.
[0062] In summary, this invention, through steps 101 to 109, proposes a cornfield weed detection method based on an improved YOLOv11. This method aims to address the problems of high false negative rates, feature confusion, and weak model generalization ability in weed detection under complex field environments. The proposed method underwent extensive ablation and comparison experiments on the self-built CornWeed8 dataset and was validated on multiple datasets, including the larger sample size CottonWeedDet12 and the smaller sample size 4WEED DATASET. Experimental results and inference visualization analysis show that this invention demonstrates superior performance in detection accuracy, bounding box regression accuracy, and handling complex scenarios such as occlusion. It also possesses stronger model generalization ability and robustness, exhibiting promising application prospects and widespread application value.
[0063] Example 2
[0064] The following is a further introduction to the scheme in Example 1. This invention proposes a lightweight target detection model, CW-YOLO, for weed detection in cornfields, which has the advantages of high accuracy, low computational cost, and deployment friendliness. The method first constructs a multi-class weed dataset, CornWeed8, in a real, complex field environment, to compensate for the shortcomings of existing datasets. Secondly, it makes several improvements based on the YOLOv11 structure, including compressing the backbone network, introducing the parameter-free spatial attention mechanism SimAM to enhance feature attention capabilities, designing a lightweight module AC_C3k2 that integrates convolutional additive attention and gating mechanisms to improve context modeling capabilities, and employing the efficient dynamic upsampling module DySample to enhance the quality of spatial detail recovery. Systematic ablation experiments and comparative tests on multiple datasets verify the effectiveness and synergistic gain of each module. CW-YOLO outperforms mainstream detection models in terms of accuracy, speed, model complexity, and generalization ability, and is particularly suitable for resource-constrained agricultural edge devices and practical deployment scenarios, demonstrating significant practical value and promotion potential. Details are described below:
[0065] Step 201: Collect weed images, label them using the LabelImg tool, and construct a dataset with 8 types of weeds;
[0066] In response to the shortage of real-world weed datasets with similar characteristics, weed image collection was conducted at Huaxing Farm in Changji City, Changji Hui Autonomous Prefecture, Xinjiang Uygur Autonomous Region, China. The data images were RGB (red-green-blue) color images captured using a Canon EOS 600D, with an aspect ratio of 4:3 and a resolution of 5202×3464. Exposure, focus, and other functions were turned off before shooting to ensure the originality of the image data was not compromised by the device's built-in algorithms. (See below.) Figure 2 The final dataset consists of eight weed species (Amaranthus retroflexus, lambsquarters, Solanum nigrum, Camel thorn, Portulaca oleracea, Convolvulus arvensis, Setaria viridis, and Amaranthus chinensis), totaling 3970 images, named CornWeed8. It is primarily used for research experiments on weed detection algorithms and is stored at https: / / openxlab.org.cn / datasets / cvnet / CornWeed8. This data was collected throughout the corn growth cycle, featuring mostly complex backgrounds of corn seedlings, reflecting a realistic dataset format. The images are primarily multi-target images, providing new data support for scientific research in the field of weed detection.
[0067] The collected images were annotated using the open-source LabelImg tool by personnel with a thorough understanding of the labeling tools and the ability to clearly distinguish weed characteristics. The labeling format used was PascalVOC. The eight weed species were named sequentially: 'Amaranthus', 'Chenopodium', 'Solanum nigrum', 'Alhagi sparsifolia', 'Purslane', 'Convolvulus', 'Setaria', and 'Amaranthus polygonoides'. Figure 3 The bar chart represents the weed dataset CornWeed8, which contains object detection datasets for eight weed species, totaling 3970 images and annotating 6998 instance bounding boxes. The specific categories and number of instances are as follows: *Amaranthus retroflexus* 1296 instances, *Chenopodium album* 717 instances, *Solanum nigrum* 284 instances, *Alternanthera philoxeroides* 329 instances, *Portulaca oleracea* 1391 instances, *Convolvulus arvensis* 1228 instances, *Setaria viridis* 888 instances, and *Amaranthus glomeratus* 865 instances.
[0068] Step 202: Optimize the structure of the YOLOv11 object detection network by compressing the width and depth of the network, removing redundant modules, and reducing the number of model parameters and computational complexity.
[0069] The model parameters before and after compression are as follows: Figure 4 As shown, the backbone and feature pyramid of the YOLOv11 object detection network are simplified by adjusting the width and depth parameters of each layer, reducing the number of channels in the convolutional layers and the number of stacked layers, and removing redundant modules that have little impact on detection accuracy. This effectively reduces the number of parameters and computational complexity of the overall model, thereby improving inference speed and deployment efficiency while maintaining accuracy.
[0070] Step 203: Integrate the parameterless spatial attention mechanism SimAM module into the backbone network to enhance the model's ability to focus on weed feature regions without introducing additional parameters, thereby improving detection accuracy;
[0071] Among them, such as Figure 5 Figure (a) shows a typical channel attention mechanism. For example, the SE module obtains the global context information of each channel through global average pooling, and then uses a fully connected layer to generate attention weights between channels, thereby enhancing the expressive power of key channels and suppressing invalid features; Figure 5Image (b) illustrates a spatial attention mechanism, such as the spatial attention part in CBAM. It first extracts salient features of the spatial dimension through max pooling and average pooling, then uses convolution operations to generate a spatial attention map, guiding the network to focus more intently on the target region; while... Figure 5 As shown in (c), SimAM is a three-dimensional attention mechanism. Without introducing additional trainable parameters, it independently assigns weights to each spatial location in the input feature map, achieving more refined attention focus on key regions and thus enhancing the feature representation ability of the target region. This mechanism is a lightweight, parameter-independent attention module with adaptive adjustment capabilities. It dynamically adjusts the attention distribution based on the response intensity and information entropy characteristics of neurons to improve the overall performance of the model in object detection and category discrimination tasks.
[0072] The SimAM attention mechanism first applies attention to each channel. In spatial dimension Calculate the mean Then, the squared difference between each position and the mean is calculated, and their spatial sum (unbiased estimate) is obtained. Next, weights are generated. Finally, through the Sigmoid function... Activation weight And multiply it element-wise with the original input.
[0073] ;
[0074] ;
[0075] ;
[0076] ;
[0077] In the SimAM attention mechanism, statistical calculations are first performed on each channel of the input feature map in terms of spatial dimensions. Let the input feature map be... ,in Indicates batch size, Indicates the number of channels. and These represent the height and width of the feature map, respectively. For the first... Each channel is used to calculate its spatial dimension. mean This is used to measure the overall average response level of the channel. Next, the eigenvalues and mean values at each location in space are calculated. unbiased variance between This is used to measure the dispersion of the channel within the spatial dimension. Based on this, further calculations are performed for each spatial location. Corresponding attention score ,in Indicates the first The sample, the first The spatial location of each channel The feature value at that location. The calculation of the attention score introduces a constant. As a regularization term, to enhance numerical stability. All scores are processed using the Sigmoid function. After mapping to normalized weights, element-wise multiplication (i.e., the Hadamard product, denoted as ) is used. ) and the original input feature map Multiplication is performed to achieve weighted enhancement of features. The final output is the attention-weighted result of the SimAM module, which improves the model's ability to focus on key regions without introducing additional trainable parameters, and has good lightweightness and adaptability.
[0078] Step 204: The AC_C3k2 module, which integrates convolutional additive self-attention blocks and convolutional gated linear units, is adopted to improve the model's ability to extract global contextual information and further reduce computational costs.
[0079] Among them, the design of the AC_C3k2 module is as follows: Figure 6 As shown. In this embodiment, the AC_C3k2 module consists of two parts: a convolutional additive self-attention module (CASA) and a convolutional gated linear unit (CGLU). These two parts are sequentially connected in series to form a novel attention enhancement structure, AB_CGLU, used to replace the bottleneck module within the C3k structure of the original YOLOv11 network. Its structural flow is as follows: First, the input feature map passes through a... Convolutional processing performs channel compression to reduce computational complexity. The input is then fed into the CASA module, which introduces lightweight convolutional operations combined with additive attention to capture long-range dependencies and contextual information in the feature map, enhancing the model's understanding of the global structure. The output is then fed into the CGLU module, which splits the input feature map into two paths along the channel dimension: one path extracts the main features through standard convolution, and the other uses sigmoid activation to form gate weights. These two paths are then multiplied element-wise to recalibrate the features, strengthening important information and suppressing redundant information. Finally, the output features are processed through a... Convolutional processing restores channels and performs residual connections with the module input to preserve original semantic information. This module is compact, has few parameters, and is computationally efficient, significantly enhancing the network's ability to identify and represent weedy areas in complex farmland backgrounds, and improving overall detection accuracy and model generalization robustness.
[0080] Compared to the traditional C3k2 structure, the AC_C3k2 module has lower model parameter count and computational load, while improving model efficiency and accuracy while maintaining or enhancing recognition performance. The convolutional additive self-attention module combines convolutional operations with additive attention mechanisms to achieve interactive integration of multi-dimensional features, enabling Token Mixer to effectively capture global information without relying on complex matrix calculations, thus simplifying the computation process. The convolutional gated linear unit integrates channel attention mechanisms with local neighborhood image features, further enhancing the model's local modeling capabilities and robustness in complex environments.
[0081] Step 205: In the feature map recovery stage, introduce the ultra-lightweight and efficient dynamic upsampling module DySample to improve the feature map resolution recovery quality and reduce the upsampling computation burden.
[0082] Among them, the introduced DySample upsampling is as follows: Figure 7 As shown, DySample can adaptively integrate contextual information to extract key features, thereby improving image detail and resolution. The core of DySample lies in simplifying the implementation mechanism and improving efficiency, abandoning complex dynamic convolution operations, and achieving a win-win situation of speed and accuracy through ingenious algorithm design. DySample's main processing flow includes two stages: first, the sampling position is dynamically determined through a sampling point generator; second, the input feature map is resampled using the gridsample operation, outputting an optimized feature map. The calculation process is as follows.
[0083] ;
[0084] in, This represents the input feature map, while This is a dynamically generated set of sampling locations based on the current feature map. This is achieved by applying the grid sample operation, based on... Location information in Interpolation sampling is performed to obtain an output feature map containing more details. .
[0085] Sampling location The calculation is as follows.
[0086] ;
[0087] in, Indicates the sampling position of the regular grid. The offset is predicted by the network and is used to guide the sampling points to adaptively adjust from the standard grid position to a more suitable position.
[0088] To mitigate artifacts caused by error propagation layer by layer, a fixed coefficient of 0.25 is introduced into the offset. This coefficient, located at the theoretical critical value between overlapping and non-overlapping sampling points, is called the static range factor and is used to limit the maximum offset range of sampling points, achieving local sampling optimization. The corrected offset... The calculation process is as follows.
[0089] ;
[0090] in, It is a linear transformation layer implemented by a fully connected layer (or a 1x1 convolutional layer) used to generate the original offset.
[0091] To enhance the adaptive capability of the offset, a dynamic range adjustment mechanism based on input features is introduced. A point-by-point range factor is obtained through linear mapping and multiplied by the offset value to form the final offset. Combining the Sigmoid function with a maximum value of 0.5, the dynamic range is limited to the interval [0, 0.5], centered around a static coefficient of 0.25. The corrected offset... The calculation process is as follows:
[0092] ;
[0093] DySample offers two upsampling styles: 'lp' and 'pl'. This embodiment of the invention uses the 'pl' style to extract contextual feature information of weeds. The 'lp' method directly guides the upsampling process by generating offsets in local regions of the input feature map, so that the position of each output pixel is determined based on the content of its corresponding input region. This method is suitable for tasks that require preserving local continuity and detail. The 'pl' style, on the other hand, shuffles the pixel arrangement through a pixel shuffle operation before upsampling to enhance information interaction between channels, and then performs local perceptual upsampling. This method is more conducive to fusing contextual information.
[0094] Step 206: Based on the above improvements of YOLOv11, we propose the weed detection network CW-YOLO, a lightweight target detection network specifically designed for weed detection in cornfields.
[0095] Its overall architecture comprises three core components: a backbone feature extraction network, an enhanced feature fusion module (Neck), and a lightweight prediction head (Head). The backbone feature extraction network significantly reduces parameters and computational cost by compressing width and depth, eliminating redundant modules, and introducing the SimAM parameterless spatial attention mechanism, while simultaneously improving the feature representation ability of salient weed regions. The feature fusion module adopts an improved AC_C3k2 structure, combining convolutional additive attention and convolutional gated linear units to effectively capture multi-scale feature context and enhance recognition capabilities in complex environments. The DySample dynamic upsampling operator is introduced to improve spatial resolution and detail recovery while maintaining lightweight efficiency. The prediction head follows the YOLO multi-scale detection design, adjusting channels and classification logic for cornfield weed categories to achieve accurate bounding box regression and classification. These overall improvements significantly enhance CW-YOLO's speed, resource consumption, and detection accuracy and robustness in complex agricultural scenarios, making it suitable for practical applications (such as...). Figure 4 (As shown).
[0096] CW-YOLO, an improved weed detection model based on YOLOv11, is proposed. The AC_C3k2 module is a redesigned version combining convolutional additive self-attention blocks and convolutional gated linear units, which not only better captures contextual information but also significantly reduces model complexity. The introduction of a simple attention module and ultra-lightweight and efficient dynamic upsampling effectively enhances the focus on weed features. CW-YOLO further improves its performance in complex scenarios such as occlusion, reducing false positives and false negatives, while also being more lightweight and exhibiting superior performance.
[0097] Research on object detection algorithms, and the evaluation of algorithm performance, mainly includes detection accuracy, detection speed, and model training and deployment requirements. For accuracy comparison, this invention's embodiment selects mAP. 0.5 (Mean of average precision for each category when the IoU threshold is 0.5), mAP 0.75 (Mean of average precision for each category when the IoU threshold is 0.75), mAP 0.5:0.95 (The mean mAP is calculated at multiple thresholds from 0.5 to 0.95 (with a step size of 0.05) for IoU threshold), and the F1-score is compared. For the comparison of real-time performance, the FPS metric is selected for comparison. For the comparison of model training and deployment requirements, the Params, FLOPs, and Size (model size) metrics are selected for comparison.
[0098] To comprehensively address the challenges posed by the diversity of weed morphology, complex background environments, leaf occlusion, and high real-time requirements, this invention conducted systematic ablation experiments and comparative tests on the self-built CornWeed8 cornfield weed dataset to verify the impact of each module on model performance. To further evaluate the generalization ability and robustness of the proposed CW-YOLO model in practical applications, this invention also introduced two representative public weed datasets, CottonWeedDet12 and 4WEED DATASET, to conduct cross-dataset performance tests. In the experiments, the embodiments of this invention selected 12 current mainstream or typical object detection algorithms for comparison with the proposed CW-YOLO, including detection models widely used in the past three years: YOLOv5-n r7.0, YOLOv6-n v3.0, YOLOv7-tiny, YOLOv8-n, YOLOv9-t, YOLOv10-n, YOLOv11-n, and YOLOv12-n, as well as improved models proposed in the field of weed detection in recent years: W-YOLOv5, YOLOv8n-CBAM-C3Ghost, LW-YOLOv8n, and RLCFE-t. By comparing with these advanced algorithms on different datasets, the system evaluates the comprehensive performance of CW-YOLO in terms of detection accuracy, model complexity, inference speed, and bounding box localization. Furthermore, to further demonstrate the model's adaptability under different computing power environments, this embodiment of the invention also compares and analyzes different size versions (n, s, m, l, x) of CW-YOLO and YOLOv11. Each version incorporates different degrees of lightweight improvement strategies, significantly improving inference efficiency while ensuring detection accuracy, making it particularly suitable for computationally resource-sensitive agricultural edge deployment scenarios. Experimental results show that CW-YOLO performs better in handling similar weed category recognition, complex background interference suppression, and occluded target detection, demonstrating its application potential and practical value in the field of intelligent agricultural detection.
[0099] Step 207: Perform ablation experiments on the self-built dataset CornWeed8;
[0100] The ablation experiments of this invention were conducted on the self-built cornfield weed detection dataset CornWeed8. The experimental baseline model was a lightweight version of YOLOv11, reduced by decreasing the network width and depth to reduce computational redundancy. The trimmed YOLOv11-n was denoted as the baseline. Based on this, different modules were introduced for combined experiments, and the results are shown in Table 1. The baseline model based on YOLOv11-n achieved good accuracy, with mAP... 0.5The mAP is 0.927, and the F1-score is 0.892. After introducing the SimAM attention mechanism, the model's mAP is... 0.75 and mAP 0.5:0.95 Both improved performance, although the F1-score decreased slightly, indicating that SimAM has a positive effect on improving feature representation capabilities. Replacing with the AC_C3k2 module resulted in a slight improvement in accuracy and a reduction in the number of parameters to 1.18M, but the overall performance did not change significantly. Introducing DySample improved the model's F1-score and mAP. 0.5 Both results showed improvements, indicating that the module helps improve feature resolution and recognition capability. Further module combination experiments demonstrated that the combination of SimAM and DySample improved mAP. 0.5:0.95 The above performs best, while the combined use of SimAM, AC_C3k2, and DySample achieves optimal performance across multiple metrics, especially in mAP. 0.5 mAP 0.75 Regarding F1-score, the complementarity and synergistic effect of each module were verified. While maintaining lightweight characteristics, the combined model significantly improved detection performance.
[0101] Step 208: Comparative experiments on the self-built dataset CornWeed8;
[0102] The proposed CW-YOLO-n algorithm is compared with several mainstream lightweight object detection algorithms on the CornWeed8 dataset, covering detection accuracy (mAP). 0.5 mAP 0.5:0.95 Key metrics such as F1 score, model complexity (parameters, FLOPs), and model size are shown in Table 2. Regarding detection accuracy, CW-YOLO-n achieves high mAP. 0.5 The mAP reached 0.938, the highest among all compared models, significantly outperforming YOLOv5-n (0.908), YOLOv6-n (0.906), and YOLOv10-n (0.917). It also showed a slight improvement (+0.002) compared to the closest comparable model, YOLOv8n-CBAM-C3Ghost (0.936), indicating stronger accuracy in target localization tasks. Further analysis of mAP... 0.5:0.95Looking at the results, CW-YOLO-n achieved a score of 0.797, only slightly lower than YOLOv12-n (0.801), but surpassing mainstream models such as YOLOv11-n (0.790), YOLOv8-n (0.775), and YOLOv7-tiny (0.761), demonstrating its good adaptability to detection accuracy under different IoU thresholds. In terms of F1-score, CW-YOLO-n achieved 0.896, tying for first place with YOLOv7-tiny and YOLOv8n-CBAM-C3Ghost, indicating that it achieved an optimal balance between precision and recall. In terms of model complexity, CW-YOLO-n has only 1.19M parameters, the fewest among all compared models, far lower than YOLOv6-n (4.63M), YOLOv7-tiny (6.03M), and YOLOv8-n (3.01M). Even compared to existing lightweight methods such as YOLOv5-n (1.77M) and YOLOv9-t (1.91M), it is significantly smaller. Regarding FLOPs, CW-YOLO-n has a computational cost of 4.1G, the lowest among all models, the same as YOLOv5-n, but its mAP is higher. 0.5 The improvement reached +0.03, mAP 0.5:0.95 The improvement of +0.074 in performance and +0.025 in F1 score demonstrates CW-YOLO-n's extremely high efficiency in utilizing computational resources. In terms of model weight size, CW-YOLO-n is only 2.82MB, saving 40%-80% of storage space compared to most lightweight models, such as YOLOv8-n (5.98MB), YOLOv11-n (5.24MB), and YOLOv9-t (15.93MB), significantly reducing storage and deployment costs while maintaining accuracy. CW-YOLO-n exhibits significant advantages across various performance metrics, especially achieving the highest mAP currently available while maintaining the minimum number of model parameters and the lowest FLOPs. 0.5 The optimal F1 score demonstrates the excellent balance between lightweight design, high precision, and high performance achieved by the proposed structure. This model has broad application prospects in resource-constrained edge computing scenarios, and is particularly suitable for practical environments such as agricultural smart terminals and mobile devices that are sensitive to storage, bandwidth, and computing power.
[0103] Step 209: Comparative experimental results on the CottonWeedDet12 dataset;
[0104] The comparative experimental results on the CottonWeedDet12 dataset are shown in Table 3. CW-YOLO-n has reached or surpassed the current best level in all major detection accuracy metrics, including mAP. 0.5 With an accuracy of 0.958, it outperforms current mainstream high-precision lightweight models such as YOLOv11-n (0.955), YOLOv7-tiny (0.953), and YOLOv8n-CBAM-C3Ghost (0.950), demonstrating its exceptional performance in localization tasks. 0.5:0.95 The accuracy score was 0.899, the highest among detection models on this dataset, slightly higher than YOLOv11-n (0.898) and significantly better than YOLOv7-tiny (0.866) and YOLOv6-n (0.860), indicating that CW-YOLO-n has good predictive performance across multiple IoU thresholds. In terms of F1-score, CW-YOLO-n reached 0.905, second only to YOLOv8-n (0.908) and higher than all other models, demonstrating its excellent balance between precision and recall. In terms of model complexity, CW-YOLO-n requires only 1.20M parameters, significantly lower than YOLOv6-n (4.63M), YOLOv7-tiny (6.05M), and YOLOv8-n (3.01M). Even compared to the more compact YOLOv5-n (1.78M) and YOLOv9-t (1.92M), it is significantly lighter. Its FLOPs are 4.1G, roughly the same as YOLOv5-n, but its mAP is higher. 0.5 Increased by +0.029, mAP 0.5:0.95 An improvement of +0.083 in accuracy and +0.017 in F1 score indicates that CW-YOLO-n achieves a better balance between accuracy and complexity.
[0105] Step 210: Compare the experimental results in the 4WEED DATASET dataset;
[0106] The comparative experimental results on the 4WEED DATASET dataset are shown in Table 4. CW-YOLO-n still exhibits excellent generalization performance under small sample conditions, with mAP... 0.5 Achieving an accuracy of 0.754, it is the most accurate model on this dataset, surpassing YOLOv7-tiny (0.747), LW-YOLOv8n (0.742), and YOLOv12-n (0.727), demonstrating its excellent ability to distinguish weed categories in situations with few samples. 0.5:0.95The F1 score is 0.420, slightly lower than YOLOv11-n and YOLOv8-n's 0.431, but significantly better than most models such as YOLOv5-n (0.380) and YOLOv9-t (0.361), demonstrating its stability in boundary regression tasks. The F1 score is 0.745, second only to YOLOv7-tiny (0.770) and LW-YOLOv8n (0.739), and significantly better than YOLOv8-n (0.721) and YOLOv11-n (0.719), indicating that the model can maintain a high balance between recall and precision even with small sample sizes. In terms of model resource overhead, CW-YOLO-n once again demonstrates its leading advantage, with only 1.19M parameters, the smallest among the comparisons on this dataset; its computational complexity remains at 4.1G, the lowest FLOPs; and its model size is only 2.80MB, the lightest deployment scheme, far smaller than larger models such as YOLOv9-t (15.94MB) and YOLOv7-tiny (11.74MB). CW-YOLO-n performs excellently on two public datasets: achieving the highest accuracy and optimal efficiency on CottonWeedDet12, and maintaining stable performance and extreme lightweight design under small sample conditions on 4WEED DATASET. This fully verifies that the proposed model structure has good adaptability, robustness, and deployment friendliness under different scenarios and sample sizes, and has broad practical application prospects, especially suitable for agricultural smart terminals, mobile devices, and other resource-constrained edge computing platforms.
[0107] Step 211: Comparative experiment of YOLOv11 and CW-YOLO on the self-built dataset CornWeed8;
[0108] Table 5 shows the comparative experimental results of CW-YOLO and YOLOv11 models with different sizes on the self-built dataset CornWeed8. The experimental results show that CW-YOLO outperforms YOLOv11 in multiple performance metrics, especially in terms of model lightweighting and inference speed. CW-YOLO maintains or surpasses the accuracy of YOLOv11 while significantly reducing the number of parameters, computational complexity, and model size. Specifically, CW-YOLO-n achieves higher mAP... 0.5 mAP 0.5:0.95CW-YOLO outperforms YOLOv11-n in both F1 score and performance, with significantly reduced parameter count and computational complexity, demonstrating its advantages in resource-constrained environments. Furthermore, in comparisons between small-to-medium-sized models (such as CW-YOLO-m and YOLOv11-m) and large models (such as CW-YOLO-l and YOLOv11-l), CW-YOLO still delivers high-accuracy detection results while reducing computational resources. Particularly in the comparison between CW-YOLO-x and YOLOv11-x, despite CW-YOLO-x having lower parameter count and FLOPs, it maintains high accuracy, demonstrating greater efficiency in practical applications. Overall, by optimizing its model structure, CW-YOLO not only improves detection performance but also provides a more practical solution in terms of real-time performance and lightweight design.
[0109] Step 212: Model Detection Performance and Visualization Analysis. Experimental results and visualization analysis show that the CW-YOLO algorithm proposed in this embodiment of the invention has higher bounding box regression accuracy and stronger confidence output in complex backgrounds, and performs better than the comparative algorithms in terms of generalization and robustness. CW-YOLO has a stronger detection capability for intertwined and partially occluded weeds in actual field scenarios, significantly reducing the false negative rate. At the same time, the model is more lightweight and has lower computational complexity, maintaining high detection accuracy while having stronger deployment adaptability. The heatmap generated by CW-YOLO further verifies that its focus on weed area features is more accurate, effectively improving the model's feature perception capability and practical application value.
[0110] In this embodiment of the invention, 12 images were selected from the test set, and the inference results are as follows: Figure 8 As shown in the figure, the analysis of the image results reveals several problems with different algorithms in object detection. These include: a) In some images, different algorithms exhibited false positives, low confidence, and inaccurate bounding box regression; b) Some images showed false positives and false negatives; c) In some images, multiple algorithms showed false positives and inaccurate bounding box regression; d) Different algorithms commonly showed false positives in some images; e) In some images, multiple algorithms exhibited false positives, false negatives, and inaccurate bounding box regression; f) Some images showed a single target being misclassified as multiple targets; g) In some images, different algorithms showed false negatives and inaccurate bounding box regression; h) Different algorithms generally showed low confidence in some images; i) Some images showed false positives and inaccurate bounding box regression across different algorithms; j) In cases where the target was occluded, a single target was incorrectly detected as multiple targets; k) Some images showed false positives and inaccurate bounding box regression, with some algorithms exhibiting significant regression bias.
[0111] Based on the visualization analysis of the inference results, it is clear that the proposed CW-YOLO-n algorithm exhibits significant advantages over other algorithms. Specifically, CW-YOLO-n excels in bounding box regression accuracy, enabling more precise target localization with higher confidence and a significantly reduced false negative rate. Furthermore, the algorithm performs exceptionally well in occluded target detection, effectively reducing false positives and false negatives, and significantly improving the robustness and accuracy of target detection. Therefore, the CW-YOLO-n algorithm demonstrates a significant improvement in inference performance in complex scenarios.
[0112] To more effectively display the regions of interest of the object detection model, this embodiment of the invention uses the Grad-CAM++ method to generate heatmaps, and then overlays predicted bounding boxes and recalibrated heatmaps on top of them. This method can intuitively reveal the regions of interest that the model focuses on when making decisions, thereby improving the interpretability of the model. In the experiment, 12 images from the test set were selected, and heatmaps for both YOLOv11 and CW-YOLO models were generated. The results are as follows. Figure 9 As shown in the comparison results, CW-YOLO has a significant advantage in heatmap generation, especially in weed target detection, where its heatmap highlights are more concentrated and clearer, with less interference from irrelevant areas. In contrast, while YOLOv11's heatmap can capture the target area, the heat distribution is more dispersed and fails to effectively concentrate on the target area, especially when dealing with complex scenes (Figures c and k). In these images, CW-YOLO can accurately generate high-response areas consistent with the contours of the weed targets, thereby improving target recognition and localization accuracy. YOLOv11, on the other hand, has deviations in the alignment of heatmap response areas, affecting the final prediction results. Therefore, CW-YOLO's optimization in feature extraction and target localization significantly improves the accuracy of target detection and enhances the focusing ability of heatmaps, showing a clear advantage, particularly in the detection of complex targets.
[0113] Table 1 shows the overall ablation experimental results of CW-YOLO-n on the CornWeed8 dataset.
[0114] Model <![CDATA[mAP 0.5 ↑]]> <![CDATA[mAP 0.75 ↑]]> <![CDATA[mAP 0.5:0.95 ↑]]> F1 score↑ Params↓ FLOPs↓ Size↓ baseline 0.917 0.813 0.777 0.873 1196608 4.1G 2.58MB +SimAM 0.93 0.84 0.794 0.884 1196608 4.1G 2.59MB +AC_C3k2 0.927 0.836 0.797 0.883 1178472 4.1G 2.75MB +DySample 0.931 0.837 0.793 0.89 1213120 4.1G 2.62MB +SimAM+AC_C3k2 0.93 0.83 0.798 0.885 1178472 4.1G 2.75MB +SimAM+DySample 0.933 0.838 0.801 0.894 1213120 4.1G 2.61MB +AC_C3k2+DySample 0.935 0.836 0.795 0.891 1194984 4.1G 2.78MB +SimAM+AC_C3k2+DySample(CW-YOLO-n) 0.938 0.843 0.797 0.896 1194984 4.1G 2.82MB
[0115] Table 2 shows the comparative experimental results on the CornWeed8 dataset.
[0116] Model <![CDATA[mAP 0.5 ↑]]> <![CDATA[mAP 0.5:0.95 ↑]]> F1 score↑ Params↓ FLOPs↓ Size↓ YOLOv5-n r7.0 0.908 0.723 0.871 1.77M 4.3G 3.67MB YOLOv6-n v3.0 0.906 0.755 0.879 4.63M 11.3G 10.01MB YOLOv7-tiny 0.933 0.761 0.897 6.03M 13.2G 11.73MB YOLOv8-n 0.922 0.775 0.893 3.01M 8.2G 5.98MB YOLOv9-t 0.914 0.784 0.866 1.91M 7.3G 15.93MB YOLOv10-n 0.917 0.775 0.884 2.71M 8.4G 5.54MB YOLOv11-n 0.932 0.790 0.892 2.59M 6.4G 5.24MB YOLOv12-n 0.933 0.801 0.889 2.52M 6.0G 5.22MB W-YOLOv5 0.920 0.758 0.882 3.27M 5.3G 6.53MB YOLOv8n-CBAM-C3Ghost 0.936 0.797 0.896 3.16M 8.3G 6.28MB LW-YOLOv8n 0.921 0.768 0.885 1.45M 5.3G 3.02MB RLCFE-t 0.916 0.783 0.865 1.36M 6.1G 11.45MB CW-YOLO-n (Ours) 0.938 0.797 0.892 1.19M 4.1G 2.82MB
[0117] Table 3 shows the comparative experimental results on the CottonWeedDet12 dataset.
[0118] Model <![CDATA[mAP 0.5 ↑]]> <![CDATA[mAP 0.5:0.95 ↑]]> F1 score↑ Params↓ FLOPs↓ Size↓ YOLOv5-n r7.0 0.929 0.816 0.888 1780153 4.3G 3.69MB YOLOv6-n v3.0 0.939 0.86 0.902 4.63M 11.4G 10.06MB YOLOv7-tiny 0.953 0.866 0.900 6.05M 13.3G 11.75MB YOLOv8-n 0.948 0.805 0.908 3.01M 8.2G 5.98MB YOLOv9-t 0.925 0.861 0.882 1.92M 7.3G 15.94MB YOLOv10-n 0.927 0.856 0.893 2.71M 8.4G 5.54MB YOLOv11-n 0.955 0.898 0.906 2.59M 6.5G 5.26MB YOLOv12-n 0.947 0.885 0.904 2.52M 6.0G 5.22MB W-YOLOv5 0.939 0.862 0.899 3.27M 5.3G 6.55MB YOLOv8n-CBAM-C3Ghost 0.95 0.884 0.894 3.16M 8.3G 6.28MB LW-YOLOv8n 0.934 0.858 0.888 1.46M 5.3G 3.03MB RLCFE-t 0.929 0.867 0.870 1.36M 6.1G 11.46MB CW-YOLO-n (Ours) 0.958 0.899 0.905 1.2M 4.1G 2.8MB
[0119] Table 4 shows the comparative experimental results in dataset 4WEED DATASET.
[0120] Model <![CDATA[mAP 0.5 ↑]]> <![CDATA[mAP 0.5:0.95 ↑]]> F1 score↑ Params↓ FLOPs↓ Size↓ YOLOv5-n r7.0 0.715 0.38 0.712 1.77M 4.2G 3.74MB YOLOv6-n v3.0 0.713 0.425 0.716 4.63M 11.3G 10.0MB YOLOv7-tiny 0.747 0.42 0.770 6.02M 13.2G 11.74MB YOLOv8-n 0.734 0.431 0.721 3.01M 8.2G 5.98MB YOLOv9-t 0.615 0.361 0.623 1.91M 7.3G 15.94MB YOLOv10-n 0.605 0.373 0.616 2.71M 8.4G 5.51MB YOLOv11-n 0.705 0.431 0.719 2.59M 6.4G 5.27MB YOLOv12-n 0.727 0.428 0.711 2.52M 6.0G 5.23MB W-YOLOv5 0.709 0.406 0.716 3.27M 5.3G 6.55MB YOLOv8n-CBAM-C3Ghost 0.701 0.404 0.706 3.16M 8.3G 6.29MB LW-YOLOv8n 0.742 0.428 0.739 1.45M 5.3G 3.04MB RLCFE-t 0.715 0.41 0.719 1.36M 6.1G 11.46MB CW-YOLO-n (Ours) 0.754 0.42 0.745 1.19M 4.1G 2.8MB
[0121] Table 5 shows the experimental results comparing YOLOv11 and CW-YOLO models of different sizes on the CornWeed8 dataset.
[0122] Model <![CDATA[mAP 0.5 ↑]]> <![CDATA[mAP 0.5:0.95 ↑]]> F1-score↑ Params↓ FLOPs↓ Size↓ FPS↑ YOLOv11-n 0.932 0.79 0.892 2591400 6.4G 5.24MB 98.75 CW-YOLO-n 0.938 0.797 0.896 1194984 4.1G 2.82MB 102.33 YOLOv11-s 0.93 0.807 0.895 9430888 21.6G 18.32MB 95.6 CW-YOLO-s 0.932 0.804 0.898 3927092 12.1G 8.02MB 100.12 YOLOv11-m 0.939 0.821 0.913 20059176 68.2G 38.68MB 93.23 CW-YOLO-m 0.942 0.822 0.919 13996336 40.7G 27.42MB 92.55 YOLOv11-l 0.945 0.831 0.907 25316648 87.3G 48.86MB 88.3 CW-YOLO-l 0.945 0.83 0.915 17682084 51.4G 34.49MB 93.56 YOLOv11-x 0.947 0.838 0.907 56883016 195.5G 109.13MB 86.1 CW-YOLO-x 0.941 0.818 0.904 31313112 90.5G 60.49MB 88.27
[0123] This invention utilizes a self-built cornfield weed dataset, CornWeed8, which covers various field conditions including different time periods, light levels, and angles throughout the entire corn growth cycle. Images were collected, deduplicated, and manually labeled. LabelImg and other tools were used to generate label files containing category and bounding box information. The dataset contains 3970 images, covering eight typical weeds: Amaranthus retroflexus, lambsquarters, Solanum nigrum, Camelthorn, Portulaca oleracea, Convolvulia pulveratum, Setaria viridis, and Amaranthus chinensis. It can be used for training, validation, and evaluation of algorithms in the field of weed detection research. The publicly available address is: https: / / openxlab.org.cn / datasets / cvnet / CornWeed8.
[0124] Example 4
[0125] A cornfield weed detection device based on an improved YOLOv11 includes a processor and a memory. The memory stores program instructions, and the processor invokes the program instructions stored in the memory to cause the device to execute the following method steps in Embodiment 1:
[0126] Collect images of weeds, label them using the LabelImg tool, and construct a dataset with multiple types of weeds.
[0127] Based on the weed dataset, the structure of the YOLOv11 object detection network is optimized to obtain the first optimized network; the parameterless spatial attention mechanism SimAM module is integrated into the first optimized network to obtain the second optimized network.
[0128] Based on the second optimized network, the AC_C3k2 module is designed to obtain the third optimized network and construct the feature enhancement network;
[0129] Based on the third optimized network, the DySample upsampling operator is introduced to obtain the fourth optimized network; the fourth optimized network is used as the final lightweight weed detection network, and weeds in cornfields are detected based on the lightweight weed detection network.
[0130] The structural optimization of the YOLOv11 target detection network involves compressing the network's width and depth and removing redundant modules.
[0131] The SimAM module, which integrates the parameterless spatial attention mechanism in the first optimized network, is as follows:
[0132] For each feature map, a single channel is processed, and the mean and variance of the response of all pixels in that channel are calculated. Based on this, the response difference value of each pixel relative to the whole is calculated, and this difference value is used as its significance index. The significance index is normalized using an activation function and used as a spatial attention weight. This weight is then multiplied by the original feature map to increase the extraction of useful information, thereby enhancing key regions and suppressing invalid backgrounds.
[0133] The AC_C3k2 module is as follows:
[0134] The input weed features are fed into the CAS part for additive self-attention operation. The output global weighted feature map is then fed into the CGLU module. The CGLU module calculates the main features and the gating signal through two convolutional branches, and uses the gating mechanism to fuse the feature map output from the CAS part and the feature map processed by the CGLU module, finally generating the enhanced feature map.
[0135] The DySample upsampling operator is introduced as follows:
[0136] Based on the local information of the input feature map, a sampling offset is dynamically generated. The sampling offset is used to determine the sampling position of each pixel during the upsampling process. Using grid sampling technology, the low-resolution feature map is resampled according to the generated sampling position, thereby recovering the high-resolution feature map.
[0137] It should be noted that the device descriptions in the above embodiments correspond to the method descriptions in the embodiments, and the embodiments of the present invention will not be repeated here.
[0138] The execution entities of the aforementioned processor and memory can be devices with computing functions such as computers, microcontrollers, and single-chip microcomputers. In specific implementations, the embodiments of the present invention do not limit the execution entities and can select them according to the needs of actual applications.
[0139] Data signals are transmitted between the memory and the processor via a bus, which will not be elaborated upon in this embodiment of the invention.
[0140] Based on the same inventive concept, embodiments of the present invention also provide a computer-readable storage medium, the storage medium including a stored program, which, when the program is running, controls the device where the storage medium is located to execute the method steps in the above embodiments.
[0141] The computer-readable storage medium includes, but is not limited to, flash memory, hard disk, solid-state drive, etc.
[0142] It should be noted that the description of the readable storage medium in the above embodiments corresponds to the description of the method in the embodiments, and the embodiments of the present invention will not be repeated here.
[0143] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of the present invention is generated.
[0144] A computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. Computer instructions can be stored in or transmitted through a computer-readable storage medium. A computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium can be magnetic or semiconductor, etc.
[0145] Unless otherwise specified, the model numbers of the various devices in this embodiment of the invention are not limited, and any device that can perform the above functions is acceptable.
[0146] Those skilled in the art will understand that the accompanying drawings are merely schematic diagrams of a preferred embodiment, and the sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0147] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for detecting weeds in maize fields based on an improved YOLOv11, characterized in that, The method includes: Collect images of weeds, label them using the LabelImg tool, and construct a dataset with multiple types of weeds. Based on the weed dataset, the structure of the YOLOv11 object detection network is optimized to obtain the first optimized network; the parameterless spatial attention mechanism SimAM module is integrated into the first optimized network to obtain the second optimized network. Based on the second optimized network, the AC_C3k2 module is designed to obtain the third optimized network and construct the feature enhancement network; Based on the third optimized network, the DySample upsampling operator is introduced to obtain the fourth optimized network; the fourth optimized network is used as the final lightweight weed detection network, and weeds in cornfields are detected based on the lightweight weed detection network.
2. The method for detecting weeds in corn fields based on an improved YOLOv11 according to claim 1, characterized in that, The structural optimization of the YOLOv11 target detection network involves compressing the network's width and depth and removing redundant modules.
3. The method for detecting weeds in corn fields based on an improved YOLOv11 according to claim 1, characterized in that, The SimAM module, which integrates the parameterless spatial attention mechanism in the first optimized network, is as follows: For each feature map, a single channel is processed, and the mean and variance of the response of all pixels in that channel are calculated. Based on this, the response difference value of each pixel relative to the whole is calculated, and this difference value is used as its significance index. The significance index is normalized using an activation function and used as a spatial attention weight. This weight is then multiplied by the original feature map to enhance weed feature extraction, thereby enhancing key regions and suppressing invalid backgrounds.
4. The method for detecting weeds in corn fields based on an improved YOLOv11 according to claim 1, characterized in that, The AC_C3k2 module is: The input weed features are fed into the CAS part for additive self-attention operation. The output global weighted feature map is then fed into the CGLU module. The CGLU module calculates the main features and the gating signal through two convolutional branches, and uses the gating mechanism to fuse the feature map output from the CAS part and the feature map processed by the CGLU module, finally generating the enhanced feature map.
5. The method for detecting weeds in corn fields based on an improved YOLOv11 according to claim 1, characterized in that, The introduced DySample upsampling operator is: Based on the local information of the input feature map, a sampling offset is dynamically generated. The sampling offset is used to determine the sampling position of each pixel during the upsampling process. Using grid sampling technology, the low-resolution feature map is resampled according to the generated sampling position, thereby recovering the high-resolution feature map.
6. A weed detection device for corn fields based on an improved YOLOv11, characterized in that, The device includes a processor and a memory, the memory storing program instructions, the processor invoking the program instructions stored in the memory to cause the device to perform the method according to any one of claims 1-5.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, the computer program including program instructions that, when executed by a processor, cause the processor to perform the method described in any one of claims 1-5.
Citation Information
Cited By
Rice bacterial leaf blight disease resistance screening method based on unmanned aerial vehicle and deep learning
CN121304665A
Power quality disturbance identification method based on constraint network and priori knowledge
CN121561372A