Wheat ear counting lightweight method for unmanned aerial vehicle edge calculation

By pruning and knowledge distilling the YOLOv5s model, the model structure and parameters are optimized, which solves the problem of insufficient computing resources and adaptability of the deep learning model in wheat ear detection, and realizes real-time detection and counting on UAV edge devices. , improving efficiency and accuracy.

CN118691571APending Publication Date: 2024-09-24SHANDONG AGRICULTURAL UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410791501.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-19
Publication Date
2024-09-24

AI Technical Summary

Technical Problem

Existing deep learning models for wheat ear detection rely on powerful computing resources, resulting in data transmission delays and limited real-time detection applications. In addition, artificially designed lightweight networks may lack adaptability and generalization capabilities in field environments, which requires Expensive redesign and training.

Method used

The YOLOv5s model is used for pruning and knowledge distillation. The pruning ratio is determined through the L1 norm, redundant parameters are removed, and the teacher model is used to guide the student model to perform knowledge distillation, optimize the model structure and parameters, and reduce computing resource requirements and model size.

Benefits of technology

It achieves real-time detection and counting of wheat ears deployed on UAV edge devices, improves the real-time and accuracy of counting, significantly reduces computing resources and storage space requirements, and has high application value.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118691571A
    Figure CN118691571A
Patent Text Reader

Abstract

A wheat ear counting lightweight method for unmanned aerial vehicle edge calculation relates to the technical field of unmanned aerial vehicle edge calculation, and comprises the following steps: obtaining basic conditions and image data of a wheat field; preprocessing and labeling the image data; a YOLOv5s model is constructed and trained; carrying out model lightweight optimization on the YOLOv5s model; and deploying the lightweight model to an edge device of the unmanned aerial vehicle to realize real-time detection and counting of the wheat ears. According to the method, model compression is realized through model pruning and knowledge distillation, the complexity and parameter quantity of the model are remarkably reduced, and the method occupies less computing resources and storage space while keeping relatively high counting accuracy, so that the model can be deployed on the edge equipment of the unmanned aerial vehicle, and the possibility of real-time counting is provided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of drone edge computing technology, and in particular to a lightweight method for counting wheat ears for drone edge computing. Background Art

[0002] In agricultural production, wheat yield prediction plays a vital role in national food security and economic benefits. As a core indicator for evaluating yield, the accuracy and timeliness of wheat ear count have irreplaceable value for agricultural management and decision-making. However, traditional manual statistical methods are not only inefficient, but also have a high error rate, which to some extent restricts the accuracy of wheat yield prediction.

[0003] In recent years, with the breakthrough of deep learning in the field of image recognition and processing, it has been regarded as a key driving force for the transformation of agricultural intelligence. The deep learning model can automatically learn and identify features in images, providing a new solution for the accurate counting of wheat ears. However, the existing deep learning models, especially convolutional neural networks, usually require powerful computing resources and are deployed on ground-based central servers due to their complex network structure and large number of parameters. This model not only increases the delay of data transmission, but also limits the application scenarios of real-time wheat ear detection.

[0004] In order to improve the real-time performance of wheat ear detection and reduce communication delay, current research tends to develop lightweight deep learning models suitable for UAV edge devices. These models significantly reduce the computational complexity and model size through algorithm optimization and model compression technology, so that UAVs can perform wheat ear detection and counting tasks in real time during flight, greatly improving operation efficiency and response speed. Although some studies have designed lightweight neural network structures through hybrid deep convolution, reverse residual bottleneck, Shuffle unit and other technical means, and used them for wheat ear detection, these methods still rely on manual design and may lack sufficient adaptability and generalization capabilities for complex and changeable wheat ear images in field environments. In addition, once the network environment or task requirements change, these manually designed networks may require expensive redesign and training. Summary of the invention

[0005] The purpose of the present invention is to solve the problems raised in the above-mentioned background technology, and then proposes a lightweight method for counting wheat ears for drone edge computing.

