A method for constructing a lightweight image recognition model of fruit tree pests

CN122597848APending Publication Date: 2026-08-18HUNAN NORMAL UNIVERSITY +2
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610640801.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2026-01-22
Filing Date
2026-05-11
Publication Date
2026-08-18

AI Technical Summary

Technical Problem

①标注数据稀缺且成本高:高性能目标检测模型训练通常依赖大量高质量带框标注数据,而农业害虫图像的采集与精确标注要求专业知识,例如种类辨识、发育阶段判定等,人工标注成本高且耗时

Benefits of technology

[0015] According to the technical solution of this application, a staged feature distillation is adopted instead of a one-time full distillation. For example, in the distillation training script, the activation of distillation terms is controlled according to the training rounds. In the early stage of training, only the distillation loss between high-level features of the teacher model and the student model is calculated. After the training reaches the preset rounds, feature distillation covering low, medium and high levels of the full feature set is introduced, thereby forming a staged knowledge transfer process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122597848A_ABST
    Figure CN122597848A_ABST
Patent Text Reader

Abstract

The present application relates to the field of intelligent pest identification and monitoring, and in particular to a method for constructing a lightweight image recognition model for fruit tree pests. The method divides the distillation process into different training stages, preferentially guiding the student model to learn high-level semantic information, and gradually introducing full-scale feature distillation in the later stage, while combining the exponential moving average weight smoothing mechanism to achieve the student model's detection performance close to the teacher model without increasing the network structure complexity and parameter size. This technical solution effectively solves the problems of unstable distillation training, feature mismatch and insufficient expression ability of lightweight models in the prior art, while improving the detection accuracy and generalization stability of lightweight models in complex agricultural pest scenes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of intelligent pest identification and monitoring, specifically to a method for constructing a lightweight image recognition model for fruit tree pests. Background Technology

[0002] Fruit tree yield and quality have long been seriously threatened by a variety of pests, whose larval damage is characterized by its concealment and similar morphology.

[0003] In recent years, computer vision and deep learning have seen rapid development in the field of agricultural pest identification and monitoring. Algorithms based on convolutional neural networks and single-stage / multi-stage detectors have been widely used in pest detection and field monitoring systems to achieve automated and quantifiable pest and disease intelligence. Meanwhile, to meet the real-time requirements of agricultural field operations and terminal deployment, researchers are also dedicated to developing lightweight target detection networks and accelerated inference schemes.

[0004] Although deep learning methods perform well in experimental settings, their application in real-world orchard scenarios still faces several key technical bottlenecks, including: ① Scarce and costly labeled data: Training high-performance object detection models typically relies on a large amount of high-quality bounding box labeled data. However, the acquisition and accurate labeling of agricultural pest images require specialized knowledge, such as species identification and developmental stage determination. Manual labeling is costly and time-consuming. To reduce labeling costs and increase data scale, semi-automatic / human-machine collaborative labeling, active learning, and semi-automatic annotation methods have been proposed and applied in data construction practices across various fields in recent years, significantly improving labeling efficiency and reducing manual workload.

[0005] ② Model Lightweighting and Performance Trade-offs: Deploying detection models in orchards or on edge devices such as mobile phones, drones, and embedded terminals requires both low inference speed and low resource consumption, without drastically sacrificing detection accuracy. To this end, researchers have invested a great deal of work in model structure design, distillation compression, quantization, and engineering optimization, and have demonstrated an improved path for balancing accuracy and efficiency in agricultural target detection.

[0006] ③ Application Potential of Distillation: Knowledge distillation is a model compression and knowledge transfer technique that aims to transfer knowledge from a complex large model (often called the "teacher model") to a small model ("student model"), enabling the small model to achieve the performance level of the large model while maintaining lower computational costs. Existing work has verified the speedup and accuracy preservation effects of distillation on edge-deployed models in agricultural scenarios (e.g., weed / disease / livestock recognition).

[0007] In summary, while existing research has provided various approaches to the automated identification of agricultural pests, a systematic, engineerable, and comprehensive solution that balances annotation costs, model lightweighting, and field robustness is still lacking for the specific application of major lepidopteran pests on fruit trees. Current technologies primarily focus on single-point improvements, such as structural optimization of a particular detector, a data augmentation method, or a single distillation strategy. However, end-to-end process research and engineering practice for "starting with a small amount of manual annotation, combining iterative semi-automatic annotation, and then training a lightweight detection model suitable for edge deployment through teacher-student distillation" is insufficient. This is precisely the technological gap and practical need that this invention aims to address. Summary of the Invention

[0008] The purpose of this invention is to provide a method for constructing a lightweight image recognition model for fruit tree pests.

