Method and equipment for detecting weeds in cotton field in complex environment
By randomly expanding the weed data set in cotton field and enhancing Mixup, and structural optimization and feature fusion of YOLOV8 model, the error detection and missed detection problems of weed detection in complex field environments are solved, and higher detection accuracy and reliability.
Patent Information
- Application Number
- CN202411438727.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-15
- Publication Date
- 2025-02-14
AI Technical Summary
The existing target detection algorithms have many problems of false detection and missed detection in complex field environments, especially in the detection of weeds with many types, large size differences, dense distribution, and small target weeds.
The second training set is generated by dividing the cotton field weed data set into a training set, a validation set and a test set, and randomly augmenting the training set and Mixup enhancement. Then, the BottleNeck structure in the initial YOLOV8 model is replaced with the DWR module, and a hierarchical feature fusion module is added to the tail of the backbone network to form the first model. Add a small object detection head to the head of the first model, and introduce an adaptive spatial feature fusion mechanism to obtain the model to be trained. The second training set is input to the model to be trained for training, and a target weed detection model is generated.
It significantly improves the detection accuracy and reliability of the model in complex field environments, reduces missed and missed detection in dense weed scenarios, and improves the detection ability of small-target weeds.
Smart Images

Figure CN119445364A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of intelligent agricultural image detection, and in particular to a method and device for detecting weeds in cotton fields under complex environments. Background Art
[0002] In agricultural production, the growth of weeds poses a serious threat to the yield and quality of crops, especially in cash crop planting areas such as cotton fields, where weed competition can significantly reduce cotton yields. Traditional weed control methods mainly rely on manual or chemical means, which are inefficient and prone to environmental pollution. With the development of deep learning and computer vision technology, automated weed detection and processing technology has gradually become an important direction for the development of intelligent agriculture. However, when facing complex field environments, existing target detection algorithms still have many problems of false detection and missed detection, especially in the detection of weeds with many species, large size differences, dense distribution, and small target weeds. Therefore, how to improve the accuracy of cotton field weed target detection in complex environments has become a technical problem that needs to be solved urgently. Summary of the invention
[0003] The main purpose of this application is to provide a method and device for detecting weeds in cotton fields under complex environments, aiming to solve the technical problem of how to improve the accuracy of weed target detection in cotton fields under complex environments.
[0004] To achieve the above objectives, the present application provides a method for detecting weeds in cotton fields under complex environments, the method comprising the following steps:
[0005] The cotton field weed dataset is divided into the first training set, the validation set and the test set;
[0006] Performing random expansion and Mixup enhancement on the first training set to obtain a second training set;
[0007] The BottleNeck structure in the initial YOLOV8 model is replaced with the DWR module, and a hierarchical feature fusion module is added to the tail of the backbone network of the initial YOLOV8 model to obtain a first model;
[0008] Adding a small target detection head to the head of the first model and adding an adaptive spatial feature fusion mechanism to obtain a model to be trained;
[0009] Inputting the second training set into the model to be trained to obtain a target weed detection model;
[0010] Weed species information and weed distribution information are determined according to the target weed detection model and the image to be detected.
[0011] In one embodiment, before the step of dividing the cotton field weed dataset into a first training set, a validation set, and a test set, the method further includes:
[0012] Get a weed image set;
[0013] Based on the VGG image annotator, drawing a bounding box for each image in the weed image set;
[0014] Based on the bounding box drawing result, the weed image set is screened to obtain the cotton field weed dataset.
[0015] In one embodiment, the step of adding a small target detection head to the head of the first model and adding an adaptive spatial feature fusion mechanism to obtain the model to be trained includes:
[0016] Adding the small target detection head to the head of the first model to obtain a second model;
[0017] Replace the NMS method in the second model with the Soft-NMS method;
[0018] An adaptive spatial feature fusion mechanism is added to the replaced second model to obtain the model to be trained.
[0019] In one embodiment, before the step of adding the small target detection head to the head of the first model to obtain the second model, the step further includes:
[0020] Perform feature extraction on the first C2f module of the backbone network to obtain the initial feature map;
[0021] Upsampling the initial feature map to a preset size to obtain a sampled feature map;
[0022] The initial feature map is connected with the sampled feature map to obtain a small target detection feature map, which serves as the final input of the small target detection head.
[0023] In one embodiment, the step of determining weed species information and weed distribution information based on the target weed detection model and the image to be detected includes:
[0024] Based on the Soft-NMS method, the validation set and the test set, verifying the target weed detection model;
[0025] The image to be detected is input into the verified target weed detection model to obtain the weed species information and the weed distribution information.
[0026] In one embodiment, the step of performing random expansion and Mixup enhancement on the first training set to obtain the second training set includes:
[0027] Based on preset expansion parameters, performing random expansion processing on each image in the first training set to obtain an expanded data set, wherein the random expansion processing includes random cropping, scaling, rotation, and color jittering;
[0028] Performing Mixup data enhancement processing on the expanded data set to obtain an enhanced data set;
[0029] The first training set, the expanded data set and the enhanced data set are combined to obtain the second training set.
[0030] In addition, to achieve the above purpose, the present application also proposes a cotton field weed detection device under complex environment, the cotton field weed detection device under complex environment comprises:
[0031] A partitioning module, used for partitioning the cotton field weed data set into a first training set, a validation set and a test set;
[0032] An expansion and enhancement module, used for performing random expansion and Mixup enhancement on the first training set to obtain a second training set;
[0033] A structure replacement module, used to replace the BottleNeck structure in the initial YOLOV8 model with a DWR module, and add a hierarchical feature fusion module to the tail of the backbone network of the initial YOLOV8 model to obtain a first model;
[0034] A mechanism adding module, used to add a small target detection head to the head of the first model, and add an adaptive spatial feature fusion mechanism to obtain a model to be trained;
[0035] A training module, used for inputting the second training set into the model to be trained to obtain a target weed detection model;
[0036] The target module is used to determine the weed species information and the weed distribution information according to the target weed detection model and the image to be detected.
[0037] In addition, to achieve the above-mentioned purpose, the present application also proposes a cotton field weed detection device under a complex environment, the device comprising: a memory, a processor, and a cotton field weed detection program under a complex environment stored on the memory and executable on the processor, the cotton field weed detection program under a complex environment being configured to implement the steps of the cotton field weed detection method under a complex environment as described above.
[0038] In addition, to achieve the above objectives, the present application also proposes a storage medium, on which is stored a cotton field weed detection program under a complex environment. When the cotton field weed detection program under a complex environment is executed by a processor, the steps of the cotton field weed detection method under a complex environment as described above are implemented.
[0039] In addition, to achieve the above-mentioned purpose, the present application also proposes a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps of the cotton field weed detection method under a complex environment as described above are implemented.
[0040] The present application divides a cotton field weed data set into a first training set, a validation set and a test set; performs random expansion and Mixup enhancement on the first training set to obtain a second training set; replaces the BottleNeck structure in the initial YOLOV8 model with a DWR module, and adds a hierarchical feature fusion module to the tail of the backbone network of the initial YOLOV8 model to obtain a first model; adds a small target detection head to the head of the first model, and adds an adaptive spatial feature fusion mechanism to obtain a model to be trained; inputs the second training set into the model to be trained to obtain a target weed detection model; and determines the weed species information and the weed distribution information according to the target weed detection model and the image to be detected. This application significantly increases the diversity of training data and improves the generalization ability of the model by randomly expanding and Mixup-enhancing the cotton field weed dataset; at the same time, the BottleNeck structure in the initial YOLOv8 model is replaced with the DWR module, and a hierarchical feature fusion module is added to the tail of the backbone network, so that the model has stronger multi-scale feature extraction capabilities; in addition, the added small target detection head and adaptive spatial feature fusion mechanism further enhance the model's detection ability for small target weeds, reducing missed detections and false detections in dense weed scenes. Ultimately, the optimized model can achieve higher detection accuracy and reliability in complex field environments, providing precise technical support for intelligent weed control. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 This is a flow chart of the first embodiment of the cotton field weed detection method under a complex environment of the present application;
[0042] Figure 2 This is a schematic diagram of a sub-flow in the second embodiment of the cotton field weed detection method under a complex environment of the present application;
[0043] Figure 3 This is a schematic diagram of a sub-flow in the third embodiment of the cotton field weed detection method under a complex environment of the present application;
[0044] Figure 4This is a schematic diagram of the improved YOLOv8 model structure in an embodiment of a method for detecting weeds in a cotton field under a complex environment of this application;
[0045] Figure 5 This is a schematic diagram of the module structure of the cotton field weed detection device under a complex environment according to an embodiment of the present application;
[0046] Figure 6 Schematic diagram of the device structure of the hardware operating environment involved in the cotton field weed detection method under a complex environment in an embodiment of the present application.
[0047] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0048] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0049] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0050] It should be noted that in agricultural production, the growth of weeds poses a serious threat to the yield and quality of crops, especially in economic crop planting areas such as cotton fields, where the competition of weeds will significantly reduce the yield of cotton. Traditional weed control methods mainly rely on manual or chemical means, which are inefficient and easy to cause environmental pollution. With the development of deep learning and computer vision technology, automated weed detection and processing technology has gradually become an important direction for the development of intelligent agriculture. However, when facing complex field environments, existing target detection algorithms still have many problems of false detection and missed detection, especially in the detection of weeds with many types, large size differences, dense distribution, and small target weeds. Therefore, how to improve the accuracy of cotton field weed target detection in complex environments has become a technical problem that needs to be solved urgently.
[0051] The main solution of the present application is: the present application divides the cotton field weed data set into a first training set, a validation set and a test set; randomly expands and Mixup enhances the first training set to obtain a second training set; replaces the BottleNeck structure in the initial YOLOV8 model with a DWR module, and adds a hierarchical feature fusion module to the tail of the backbone network of the initial YOLOV8 model to obtain a first model; adds a small target detection head to the head of the first model, and adds an adaptive spatial feature fusion mechanism to obtain a model to be trained; inputs the second training set into the model to be trained for training to obtain a target weed detection model; determines the weed species information and weed distribution information according to the target weed detection model and the image to be detected.
[0052] This application significantly increases the diversity of training data and improves the generalization ability of the model by randomly expanding and Mixup-enhancing the cotton field weed dataset; at the same time, the BottleNeck structure in the initial YOLOv8 model is replaced with the DWR module, and a hierarchical feature fusion module is added to the tail of the backbone network, so that the model has stronger multi-scale feature extraction capabilities; in addition, the added small target detection head and adaptive spatial feature fusion mechanism further enhance the model's detection ability for small target weeds, reducing missed detections and false detections in dense weed scenes. Ultimately, the optimized model can achieve higher detection accuracy and reliability in complex field environments, providing precise technical support for intelligent weed control.
[0053] It should be noted that the execution subject of the method of this embodiment can be a computing service device with data processing, network communication and program running functions, or it can be a cotton field weed detection device under the above complex environment with the same or similar functions. This embodiment and the following embodiments will be described by taking a computer device as an example.
[0054] Based on this, the first embodiment of the cotton field weed detection method under complex environment of this application is proposed, please refer to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the cotton field weed detection method under complex environment of the present application.
[0055] In this embodiment, the cotton field weed detection method under the complex environment includes the following steps:
[0056] S1: Divide the cotton field weed dataset into the first training set, validation set, and test set;
[0057] It should be noted that the cotton field weed dataset is a data set consisting of images containing weeds taken in a cotton field environment. This dataset is usually annotated and contains the type and location of the weeds in each image (usually expressed in the form of a bounding box). These data are used to train, validate, and test machine learning models to achieve automated weed detection. The training set is the main dataset for model learning. The model adjusts its internal parameters by analyzing the data in the training set so that it can make correct predictions when similar unseen data is input. The validation set is independently divided from the original dataset and is used to evaluate the performance of the model during the model training process. Through the validation set, developers can monitor in real time whether the model is overfitting or underfitting, and adjust the model's hyperparameters if necessary. The test set is a dataset used to perform a final performance evaluation of the model after the model training is completed. It is used to simulate the performance of the model in actual applications and ensure that the model still has good predictive ability on data other than the training set and validation set.
[0058] Specifically, the computer device first receives a complete cotton field weed dataset, which contains a large number of images, each of which is labeled with different types of weeds. Then, the computer device divides the dataset into three subsets according to a preset ratio (usually 70% for training, 15% for verification, and 15% for testing): the first training set, the verification set, and the test set. The computer device allocates 70% of the images in the original dataset to the training set. This part of the data will be used for the preliminary training of the model, through which the weights and parameters of the model are adjusted.
[0059] Further, the computer device allocates 15% of the images to the validation set. This part of the data is used to evaluate the intermediate performance of the model during the model training process. Through the feedback of the validation set, the developer can detect whether the model has overfitting or underfitting problems and make timely adjustments, such as changing the learning rate, adding regularization measures, etc. The computer device allocates the remaining 15% of the data to the test set. The data in the test set does not participate in the training process of the model and is only used to evaluate the final performance of the model after the training is completed. This step ensures that the model can maintain good predictive ability on new data in the real world.
[0060] By dividing the dataset into training set, validation set and test set, it can be ensured that the model can not only learn the rules in the data, but also avoid overfitting. The validation set and test set provide independent data sources to ensure that the model can also show good predictive ability on unseen data, thereby improving the generalization ability of the model. The use of the validation set allows developers to monitor the performance of the model during the training process and adjust the training strategy in time to avoid overfitting or underfitting. This real-time feedback mechanism helps to develop more robust and efficient models. The final evaluation of the model through the test set can objectively measure the performance of the model in real application scenarios. This step ensures that the model can effectively detect and classify weeds in actual operation, thereby improving the automation level of weed management in cotton fields. In summary, step S1 provides a solid foundation for the efficient training, verification and evaluation of subsequent models by reasonably dividing the dataset, thereby improving the overall performance and application value of the model.
[0061] S2: performing random expansion and Mixup enhancement on the first training set to obtain a second training set;
[0062] It should be noted that random expansion is a method of data enhancement, which generates diverse training samples by making random geometric or color changes to images, such as random cropping, rotation, scaling, flipping, color jittering, etc. This method helps to improve the robustness of the model, enabling it to better cope with images taken under different conditions. Mixup is a data enhancement technique that generates a new training sample by linearly mixing two images and their corresponding labels in a certain proportion. Specifically, Mixup weights the pixel values of the two images in a certain proportion and also weights the labels in a corresponding proportion. This method enables the model to better learn the features between different categories and reduce overfitting.
[0063] Specifically, the computer device first performs a series of random expansion operations on the images in the first training set. The expansion methods include but are not limited to random cropping, rotation, scaling, flipping and color jittering. These operations randomly transform the original images so that each image may generate multiple different versions of images, thereby increasing the diversity of training samples. After random expansion, the computer device further applies Mixup enhancement technology to the expanded images. The computer device randomly selects two expanded images, and performs weighted averaging of the two images and their corresponding labels according to a predetermined Mixup coefficient to generate a new composite image and a corresponding mixed label. This processing method helps the model learn more complex feature interactions and improves the ability to classify different types of weeds.
[0064] Furthermore, after the above random expansion and Mixup enhancement processing, all the generated new images and corresponding labels are integrated into a new training set, namely the second training set. This training set contains more diverse samples than the initial training set, which helps the model to be exposed to more variant data during training, thereby improving the generalization ability of the model.
[0065] Through random expansion operations, each image in the original training set may generate multiple different versions, which greatly improves the diversity of the training data set. In this way, the model can learn richer features during training, reduce the model's dependence on specific samples, and thus improve the generalization ability of the model. Mixup enhancement technology generates more complex training samples by mixing different images and labels, so that the model can better understand and distinguish the features between different categories. This enhancement method not only helps the model cope with mixed or transitional scenes, but also reduces the risk of model overfitting and improves the model's prediction ability for unseen data. Random expansion and Mixup enhancement increase the diversity and complexity of the data set, so that the model is exposed to more changing samples during training, thereby reducing the risk of the model overfitting the training set. This makes the model more robust on the validation set and test set, and further improves the reliability of the model in practical applications. In summary, by randomly expanding and Mixup enhancing the first training set, the second training set generated effectively improves the generalization ability and robustness of the model, provides a richer and more diverse data basis for subsequent model training, and thus improves the overall performance of the weed detection model in complex environments.
[0066] S3: Replace the BottleNeck structure in the initial YOLOV8 model with the DWR module, and add a hierarchical feature fusion module to the tail of the backbone network of the initial YOLOV8 model to obtain the first model;
[0067] It should be noted that YOLOv8 is a version of the YOLO (You Only Look Once) series, which is a deep learning model for real-time target detection. YOLOv8 inherits the fast and accurate detection characteristics of the YOLO series, and further optimizes the model structure and performance. The initial YOLOv8 model refers to the original model structure that has not been improved. The BottleNeck structure is a common convolutional neural network module, which is mainly used to reduce the number of network parameters and calculations while retaining effective features. It usually consists of a 1x1 convolution layer (for dimensionality reduction), a 3x3 convolution layer (for feature extraction), and another 1x1 convolution layer (for dimension recovery). In YOLOv8, the BottleNeck structure is used to improve the computational efficiency and feature expression ability of the network. The DWR (Dilated Wider Residual) module is an improved convolution module that uses multi-branch dilated convolution to extract multi-scale features. The DWR module can better capture information of different scales by extending the convolution kernel and multi-branch structure, thereby enhancing the model's ability to detect targets, especially in multi-scale target detection in complex backgrounds. The hierarchical feature fusion module is a module used to fuse features from different levels in the network. It enhances the model's perception of multi-scale contextual information by combining feature maps from different network layers. This fusion can help the model better understand objects of different scales in the image and improve the overall detection performance.
[0068] Specifically, the computer device first identifies the BottleNeck structure in the initial YOLOv8 model and replaces it with the DWR module. The DWR module can capture multi-scale feature information in the image through a multi-branch extended convolution method. Specifically, the DWR module replaces the standard 3x3 convolution with multiple convolution kernels with different expansion rates, thereby expanding the receptive field, allowing the model to focus on details in the image and a wider range of contextual information at the same time. After completing the replacement of the DWR module, the computer device adds a hierarchical feature fusion module to the tail of the backbone network of the initial YOLOv8 model. The module extracts feature maps from different levels in the network and fuses these feature maps to enhance the multi-scale feature expression capability of the model. In this way, the model can better detect targets of various scales, whether large or small weeds, and can achieve high-precision detection.
[0069] Furthermore, after the above structural optimization, the computer device finally obtains an improved YOLOv8 model, referred to as the first model. Compared with the initial YOLOv8 model, the first model has significantly improved multi-scale feature extraction and target detection capabilities, especially in scenes with complex backgrounds and targets of different scales.
[0070] By replacing the BottleNeck structure with the DWR module, the model can better extract multi-scale features. The multi-branch dilated convolution design of the DWR module enables the model to simultaneously focus on a wide range of contextual information and image details in the face of complex backgrounds, thereby improving the performance of the model in multi-scale target detection. After adding the hierarchical feature fusion module, the model can better integrate feature information from different network layers. This feature fusion enhances the model's perception of targets of different scales, making the model more accurate in detecting weed targets of different sizes, thereby reducing missed detections and false detections. The first model significantly improves the robustness of the model in complex environments through structural optimization and feature fusion. Whether under variable field lighting conditions or when there are many types of weeds of different sizes, the model can maintain efficient detection capabilities and is more adaptable. In summary, by replacing the BottleNeck structure with the DWR module and adding the hierarchical feature fusion module at the end of the backbone network, the first model obtained significantly enhances the multi-scale feature extraction capability and detection accuracy of the YOLOv8 model, making it perform better in weed detection tasks in complex environments.
[0071] S4: Add a small target detection head to the head of the first model, and add an adaptive spatial feature fusion mechanism to obtain a model to be trained.
[0072] Needless to say, in the deep learning object detection model, the head refers to the last few layers of the network, which is responsible for outputting the final detection results (such as bounding box position, object category, etc.). In the YOLOv8 model, the head usually includes multiple detection layers, which process feature maps of different scales respectively for detecting objects of different sizes. The small object detection head is a network module specially designed to detect small-sized objects in images. By adding a small object detection head, the model can better handle the detection task of small objects and avoid missed detection or inaccurate detection. The adaptive spatial feature fusion mechanism is a technology for dynamic weighted fusion between multi-scale features. ASFF can adaptively adjust the weights of feature maps of different scales in the final detection according to their importance, thereby reducing the conflicts generated in the multi-scale feature fusion process and improving the detection accuracy.
[0073] Specifically, the computer device adds a small target detection head to the head of the first model. This small target detection head is specially designed for processing small-sized targets (such as small-volume weeds) in images. By extracting and processing high-resolution feature maps from shallow networks, the small target detection head can detect small-sized targets more accurately. On the basis of the small target detection head, the computer device further adds an adaptive spatial feature fusion mechanism (ASFF). The ASFF mechanism adaptively weights feature maps of different scales and fuses them into a unified feature map. The purpose of this is to reduce conflicting information in the process of multi-scale feature fusion and ensure that features of different scales can work together when detecting small targets, thereby improving the accuracy and reliability of detection. After the above improvements, the computer device generates a new model, namely the model to be trained. The model to be trained inherits the basic structure of the first model, and further enhances the detection capability and overall detection performance of small targets by adding the small target detection head and the ASFF mechanism.
[0074] By adding a small target detection head to the head, the model can detect small-sized targets in the image more sensitively and avoid missing small targets. This is particularly important for tasks such as detecting small-volume weeds, because these targets are often easily overlooked in the image. By introducing the adaptive spatial feature fusion mechanism (ASFF), the model can dynamically adjust the weights of feature maps of different scales in the detection process and reduce conflicting information in the feature fusion process. This enables the model to better integrate multi-scale information when dealing with targets of different sizes and improve the overall accuracy of detection. By adding a small target detection head and the ASFF mechanism, the model to be trained shows stronger robustness and adaptability when facing multiple types and multi-scale targets in complex scenes. Whether detecting large-sized targets or small-sized weeds, the model can maintain a high detection accuracy. In summary, by adding a small target detection head to the head of the first model and introducing the adaptive spatial feature fusion mechanism, the generated model to be trained shows significant advantages in dealing with small target detection and multi-scale target fusion, greatly improving the detection ability and accuracy of the model in complex field environments.
[0075] S5: inputting the second training set into the model to be trained to obtain a target weed detection model;
[0076] It should be noted that the second training set is a training data set after data enhancement, including diversified samples generated by random expansion and Mixup enhancement. This data set contains more sample variants than the initial training set, aiming to improve the generalization ability of the model. The model to be trained is the YOLOv8 model after structural optimization, including improvements such as adding a small target detection head and an adaptive spatial feature fusion mechanism. This model has not been trained yet, so it needs to be trained with the second training set to optimize its parameters and improve detection performance. The target weed detection model is the final model after training, which can be used to detect and identify weeds in practical applications. During the training process, the model learned various features in the second training set and optimized the weights of the model to achieve high-precision weed detection in practical applications.
[0077] Specifically, the computer device first loads the second training set into the memory, and prepares to input these enhanced training samples into the model to be trained. The second training set includes image data and corresponding labels that have been randomly expanded and enhanced by Mixup. These data sets have greater diversity and complexity through expansion and enhancement processing.
[0078] Further, the model to be trained accepts the second training set as input and starts the training process. The training process includes forward propagation and back propagation: Forward propagation: The computer device inputs each batch of training images into the model to be trained, and the model processes the input image and outputs the prediction result (such as the bounding box and the category label); Loss calculation: The computer device calculates the difference between the prediction result and the true label, that is, the loss function value. The loss function usually measures the prediction error of the model. Common loss functions include cross entropy loss and regression loss; Back propagation and weight update: The computer device calculates the gradient of the loss function relative to the model parameters through the back propagation algorithm, and updates the parameters (weights) of the model according to these gradients. This process is repeated until the loss function of the model converges to a lower value or reaches a preset number of training times. After multiple rounds of iterative training, the weight of the model to be trained is optimized, and the computer device finally generates a target weed detection model. The model can detect and classify the input weed images with high accuracy in practical applications, and determine the types and distribution locations of weeds.
[0079] By using the second training set that has been randomly expanded and enhanced by Mixup for training, the model can be exposed to more sample variants and complex scenes, thereby improving the generalization ability of the model and making it more stable and accurate when facing unseen data. During the training process, the model continuously updates the weights through forward propagation and back propagation iterations to gradually reduce the prediction error. Through this process, the detection accuracy of the model is significantly improved, and it can more accurately identify and locate weed targets in the image. The target weed detection model finally generated, after optimized structure and training with enhanced data, has the ability to accurately detect weeds in complex field environments. The model can not only identify a variety of weeds, but also provide reliable detection results in practical applications, providing technical support for intelligent agricultural management. In summary, the second training set is input into the model to be trained for training. After multiple rounds of iterative optimization, a target weed detection model with high accuracy and robustness is finally obtained, which provides a stable and effective solution for the actual weed detection task.
[0080] S6: Determine weed species information and weed distribution information according to the target weed detection model and the image to be detected.
[0081] It should be noted that the target weed detection model is a trained deep learning model specifically used to identify and detect weeds in images. The model has optimized its parameters through the second training set and can perform efficient weed detection on the input images in practical applications. The image to be detected refers to the image to be input into the target weed detection model for analysis. These images are usually taken in cotton fields or other farmland environments and contain various possible weeds and crops. The image to be detected is the input data of the detection process. The weed species refers to the category of specific weeds identified by the target weed detection model in the image to be detected. The model determines the weed species corresponding to each target area in the image, such as a specific type of weed. The weed distribution information refers to the spatial location and coverage of different weeds in the image to be detected. The distribution information is usually represented in the form of a bounding box or mask, which identifies the exact location and area of each weed in the image.
[0082] Specifically, the computer device inputs the image to be detected into the target weed detection model. The image to be detected may contain different types of weeds distributed in various areas of the image. The goal is to identify the types and locations of these weeds through the model. The target weed detection model performs forward propagation on the input image and processes the image layer by layer using previously trained weights and parameters. The model will identify the target areas in the image, predict the categories of these areas (i.e., weed types), and generate corresponding bounding boxes or masks to indicate the distribution location of the weeds. The output of the model includes two parts: one is the predicted label of the weed type, and the other is the distribution information of the weeds (such as the coordinates and area of the bounding box).
[0083] Furthermore, the computer device determines the type of each weed detected in the image based on the output of the model. By analyzing the bounding box or mask generated by the model, the device can also determine the specific distribution of each weed in the image. Finally, the computer device organizes these detection results into an easy-to-understand format, which may include a list of weed types, the location coordinates of each weed, and its coverage area.
[0084] Through the analysis of the target weed detection model, the equipment can accurately identify different weed species in the image to be detected. This process effectively reduces the time and error of manual identification and improves the efficiency of weed management. The determination of weed distribution information enables farm managers to accurately understand the spatial distribution of weeds in the field. This helps to formulate accurate weeding plans and avoid excessive or insufficient weed treatment, thereby improving weed control effects and reducing the use of chemical agents. By combining weed species and distribution information, farm managers can better understand the situation of weeds in the field and make smarter decisions. This not only improves the efficiency of weed control, but also helps to reduce costs and improve the overall benefits of agricultural production. In summary, through the analysis of the image to be detected by the target weed detection model, the computer equipment can accurately determine the type and distribution information of weeds. This process effectively improves the accuracy and efficiency of weed management and provides strong technical support for agricultural production.
[0085] This embodiment divides the cotton field weed data set into a first training set, a validation set and a test set; performs random expansion and Mixup enhancement on the first training set to obtain a second training set; replaces the BottleNeck structure in the initial YOLOV8 model with a DWR module, and adds a hierarchical feature fusion module to the tail of the backbone network of the initial YOLOV8 model to obtain a first model; adds a small target detection head to the head of the first model, and adds an adaptive spatial feature fusion mechanism to obtain a model to be trained; inputs the second training set into the model to be trained to obtain a target weed detection model; and determines the weed species and weed distribution information according to the target weed detection model and the image to be detected. This embodiment significantly increases the diversity of training data and improves the generalization ability of the model by randomly expanding and Mixup-enhancing the cotton field weed data set; at the same time, the BottleNeck structure in the initial YOLOv8 model is replaced with the DWR module, and a hierarchical feature fusion module is added to the tail of the backbone network, so that the model has a stronger multi-scale feature extraction capability; in addition, the added small target detection head and adaptive spatial feature fusion mechanism further enhance the model's detection ability for small target weeds, reducing missed detection and false detection in dense weed scenes. Ultimately, the optimized model can achieve higher detection accuracy and reliability in complex field environments, providing precise technical support for intelligent weeding.
[0086] Based on the above first embodiment, a second embodiment of the cotton field weed detection method under complex environment is proposed. Figure 2 , Figure 2 This is a schematic diagram of a sub-process in the second embodiment of the cotton field weed detection method under a complex environment of the present application.
[0087] like Figure 2 As shown, in this embodiment, before step S1, the following steps are also included:
[0088] S1a: Get weed image set;
[0089] S1b: Based on the VGG image annotator, draw a bounding box for each image in the weed image set;
[0090] S1c: Based on the bounding box drawing result, the weed image set is screened to obtain the cotton field weed dataset.
[0091] It should be noted that the weed image set refers to a collection of images containing weeds collected from the actual environment. These images are usually taken in cotton fields or other farmland, showing different types and forms of weeds. These images are used to train, validate, and test target detection models. VGG Image Annotator (VIA) is a tool for manually annotating images, which is usually used to generate training data for deep learning models. With VGG Image Annotator, users can draw bounding boxes on images to mark the location and category of target objects. These annotation information is usually saved in JSON or other data formats for model training. Bounding box drawing refers to marking the specific location and range of target objects (such as weeds) in the image, usually in the form of a rectangular box. Bounding boxes are used to define regions of interest (ROIs) in the image, which contain targets that the model needs to detect and classify. The cotton field weed dataset is a dataset obtained by annotating and filtering the original weed image set. This dataset is specifically used to train and evaluate models to identify and detect weeds in cotton field environments. Each image in the dataset is accompanied by annotation information, including the type and location of the weed.
[0092] Specifically, a computer device or a human operator collects a large number of images from an actual field environment to construct a weed image set. These images show different types of weeds and may contain shooting conditions in various environments, such as different lighting, angles, and densities. These image sets provide basic data for subsequent model training. Using the VGG image annotator, the operator or computer device annotates each image in the weed image set. The specific operation includes marking the location and range of each weed in the image, drawing the corresponding bounding box, and assigning a corresponding category label to each bounding box. These annotation information records the location and type of each target object in the image, providing the necessary supervision signal for training the target detection model. After the annotation is completed, the computer device or operator screens the weed image set according to the drawing results of the bounding box. The screening criteria may include: ensuring the accuracy of the annotation, excluding images of poor quality (such as blurred or severely occluded images), and selecting diverse samples (covering different types of weeds and different environmental conditions). Through screening, a high-quality cotton field weed dataset is finally obtained, which is used for subsequent model training and evaluation.
[0093] The weed images are accurately annotated by the VGG image annotator, and the dataset is screened after the annotation is completed, ensuring that the final cotton field weed dataset has high-quality annotation information. These high-quality data are crucial for training a high-performance target detection model because it directly affects the learning effect and detection accuracy of the model. By screening the image set, diverse and representative samples are retained, allowing the model to learn a wider range of features. This diverse training data can improve the generalization ability of the model, so that it can still maintain high-precision detection performance when facing different environments and weed types. Through a strict annotation and screening process, low-quality images that may introduce noise are filtered out to ensure the accuracy of the training data. This method reduces errors and deviations in model training and improves the stability and reliability of the model in practical applications. In summary, by obtaining a weed image set, drawing bounding boxes based on the VGG image annotator, and screening the annotation results, the cotton field weed dataset finally generated provides a high-quality data foundation for model training, significantly improving the detection performance of the model and the reliability in practical applications.
[0094] Based on the above first embodiment, in this embodiment, step S4 includes:
[0095] S41: adding the small target detection head to the head of the first model to obtain a second model;
[0096] S42: replacing the NMS method in the second model with the Soft-NMS method;
[0097] S43: Adding an adaptive spatial feature fusion mechanism to the replaced second model to obtain the model to be trained.
[0098] It should be noted that the first model is a model obtained by optimizing the structure of the initial YOLOv8 model, including replacing the BottleNeck structure with the DWR module and adding a hierarchical feature fusion module at the end of the backbone network. This model already has good multi-scale feature extraction capabilities. The small target detection head is a special module in the network structure, designed to improve the model's detection ability for small-sized targets (such as small-volume weeds). By adding a small target detection head to the head, the model can more sensitively identify and locate small targets in the image. The second model is a model obtained by adding a small target detection head to the head on the basis of the first model. This model has higher accuracy when dealing with small-sized target detection tasks. NMS is a post-processing algorithm that retains the highest-scoring one from multiple overlapping bounding boxes output by the detection model and removes other boxes with larger overlaps, thereby ensuring that each target corresponds to only one bounding box. Soft-NMS is an improvement on the traditional NMS method. Unlike NMS, which directly suppresses overlapping boxes, Soft-NMS reduces the scores of overlapping boxes instead of directly deleting them to reduce missed detections or false detections in dense target scenes. The adaptive spatial feature fusion mechanism is a technique for dynamically weighted fusion between multi-scale features, aiming to improve the accuracy of multi-scale feature fusion. Through ASFF, the model can adaptively adjust the contribution of different feature maps in detection according to their importance, thereby optimizing detection performance.
[0099] Specifically, the computer device first identifies the head structure of the first model and adds a small target detection head to it. The small target detection head is specifically used to process small-sized targets in the image, and can improve the model's detection accuracy for these targets. After this operation, a second model with stronger small target detection capabilities is generated. Next, the computer device performs post-processing optimization on the second model, replacing the traditional NMS method with the Soft-NMS method. Soft-NMS reduces the problem of missed detection that may occur in dense weed scenes by gradually lowering the scores of overlapping bounding boxes instead of directly deleting them. This improvement makes the second model more stable and reliable when processing densely distributed weed targets.
[0100] Furthermore, after replacing the NMS method with Soft-NMS, the computer device further adds an adaptive spatial feature fusion mechanism (ASFF) to the second model. ASFF optimizes the fusion process of multi-scale features by dynamically adjusting the weights of feature maps of different scales. This operation ensures that the model can detect targets more accurately when facing complex backgrounds and multi-scale targets. Finally, the computer device generates a model to be trained after the above series of optimizations. This model not only has a strong small target detection capability, but also significantly improves the detection accuracy and robustness in complex environments through the improvements of Soft-NMS and ASFF.
[0101] By adding a small target detection head to the head, the model can more accurately detect small-sized targets in the image, such as small weeds, and significantly reduce missed detections. This improvement is of great significance to improving the practicality of the model in complex field environments. The introduction of the Soft-NMS method optimizes the post-processing steps and reduces false detections and missed detections in dense target scenes. Compared with the traditional NMS method, Soft-NMS can better retain important target information and ensure that the model performs more reliably when dealing with complex environments. The addition of the adaptive spatial feature fusion mechanism (ASFF) enables the model to dynamically adjust the fusion process of features of different scales and reduce the conflict between multi-scale feature maps. This improvement enhances the model's detection ability for targets of different scales and further improves the overall detection accuracy. In summary, by adding a small target detection head to the head of the first model, replacing NMS with the Soft-NMS method, and adding an adaptive spatial feature fusion mechanism, the final trained model performs better in dealing with multi-scale target detection tasks in complex environments, with stronger small target detection capabilities and higher overall detection accuracy.
[0102] This embodiment divides the cotton field weed data set into a first training set, a validation set and a test set; performs random expansion and Mixup enhancement on the first training set to obtain a second training set; replaces the BottleNeck structure in the initial YOLOV8 model with a DWR module, and adds a hierarchical feature fusion module to the tail of the backbone network of the initial YOLOV8 model to obtain a first model; adds a small target detection head to the head of the first model, and adds an adaptive spatial feature fusion mechanism to obtain a model to be trained; inputs the second training set into the model to be trained to obtain a target weed detection model; and determines the weed species and weed distribution information according to the target weed detection model and the image to be detected. This embodiment significantly increases the diversity of training data and improves the generalization ability of the model by randomly expanding and Mixup-enhancing the cotton field weed data set; at the same time, the BottleNeck structure in the initial YOLOv8 model is replaced with the DWR module, and a hierarchical feature fusion module is added to the tail of the backbone network, so that the model has a stronger multi-scale feature extraction capability; in addition, the added small target detection head and adaptive spatial feature fusion mechanism further enhance the model's detection ability for small target weeds, reducing missed detection and false detection in dense weed scenes. Ultimately, the optimized model can achieve higher detection accuracy and reliability in complex field environments, providing precise technical support for intelligent weeding.
[0103] Based on the above second embodiment, a third embodiment of the cotton field weed detection method under complex environment is proposed. Figure 3 , Figure 3 This is a schematic diagram of a sub-process in the third embodiment of the cotton field weed detection method under a complex environment of the present application.
[0104] In this embodiment, before step S41, the method further includes:
[0105] S41a: extract features from the first C2f module of the backbone network to obtain an initial feature map;
[0106] S41b: Upsampling the initial feature map to a preset size to obtain a sampled feature map;
[0107] S41c: Connect the initial feature map and the sampled feature map to obtain a small target detection feature map, and use it as the final input of the small target detection head.
[0108] It should be noted that the backbone network is the main part of the deep learning model, which is responsible for extracting high-level features from the input image. In the YOLOv8 model, the backbone network includes multiple convolutional layers and other modules to gradually extract and compress the feature information of the image. The C2f (Cross Stage Partial networks with Fused features) module is an important component in YOLOv8, which improves the efficiency and expression of feature extraction by sharing and fusing some features. In the backbone network, the C2f module is used to extract multi-scale features from the image. Feature extraction refers to extracting useful information or feature maps from an image for subsequent target detection tasks. In deep learning, feature extraction is usually performed by convolutional layers, and the extracted feature maps are used to capture the spatial structure and semantic information of the image. Upsampling refers to increasing the resolution of the feature map to a preset size in order to restore or enhance the detail information in the image. In deep learning, common upsampling methods include bilinear interpolation, deconvolution, etc., which are usually used to process small targets or tasks that require higher resolution features. The sampled feature map is a high-resolution feature map obtained by upsampling. It is usually used to capture detailed information in an image, especially in small target detection tasks. Sampling feature maps can improve the model's sensitivity to small targets. Small target detection feature maps refer to feature maps used for small target detection tasks after specific processing. By integrating feature maps of different scales, it can more effectively capture information about small-sized targets and improve detection accuracy.
[0109] Specifically, the computer device first extracts features from the first C2f module of the backbone network. The C2f module extracts multi-scale features from the input image using the mechanism of partial feature sharing and cross-stage fusion. Through this operation, the computer device obtains an initial feature map, which contains key information in the image, especially the spatial structure and texture information of the image. In order to better detect small targets, the computer device upsamples the initial feature map to increase its resolution to a preset size. This process enlarges the low-resolution initial feature map to a higher-resolution sampled feature map through methods such as interpolation or deconvolution. The upsampled feature map retains more detail information, making the model more sensitive when processing small-sized targets.
[0110] Furthermore, the computer device connects the initial feature map with the sampled feature map obtained by upsampling (usually by channel dimension). This connection operation fuses feature maps of different resolutions, combines low-level detail information with high-level abstract features, and obtains a more comprehensive small target detection feature map. Finally, the computer device uses the generated small target detection feature map as the input of the small target detection head. In this way, the model can more effectively identify and locate small targets in the image, especially in complex backgrounds or low resolutions, while still maintaining high detection accuracy.
[0111] By extracting features and upsampling the first C2f module of the backbone network, the model can better capture the details of small-sized targets. The upsampled high-resolution feature map makes the model more sensitive when dealing with small targets and significantly reduces missed detection. Connecting the initial feature map with the upsampled sampled feature map helps to fuse features of different resolutions. This feature fusion enables the model to use both detail information and global semantic information when detecting small targets, thereby improving the accuracy and robustness of detection. By using the generated small target detection feature map as the input of the small target detection head, the model can maintain efficient and accurate detection performance when facing small-sized weed targets. This optimization is particularly important for small target detection tasks in complex field environments, ensuring the high detection accuracy of the model. In summary, by performing feature extraction, upsampling, and feature map connection operations on the C2f module of the backbone network, the computer device generates a high-resolution feature map for small target detection. This process significantly enhances the detection accuracy of the model, especially the detection ability of small targets in complex environments, and improves the overall performance and application value of the model.
[0112] Based on the above second embodiment, in this embodiment, step S6 includes:
[0113] S61: verifying the target weed detection model based on the Soft-NMS method, the verification set and the test set;
[0114] S62: Inputting the image to be detected into the verified target weed detection model to obtain the weed species information and the weed distribution information.
[0115] It should be noted that weed species information refers to the weed categories identified by the model in the image to be detected, such as different weed varieties. This information helps farm managers understand the weed composition in the field. Weed distribution information refers to the location and range of weeds marked in the image, usually in the form of a bounding box or mask. This information helps determine the specific distribution of each weed in the field.
[0116] Specifically, the computer device first applies the Soft-NMS method to the output results of the target weed detection model. The Soft-NMS method retains more information about potential targets by performing score attenuation on overlapping bounding boxes instead of directly removing them, especially in scenes with dense weeds. This method can reduce missed detections and improve detection accuracy. After the model training is completed, the computer device inputs the validation set into the target weed detection model for performance evaluation. The validation set is used to monitor the performance of the model, especially to evaluate the model's ability to process unseen data. The results of the validation can help developers determine whether the model needs further adjustment or improvement. After the validation is passed, the computer device uses an independent test set to perform a final evaluation of the target weed detection model. The data in the test set is independent of the model training process and is intended to simulate the performance of the model in actual applications. Through the test set, the computer device can obtain data on the final detection accuracy and robustness of the model, providing a reference for the application of the model in actual scenarios.
[0117] Further, after verification and test confirmation, the computer device inputs the image to be detected into the verified target weed detection model. The model processes the image, identifies the weed species in the image, and generates corresponding distribution information. The computer device sorts out the weed species information and distribution information in the image to be detected based on the output results of the model. This information includes the specific category of each weed, its location in the image, and its coverage (usually expressed in the form of a bounding box or mask). Ultimately, the device uses this information for agricultural management or automated weeding operations.
[0118] By processing the model output through the Soft-NMS method, the possible missed detection caused by the traditional NMS method is reduced, especially when dealing with dense weed scenes, the target can be identified more accurately. This improvement ensures that the model performs more robustly on the validation set and test set. By evaluating the model using independent validation sets and test sets, the computer equipment can ensure that the model performs as expected in practical applications. The model has been rigorously verified and tested, with higher reliability and accuracy. In practical applications, the computer equipment can accurately identify the types and distribution information of weeds in the images to be detected. This information can help farmland managers develop more accurate weed control plans, optimize agricultural production efficiency, reduce pesticide use, and improve yield and quality. In summary, the target weed detection model is verified by the Soft-NMS method, validation set, and test set, ensuring the high accuracy and stability of the model in practical applications. Using the verified model to analyze the images to be detected can accurately determine the types and distribution information of weeds, providing strong support for intelligent agricultural management.
[0119] Based on the above second embodiment, in this embodiment, step S2 includes:
[0120] S21: Based on preset expansion parameters, performing random expansion processing on each image in the first training set to obtain an expanded data set, wherein the random expansion processing includes random cropping, scaling, rotation, and color jittering;
[0121] S22: performing Mixup data enhancement processing on the expanded data set to obtain an enhanced data set;
[0122] S23: Merge the first training set, the expanded data set, and the enhanced data set to obtain the second training set.
[0123] It should be noted that the preset expansion parameters refer to the operation parameters pre-set when performing data expansion processing. These parameters usually include the ratio of random cropping, the range of scaling, the angle of rotation, the intensity of color jittering, etc., which are used to guide how to perform random expansion operations on images. Random expansion processing is a data enhancement technology that generates diverse training samples by performing various random transformations on images. These transformations include random cropping, scaling, rotation, and color jittering, etc., with the purpose of improving the generalization ability of the model so that it can adapt to different image conditions. The expanded data set is a new data set generated by randomly expanding the images in the first training set. This data set contains a variety of image samples that have undergone different transformations, which are used to improve the performance of the model under different conditions. Mixup is a data enhancement technology that generates new training samples by linearly mixing two images and their corresponding labels in a certain proportion. Mixup enables the model to better learn the relationship between different categories and reduce the overfitting phenomenon of the model. The enhanced data set is a data set generated by performing Mixup data enhancement processing on the expanded data set. This data set further increases the diversity and complexity of the samples, which helps to improve the generalization ability of the model. The second training set is the final training set obtained by merging the first training set, the expanded dataset, and the enhanced dataset. This dataset contains rich and diverse training samples, providing a stronger learning foundation for the model to improve detection performance.
[0124] Specifically, the computer device performs random expansion processing on each image in the first training set based on preset expansion parameters. These expansion processing include the following operations: random cropping: randomly cropping an area at different positions of the image to retain or enlarge a specific part of the image; scaling: randomly scaling the image so that the target object appears in different sizes in the image; rotation: randomly rotating the image by a certain angle to increase the robustness of the model to different viewing angles; color jittering: randomly adjusting the brightness, contrast, saturation and hue of the image to simulate different lighting conditions; through these operations, the computer device generates an expanded data set containing diverse images.
[0125] Furthermore, the computer device then performs Mixup data enhancement processing on the expanded data set. The specific operation is to randomly select two images from the expanded data set, and weightedly mix their pixel values and labels according to the preset Mixup ratio. In this way, the computer device generates new image and label pairs, which not only retain the characteristics of the original images, but also introduce new mixed information to form an enhanced data set. Finally, the computer device merges the first training set, the expanded data set, and the enhanced data set. Through the merger, these data sets from different sources are integrated into a larger and diverse second training set. The training set contains more sample variants, so that the model can be exposed to richer image information during the training process, thereby improving the generalization ability and detection accuracy of the model.
[0126] Through random expansion processing, the images in the original training set have obtained multiple variants. This diversity can help the model learn more image features during training, thereby enhancing its performance under different conditions. Mixup data enhancement generates more complex training samples by mixing images and labels. This complexity makes it difficult for the model to remember specific image features during training, thereby reducing overfitting and improving the generalization ability of the model. The second training set finally generated provides the model with richer and more diverse training data by merging samples from multiple sources. These data help the model better learn the target features under different conditions, improve the detection accuracy of the model and the robustness in complex environments. In summary, by performing random expansion processing and Mixup data enhancement processing on the first training set, and merging these expanded and enhanced data sets, the computer device generates a diverse second training set. This process significantly improves the training effect of the model, enhances the generalization ability and detection accuracy of the model, and makes it more stable and accurate in practical applications.
[0127] This embodiment divides the cotton field weed data set into a first training set, a validation set and a test set; performs random expansion and Mixup enhancement on the first training set to obtain a second training set; replaces the BottleNeck structure in the initial YOLOV8 model with a DWR module, and adds a hierarchical feature fusion module to the tail of the backbone network of the initial YOLOV8 model to obtain a first model; adds a small target detection head to the head of the first model, and adds an adaptive spatial feature fusion mechanism to obtain a model to be trained; inputs the second training set into the model to be trained to obtain a target weed detection model; and determines the weed species and weed distribution information according to the target weed detection model and the image to be detected. This embodiment significantly increases the diversity of training data and improves the generalization ability of the model by randomly expanding and Mixup-enhancing the cotton field weed data set; at the same time, the BottleNeck structure in the initial YOLOv8 model is replaced with the DWR module, and a hierarchical feature fusion module is added to the tail of the backbone network, so that the model has a stronger multi-scale feature extraction capability; in addition, the added small target detection head and adaptive spatial feature fusion mechanism further enhance the model's detection ability for small target weeds, reducing missed detection and false detection in dense weed scenes. Ultimately, the optimized model can achieve higher detection accuracy and reliability in complex field environments, providing precise technical support for intelligent weeding.
[0128] For example, in order to help understand the technical concept or technical principle of the cotton field weed detection method under a complex environment in the above embodiment, please refer to Figure 4 , Figure 4 This is a schematic diagram of the improved YOLOv8 model structure in an embodiment of the cotton field weed detection method under a complex environment of this application.
[0129] like Figure 4 As shown in the figure, compared with the original YOLOV8 model, the improved model first replaces the C2f network BottleNeck structure with the DWR module, and adds a hierarchical feature fusion module Multi-Scale Block at the tail of the backbone to obtain multi-scale context information of cotton weeds. Secondly, a small target detection head is added to the head to improve the detection ability of small target weeds, and an adaptive spatial feature fusion mechanism is added to the detection head to filter out contradictory features. Finally, the traditional non-maximum suppression NMS is replaced with SoftNMS to improve the performance of dense weed detection.
[0130] The present application also provides a cotton field weed detection device under complex environment. Figure 5 , Figure 5 This is a schematic diagram of the module structure of a cotton field weed detection device under a complex environment according to an embodiment of the present application. The cotton field weed detection device under a complex environment includes:
[0131] A division module 501 is used to divide the cotton field weed data set into a first training set, a validation set and a test set;
[0132] An expansion and enhancement module 502 is used to perform random expansion and Mixup enhancement on the first training set to obtain a second training set;
[0133] A structure replacement module 503 is used to replace the BottleNeck structure in the initial YOLOV8 model with a DWR module, and add a hierarchical feature fusion module to the tail of the backbone network of the initial YOLOV8 model to obtain a first model;
[0134] A mechanism adding module 504 is used to add a small target detection head to the head of the first model, and add an adaptive spatial feature fusion mechanism to obtain a model to be trained;
[0135] A training module 505 is used to input the second training set into the model to be trained to obtain a target weed detection model;
[0136] The target module 506 is used to determine the weed species information and the weed distribution information according to the target weed detection model and the image to be detected.
[0137] The cotton field weed detection device under complex environment provided in the embodiment of the present application adopts the cotton field weed detection method under complex environment in the above embodiment, which can solve the technical problem of how to improve the accuracy of cotton field weed target detection. Compared with the prior art, the beneficial effects of the cotton field weed detection device under complex environment provided in the embodiment of the present application are the same as the beneficial effects of the cotton field weed detection method under complex environment provided in the above embodiment, and other technical features of the cotton field weed detection device under complex environment are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0138] The present application provides a cotton field weed detection device under a complex environment, the cotton field weed detection device under a complex environment comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the cotton field weed detection method under a complex environment in the above-mentioned embodiment.
[0139] Reference below Figure 6, which shows a schematic diagram of the structure of a cotton field weed detection device under a complex environment suitable for implementing the embodiment of the present application. The cotton field weed detection device under a complex environment in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 6 The cotton field weed detection device in a complex environment shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0140] like Figure 6 As shown, the cotton field weed detection device under complex environment may include a processing device 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the cotton field weed detection device under complex environment are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1003 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 1009. The communication device 1009 can allow the cotton field weed detection device under a complex environment to communicate wirelessly or wired with other devices to exchange data. Although the figure shows a cotton field weed detection device under a complex environment with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or provided alternatively.
[0141] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0142] The cotton field weed detection device under complex environment provided by the present application adopts the cotton field weed detection method under complex environment in the above embodiment, which can solve the technical problem of how to improve the accuracy of cotton field weed target detection. Compared with the prior art, the beneficial effects of the cotton field weed detection device under complex environment provided by the present application are the same as the beneficial effects of the cotton field weed detection method under complex environment provided by the above embodiment, and other technical features of the cotton field weed detection device under complex environment are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0143] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0144] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0145] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the cotton field weed detection method under a complex environment in the above-mentioned embodiment.
[0146] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0147] The computer-readable storage medium may be included in the cotton field weed detection device under complex environment; or may exist independently without being assembled into the cotton field weed detection device under complex environment.
[0148] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the cotton field weed detection device under a complex environment, the cotton field weed detection device under a complex environment: divides the cotton field weed data set into a first training set, a validation set and a test set; performs random expansion and Mixup enhancement on the first training set to obtain a second training set; replaces the BottleNeck structure in the initial YOLOV8 model with a DWR module, and adds a hierarchical feature fusion module to the tail of the backbone network of the initial YOLOV8 model to obtain a first model; adds a small target detection head to the head of the first model, and adds an adaptive spatial feature fusion mechanism to obtain a model to be trained; inputs the second training set into the model to be trained to obtain a target weed detection model; determines weed species information and weed distribution information according to the target weed detection model and the image to be detected. Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0149] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0150] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0151] The readable storage medium provided in the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned cotton field weed detection method under complex environment, and can solve the technical problem of how to improve the accuracy of cotton field weed target detection. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the present application are the same as the beneficial effects of the cotton field weed detection method under complex environment provided in the above-mentioned embodiment, and will not be elaborated here.
[0152] An embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the cotton field weed detection method under a complex environment as described above.
[0153] The computer program product provided in this application can solve the technical problem of how to improve the accuracy of cotton field weed target detection. Compared with the prior art, the beneficial effects of the computer program product provided in the embodiment of this application are the same as the beneficial effects of the cotton field weed detection method under complex environment provided in the above embodiment, which will not be repeated here.
[0154] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent processing scope of the present application.
Claims
1. A method for detecting weeds in cotton fields under complex environments, characterized in that: The method comprises: The cotton field weed dataset is divided into the first training set, the validation set and the test set; Performing random expansion and Mixup enhancement on the first training set to obtain a second training set; The BottleNeck structure in the initial YOLOV8 model is replaced with the DWR module, and a hierarchical feature fusion module is added to the tail of the backbone network of the initial YOLOV8 model to obtain a first model; Adding a small target detection head to the head of the first model and adding an adaptive spatial feature fusion mechanism to obtain a model to be trained; Inputting the second training set into the model to be trained to obtain a target weed detection model; Weed species information and weed distribution information are determined according to the target weed detection model and the image to be detected.
2. The method according to claim 1, characterized in that Before the step of dividing the cotton field weed data set into a first training set, a validation set, and a test set, the method further includes: Get a weed image set; Based on the VGG image annotator, drawing a bounding box for each image in the weed image set; Based on the bounding box drawing result, the weed image set is screened to obtain the cotton field weed dataset.
3. The method according to claim 1, characterized in that The step of adding a small target detection head to the head of the first model and adding an adaptive spatial feature fusion mechanism to obtain a model to be trained includes: Adding the small target detection head to the head of the first model to obtain a second model; Replace the NMS method in the second model with the Soft-NMS method; An adaptive spatial feature fusion mechanism is added to the replaced second model to obtain the model to be trained.
4. The method according to claim 3, characterized in that Before the step of adding the small target detection head to the head of the first model to obtain the second model, the method further includes: Perform feature extraction on the first C2f module of the backbone network to obtain the initial feature map; Upsampling the initial feature map to a preset size to obtain a sampled feature map; The initial feature map is connected with the sampled feature map to obtain a small target detection feature map, which serves as the final input of the small target detection head.
5. The method according to claim 3, characterized in that The step of determining weed species information and weed distribution information according to the target weed detection model and the image to be detected includes: Based on the Soft-NMS method, the validation set and the test set, verifying the target weed detection model; The image to be detected is input into the verified target weed detection model to obtain the weed species information and the weed distribution information.
6. The method according to any one of claims 1 to 5, characterized in that: The step of randomly expanding and Mixup-enhancing the first training set to obtain a second training set includes: Based on preset expansion parameters, performing random expansion processing on each image in the first training set to obtain an expanded data set, wherein the random expansion processing includes random cropping, scaling, rotation, and color jittering; Performing Mixup data enhancement processing on the expanded data set to obtain an enhanced data set; The first training set, the expanded data set and the enhanced data set are combined to obtain the second training set.
7. A cotton field weed detection device under complex environment, characterized in that: The device comprises: A partitioning module, used for partitioning the cotton field weed data set into a first training set, a validation set and a test set; An expansion and enhancement module, used for performing random expansion and Mixup enhancement on the first training set to obtain a second training set; A structure replacement module, used to replace the BottleNeck structure in the initial YOLOV8 model with a DWR module, and add a hierarchical feature fusion module to the tail of the backbone network of the initial YOLOV8 model to obtain a first model; A mechanism adding module, used to add a small target detection head to the head of the first model, and add an adaptive spatial feature fusion mechanism to obtain a model to be trained; A training module, used for inputting the second training set into the model to be trained to obtain a target weed detection model; The target module is used to determine the weed type and weed distribution information according to the target weed detection model and the image to be detected.
8. A computer device, characterized in that: The device comprises: a memory, a processor, and a cotton field weed detection program under a complex environment stored in the memory and executable on the processor, wherein the cotton field weed detection program under a complex environment is configured to implement the steps of the cotton field weed detection method under a complex environment as described in any one of claims 1 to 6.
9. A storage medium, characterized in that: The storage medium stores a cotton field weed detection program under a complex environment, and when the cotton field weed detection program under a complex environment is executed by the processor, the steps of the cotton field weed detection method under a complex environment as claimed in any one of claims 1 to 6 are implemented.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the method for detecting weeds in a cotton field under a complex environment according to any one of claims 1 to 6 are implemented.