[0006] The technical solution adopted by the present invention to solve the technical problem is:

[0007] A lightweight method for counting wheat ears for UAV edge computing includes the following steps:

[0008] S1. Obtain basic information and image data of the wheat field;

[0009] S2, preprocessing and labeling image data;

[0010] S3. Build and train the YOLOv5s model;

[0011] S4. Perform lightweight optimization on the YOLOv5s model;

[0012] S5. Deploy the lightweight model to the edge device of the drone to achieve real-time detection and counting of wheat ears.

[0013] Furthermore, the specific steps of step S4 are as follows:

[0014] S41. When pruning the YOLOv5s model, the L1 norm is used to determine the pruning ratio and prune redundant parameters. By eliminating redundant connections and parameters in the model to reduce the model size, the computing resource requirements can be effectively reduced and the reasoning speed can be improved.

[0015] S42, perform knowledge distillation and optimize the lightweight model;

[0016] S43. Evaluate and verify the performance of the lightweight model.

[0017] Furthermore, in step S41, when the YOLOv5s model is pruned, the pruning ratio is determined by the L1 norm to prune redundant parameters.

[0018] Furthermore, the L1 norm calculation formula is as follows:

[0019]

[0020] Furthermore, in step S42, when performing knowledge distillation, the teacher model is introduced to guide the learning of the student model.

[0021] Furthermore, the pruned model of the YOLOv5s model is used as the student model, and the unpruned YOLOv5s model is used as the teacher model for knowledge distillation training. The difference between the student model and the teacher model is calculated through the distillation loss function to optimize the performance of the student model.

[0022] Furthermore, the calculation formula of the distillation loss function is as follows:

[0023]

[0024] where α i According to the predicted probability p i The calculated adjustment factor, N is the number of samples;

[0025] The knowledge distillation loss function calculates the student model output p and the teacher model output t p Mean square error (MSE) between:

[0026]

[0027] in N is the sample size.

[0028] Furthermore, in step S41, the DependencyGraph class in the torch_pruning library is used in the YOLOv5s model to construct a dependency graph of the model, and a forward propagation path of the model is constructed according to the input sample, and a pruning plan is calculated according to the weight matrix of the model using the L1 strategy, and the model is pruned according to the obtained pruning plan, and the pruned YOLOv5s model is fine-tuned, and the number of rounds of fine-tuning training is at least 100.

[0029] Furthermore, in the YOLOv5s model structure, the pruning plan is determined according to the weight matrix and L1 strategy of each convolutional layer.

[0030] Furthermore, when executing the pruning plan, each layer of the model is traversed, and the pruning operation is performed according to the pruning plan to set unnecessary parameters to zero. In the YOLOv5s model, the pruning_p l an.exec() method is used to perform the pruning operation to achieve pruning of the model parameters.

[0031] Compared with the prior art, the beneficial effects of the present invention are as follows: based on pruning and knowledge distillation methods, the present invention comprehensively considers the structural complexity and parameter quantity of the model, achieves lightweight by optimizing the model, and significantly reduces the model size and parameter quantity while maintaining a high counting accuracy, so that it can be deployed on the edge device of the drone to achieve real-time detection and counting of wheat ears. The scheme of the present invention not only improves the real-time performance and accuracy of wheat ear counting, but also effectively reduces the demand for computing resources and storage space, and has a high application value. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 This is a schematic diagram of the wheat field selection;

[0033] Figure 2 This is the parameter setting diagram when the drone collects wheat ear data;

[0034] Figure 3 It is a diagram of the model lightweighting process;

[0035] Figure 4 It is a schematic diagram of pruning;

[0036] Figure 5It is a diagram of the knowledge distillation training process;

[0037] Figure 6 This is the mAP change graph before and after model compression;

[0038] Figure 7 This is a schematic diagram of the drone edge computing method for real-time counting of wheat ears. DETAILED DESCRIPTION