[0009] The method for constructing a lightweight image recognition model for fruit tree pests according to the present invention includes the following steps: S1 Construction and Labeling of the Complete Dataset: Collect images of the target pests, perform detailed labeling on the selected images, and form a dataset containing labeled images of multiple species; S2 teacher model training, wherein the teacher model is a stage-based object detection network architecture based on multi-scale feature fusion, and the teacher model includes: Feature extraction module: Used to perform multi-layer convolution and downsampling processing on the input image to extract basic feature representations at different semantic levels. Multi-scale feature fusion module: Used to perform scale alignment and information fusion on feature maps from different levels to enhance the detection capability of targets of different sizes. Decoupled prediction head module: used to input the fused features into the classification branch and the bounding box regression branch respectively, so as to achieve decoupled output of target category prediction and spatial location prediction; S3 student model training and knowledge distillation utilizes the teacher model to transfer knowledge to the student model, wherein... The student model includes: The backbone feature extraction module is used to perform multi-layer convolution and downsampling processing on the input image, extract basic visual features, and form multi-level feature representations. Feature fusion module: Used to scale-align and fuse features from different levels to enhance the perception of pest targets of different sizes. Detection head module: Used to output target category prediction results and bounding box regression results based on fused features. Exponential moving average weight storage module: Used to exponentially weight and smooth the parameters of the Euclidean Student model during training to obtain model weights with better stability during the inference phase. The training and knowledge distillation of the student model include: S3.1 Student Model Initialization: Set training parameters for the student model and initialize the exponential moving average weight storage module to record the smoothing parameters of the student model during training. S3.2 Teacher Model Loading and Freezing: Load the weights of the trained teacher model, set the teacher model to inference mode, freeze all parameters so that it does not participate in backpropagation during training, and read the feature output layer indices of the teacher model at different depths. S3.3 Knowledge Distillation: During the training process, the following knowledge distillation tasks are activated collaboratively in stages: S3.3.1 In the early stages of training, feature distillation based on high-level feature groups is enabled to guide the student model in learning the overall semantic features of the target species, including: Feature layer alignment: Automatically analyze the multi-scale feature layers of the teacher model and the student model in the backbone network and feature fusion network, and match the high-level feature groups in the teacher model and the student model according to the layer depth, wherein, The high-level feature group refers to the high semantic layer features near the output end in the feature extraction process of the teacher model and the student model, which represent the overall morphology, category semantics, and global structural information of the target fruit tree pest. In the later stages of training, after a certain number of training epochs, full feature distillation is gradually introduced to enable the student model to obtain more refined multi-scale feature representation capabilities. Simultaneously, class distribution distillation and bounding box regression distillation are also enabled. The full feature set refers to a set of features at multiple different depth levels covering the feature extraction module and the multi-scale feature fusion module of the teacher model, and the backbone feature extraction module and the feature fusion module of the student model, including low-level texture information, mid-level structural information, and high-level semantic information. The category distribution distillation involves extracting the category confidence distribution for each image from the output of the teacher model, aligning it with the output category distribution of the student model, and calculating the difference between the category confidence distribution extracted by the teacher model and the category confidence distribution output by the student model. The bounding box regression distillation involves extracting the average bounding box position and scale information for each image from the teacher model's prediction results, comparing it with the student model's output, calculating the difference in box positions between the two, and enabling the student model to learn the teacher model's spatial discrimination ability for the target location. S3.3.3 Batch-level knowledge distillation: In each training batch, perform the following steps: (1) Register a feature extraction hook and activate it at the start of forward inference of the student model to capture multi-scale feature maps. (2) For the same batch of input images, perform synchronous forward inference of the teacher model and the student model to obtain the feature maps of the teacher model and the student model on their respective feature layers. (3) Feature distillation loss calculation: The difference between the teacher model and the student model on the multi-scale feature map is calculated using a loss function based on channel-weighted feature difference. Specifically, the distillation losses from feature distillation of the high-level feature group, feature distillation of the entire feature group, category distribution distillation, and bounding box regression distillation during the training phase are fused according to dynamic weights and added to the conventional model loss of the student model to form the total training loss. The distillation terms work synergistically to jointly constrain the student model's feature representation, category discrimination, and spatial localization capabilities. The student model described in S3.4 performs backpropagation and updates the weights, while simultaneously updating the smoothed weights in the exponential moving average weight storage module, so that they gradually approach the average convergence point of the training process. S3.5 Remove feature hooks and proceed to the next batch iteration. After distillation loss fusion, the system automatically removes hooks to avoid cross-batch interference and enters the next training iteration. S3.6 Model saving and distillation result output: After training is completed, the weights of the final student model are saved, and the smoothed weights in the exponential moving average weight storage module are saved as a deployable model.

[0010] The method for constructing a lightweight image recognition model for fruit tree pests according to the present invention includes the following steps: Data acquisition: Acquire images of the target pests; Initial manual fine annotation: The selected images are finely annotated to form a small-scale annotated dataset containing multiple species; Training of auxiliary annotation model: The auxiliary annotation model is a lightweight configuration mode. It uses the small-scale annotation dataset as input, randomly divides the small-scale annotation dataset into training set and validation set, loads pre-trained general image feature extraction weights, sets the initial learning rate, decay strategy and batch size, trains the auxiliary annotation model, and verifies the auxiliary annotation model after training is completed. Batch automatic annotation: Load the weights of the trained auxiliary annotation model for batch inference on unlabeled images, traverse the directory of unlabeled images, the auxiliary annotation model performs forward propagation according to the weights, and outputs a visualized image with annotation results; Correction and quality review of automatic annotation results: The visualized images with annotation results output by the batch automatic annotation step are corrected to obtain a dataset of annotated images containing multiple species.