[0039] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. The present invention is further described in combination with the drawings and embodiments:

[0040] like Figure 1-Figure 7 As shown in the figure, a lightweight method for wheat ear counting for UAV edge computing integrates pruning strategy and knowledge distillation method, builds a lightweight model based on the YOLOv5s model, and establishes a model compression scheme with the goal of minimizing model size and maximizing computational efficiency by comprehensively considering pruning ratio, distillation temperature and accuracy requirements. The optimization model is solved based on model compression theory, and finally the optimal model structure and parameter configuration are determined.

[0041] Specifically, the lightweight method for counting wheat ears for drone edge computing includes the following steps:

[0042] S1. Obtain basic information and image data of the wheat field;

[0043] S2, preprocessing and labeling image data;

[0044] S3. Build and train the YOLOv5s model;

[0045] S4. Perform lightweight optimization on the YOLOv5s model;

[0046] S5. Deploy the lightweight model to the edge device of the drone to achieve real-time detection and counting of wheat ears.

[0047] In at least one embodiment, the specific steps of step S4 are as follows:

[0048] S41. When pruning the YOLOv5s model, the L1 norm is used to determine the pruning ratio and prune redundant parameters. By eliminating redundant connections and parameters in the model to reduce the model size, the computing resource requirements can be effectively reduced and the reasoning speed can be improved.

[0049] S42, perform knowledge distillation and optimize the lightweight model;

[0050] S43. Evaluate and verify the performance of the lightweight model.

[0051] Furthermore, in step S41, when the YOLOv5s model is pruned, the pruning ratio is determined by the L1 norm to prune redundant parameters;

[0052] The scheme is refined, and the L1 norm calculation formula is as follows:

[0053]

[0054] Furthermore, in step S42, when performing knowledge distillation, the teacher model is introduced to guide the learning of the student model, thereby reducing the model size while maintaining the model performance.

[0055] The scheme is refined, with the pruned YOLOv5s model as the student model and the unpruned YOLOv5s model as the teacher model for knowledge distillation training; the difference between the student model and the teacher model is calculated through the distillation loss function to optimize the performance of the student model.

[0056] The scheme is refined, and the calculation formula of the distillation loss function is as follows:

[0057]

[0058] where α i According to the predicted probability p i The adjustment factor to be calculated, where N is the number of samples.

[0059] The knowledge distillation loss function calculates the student model output p and the teacher model output t p Mean square error (MSE) between:

[0060]

[0061] in N is the sample size.

[0062] Take a wheat field as a research example:

[0063] The wheat field covers an area of ​​50 mu and is divided into several plots. Data is collected and processed in each plot. A DJI PHANTOM 4PRO V2.0 drone is used to collect wheat ear data. The flight altitude is set to 1.8 meters, the flight speed is 1 meter per second, and the gimbal lens angle is set to -55° to ensure image clarity and coverage.

[0064] 1. Data collection and preprocessing

[0065] First, multiple flights were carried out at different time periods, row spacings and lighting conditions to collect wheat ear image data. To improve image quality and diversity, HSV color space adjustment, image translation, scaling and flipping were used to preprocess the images.

[0066] 2. Data Annotation

[0067] Label Img was used to annotate the preprocessed image data and mark the position of wheat ears in each image. A total of 3376 annotated image data were obtained, 3038 of which were randomly selected as training sets and validation sets, and the remaining 338 were used as test sets.

[0068] 3. Model selection and training

[0069] The YOLOv5s model is selected as the basic model. The model consists of three parts: Backbone, Neck and Detect, which are used for feature extraction, feature fusion and target detection respectively. The labeled data set is input into the model for training, and the training rounds are set to 100 rounds.

[0070] 4. Model pruning and knowledge distillation