[0011] The method for constructing a lightweight image recognition model for fruit tree pests according to the present invention includes the following steps in the S2 teacher model training step: S2.1 The dataset containing labeled images of multiple species is divided into a training set, a validation set, a category list, and image path metadata; S2.2 Initialize the teacher model, load initial weights, and set key training hyperparameters; S2.3 trains the teacher model, including: S2.3.1 Data Preprocessing: The preprocessed input image is then sent to the feature extraction module of the teacher model. S2.3.2 Forward Inference: The feature extraction module of the teacher model generates multi-scale feature maps, the multi-scale feature fusion module performs weighted fusion of features at different scales, and the decoupled prediction head module outputs classification scores and bounding box regression results. S2.3.3 Calculate the loss function. For each layer's output, calculate the classification loss, bounding box location loss, and distribution regression loss separately, and combine them with certain weights to form the total loss. S2.3.4 Backpropagation and Parameter Update: Based on the calculated total loss, backpropagation is performed to optimize and update the parameters of the teacher model. S2.3.5 Dynamic Learning Rate Adjustment: Gradually reduce the learning rate during training to promote stable model convergence, and S2.3.6 Model Persistence: Logs are recorded at the end of each training cycle, and the current model state is saved; when the performance of the validation set improves, it is automatically saved as a new best teacher model; S2.4 Validation and Performance Evaluation: After training, the teacher model is validated; and S2.5 Visualization and Result Generation: Read the original image from the validation phase of the teacher model, draw prediction boxes on the image, label the insect names, and output a visualization.

[0012] According to the method for constructing a lightweight image recognition model for fruit tree pests according to the present invention, in the step of initializing the teacher model in S2.2, the key training hyperparameters include input image size, training batch size, initial learning rate and learning rate descent strategy, optimizer type, weight decay coefficient, number of training rounds, and data augmentation strategy.

[0013] According to the method for constructing a lightweight image recognition model for fruit tree pests according to the present invention, in the step of S2.3.1 data preprocessing, the preprocessing includes normalizing, scaling and color perturbation of the input image.

[0014] According to the method for constructing a lightweight image recognition model for fruit tree pests according to the present invention, when performing the category distribution distillation, the category confidence distribution of each image is extracted from the output of the teacher model and aligned with the output category distribution of the student model. The difference between the category confidence distribution extracted by the teacher model and the category confidence distribution output by the student model is calculated using temperature-regulated Kullback-Leibler divergence. Beneficial technical effects:

[0015] According to the technical solution of this application, a staged feature distillation is adopted instead of a one-time full distillation. For example, in the distillation training script, the activation of distillation terms is controlled according to the training rounds. In the early stage of training, only the distillation loss between high-level features of the teacher model and the student model is calculated. After the training reaches the preset rounds, feature distillation covering low, medium and high levels of the full feature set is introduced, thereby forming a staged knowledge transfer process.

[0016] According to the proposed technical solution, instead of fixing the corresponding layer numbers of the teacher model and the student model, it captures multi-scale feature outputs through forward feature hooks and automatically matches the high-level semantic feature groups of the teacher model with the corresponding feature layers of the student model based on the relationship between network depth and semantic hierarchy, thereby avoiding invalid distillation caused by semantic mismatch.

[0017] According to the technical solution of this application, dynamic evolution of distillation weights is adopted, with non-fixed weights. The weights of the distillation loss are dynamically adjusted according to the training stage. In the early stage of training, the distillation constraint strength is reduced to ensure the autonomous convergence of the student model. In the middle and later stages, the distillation weights are gradually increased to enhance the knowledge transfer effect. At the same time, feature distillation (including feature distillation of high-level feature groups and feature distillation of the entire feature group), category distribution distillation, and bounding box regression distillation are weighted and fused in stages to achieve a balance between training stability and performance improvement.

[0018] According to the technical solution of this application, EMA collaborative stabilization is introduced in distillation training. During the knowledge distillation training process, an exponential moving average weight update mechanism is simultaneously introduced to smooth the parameters of the student model, thereby reducing gradient fluctuations caused by the difference between the outputs of the teacher model and the student model, and improving the stability of distillation training and the reliability of the inference stage.

[0019] According to the technical solution of this application, a multi-task distillation collaboration is adopted. In the later stage, feature distillation, category distribution distillation and bounding box regression distillation are activated simultaneously to achieve collaborative optimization of feature, classification and spatial localization capabilities, avoid performance bias caused by a single distillation signal, and thus improve the comprehensive detection capability of the lightweight model.

[0020] Therefore, the technical solution of this application, by introducing stage control logic, feature layer adaptive matching mechanism, multi-task distillation collaboration, dynamic scheduling of distillation weights, and EMA stabilization strategy into the training script, transforms the distillation process from a simple loss aggregation into a systematic training process tailored to the characteristics of lightweight object detection models. This process is not explicitly taught in existing general distillation implementations, thus demonstrating the inventiveness of this application. Attached Figure Description

[0021] Figure 1 A flowchart showing the method for constructing a lightweight image recognition model for fruit tree pests according to this application is displayed; Figure 2 Build a flowchart for the complete dataset. Detailed Implementation

[0022] Currently, there are two main technical challenges in agricultural applications: First, the labeling of pest datasets is costly and highly specialized. Fruit trees are mainly infested with a wide variety of lepidopteran pests, which are small in size and exhibit great morphological variation. Traditional labeling methods are labor-intensive and time-consuming, making it difficult to quickly build large-scale training sets. Second, field deployment is limited by hardware performance and there is a strong need for lightweight design. In orchards, lightweight devices such as mobile phones, drones, and agricultural machinery terminals are often used for real-time identification. While existing large models have high accuracy, their large parameters make it difficult to deploy them on these devices and achieve efficient inference.

[0023] In the context of agricultural pests where data is scarce and labeling costs are high, how can we quickly construct high-quality training datasets? The key technical challenges for achieving intelligent identification and monitoring of fruit tree pests are: how to make the target detection model lightweight and capable of real-time operation on edge devices while maintaining detection accuracy; and how to improve model training efficiency by combining semi-automatic annotation processes with knowledge distillation mechanisms. Therefore, it is necessary to develop lightweight detection models that require less computation, have faster inference speeds, and maintain accuracy close to that of larger models.