[0071] Model pruning: In model pruning, the L1 strategy is widely used in structured pruning. Its core principle is to use the L1 norm (i.e., the sum of the absolute values ​​of the parameters) to evaluate the importance of each convolution kernel in the convolution layer. By calculating the L1 norm of the weight matrix of each convolution kernel, its contribution to the model performance can be determined. During the pruning process, according to the preset pruning ratio, those convolution kernels with a smaller L1 norm are removed. That is, it is believed that this part of the weight has little impact on the model and can be pruned to reduce the model complexity and computational cost, while trying to keep the model performance stable. This method not only effectively reduces the number of model parameters, but also improves computational efficiency.

[0072] The process of pruning the YOLOv5s model is as follows:

[0073] (1) Constructing the model’s dependency graph

[0074] This is the first step in the pruning process. The dependency graph records the dependencies between the model structure and its parameters. In the YOLOv5s model, the DependencyGraph class in the torch_pruning library can be used to build the model's dependency graph and construct the model's forward propagation path based on the input samples.

[0075] (2) Determine the pruning plan

[0076] The L1 strategy is used to calculate the pruning plan based on the model's weight matrix. The pruning plan includes the pruning strategy for the model parameters, that is, which parameters need to be pruned and the specific method of pruning. In the YOLOv5s model structure, the pruning plan can be determined based on the weight matrix and L1 strategy of each convolutional layer.

[0077] (3) Perform pruning operations

[0078] According to the obtained pruning plan, the model is pruned. The process is as follows Figure 6 As shown. Traverse each layer of the model, perform pruning operations according to the pruning plan, and set unnecessary parameters to zero. In the YOLOv5s model, you can use the prun ing_p l an.exec() method to perform pruning operations and prune model parameters.

[0079] (4) Model fine-tuning

[0080] Pruning operations will cause a loss in model accuracy. In order to ensure that the model can fully adapt to the new network structure and restore its performance level as much as possible, fine-tuning training is often performed. The number of rounds of fine-tuning training is generally set to a larger value, which is set to 100 rounds in this experiment.

[0081] The YOLOv5s model is pruned using the L1 norm to remove redundant convolution kernels. The model structure and parameter relationships are recorded through the dependency graph, the pruning plan is determined, and the model is pruned. After pruning, the number of model parameters is reduced by 79.61% and the model size is reduced by 76%.

[0082] Knowledge distillation: The principle of the distillation method is based on using a large trained teacher model to guide a smaller student model. When training the student model, not only the traditional loss function is used to train based on the true label, but also an additional distillation loss is introduced. This distillation loss calculates the difference between the output of the student model and the output of the teacher model, with the aim of enabling the student model to mimic the predictive behavior and internal feature expression of the teacher model. In this way, the student model can inherit the knowledge and performance of the teacher model while maintaining a small scale, thereby improving efficiency and accuracy.

[0083] The process of knowledge distillation:

[0084] (1) Selecting a teacher model

[0085] The high-performance model of YOLOv5s before pruning is selected as the teacher model. This model has been fully trained on the dataset and has strong feature extraction and generalization capabilities.

[0086] (2) Prepare the data set and loss function

[0087] This application designs a special loss function to guide the training of the student model. This loss function not only includes the traditional cross entropy loss formula, but also adds a distillation loss term formula, which imitates the high-order probability distribution of the teacher model by softening the output of the student model.

[0088]

[0089] where α i According to the predicted probability p i The adjustment factor to be calculated, where N is the number of samples.

[0090] The knowledge distillation loss function calculates the student model output p and the teacher model output t p Mean square error (MSE) between:

[0091]

[0092] in N is the sample size.

[0093] (3) Training the student model

[0094] In this process, the student model generates accurate prediction probabilities by optimizing the loss function. The output feature map of the teacher model is used as one of the auxiliary targets, combined with the labels of the original data, to guide the training of the student model, thereby improving its prediction accuracy and robustness.

[0095] (4) Evaluating the student model