[0024] This invention proposes a systematic technical approach for agricultural scenarios, namely "semi-automatic annotation, high-precision teacher model training, and lightweight deployment of knowledge distillation," to solve the technical challenge of balancing data quality, model accuracy, and deployment cost using traditional methods.

[0025] Based on the above application requirements, this invention aims to simultaneously solve the three common problems in agricultural scenarios: insufficient annotation efficiency, insufficient detection accuracy, and insufficient deployment performance.

[0026] Based on the aforementioned design motivation, this invention proposes a semi-automated data annotation and model building technical solution for agricultural pest image data, to address the problems of high manual annotation costs, limited sample size, and insufficient model generalization ability in existing technologies. The technical solution of this application incorporates the following improvements compared to existing technologies.

[0027] According to the technical solution of this application, a semi-automatic annotation data production process is constructed: first, an auxiliary annotation model is trained based on a small amount of manually labeled data, then the model is used for the preliminary automatic detection of unlabeled images, and a manual rapid correction mechanism is introduced to realize a closed loop of "machine pre-annotation and manual review", which significantly improves annotation efficiency and data consistency.

[0028] According to the technical solution of this application, a high-precision teacher model is trained for knowledge extraction: after obtaining a high-quality training set, a high-precision teacher model is trained based on a high-performance detection framework. This model is used to provide stronger feature representation and detection capabilities, providing a knowledge source for subsequent lightweight models.

[0029] According to the technical solution of this application, a lightweight student model is constructed and knowledge distillation compression is performed: a small student model suitable for edge deployment is designed, and the detection characteristics of the teacher model are transferred to the student model through the knowledge distillation method, thereby reducing the number of parameters, improving the inference speed, and at the same time maintaining the accuracy as much as possible.

[0030] Ultimately, this invention achieves efficient data construction, high-precision teacher model training, knowledge distillation to quantify lightweight student models, and real-time deployment on edge devices, enabling automatic detection and monitoring of lepidopteran pests on fruit trees with high accuracy, low latency, and low computational dependence.

[0031] The technical solution of this application is described below with reference to the accompanying drawings.

[0032] like Figure 1 As shown, the method for constructing a lightweight image recognition model for fruit tree pests according to this application includes the following steps: Construct and label the complete dataset; Teacher model training; Student model training and knowledge distillation.

[0033] like Figure 2 As shown, the steps for constructing and labeling the complete dataset include the following: Data collection; Initial manual fine-grained annotation; Assisted annotation model training; Batch automatic annotation; Manual correction and quality review of automatically labeled results. Example 1: Constructing a lightweight image recognition model for fruit tree pests

[0034] Step 1: Data collection: Data sources include (1) Online public platforms: Search for images of target pests to ensure that the source is clear, the images are real, and have identifiable morphological features; (2) Laboratory photography: Take indoor microscopic or fixed background photos of pest specimens, covering different developmental stages such as adults and larvae, and control the lighting and background to obtain high-quality details; (3) Collect existing field survey, microscopic observation and trap images to enhance the model's ability to identify subtle features; (4) Photograph pests in natural habitats such as orchards and farmlands to obtain image samples in real environments.

[0035] Step 2: Initial Manual Fine-Grained Annotation: A small-scale, high-precision annotation set is manually constructed as the training basis for subsequent auxiliary annotation models. This includes: Sample selection: Select images from the collected data that are clear, have complete targets, and have obvious key morphological features; Expert annotation: The selected images are meticulously annotated by entomologists. The annotations require bounding boxes to fit the outer edge of the target, accurate classification, support for multiple targets in a single image, and output of annotation files in a uniform format. Dataset construction: A small-scale, high-quality labeled dataset containing multiple species is formed, with at least 30 high-quality labeled images for each pest species. Finally, a small-scale, high-quality labeled dataset containing multiple species is generated to assist in the initial training of the labeled model.

[0036] 3.1 Data Preparation: Use the high-quality finely labeled dataset from step 2 as input (e.g., 30 classes of finely labeled data); configure the dataset description file, including class names, image paths, annotation paths, etc.; randomly divide the training set and validation set to ensure class balance.

[0037] 3.2 Model Initialization: Load the model into lightweight configuration mode, including: fixing the input size to 640×640; loading pre-trained general image feature extraction weights; setting the initial learning rate, decay strategy, and batch size; and enabling data caching to improve training read efficiency.

[0038] 3.3 Training Process Optimization: The following strategies were adopted during the training process: ① Data augmentation modules were automatically enabled, including Mosaic stitching enhancement, color perturbation, scale adjustment, and random cropping. ② End-to-end optimized loss function was adopted, combining localization loss, classification loss, and scale loss to adapt the model to the small target characteristics of pests. ③ A dynamic learning rate decay mechanism was used (decaying from 0.001 to a final 0.01 × initial learning rate). ④ GPU-accelerated training was used (if applicable) to improve training speed.

[0039] During training, the following are automatically recorded: precision, recall, average detection error, loss curve, and optimal weights (based on the validation set).

[0040] 3.4 Model Validation: After training, perform independent validation: keep input size and augmentation strategy consistent; automatically output evaluation metrics (precision, recall, and overall detection evaluation); export the optimal model in deployment format for automatic annotation.

[0041] 4.1 Model Loading: The server loads the auxiliary annotation model weight file trained in step 3 from the preset path. This model serves as a pre-annotated model for batch inference on unannotated images.

[0042] 4.2 Input Data Directory Scanning: The server traverses the unlabeled image directory according to the set source_path. The system ensures that each image enters the inference queue, realizing large-scale batch processing capabilities.

[0043] 4.3 Model Inference and Box Generation: ① Image Preprocessing: The input image is automatically scaled to 640 × 640 resolution; aspect ratio is maintained, and edges are filled; data normalization is performed to improve model accuracy. ② Forward Inference: The model performs forward propagation based on the weight file, outputting the following for each candidate box: class prediction, confidence score, and coordinate information (x, y, w, h). ③ Post-processing: YOLO's built-in NMS (Non-Maximum Suppression) algorithm is used for: overlapping box filtering, low-confidence box filtering (<0.3), and the final detection result is output. This process is executed automatically without user intervention.

[0044] This step normalizes the coordinates (range 0-1); it is fully compatible with mainstream training frameworks; and it can be directly used for subsequent teacher model training.

[0045] 4.4 Automatic generation of visual annotation maps: The system automatically exports visual images with detection boxes, including: target location boxes, category labels, and confidence values, which can be used for quick manual review.

[0046] Objective: To review, revise, and confirm the batch annotation results generated in step 4, remove erroneous labels, and ensure that the final training set meets high-quality requirements.

[0047] Input data: Batch prediction results output by the auxiliary annotation model in step 4, including images, preliminary bounding boxes, and categories.

[0048] Use offline annotation tools for visual inspection and editing.

[0049] Operational Procedure: ① Batch import automatic annotation results: Import the predicted annotation files generated by the auxiliary annotation model along with the images into the annotation tool. ② Review the detection box positions for each image: Check if the bounding boxes accurately enclose the targets, adjust the offset boxes generated by the model (whether they are too large or too small), and delete samples with incorrect box positions or obvious positioning errors. ③ Verify the accuracy of the category labels: Compare with reference species characteristic data, standardize the category naming format, and correct samples with misclassified categories. ④ Supplement targets missed by the model: Manually add missing annotation boxes to ensure that all targets in the image are correctly labeled; verify each multi-target image individually. ⑤ Consistency and quality review: Perform a second check on the data by category to ensure that the bounding box size, annotation style, and category standards are consistent; delete severely blurry or noisy images unsuitable for training. ⑥ Export a high-quality training set: Establish a clear directory structure for the dataset (images / train, labels / train, etc.). Output: By mixing the manually annotated image data from step 2 with the batch semi-automatically annotated and corrected image data, a high-quality annotated dataset is obtained, which can be directly used for teacher model training in step 6. This dataset has higher accuracy than the automatically annotated results, and can significantly improve the performance of subsequent model training and the quality of actual deployment.

[0050] Objective: To construct a high-precision "teacher model" for knowledge distillation in a subsequent lightweight student model. This teacher model employs a one-stage target detection network architecture based on multi-scale feature fusion. The network includes a feature extraction module, a feature pyramid fusion module, and a decoupled prediction head module, enabling real-time and accurate detection of insect targets in input images. Its training process is as follows: 6.1 Data Preparation and Configuration Loading: Annotated data containing the target species are compiled into a unified data description file (e.g., YAML or JSON format), including metadata such as training set, validation set, category list, and image paths. The network structure configuration file of the teacher model is loaded from the model configuration library. This file defines: the backbone feature extraction network, the multi-scale feature fusion network, the decoupled detection head structure, activation functions, normalization strategies, and anchor box / no-anchor box settings. Pre-trained weights from a general dataset are loaded as initialization parameters to improve convergence speed and generalization performance.

[0051] 6.2 Model Initialization and Hyperparameter Setting: When initializing the teacher model, set the following key training hyperparameters: input image size (e.g., 640×640 or 768×768), training batch size, initial learning rate and learning rate descent strategy (e.g., cosine annealing), optimizer type (e.g., AdamW or SGD), weight decay coefficient, number of training epochs, and data augmentation strategies (random flipping, color perturbation, mixed augmentation, etc.). Among these, multi-scale augmentation (e.g., Mosaic, MixUp) can effectively improve the sample diversity of small insect targets.

[0052] 6.3 Teacher Model Training Process: ① Data Preprocessing: Input images are normalized, scaled, and color-dithered before being fed into the network. Label boxes are simultaneously scaled and converted to the format required by the model. ② Forward Inference: The model's feature extraction module generates multi-scale feature maps, and the feature fusion module performs weighted fusion of features at different scales. The classification score and bounding box regression results are then output through a decoupled detection head. ③ Loss Function Calculation: For each layer's output, the following losses are calculated: classification loss (e.g., Focal Loss or BCE), bounding box position loss (e.g., IoU / GIoU / CIoU), and distribution regression loss (e.g., DFL). The losses from multiple components are combined with certain weights to form the total loss, which is used to update the gradient. ④ Backpropagation and Parameter Update: Based on the calculated total loss, backpropagation is performed to update the model parameters through the optimizer. ⑤ Dynamic Learning Rate Adjustment: During training, the learning rate is gradually reduced according to a strategy to promote stable model convergence. ⑥ Model Persistence: Logs are recorded after each training cycle, and the current model state is saved; when the validation set performance improves, it is automatically saved as a new best teacher model.