[0096] After the student model training is completed, a detailed performance evaluation is performed to test its effect on the test dataset and verify the performance improvement brought by the distillation method.

[0097] The pruned model is used as the student model and the unpruned YOLOv5s model is used as the teacher model for knowledge distillation training. The distillation loss function is introduced to enable the student model to inherit the knowledge of the teacher model while maintaining high efficiency, further optimizing the model performance.

[0098] 5. Model evaluation and deployment

[0099] The lightweight model after pruning and distillation was evaluated, and the counting accuracy on the test set was 93.3% and the mAP reached 94.4%. The optimized model was converted to ONNX format and deployed on the edge device of the drone, using the computing power of the edge device to count wheat ears in real time.

[0100] After being deployed on the edge device of the drone, this lightweight model can detect and count wheat ears in real time during the flight, improving operational efficiency and data processing speed.

[0101] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, which fall within the scope of the present invention. The scope of the present invention is defined by the attached claims and their equivalents.

Claims

1. A lightweight method for counting wheat ears based on edge computing of unmanned aerial vehicles, characterized in that: The following steps are involved: S1. Obtain basic information and image data of the wheat field; S2, preprocessing and labeling image data; S3. Build and train the YOLOv5s model; S4. Perform lightweight optimization on the YOLOv5s model; S5. Deploy the lightweight model to the edge device of the drone to achieve real-time detection and counting of wheat ears.

2. The lightweight method for counting wheat ears for edge computing of drones according to claim 1 is characterized in that: The specific steps of step S4 are as follows: S41. When pruning the YOLOv5s model, the pruning ratio is determined by the L1 norm and redundant parameters are pruned; S42, perform knowledge distillation and optimize the lightweight model; S43. Evaluate and verify the performance of the lightweight model.

3. The lightweight method for counting wheat ears for drone edge computing according to claim 2 is characterized in that: In step S41, the L1 norm calculation formula is as follows:

4. The lightweight method for counting wheat ears for drone edge computing according to claim 2 or 3, characterized in that: In step S42, when performing knowledge distillation, the teacher model is introduced to guide the learning of the student model.

5. The lightweight method for counting wheat ears for edge computing of unmanned aerial vehicles according to claim 4 is characterized in that: The pruned model of the YOLOv5s model is used as the student model, and the unpruned YOLOv5s model is used as the teacher model for knowledge distillation training. The difference between the student model and the teacher model is calculated through the distillation loss function to optimize the performance of the student model.

6. The lightweight method for counting wheat ears for edge computing of unmanned aerial vehicles according to claim 5 is characterized in that: The calculation formula of the distillation loss function is as follows: where α i According to the predicted probability p i The calculated adjustment factor, N is the number of samples; The knowledge distillation loss function calculates the student model output p and the teacher model output t p Mean square error (MSE) between: in N is the sample size.

7. The lightweight method for counting wheat ears for edge computing of drones according to claim 2 is characterized in that: In step S41, the DependencyGraph class in the torch_pruning library is used in the YOLOv5s model to build a dependency graph of the model, and the forward propagation path of the model is built according to the input sample. The L1 strategy is used to calculate the pruning plan according to the weight matrix of the model. According to the obtained pruning plan, the model is pruned, and the pruned YOLOv5s model is fine-tuned, and the number of rounds of fine-tuning training is at least 100.

8. The lightweight method for counting wheat ears based on edge computing of unmanned aerial vehicles according to claim 7 is characterized in that: In the YOLOv5s model structure, the pruning plan is determined based on the weight matrix and L1 strategy of each convolutional layer.

9. The lightweight method for counting wheat ears based on edge computing of unmanned aerial vehicles according to claim 8, characterized in that: When executing the pruning plan, traverse each layer of the model, perform pruning operations according to the pruning plan, and set unnecessary parameters to zero. In the YOLOv5s model, use the pruning_plan.exec() method to perform pruning operations to prune model parameters.