[0053] 6.4 Validation and Performance Evaluation: After training, the teacher model undergoes systematic validation, including: (1) Perform inference on the validation set and calculate metrics such as mAP (different IoU thresholds), Precision, and Recall; (2) Use Test-Time Enhancement (TTA) to improve evaluation stability; (3) Save the detection visualization results, including the target bounding box and the corresponding category label; (4) Compare the model output with the manually labeled data to confirm the learning effect of the model in the small target insect scene; ⑤ The model weights with the best performance are used as the "teacher model" and then proceed to the knowledge distillation stage in the next step.

[0054] 6.5 Visualization and Result Generation: The system supports rendering Chinese labels for verification results, including: Read the original image from the verification phase, draw prediction boxes on the image, label the insect names using Chinese fonts, and save the visualization to the output directory with the original image name.

[0055] This step aims to transfer knowledge from a high-precision teacher model to a lightweight student model, using the obtained optimal teacher model to transfer knowledge to the lightweight student model, enabling the student model to achieve detection accuracy close to that of the teacher model while maintaining inference speed. The student model includes: The backbone feature extraction module is used to perform multi-layer convolution and downsampling processing on the input image, extract basic visual features, and form multi-level feature representations. Feature fusion module: used to scale-align and fuse features from different levels to enhance the perception of pest targets of different sizes; Detection head module: used to output target category prediction results and bounding box regression results based on fused features; Exponential moving average weight storage module: Used to exponentially weight and smooth the student model parameters during training to obtain model weights with better stability during the inference phase. The student model's backbone feature extraction module and feature fusion module functionally correspond to the teacher model, but its network size and number of parameters are smaller. The student model training and knowledge distillation include: 7.1 Student Model Initialization: Set training parameters for the student model and initialize the exponential moving average weight storage module to record the smoothing parameters of the student model during training. 7.2 Teacher Model Loading and Freezing: Load the weights of the trained teacher model, set the teacher model to inference mode, freeze all parameters so that it does not participate in backpropagation during training, and read the feature output layer indices of the teacher model at different depths. 7.3 Knowledge distillation: During the training process, feature distillation, category distribution distillation, and bounding box regression distillation are collaboratively enabled in stages, including the following aspects: 7.3.1 In the early stages of training, feature distillation based on high-level feature groups is primarily employed to guide the student model in quickly learning the overall semantic features of the target species, including: Feature layer alignment: Automatically analyze the multi-scale feature layers of the teacher model and the student model in the backbone network and feature fusion network, and match the high-level feature groups and full feature groups in the teacher model and the student model according to the layer depth. The high-level feature group refers to several high semantic layer features near the output end in the feature extraction process of the teacher model and the student model, which mainly represent the overall shape, category semantics and global structural information of the target. 7.3.2 In the later stages of training, after a certain number of training rounds, full feature set distillation is gradually introduced to enable the student model to obtain more refined multi-scale feature representation capabilities. Simultaneously, class distribution distillation and bounding box regression distillation are enabled to allow the student model to obtain refined class discrimination and spatial localization capabilities while maintaining convergence stability. The full feature set refers to a set of features at multiple different depth levels covering the feature extraction module and multi-scale feature fusion module of the teacher model, and the backbone feature extraction module and feature fusion module of the student model. This set includes low-level texture information, mid-level structural information, and high-level semantic information. The category distribution distillation involves extracting the category confidence distribution for each image from the output of the teacher model and aligning it with the output category distribution of the student model. The difference between the teacher and student distributions is then calculated using temperature-regulated Kullback-Leibler divergence. The bounding box regression distillation involves extracting the average bounding box position and scale information for each image from the teacher model's prediction results and comparing it with the student model's output. The difference in box positions between the two is calculated using the mean squared error, enabling the student model to learn the teacher model's spatial discrimination ability regarding the target location. 7.3.3 Batch-level knowledge distillation: In each training batch, perform the following steps: (1) Register feature extraction hooks: When the forward inference of the student model begins, activate the feature extraction hooks to capture multi-scale feature maps. (2) For the same batch of input images, perform synchronous forward inference of the teacher model and the student model to obtain the feature maps of the two models on their respective feature layers. (3) Feature distillation loss calculation: The differences between teachers and students on multi-scale feature maps are calculated using a loss function based on channel-weighted feature difference. In this training process, the feature distillation losses of the high-level feature group, the full feature group, the category distribution distillation, and the bounding box regression distillation are dynamically weighted and fused together. This fusion is then added to the student model's conventional model loss to form the total training loss. The distillation weights are dynamically adjusted throughout the training phase, and the various distillation terms work synergistically to constrain the student model's feature representation, category discrimination, and spatial localization capabilities. This avoids performance bias caused by a single distillation signal, allowing the feature distillation weights to gradually increase from low to high and gradually converge in the later stages of training to ensure training stability. 7.4 The student model performs backpropagation and updates the weights, while simultaneously updating the smoothed weights in the exponential moving average weight storage module, so that they gradually approach the average convergence point of the training process. 7.5 Remove feature hooks and proceed to the next batch iteration. After distillation loss fusion, the system automatically removes hooks to avoid cross-batch interference and proceeds to the next training iteration. 7.6 Model Saving and Distillation Result Output: After training is complete, the final student model weights are saved, and the smoothed weights are saved as a deployable model for stable output during the inference phase. Training logs are generated, including curves of various types of distillation loss as a function of epochs, validation set mAP, precision and recall metrics, etc.

[0056] This application addresses the issues of teacher-student structural differences, training stability, and the limited multi-scale feature representation capabilities of lightweight models in object detection tasks. It proposes a joint distillation training method that incorporates staged feature distillation, adaptive feature layer matching, multi-task distillation collaboration, dynamic weight scheduling, and EMA stabilization.

[0057] This method divides the distillation process into different training stages, prioritizing the learning of high-level semantic information by the student model, and gradually introducing full-scale feature distillation in the later stages. Simultaneously, it incorporates an exponential moving average (EMA) weight smoothing mechanism, enabling the student model to achieve detection performance close to that of the teacher model without increasing network complexity or parameter size. This technical solution effectively solves the problems of unstable distillation training, feature mismatch, and insufficient expressive power of lightweight models in existing technologies, while improving the detection accuracy and generalization stability of lightweight models in complex agricultural pest scenarios. Example 2: Model Packaging and Mobile App Deployment

[0058] The lightweight student model trained through distillation balances inference speed and detection accuracy, making it suitable for mobile deployment. This step aims to engineer and package the aforementioned trained lightweight student model so that it can run in real-time on mobile devices (Android) for rapid identification of major lepidopteran pests on fruit trees in the field. This step includes model format conversion, inference engine construction, mobile API design, application interface module design, performance optimization, and local acceleration.

[0059] The trained detection model is converted from a dynamic graph to a static execution graph, which unifies the model input size and preprocessing method, solidifies the inference process, and avoids the additional overhead caused by the dynamic graph at runtime.

[0060] Export the model to a cross-platform compatible intermediate format (such as intermediate formats supported by ONNX or NNAPI) for easy loading on different devices. Convert it to a mobile-specific model, and for Android devices, convert it to a lightweight computation graph format (such as a customized operator model package) for model quantization and pruning.

[0061] To enable the model to run in real time on mobile devices, a lightweight edge inference engine was built, which includes: The input preprocessing submodule performs image scaling and normalization; adjusts channel arrangement; and automatically adapts to different mobile phone camera image formats (NV21, RGB, YUV).

[0062] The inference core module schedules mobile computing units (CPU, GPU, DSP, or NPU); it uses asynchronous queues to execute inference, avoiding UI lag; and it supports a real-time detection mode with a batch size of 1.

[0063] The post-processing module includes Non-Maximum Suppression (NMS), a small target enhancement strategy, multi-class confidence filtering, and results encapsulated in a unified JSON format for return to the front end.

[0064] Real-time detection module: Opens the camera stream; sends the image frame by frame to the inference engine; selects detected pests in real time and displays the category name; displays the confidence level (percentage).

[0065] Biological dictionary module: Linked to the detection results; click on the recognition results to view the pest name, morphological characteristics, damage characteristics, occurrence patterns, control measures, etc.

[0066] AI Question Answering Module: Integrates with mainstream large language model APIs to enable interactive question answering in chat boxes.

[0067] The above embodiments are only used to understand the technical solutions of this application and do not limit the scope of protection of this application.

Claims

1. A method for constructing a lightweight image recognition model for fruit tree pests, characterized in that, The method includes the following steps: S1 Construction and Labeling of the Complete Dataset: Collect images of the target pests, perform detailed labeling on the selected images, and form a dataset containing labeled images of multiple species; S2 teacher model training, wherein the teacher model is a stage-based object detection network architecture based on multi-scale feature fusion, and the teacher model includes: Feature extraction module: Used to perform multi-layer convolution and downsampling processing on the input image to extract basic feature representations at different semantic levels. Multi-scale feature fusion module: Used to perform scale alignment and information fusion on feature maps from different levels to enhance the detection capability of targets of different sizes. Decoupled prediction head module: used to input the fused features into the classification branch and the bounding box regression branch respectively, so as to achieve decoupled output of target category prediction and spatial location prediction; S3 student model training and knowledge distillation utilizes the teacher model to transfer knowledge to the student model, wherein... The student model includes: The backbone feature extraction module is used to perform multi-layer convolution and downsampling processing on the input image, extract basic visual features, and form multi-level feature representations. Feature fusion module: Used to scale-align and fuse features from different levels to enhance the perception of pest targets of different sizes. Detection head module: Used to output target category prediction results and bounding box regression results based on fused features. Exponential moving average weight storage module: Used to exponentially weight and smooth the parameters of the Euclidean Student model during training to obtain model weights with better stability during the inference phase. The training and knowledge distillation of the student model include: S3.1 Student Model Initialization: Set training parameters for the student model and initialize the exponential moving average weight storage module to record the smoothing parameters of the student model during training. S3.2 Teacher Model Loading and Freezing: Load the weights of the trained teacher model, set the teacher model to inference mode, freeze all parameters so that it does not participate in backpropagation during training, and read the feature output layer indices of the teacher model at different depths. S3.3 Knowledge Distillation: During the training process, the following knowledge distillation tasks are activated collaboratively in stages: S3.3.1 In the early stages of training, feature distillation based on high-level feature groups is enabled to guide the student model in learning the overall semantic features of the target species, including: Feature layer alignment: Automatically analyze the multi-scale feature layers of the teacher model and the student model in the backbone network and feature fusion network, and match the high-level feature groups in the teacher model and the student model according to the layer depth, wherein, The high-level feature group refers to the high semantic layer features near the output end in the feature extraction process of the teacher model and the student model, which represent the overall morphology, category semantics, and global structural information of the target fruit tree pest. In the later stages of training, after a certain number of training epochs, full feature distillation is gradually introduced to enable the student model to obtain more refined multi-scale feature representation capabilities. Simultaneously, class distribution distillation and bounding box regression distillation are also enabled. The full feature set refers to a set of features at multiple different depth levels covering the feature extraction module and the multi-scale feature fusion module of the teacher model, and the backbone feature extraction module and the feature fusion module of the student model, including low-level texture information, mid-level structural information, and high-level semantic information. The category distribution distillation involves extracting the category confidence distribution for each image from the output of the teacher model, aligning it with the output category distribution of the student model, and calculating the difference between the category confidence distribution extracted by the teacher model and the category confidence distribution output by the student model. The bounding box regression distillation involves extracting the average bounding box position and scale information for each image from the teacher model's prediction results, comparing it with the student model's output, calculating the difference in box positions between the two, and enabling the student model to learn the teacher model's spatial discrimination ability for the target location. S3.3.3 Batch-level knowledge distillation: In each training batch, perform the following steps: (1) Register a feature extraction hook and activate it at the start of forward inference of the student model to capture multi-scale feature maps. (2) For the same batch of input images, perform synchronous forward inference of the teacher model and the student model to obtain the feature maps of the teacher model and the student model on their respective feature layers. (3) Feature distillation loss calculation: The difference between the teacher model and the student model on the multi-scale feature map is calculated using a loss function based on channel-weighted feature difference. Specifically, the distillation losses from feature distillation of the high-level feature group, feature distillation of the entire feature group, category distribution distillation, and bounding box regression distillation during the training phase are fused according to dynamic weights and added to the conventional model loss of the student model to form the total training loss. The distillation terms work synergistically to jointly constrain the student model's feature representation, category discrimination, and spatial localization capabilities. The student model described in S3.4 performs backpropagation and updates the weights, while simultaneously updating the smoothed weights in the exponential moving average weight storage module, so that they gradually approach the average convergence point of the training process. S3.5 Remove feature hooks and proceed to the next batch iteration. After distillation loss fusion, the system automatically removes hooks to avoid cross-batch interference and enters the next training iteration. S3.6 Model saving and distillation result output: After training is completed, the weights of the final student model are saved, and the smoothed weights in the exponential moving average weight storage module are saved as a deployable model.

2. The method for constructing a lightweight image recognition model for fruit tree pests according to claim 1, characterized in that, The steps for constructing and labeling the complete dataset include the following: Data acquisition: Acquire images of the target pests; Initial manual fine annotation: The selected images are finely annotated to form a small-scale annotated dataset containing multiple species; Training of auxiliary annotation model: The auxiliary annotation model is a lightweight configuration mode. It uses the small-scale annotation dataset as input, randomly divides the small-scale annotation dataset into training set and validation set, loads pre-trained general image feature extraction weights, sets the initial learning rate, decay strategy and batch size, trains the auxiliary annotation model, and verifies the auxiliary annotation model after training is completed. Batch automatic annotation: Load the weights of the trained auxiliary annotation model for batch inference on unlabeled images, traverse the directory of unlabeled images, the auxiliary annotation model performs forward propagation according to the weights, and outputs a visualized image with annotation results; Correction and quality review of automatic annotation results: The visualized images with annotation results output by the batch automatic annotation step are corrected to obtain a dataset of annotated images containing multiple species.

3. The method for constructing a lightweight image recognition model for fruit tree pests according to claim 1, characterized in that, The training steps of the S2 teacher model include the following steps: S2.1 The dataset containing labeled images of multiple species is divided into a training set, a validation set, a category list, and image path metadata; S2.2 Initialize the teacher model, load initial weights, and set key training hyperparameters; S2.3 trains the teacher model, including: S2.3.1 Data Preprocessing: The preprocessed input image is then sent to the feature extraction module of the teacher model. S2.3.2 Forward Inference: The feature extraction module of the teacher model generates multi-scale feature maps, the multi-scale feature fusion module performs weighted fusion of features at different scales, and the decoupled prediction head module outputs classification scores and bounding box regression results. S2.3.3 Calculate the loss function. For each layer's output, calculate the classification loss, bounding box location loss, and distribution regression loss separately, and combine them with certain weights to form the total loss. S2.3.4 Backpropagation and Parameter Update: Based on the calculated total loss, backpropagation is performed to optimize and update the parameters of the teacher model. S2.3.5 Dynamic Learning Rate Adjustment: Gradually reduce the learning rate during training to promote stable model convergence, and S2.3.6 Model Persistence: Logs are recorded at the end of each training cycle, and the current model state is saved; when the performance of the validation set improves, it is automatically saved as a new best teacher model; S2.4 Validation and Performance Evaluation: After training, the teacher model is validated; and S2.5 Visualization and Result Generation: Read the original image from the validation phase of the teacher model, draw prediction boxes on the image, label the insect names, and output a visualization.

4. The method for constructing a lightweight image recognition model for fruit tree pests according to claim 3, characterized in that, In the step of initializing the teacher model in S2.2, the key training hyperparameters include input image size, training batch size, initial learning rate and learning rate descent strategy, optimizer type, weight decay coefficient, number of training rounds, and data augmentation strategy.

5. The method for constructing a lightweight image recognition model for fruit tree pests according to claim 3, characterized in that, In step S2.3.1, data preprocessing includes normalizing, scaling, and color perturbation of the input image.

6. The method for constructing a lightweight image recognition model for fruit tree pests according to claim 1, characterized in that, During the class distribution distillation, the class confidence distribution of each image is extracted from the output of the teacher model and aligned with the output class distribution of the student model. The difference between the class confidence distribution extracted by the teacher model and the class confidence distribution output by the student model is calculated using temperature-regulated Kullback-Leibler divergence.