Knowledge distillation-based lightweight insect identification method and customs real-time universal equipment

By employing a lightweight insect identification method based on knowledge distillation, the problems of low insect identification efficiency and weak cross-device generalization ability of the model at customs ports are solved, enabling real-time insect identification and efficient inspection on edge devices, and applicable to general customs equipment.

CN120997882APending Publication Date: 2025-11-21中国电子口岸数据中心黄埔分中心

Patent Information

Application Number
CN202511139546.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-14
Publication Date
2025-11-21

AI Technical Summary

Technical Problem

Existing insect identification technologies suffer from low efficiency, high subjectivity, and a scarcity of expert resources at customs ports. Furthermore, deep learning-based models have a large number of parameters and are computationally complex, making them difficult to run in real time on edge devices. They also have weak cross-device generalization capabilities and cannot meet the real-time judgment requirements in environments without or with weak networks.

Method used

A lightweight insect identification method based on knowledge distillation is adopted. The image input processing module performs local preprocessing, and a lightweight student model is used for local inference. The model includes a front-end convolution module, a patch embedding module, a local self-attention mechanism module, and a fully connected classification output module. The top-k candidate insect species and their confidence scores are output. The lightweight student model is obtained from the teacher model through knowledge distillation.

Benefits of technology

It enables real-time insect identification in port environments with no or weak netting, improves the accuracy of identifying morphologically similar species, reduces reliance on expert resources, supports immediate judgment and efficient inspection, and is applicable to general customs equipment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120997882A_ABST
    Figure CN120997882A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of insect image recognition, and discloses a lightweight insect recognition method based on knowledge distillation, which comprises the following steps: carrying out local preprocessing on an insect image to be recognized to obtain a preprocessed image; performing feature extraction and channel expansion on the preprocessed image to obtain a convolution feature map; dividing the convolutional feature map into a plurality of image blocks with fixed sizes, and mapping each image block into a corresponding Token to obtain a Token sequence for a local self-attention mechanism; applying self-attention to local regions of the Token sequence for the local self-attention mechanism to model a global relationship of the local regions in the image to obtain a Token sequence for classification; the Token sequences used for classification are converted and fused into global image representation, and softmax probability vectors corresponding to candidate insect species are output; the softmax probability vectors are processed in a descending order, the first k categories are selected as candidate results, a top-k candidate list is output, and local lightweight insect recognition processing can be achieved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of insect image recognition, in particular to a lightweight insect identification method based on knowledge distillation and a customs real-time general device. BACKGROUND

[0002] With the rapid development of globalization trade, the demand for pest quarantine of imported goods and carried objects at customs ports has increased dramatically.

[0003] Traditional insect identification mainly relies on manual visual identification or laboratory microscopic observation, which has problems such as low efficiency, strong subjectivity, and scarcity of expert resources. In recent years, image recognition technology based on deep learning has been introduced into this field, but still faces the following key bottlenecks: Existing high-precision identification models (such as ResNet, VGG) have large parameter quantity and complex calculation, which makes it difficult to run in real time on edge devices (such as customs Pad, portable microscope terminal). Relying on cloud inference leads to high network delay, which cannot meet the immediate determination needs in the port environment without / weak network. Insect identification relies on fine anatomical structures such as wing veins and antennae, and the traditional convolutional network has limited ability to perceive local features, resulting in high misjudgment rate for similar species (such as mimic insects). The resolution and color format of images collected by different terminals differ significantly, and there is a lack of unified preprocessing mechanism, resulting in weak model cross-device generalization ability.

[0004] Therefore, it is necessary to provide a lightweight insect identification method based on knowledge distillation and a customs real-time general device to solve at least one of the above problems. SUMMARY

[0005] Therefore, it is necessary to provide a lightweight insect identification method based on knowledge distillation and a customs real-time general device to solve at least one of the above problems.

[0006] The first aspect of the present application provides a lightweight insect identification method based on knowledge distillation, characterized in that it comprises: performing local preprocessing on the insect image to be identified by an image input processing module to obtain a preprocessed image; performing local inference on the preprocessed image input by a lightweight student model to output top-k candidate insect species and corresponding confidence; The lightweight student model is obtained by knowledge distillation from a teacher model, and the local inference includes feature extraction and channel expansion of the preprocessed image by a front-end convolution module to obtain a convolution feature map; the convolution feature map is divided into a plurality of fixed-size image blocks by a Patch Embedding module, and each image block is mapped to a corresponding Token to obtain a Token sequence for local self-attention mechanism; the local self-attention mechanism module applies self-attention to the local region of the Token sequence for local self-attention mechanism to model the global relationship of each local region in the image, and obtains a Token sequence for classification; the Token sequence for classification is converted and fused into a global image representation by a fully connected classification output module, and a Softmax probability vector corresponding to the candidate insect species is output; the Softmax probability vector is sorted in descending order by a candidate output generation module, the top-k categories are selected as candidate results, and a top-k candidate list is output, wherein the top-k candidate list includes confidence degrees corresponding to the top-k candidate insect species.

[0007] In some embodiments, in the step of obtaining the lightweight student model by knowledge distillation from the teacher model, the following steps are included: The lightweight student model is optimized by a joint loss function composed of KL divergence and cross-entropy, and the expression of the joint loss function is: ; wherein, is the corresponding output of the lightweight student model according to the input image, is the softmax probability vector output by the teacher model according to the input image, KL is the Kullback-Leibler divergence, CE is the cross-entropy loss function, y is the true label of the image, and 0.7≤α≤0.9.

[0008] In some embodiments, the probability softening processing is performed on the output of the teacher model based on a temperature parameter before calculating the KL divergence, and the probability softening processing is expressed in a normalized form as: ; wherein, is the original prediction output of the teacher model, j is the index of the category, represents the jth category, and the value range is equal to the number of categories, is the original probability output of the teacher model on the jth category, T is the temperature parameter, exp represents the exponential operation function with the natural constant e as the base, which is used to map the input real number to a positive number, and the numerical value increases exponentially with the increase of the input.

[0009] In some embodiments, the Softmax probability vector is represented as: ; wherein N is the number of all supported identified species, Pi represents the confidence of the i-th supported identified species; i represents the i-th supported identified species; The top-k candidate list is represented as: ; wherein, is the class index of the i-th largest probability after sorting, is the corresponding confidence.

[0010] In some embodiments, the feature extraction and channel expansion of the preprocessed image by the front-end convolution module include: Taking the preprocessed image as the initial input, sequentially performing feature extraction and channel expansion through three layers of depth separable convolution blocks, the output of the previous depth separable convolution block being the input of the next depth separable convolution block, the depth separable convolution block including a convolution that separately performs 3x3 convolution on each input channel without channel fusion, and a convolution that linearly combines each channel to realize feature interaction and channel expansion; wherein, after each layer of depth separable convolution block, BatchNorm and GELU activation are connected, and the tensor dimension of the finally output convolution feature map is: X0∈R 1×128×H′×W′ .

[0011] In some embodiments, the division of the convolution feature map into a plurality of fixed-size image blocks by the Patch Embedding module, and the mapping of each image block into a corresponding Token to obtain a Token sequence for local self-attention mechanism include: dividing the convolution feature map into P image blocks through flattening and rearrangement operations, wherein P is the image block set; mapping each image block into a Token using a linear mapping layer, the Token being a d-dimensional embedding vector; obtaining a Token sequence for local self-attention mechanism, the Token sequence for local self-attention mechanism being represented as: ; wherein, t i represents the i-th Token.

[0012] ​​In some embodiments, the local region of the Token sequence for local self-attention mechanism is subjected to self-attention by the local self-attention mechanism module to model the global relationship of each local region in the image, and a Token sequence for classification is obtained, comprising: The local Token region of the Token sequence for local self-attention mechanism is subjected to self-attention by a two-layer lightweight Transformer encoder, and a Token sequence for classification is obtained; Wherein, the self-attention of the local Token region of the Token sequence for local self-attention mechanism comprises: Each layer of the Transformer encoder respectively performs multi-head self-attention calculation, feedforward network processing, residual connection and layer normalization processing on the input, and finally the local self-attention mechanism module outputs the Token sequence for classification; Wherein, the Token sequence for classification is represented as: ; The multi-head self-attention calculation is represented as: ; Q, K, V are obtained by linear mapping of input Token, h=2 Attention Heads are adopted, and the dimension of each Head is d / h; The feedforward network is represented as: ; .

[0013] In some embodiments, the Token sequence for classification is converted and fused into a global image representation by the fully connected classification output module, and a softmax probability vector corresponding to the candidate insect species is output, comprising: All Tokens of the Token sequence for classification are aggregated by Token Pooling using mean pooling to obtain an image global representation vector; The image global representation vector is processed by a two-layer fully connected classifier to determine the category of the candidate insect species and the corresponding confidence score; Based on the category of the candidate insect species and the corresponding confidence score, a softmax probability vector is output; Wherein, the image global representation vector is represented as: ; The fully connected classifier is represented as: ; The softmax probability vector is represented as: ; , N represents the number of categories; wherein, in the knowledge distillation stage, the Softmax probability vector is used for distillation alignment with the teacher model output.

[0014] In some embodiments, before the local preprocessing of the to-be-identified insect image by the image input processing module to obtain the preprocessed image, it further includes obtaining the to-be-identified insect image; and / or, the local preprocessing includes scaling or cropping the to-be-identified insect image of any resolution to a uniform input size in proportion; normalizing the image pixel value to the range of [0, 1] or [-1, 1]; changing the format of the image from HxWxN to NxHxW; constructing a standard tensor through NumPy and PyTorch backend; and / or, the lightweight student model is obtained by knowledge distillation from the teacher model, including sending the same input image into the frozen teacher model and the to-be-trained lightweight student model to obtain the corresponding Softmax probability vector and ; calculating the weighted total loss of KL divergence and cross-entropy, and only using the weighted total loss as the joint loss function to backpropagate to all parameters of the lightweight student model; after stable convergence in training, exporting the lightweight student model weight in a deployment format to adapt to the local inference environment of a mobile device; wherein, during the training process, the teacher model does not participate in parameter update at all, and only serves as a source of guidance signal; and / or, the training process of the teacher model includes: selecting a MobileNet model as the model structure of the teacher model; using multiple insect images obtained by the customs laboratory as a data set, and using standard classification labels at the image level for supervised learning; using cross-entropy as the loss function during training, combining the Adam optimizer and introducing the Warm-up and learning rate decay strategy for optimization; until the accuracy of the teacher model on the validation set is improved to a Top-1 accuracy rate of not less than 90%, and the training is completed.

[0015] The second aspect of the present application provides a customs real-time general device, comprising: an image input processing module for local preprocessing of a to-be-identified insect image to obtain a preprocessed image; a lightweight student model obtained by knowledge distillation from a teacher model, the lightweight student model comprising: a front-end convolution module for feature extraction and channel expansion of the preprocessed image to obtain a convolution feature map; a Patch Embedding module, configured to divide the convolution feature map into a plurality of fixed-size image blocks, and map each of the image blocks into a corresponding Token, to obtain a Token sequence for local self-attention mechanism; a local self-attention mechanism module, configured to apply self-attention to a local region of the Token sequence for local self-attention mechanism, to model the global relationship of each local region in the image, and obtain a Token sequence for classification; a fully connected classification output module, configured to convert and fuse the Token sequence for classification into a global image representation, and output a Softmax probability vector corresponding to the candidate insect species; a candidate output generation module, configured to perform descending order sorting on the Softmax probability vector, select the top-k categories as candidate results, and output a top-k candidate list, the top-k candidate list including the confidence of the top-k candidate insect species.

[0016] The present application has the following advantages: 1. The present application solves the problem of weak generalization ability by local preprocessing of the insect image to be recognized through an image input processing module, which obtains a preprocessed image.

[0017] 2. The present application uses a lightweight student model to perform local inference on the preprocessed image, which is obtained by knowledge distillation from a teacher model. The local inference includes feature extraction and channel expansion of the preprocessed image through a front-end convolution module to obtain a convolution feature map; the convolution feature map is divided into a plurality of fixed-size image blocks through a Patch Embedding module, and each of the image blocks is mapped into a corresponding Token to obtain a Token sequence for local self-attention mechanism; self-attention is applied to a local region of the Token sequence for local self-attention mechanism through a local self-attention mechanism module to model the global relationship of each local region in the image, and obtain a Token sequence for classification; the Token sequence for classification is converted and fused into a global image representation through a fully connected classification output module, and a Softmax probability vector corresponding to the candidate insect species is output; the Softmax probability vector is sorted in descending order through a candidate output generation module, the top-k categories are selected as candidate results, and a top-k candidate list is output, the top-k candidate list including the confidence of the top-k candidate insect species. The lightweight student model is used to realize insect recognition, and high-precision identification models with large parameter quantity and complex calculation are no longer needed, which are difficult to run in real time on edge devices.

[0018] 3. The lightweight student model of the present application is obtained by knowledge distillation from the teacher model, and the local self-attention mechanism module of the lightweight student model applies self-attention to the local area of the Token sequence for local self-attention mechanism to model the global relationship of each local area in the image, and the perception ability of local features is high, and the misjudgment rate of similar species (such as mimic insects) is low.

[0019] 4. The present application realizes real-time insect species identification through local inference of the lightweight student model, and can meet the instant judgment demand in the port without network / weak network environment. BRIEF DESCRIPTION OF DRAWINGS

[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or prior art description will be briefly introduced below. Obviously, the drawings in the following description are only embodiments of the present application, and those skilled in the art can obtain other drawings of embodiments according to these drawings without creative labor.

[0021] Figure 1 The step flow chart of the lightweight insect identification method based on knowledge distillation provided for the embodiments of the present application.

[0022] Figure 2 The step flow chart of the local inference on the pre-processed image input provided for the embodiments of the present application; Figure 3 The comparison flowchart of the lightweight model distillation method, the insect image identification method, and the running method on the general terminal device provided for the embodiments of the present application; Figure 4 The network structure diagram of the lightweight academic model provided for the embodiments of the present application; Figure 5 The schematic diagram of the real-time general device of the customs provided for the embodiments of the present application. DETAILED DESCRIPTION

[0023] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and easy to understand, the specific embodiments of the present application will be described in detail below with reference to the drawings. In the following description, a lot of specific details are set forth in order to facilitate a full understanding of the present application. However, the present application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar improvements without departing from the connotation of the present application, therefore the present application is not limited by the specific embodiments disclosed below.

[0024] In the description of the application, it should be understood that the orientation or positional relationship indicated by terms such as "central", "longitudinal", "lateral", "length", "width", "thickness", "upper", "lower", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer", "clockwise", "counterclockwise", "axial", "radial", "circumferential" and the like is based on the orientation or positional relationship shown in the drawings, and is only for the purpose of facilitating the description of the application and simplifying the description, and therefore cannot be understood as indicating or implying that the device or element referred to must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as limiting the application.

[0025] In addition, the terms "first", "second", "third", etc. are used only for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined with "first", "second", etc. can explicitly or implicitly include at least one of the features. In the description of the application, the meaning of "a plurality of" is at least two, such as two, three, etc., unless otherwise explicitly specified and limited.

[0026] In the present application, unless otherwise explicitly specified and limited, the terms "mounting", "connection", "connection", "fixing" and the like should be understood in a broad sense, for example, it can be fixedly connected, or it can be detachably connected, or it can be integrated; it can be mechanically connected, or it can be electrically connected; it can be directly connected, or it can be indirectly connected through an intermediate medium; it can be the internal communication of two elements or the interaction relationship between two elements, unless otherwise explicitly limited. For those skilled in the art, the specific meaning of the above terms in the present application can be understood according to the specific circumstances.

[0027] In the present application, unless otherwise explicitly specified and limited, the feature "on" or "under" the second feature can be in direct contact with the second feature, or indirectly in contact with the second feature through an intermediate medium. Moreover, the feature "on", "above" and "on" the second feature can be the feature directly above or obliquely above the second feature, or only indicate that the feature is higher than the second feature in horizontal height. The feature "under", "below" and "under" the second feature can be the feature directly below or obliquely below the second feature, or only indicate that the feature is lower than the second feature in horizontal height.

[0028] It should be noted that when an element is referred to as "fixed to" or "provided on" another element, it can be directly on the other element or there can be a middle element. When an element is considered to be "connected" to another element, it can be directly connected to another element or there can be a middle element. The terms "vertical", "horizontal", "up", "down", "left", "right" and similar expressions used herein are only for the purpose of illustration and do not represent the only implementation.

[0029] Referring to Figures 1-4 , Figure 1 A step flowchart of a lightweight insect recognition method based on knowledge distillation provided for an embodiment of the present application is shown. Figure 2 A step flowchart of local inference on a pre-processed image input provided for an embodiment of the present application is shown. Figure 3 A comparison flowchart of a lightweight model distillation method, an insect image recognition method, and a running method on a general terminal device provided for an embodiment of the present application is shown. Figure 4 A network structure diagram of a lightweight scientific model provided for an embodiment of the present application is shown. The lightweight model is a lightweight biological model. Image input processing corresponds to an image input processing module, lightweight recognition inference corresponds to a front-end convolution module, a Patch Embedding module, a local self-attention mechanism module, and a fully connected classification output module. Candidate output generation corresponds to a candidate output generation module.

[0030] Referring to Figures 1-5 , an embodiment of the present application provides a lightweight insect recognition method based on knowledge distillation, which includes: Step 200, pre-processing a to-be-recognized insect image locally through an image input processing module to obtain a pre-processed image; Step 400, performing local inference on the pre-processed image input through a lightweight biological model to output top-k candidate insect species and corresponding confidence; Wherein, referring to Figures 1-5 , the lightweight biological model is obtained by knowledge distillation from a teacher model, and the local inference includes: Step 410, performing feature extraction and channel expansion on the pre-processed image through a front-end convolution module to obtain a convolution feature map; Step 420, dividing the convolution feature map into a plurality of fixed-size image blocks through a Patch Embedding module, mapping each image block to a corresponding Token respectively to obtain a Token sequence for local self-attention mechanism. Explanatorily, an image block is a Patch. Step 430, applying self-attention to a local area of the Token sequence for local self-attention mechanism through a local self-attention mechanism module to model the global relationship of each local area in the image to obtain a Token sequence for classification; Step 440, converting and fusing the Token sequence for classification into a global image representation through a fully connected classification output module and outputting a Softmax probability vector corresponding to the candidate insect species; Step 450, performing descending order sorting on the Softmax probability vector by the candidate output generation module, selecting the top-k categories as candidate results, and outputting a top-k candidate list, wherein the top-k candidate list includes confidence degrees corresponding to the top-k candidate insect species.

[0031] An advantage of the embodiments of the present application is that the image input processing module is used to pre-process the to-be-identified insect image locally to obtain a pre-processed image, thereby solving the problem that the image resolution and color format collected by different terminals differ significantly and lack a unified pre-processing mechanism, resulting in weak model cross-device generalization capability. The lightweight student model is obtained through knowledge distillation from the teacher model. The local self-attention mechanism module of the lightweight student model applies self-attention to the local area of the Token sequence used for local self-attention mechanism to model the global relationship of each local area in the image, and the perception ability of local features is high, and the misjudgment rate of morphologically similar species (such as mimic insects) is low. Insect identification is realized through the lightweight student model, and a high-precision identification model with large parameter quantity and complex calculation, which is difficult to run in real time on edge devices, is no longer needed. Real-time insect species identification is realized through local inference of the lightweight student model, which can meet the instant judgment needs in the port network / weak network environment.

[0032] Specifically, the embodiments of the present application are particularly suitable for deployment on general terminal devices of port customs, such as quarantine laboratory workstations connected to microscopic camera modules, on-site administrative law enforcement pads equipped with camera capabilities, portable customs equipment, etc. In these devices, due to actual constraints such as unstable network, limited computing resources, and strict response time requirements, traditional deep identification models are difficult to directly deploy and run. The present application constructs a high-precision teacher model and obtains a lightweight student model through knowledge distillation, embeds the lightweight student model in the terminal device as a local model, and realizes efficient insect identification function in an offline state.

[0033] Furthermore, the embodiments of the present application are designed specifically for customs animal and plant quarantine and entry carried article inspection business scenarios, and have strong practicality and industry adaptability. Compared with traditional identification methods relying on manual atlas retrieval or expert judgment, the embodiments of the present application are deployed on general devices such as administrative pads or microscopic image collection terminals used by customs front-line personnel, realizing an intelligent identification process without networking, instant response, and structural enhancement, which brings the following significant benefits in actual business: First, in terms of work efficiency, the time for manual retrieval and waiting for expert feedback is significantly reduced. The system supports instant identification by taking pictures on the spot in the physical inspection site, and supports second-level judgment, which is particularly suitable for scenarios where a large number of samples need to be quickly pre-screened during peak inspection periods. Even in environments where the network condition at the port is limited or there is no network, the system can still run independently, ensuring uninterrupted on-site inspection work.

[0034] Secondly, in terms of recognition accuracy, not only the discriminative ability of the deep model is preserved, but also the structural perception ability is introduced through knowledge distillation and local attention mechanism, which significantly improves the recognition accuracy of insects with similar morphology, different species or mimicry camouflage. The automatic focusing on key anatomical parts such as insect wing veins, antennae and intersegmental parts enhances the discriminability and interpretability of the recognition results while ensuring computational efficiency, thereby providing technical support for precise interception of high-risk alien species or important economic crop pests.

[0035] In addition, its lightweight structure and stable running mechanism support long-term residence in mobile administrative terminals or professional microscope platforms, combined with periodically updated knowledge distillation model versions, can realize low-cost and high-coverage intelligent inspection capability deployment, thereby reducing the dependence of customs on high-level artificial experts and improving the intelligent level of business at the grassroots level.

[0036] In summary, the embodiments of the present application not only solve the problem of model deployment and computational resource limitation, but also provide a fast, reliable and interpretable identification support tool in the customs inspection scenario, significantly enhancing the risk screening efficiency and accuracy of imported insect samples at the port, and having obvious industry promotion value and social benefits.

[0037] In some embodiments, referring to Figures 1-5 Before the step 200, the local preprocessing of the insect image to be identified by the image input processing module to obtain the preprocessed image, it further includes: Step 100, obtaining an insect image to be identified.

[0038] Specifically, the insect image to be identified can come from an industrial camera in a microscope workstation, a built-in camera on a customs administrative Pad, or an externally uploaded image file.

[0039] Referring to Figures 1-5 In some embodiments, the local preprocessing in the step 200 includes: Step 210, scaling or cropping the insect image to be identified with any resolution to a uniform input size in proportion; Step 220, normalizing the image pixel value to the range of [0, 1] or [-1, 1]; Step 230, converting the format of the image from HxWxN to NxHxW; Step 240, constructing a standard tensor through NumPy and PyTorch backend.

[0040] As above, the method of steps 210-240 supports unified preprocessing and standardization of microscope and Pad images, automatically adapts different input data formats and image clarity, and ensures consistency and robustness of subsequent identification. The insect images to be identified can come from industrial cameras in the microscope workstation, built-in cameras on the customs administrative Pad, or externally uploaded image files. In the local preprocessing stage, the insect images to be identified (i.e. original images) are subjected to size resampling (supporting two resolutions of 224x224 and 256x256), color normalization and channel adjustment, and converted into standard tensor format, such as [1, 3, 256, 256]. This processing procedure is completely performed locally and does not rely on external networks and servers.

[0041] Explanatory, NumPy is an open-source scientific computing library that provides efficient multi-dimensional array objects and rich mathematical functions for numerical computation and data processing. It supports array creation, operation, linear algebra, random number generation, and other functions, and is an important basic component of the Python scientific computing ecosystem. PyTorch is an open-source deep learning framework based on dynamic graph mechanism, supporting tensor computation and automatic differentiation, facilitating the construction and training of neural network models. PyTorch provides a rich set of neural network modules, optimizers and tool libraries, and is widely used in machine learning and artificial intelligence fields.

[0042] The specific method and process of knowledge distillation are introduced below.

[0043] Reference Figures 1-5 In some embodiments, the lightweight student model in step 400 is obtained by knowledge distillation from the teacher model, including: Step 000, the same input image is sent into the frozen teacher model and the lightweight student model to be trained, respectively, to obtain the corresponding softmax probability vectors and ; Step 010, calculate the weighted total loss of KL divergence and cross-entropy, and only use the weighted total loss as the joint loss function to backpropagate to all parameters of the lightweight student model; Step 020, after stable convergence in training, export the lightweight student model weights in deployment format to adapt to the local inference environment of mobile devices; during training, the teacher model does not participate in parameter update at all, only as a source of guidance signal.

[0044] The knowledge distillation training can be performed on a complete labeled dataset, and also supports a small sample few-shot scene. As steps 000-020 above, in order to enable the lightweight student model to have recognition performance close to or even partially surpass the teacher model on the terminal device, an embodiment of the present application adopts a knowledge distillation method based on probability output alignment, the core idea of which is to guide the lightweight student model to imitate the judgment behavior of the teacher model on the class probability distribution, so that it can also capture rich inter-class boundary information under a small-scale structure. It can adapt to the local inference environment of mobile devices and realize real-time insect recognition capability with low delay and high accuracy.

[0045] In some embodiments, referring to Figures 1-5 In the step of obtaining the lightweight student model by knowledge distillation from the teacher model in step 400, the following steps are included: The lightweight student model is optimized by a joint loss function composed of KL divergence and cross entropy. The specific implementation is to calculate the weighted total loss of KL divergence and cross entropy in step 010, and only the weighted total loss is used as the joint loss function to backpropagate to all parameters of the lightweight student model.

[0046] Specifically, the expression of the joint loss function is: ; Among them, is the corresponding output of the lightweight student model according to the input image, is the Softmax probability vector output by the teacher model according to the input image, KL is the Kullback-Leibler divergence, CE is the cross entropy loss function, y is the true label of the image, and a is the distillation balance coefficient, 0.7≤a≤0.9.

[0047] As above, the knowledge distillation process is optimized by a joint loss function, which is composed of two parts: one is the Kullback-Leibler (KL) divergence between the output of the student model and the output of the teacher model, which is used to measure the similarity of the two probability distributions; the second is the cross entropy (Cross Entropy, CE) between the output of the student model and the true label, which ensures that it does not deviate from the basic supervision signal.

[0048] In addition, referring to Figures 1-5 In some embodiments, before calculating the weighted total loss of KL divergence and cross entropy in step 010, the KL divergence needs to be calculated. Further, before calculating the KL divergence, a probability softening process is performed on the output of the teacher model based on a temperature parameter, which is represented as: ; Among them, is the original prediction output of the teacher model, j is the index of the class, representing the jth class, and the value range is equal to the number of classes, is the original probability output of the teacher model on the jth class, T is a temperature parameter, exp represents an exponential operation function with the natural constant e as the base, which is used to map the input real number to a positive number, and the numerical value increases exponentially with the increase of the input. A higher temperature will make the softmax probability vector output of the teacher model smoother, exposing the fine-grained distinction relationship between non-target classes, thereby helping the student model to better learn the "dark knowledge" of the teacher model.

[0049] For the training of a high-precision teacher model, see Figures 1-5 In some embodiments, the training process of the teacher model comprises: Step 001, selecting a MobileNet model as the model structure of the teacher model; Step 002, using multiple insect images obtained by the Customs Laboratory as a data set, and adopting standard classification labels at the image level for supervised learning; for example, 600 insect images as a data set; Step 003, using cross-entropy as the loss function during training, combining the Adam optimizer and introducing the Warm-up and learning rate decay strategies for optimization; Step 004, until the accuracy of the teacher model on the validation set is improved to a Top-1 accuracy rate of not less than 90%, the training is completed.

[0050] The following describes a lightweight student model and its execution steps in a specific implementation.

[0051] The lightweight student model is the core recognition model finally deployed on general terminal devices (such as mobile devices, embedded AI chips, etc.), which needs to maintain good insect classification and recognition accuracy under the premise of compressing the model size and computational complexity as much as possible. Therefore, the lightweight student model of the present application belongs to a set of lightweight deep neural network structure, which can realize smooth forward inference in a limited computing environment such as mobile CPU or NNAPI, and supports user-defined input image size. The size used in the present embodiment is 256x256.

[0052] In some embodiments, see Figures 1-5 , the step 410 comprises: The pre-processed image is taken as the initial input, and feature extraction and channel expansion are sequentially performed through three layers of depth separable convolution blocks, the output of the previous depth separable convolution block being taken as the input of the next depth separable convolution block, the depth separable convolution block including a Depthwise convolution that separately performs 3x3 convolution on each input channel without channel fusion, and a Pointwise convolution that linearly combines each channel to achieve feature interaction and channel expansion; wherein BatchNorm and GELU activation are connected after each layer of depth separable convolution blocks, and the tensor dimension of the final output convolution feature map is: X0∈R 1×128×H′×W′ For example, H' = 64, W' = 64.

[0053] Specifically, if the initial input is an image with a size of [1, 3, H, W], after passing through the three convolution layers of the front-end convolution module, the number of image channels is from 3→32→64→128, and the feature map size is gradually down-sampled.

[0054] For X0∈R 1×128×H′×W′ Explanation of X0∈R 1×128×H′×W′ : X0 represents the convolution feature map obtained after processing by three layers of depth separable convolution blocks and subsequent BatchNorm and GELU activation functions. 1 represents the batch size, i.e., the tensor contains the features of 1 sample. 128: represents the number of feature channels (channel number), i.e., after channel expansion by the depth separable convolution block, the channel dimension of the feature map is 128. H' represents the height of the feature map, i.e., the spatial height dimension of the input image after convolution and possible down-sampling. W' represents the width of the feature map, i.e., the spatial width dimension of the input image after convolution and possible down-sampling.

[0055] wherein BatchNorm is a method used to accelerate the training speed and stabilize the network when training a deep neural network. It normalizes the neuron activation values in each batch to make their mean close to 0 and their variance close to 1, and then adjusts them through learnable scaling and translation parameters. GELU (Gaussian Error Linear Unit) is a nonlinear activation function that combines the probability distribution characteristics of input values and smoothly activates neurons.

[0056] Referring to Figures 1-5 In some embodiments, the step 420 includes dividing the convolution feature map into a plurality of fixed-size image blocks by a Patch Embedding module, mapping each image block into a corresponding Token respectively, to obtain a Token sequence for local self-attention mechanism, including: dividing the convolution feature map by flattening and rearranging operation, where P is a set of image patches; Each image patch is mapped to a Token using a linear mapping layer, where the Token is a d-dimensional embedding vector. The Token sequence for local self-attention mechanism is obtained, denoted as: The Token sequence for local self-attention mechanism is obtained, denoted as: ; where t i represents the i-th Token.

[0057] To introduce the Transformer mechanism, the Patch Embedding module divides the convolutional feature map into a plurality of fixed-size image patches, for example, 16x16. Step 420 effectively converts two-dimensional spatial information into a sequence input format for Transformer processing.

[0058] In some embodiments, referring to Figures 1-5 Step 430 applies self-attention to local regions of the Token sequence for local self-attention mechanism through a local self-attention mechanism module to model the global relationship of each local region in the image, obtaining a Token sequence for classification, including: The Token sequence for local self-attention mechanism is obtained by applying self-attention to local Token regions of the Token sequence for local self-attention mechanism through a two-layer lightweight Transformer encoder. The self-attention to local Token regions of the Token sequence for local self-attention mechanism includes: Each layer of the Transformer encoder respectively performs multi-head self-attention calculation, feedforward network processing, residual connection and layer normalization processing on the input, and finally the local self-attention mechanism module outputs the Token sequence for classification. The Token sequence for classification is denoted as: The multi-head self-attention calculation is denoted as: ; Q, K, V are obtained by linear mapping of input Token, with h=2 Attention Heads, and the dimension of each Head is d / h; the feedforward network is denoted as: ; .

[0059] As mentioned above, step 430 introduces the local self-attention mechanism. In order to preserve the powerful local modeling capability of the Transformer but avoid the computational bottleneck, the local self-attention mechanism module in the present application uses a 2-layer lightweight Transformer encoder, which only applies self-attention to the local Token region, and finally outputs the Token sequence for classification, which compresses the calculation range of context modeling while preserving the sequence structure.

[0060] Referring to Figures 1-5 In some embodiments, the step 440, the Token sequence for classification is converted and fused into a global image representation by a fully connected classification output module, and a softmax probability vector corresponding to the candidate insect species is output, including: The Token sequence for classification is aggregated by mean pooling through Token Pooling to obtain an image global representation vector; The image global representation vector is processed by a two-layer fully connected classifier to determine the category of the candidate insect species and the corresponding confidence score Based on the category of the candidate insect species and the corresponding confidence score, a softmax probability vector is output; Wherein, the image global representation vector is represented as: ; The fully connected classifier is represented as: ; The softmax probability vector is represented as: ; N is the number of species categories; Wherein, N represents the number of minimum embedding units (Tokens) for classification, i.e. the length of the Token sequence. ti represents the embedding vector of the i-th Token, with a dimension of d. v represents the global representation vector of the image. d represents the dimension of the Token, which is also the dimension of the global representation vector. d' represents the hidden layer dimension, which is the dimension of the output of the first layer of the fully connected layer. R represents the set of real numbers. W1 represents the first layer weight matrix in the fully connected classifier, which maps the global representation vector from dimension d to the hidden layer dimension d'. b1 represents the bias vector of the first layer of the fully connected classifier. b2 is the bias vector of the second layer of the fully connected classifier. W2 is the second layer weight matrix of the fully connected classifier, which maps the hidden layer output to the category space, with a category number of N. GELU is the Gaussian Error Linear Unit activation function, which performs nonlinear transformation on the linear transformation result. z is the final linear output vector of the fully connected classifier, representing the original score corresponding to each category. sis a probability vector obtained by applying a softmax function to z, and each element represents the confidence probability of the corresponding class.

[0061] wherein, in the knowledge distillation stage, the softmax probability vector is used for distillation alignment with the teacher model output.

[0062] It combines convolution and Transformer, taking into account the ability to capture local details and the ability to understand context semantics. Under the guidance of knowledge distillation, it can obtain recognition ability similar to the teacher model, and has excellent mobile deployment characteristics. It is easy to deploy in TFLite, ONNX, CoreML, etc. It supports end-side CPU, GPU, NNAPI, NPU acceleration execution.

[0063] Explanatory, Token Pooling (embedding vector unit pooling) refers to the aggregation operation on the input Token sequence to obtain the overall representation vector of the sequence. It is usually applied to image classification and other tasks, and the features of multiple local Tokens are fused into a global feature, thereby simplifying the input of the subsequent classifier. Mean Pooling (Mean Pooling) is a commonly used aggregation method, which calculates the arithmetic mean of the corresponding dimension elements of a group of vectors to obtain a new vector representing the overall features of the input vector.

[0064] In some embodiments, referring to Figures 1-5 , the step 450, the softmax probability vector is sorted in descending order by the candidate output generation module, the top-k categories are selected as candidate results, and a top-k candidate list is output. The top-k candidate list includes the confidence of the top-k candidate insect species corresponding to the softmax probability vector and the representation of the top-k candidate list as follows: The softmax probability vector is represented as: ; wherein, N is the number of all supported recognition species, p i represents the confidence of the i-th supported recognition species; i represents the i-th supported recognition species; Specifically, p i represents the confidence of the model for the i-th supported recognition species, and the value range is [0, 1], and the sum of the confidence of all species is 1. i represents the i-th species in the supported recognition species set, wherein i is the index number, the value range is {1, 2, …, N}, and N is the total number of species supported by the system for recognition.

[0065] The top-k candidate list is represented as: ; wherein, is the class index of the i-th largest probability after sorting, is the corresponding confidence.

[0066] Specifically, C represents a top-k candidate list, which contains the first k classes in descending order of confidence and the corresponding confidence values. i represents the class index corresponding to the i-th largest probability in the sorted result, where i e {1, 2, …, k}.

[0067] Based on the above, the running method of the application on a general terminal device is introduced as follows.

[0068] The lightweight insect recognition method based on knowledge distillation proposed in the application is dedicated to the entry and exit quarantine inspection scene in the field of port customs, and the system is particularly suitable for two types of terminal platforms: one is the video acquisition and analysis terminal on the side of the microscope (such as a microscope interface computing module, an embedded edge recognition box); the second is the administrative Pad (such as a domestic Android device) equipped for the frontline customs inspectors. The implementation mode of the application can operate independently off the network, has the characteristics of fast response speed, high precision, and low resource occupation, and meets the multiple requirements of mobility, stability, low delay, and non-network operation in actual business processes.

[0069] The overall operation follows the modular pipeline logic and is divided into an initialization phase, a data input phase, an inference calculation phase, and a result output phase. The specific process is as follows: Initialization phase: after running, the lightweight student model optimized by knowledge distillation is automatically loaded, which has a small structure and weight volume and can be directly run on: embedded computing modules; domestic government devices; microscope intelligent recognition terminals, etc.

[0070] Data input phase: receive the image input source (insect image to be recognized) and perform local preprocessing. The input form can be a single image or a continuous image stream. For example, in the microscope terminal, the image source is a continuous observation picture, which is captured and processed by selecting clear frames; while on the administrative Pad, the image source is usually a close-up shot by a camera or a scanner. The input image is executed by the image input processing module for size resampling (256x256), pixel value normalization (between 0 and 1), RGB channel adjustment, and format conversion to a standard tensor (float32 type, dimension [1,3,H,W]).

[0071] ​Inference calculation stage: the image tensor (pre-processed image) is sent to the distilled and optimized lightweight student model for a complete forward propagation. This inference calculation stage is completed by the front-end convolution module, the Patch Embedding module, the local self-attention mechanism module, the fully connected classification output module, and the candidate output generation module, and can output a softmax probability vector corresponding to the target species. The inference stage is completely executed locally on the terminal device and does not rely on network connection. Then, the top-k species names with the highest scores and confidence are selected from the probability vector to form a top-k candidate list, which has good interpretability and practicability and is suitable for the customs quarantine identification task with a large number of insect species and complex distribution of different species in the same genus.

[0072] Result output stage: the top-k candidate list is arranged into a structured data object, including the candidate species name, corresponding confidence, inference time consumption, current timestamp, and model version used, etc. The result is transmitted out through a unified interface, which is convenient for connecting front-end display systems, data acquisition control programs, or back-end log recording systems, etc. In actual application, different presentation modes and interaction logics can be designed according to requirements.

[0073] It should be particularly pointed out that the present application only relates to the improvement of the identification method itself and does not include the outer adaptation part such as specific front-end UI, graphical interface interaction, result management system, etc. The output is only structured data, and the user can freely integrate and develop the upper application system according to the scene requirements.

[0074] Through the cooperative work of the above-mentioned modules, the present application provides an insect identification method based on knowledge distillation suitable for the customs quarantine scene, which can be widely deployed on microscope terminals and administrative pads and other customs real-time general-purpose devices to realize efficient, accurate, low-delay, and off-network operation of on-site identification capability, and provides technical support for import and export animal and plant quarantine, invasive species screening, and preliminary judgment of high-risk specimens.

[0075] Two application cases are introduced below, i.e. the application of the present application in the microscopic image identification system of the port quarantine laboratory and the application of the on-site real-time identification system of the administrative Pad of the frontline customs Application Case One: Application in the Microscopic Image Identification System of the Port Quarantine Laboratory This application case shows the application mode of the present application as a microscopic insect image identification tool in the customs port insect quarantine laboratory. The system as a whole is composed of a microscopic imaging device, an image acquisition module, and a workstation PC, which are matched to run the lightweight insect identification method based on knowledge distillation of the present application.

[0076] After the program starts, the system loads the distilled optimized lightweight student model, which resides in the local memory, ready for input. The quarantine personnel places the suspicious sample under the microscope for observation, and the image is captured by the image acquisition module and transmitted to the image input processing module. The image input processing module automatically adjusts the size of the image (uniformly to 256x256 resolution), standardizes the color channel, and converts it to a three-channel tensor.

[0077] After processing is complete, the pre-processed image is input into the lightweight student model, which performs a forward inference and outputs a probability vector for each type of insect. The program filters the top-3 candidate results and returns the candidate species name, confidence, inference delay, and current timestamp. The above process is completed on the local PC without the need for networking and without interrupting the microscopic observation process.

[0078] The final result is fed back to the laboratory information system through the local standard interface, which can be used to generate electronic sample reports and assist experts in secondary interpretation. Laboratory staff can also save the identification results into the database for specimen archiving. This application case shows that the present application can be used as an automatic identification supplement to traditional manual visual quarantine, greatly improving the efficiency of high-throughput sample processing.

[0079] Application Case Two: Application in a real-time identification system deployed on a frontline customs administrative Pad This application case demonstrates the application of the present application as a mobile insect rapid identification tool in the administrative Pad used by frontline customs inspectors. The terminal device is a portable customs-specific Pad that supports camera image acquisition and local model deployment.

[0080] After deploying the relevant software of the lightweight insect identification method based on knowledge distillation of the present application on the Pad, the system loads the lightweight student model when it is first started. The inspector can take pictures of the insects carried or smuggled by using the in-app camera function. After the image is uploaded, it automatically enters the preprocessing process of the image input processing module, which unifies the image format and generates an input tensor.

[0081] The front-end convolution module of the lightweight student model performs forward propagation locally on the Pad. The inference result is returned in top-k format, including the candidate species Chinese and Latin names, probability value, current time, and other attribute information, and supports automatic recording of pictures and identification results to form local records.

[0082] The present application can be integrated with the on-site handling system in the Pad, supporting subsequent operations such as retrieving historical identification records, marking uncertain samples for re-inspection, matching existing prohibited and restricted lists, and generating case records. This application case demonstrates the practical deployability of the present application in non-laboratory environments, low computational power, and strong mobility scenarios, and has high practical value and broad prospects for promotion.

[0083] Further, as mentioned above, corresponding to the knowledge distillation based lightweight insect recognition method of the above, see Figures 1-5 Figures 1-5 Figures 1-5 Figures 1-5 Figures 1-5 Figures 1-5 Figures 1-5 Figures 1-5 Figures 1-5 Embodiments of the present application also provide a customs real-time general device, which comprises: An image input processing module, configured to locally pre-process an insect image to be recognized to obtain a pre-processed image; A lightweight student model, which is obtained by knowledge distillation from a teacher model, and comprises: A front-end convolution module, configured to extract features and expand channels of the pre-processed image to obtain a convolution feature map; A Patch Embedding module, configured to divide the convolution feature map into a plurality of image blocks of a fixed size, map each image block to a corresponding Token, and obtain a Token sequence for local self-attention mechanism; A local self-attention mechanism module, configured to apply self-attention to a local region of the Token sequence for local self-attention mechanism to model global relationships of local regions in the image, and obtain a Token sequence for classification; A fully connected classification output module, configured to convert and fuse the Token sequence for classification into a global image representation and output a softmax probability vector corresponding to a candidate insect species; A candidate output generation module, configured to perform descending order sorting on the softmax probability vector, select the top-k categories as candidate results, and output a top-k candidate list, wherein the top-k candidate list comprises confidence degrees corresponding to top-k candidate insect species.

[0084] Explanatorily, the Patch Embedding module is configured to convert the convolution feature map output by the front-end convolution module into a Token sequence suitable for local self-attention mechanism processing.

[0085] The working process of the Patch Embedding module comprises: Feature map segmentation: dividing the convolution feature map into a plurality of non-overlapping image blocks (Patches) according to a preset fixed spatial size; Flattening and rearranging: flattening the two-dimensional features of each image block into a one-dimensional vector and rearranging in order to form a Patch vector sequence; Linear mapping: mapping each Patch vector to a unified d-dimensional embedding space through a fully connected layer (or an equivalent 1x1 convolution) to obtain a corresponding Token; Output Token sequence: all mapped Tokens are arranged in the original patch order to form a Token sequence, which is input into the local self-attention mechanism to model the global relationship of local regions in the image.

[0086] Explanatorily, Token (embedding vector unit) refers to a vector unit with fixed dimensions obtained by image or convolution feature map after segmentation, flattening and mapping processing, which is the basic input unit for feature modeling of the local self-attention mechanism or the Transformer module. Each Token corresponds to a local region in the image or feature map, and represents the feature information of the region in the embedding space.

[0087] Softmax (normalized exponential function) is a function for converting a group of real number vectors into a probability distribution. The calculation process is as follows: perform exponential operation on each element of the input vector, and then divide the exponential value by the sum of all element exponential values to obtain the normalized probability value of the corresponding element.

[0088] Finally, it should be noted that the technical features of the above embodiments can be combined arbitrarily, and in order to make the description simple, not all possible combinations of the technical features in the above embodiments are described, however, as long as the combination of the technical features does not exist contradictory, it should be considered as the scope of the description.

[0089] The above-described embodiments only express some implementation manners of the present application, which are described in detail and specifically, but should not be understood as a limitation on the scope of the patent. It should be pointed out that for ordinary skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are all within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.

Claims

1. A lightweight insect recognition method based on knowledge distillation, characterized in that, The method comprises the following steps: performing local preprocessing on an insect image to be recognized by an image input processing module to obtain a preprocessed image; performing local inference on the preprocessed image input by a lightweight student model to output top-k candidate insect species and corresponding confidence; wherein the lightweight student model is obtained by knowledge distillation from a teacher model, and the local inference comprises: performing feature extraction and channel expansion on the preprocessed image by a front-end convolution module to obtain a convolution feature map; dividing the convolution feature map into a plurality of fixed-size image blocks by a Patch Embedding module, and mapping each image block into a corresponding Token to obtain a Token sequence for local self-attention mechanism; applying self-attention to the local region of the Token sequence for local self-attention mechanism by a local self-attention mechanism module to model the global relationship of each local region in the image, and obtaining a Token sequence for classification; converting and fusing the Token sequence for classification into a global image representation by a fully connected classification output module, and outputting a softmax probability vector corresponding to the candidate insect species; performing descending order sorting on the softmax probability vector by a candidate output generation module, selecting the top-k categories as the candidate results, and outputting a top-k candidate list, wherein the top-k candidate list comprises the confidence corresponding to the top-k candidate insect species.

2. The knowledge distillation-based lightweight insect recognition method according to claim 1, wherein, In the step of obtaining the lightweight student model by knowledge distillation from the teacher model, the following steps are included: optimizing the lightweight student model by a joint loss function composed of KL divergence and cross-entropy, and the expression of the joint loss function is: ; wherein, is the corresponding output of the lightweight student model according to an input image, is the softmax probability vector output by the teacher model according to the input image, KL is the Kullback-Leibler divergence, CE is the cross-entropy loss function, y is the true label of the image, and a is a distillation balance coefficient, 0.7≤a≤0.

9.

3. The knowledge distillation-based lightweight insect recognition method according to claim 2, characterized in that, performing probability softening processing on the output of the teacher model based on a temperature parameter before calculating the KL divergence, and the probability softening processing is expressed in a normalized form as: ; wherein, is the original prediction output of the teacher model, j is the index of the class, represents the jth class, and the value range is equal to the number of classes, is the original probability output of the teacher model on the jth class, T is a temperature parameter, and exp represents an exponential operation function with the natural constant e as the base, which is used to map the input real number to a positive number, and the numerical value increases exponentially with the increase of the input.

4. The knowledge distillation-based lightweight insect recognition method according to claim 1, characterized in that, The softmax probability vector is represented as: ; wherein N is the number of all supported identification species, pi represents the confidence of the i-th supported identification species, and i represents the i-th supported identification species; The top-k candidate list is represented as: ; wherein, is the index of the class with the largest probability after sorting, is the corresponding confidence.

5. The knowledge distillation-based lightweight insect recognition method according to claim 1, characterized in that, the feature extraction and channel expansion on the preprocessed image by the front-end convolution module to obtain the convolution feature map comprises: taking the preprocessed image as the initial input, sequentially performing feature extraction and channel expansion by three layers of depth separable convolution blocks, taking the output of the previous depth separable convolution block as the input of the next depth separable convolution block, and the depth separable convolution block includes a convolution that separately performs 3x3 convolution on each input channel without channel fusion, and a convolution that linearly combines each channel to realize feature interaction and channel expansion; wherein each layer of the depthwise separable convolution block is followed by a BatchNorm and a GELU activation, and the tensor dimension of the final output of the convolution feature map is: X0∈R 1×128×H′×W′ .

6. The knowledge distillation-based lightweight insect recognition method according to claim 1, characterized in that, the division of the convolution feature map into a plurality of fixed-size image blocks by the Patch Embedding module, and the mapping of each image block into a corresponding Token to obtain a Token sequence for local self-attention mechanism comprises: convolutional feature maps are split into image patches, where P is a set of image patches; each image block is mapped into a Token by a linear mapping layer, and the Token is a d-dimensional embedding vector; The Token sequence for local self-attention mechanism is obtained, which is represented as: ; where t i represents the i-th Token.

7. The knowledge distillation-based lightweight insect recognition method according to claim 1, characterized in that, The local area of the Token sequence for local self-attention mechanism is subjected to self-attention by the local self-attention mechanism module to model the global relationship of each local area in the image, and a Token sequence for classification is obtained, including: The local Token area of the Token sequence for local self-attention mechanism is subjected to self-attention by a two-layer lightweight Transformer encoder to obtain a Token sequence for classification; The local Token area of the Token sequence for local self-attention mechanism is subjected to self-attention, including: Each layer of the Transformer encoder respectively performs multi-head self-attention calculation, feedforward network processing, residual connection and layer normalization processing on the input, and finally the local self-attention mechanism module outputs a Token sequence for classification; Among them, the Token sequence for classification is represented as: ; The multi-head self-attention calculation is represented as: ; Q, K, V are linearly mapped from the input Token, h = 2 Attention Heads are adopted, and the dimension of each Head is d / h; The feedforward network is represented as: ; .

8. The knowledge distillation-based lightweight insect recognition method according to claim 1, wherein, The Token sequence for classification is converted and fused into a global image representation by the fully connected classification output module, and a softmax probability vector corresponding to the candidate insect species is output, including: All Tokens of the Token sequence for classification are aggregated by Token Pooling using mean pooling to obtain an image global representation vector; The image global representation vector is processed by a two-layer fully connected classifier to determine the category and corresponding confidence score of the candidate insect species; Based on the category and corresponding confidence score of the candidate insect species, a softmax probability vector is output; The image global representation vector is represented as: The fully connected classifier is represented as: The softmax probability vector is represented as: ; N is the number of species categories. wherein, in the knowledge distillation phase, the softmax probability vector for distillation alignment with the teacher model output.

9. The knowledge distillation-based lightweight insect recognition method according to any one of claims 1-8, characterized in that, Before the preprocessed image is obtained by the image input processing module, the method further comprises obtaining the insect image to be identified; And / or, The local preprocessing includes scaling or cropping the insect image to be identified at any resolution to a uniform input size, normalizing the image pixel values to the range of [0, 1] or [-1, 1], converting the image format from HxWxN to NHxW, and constructing a standard tensor through NumPy and PyTorch backends; And / or, The lightweight student model is obtained by knowledge distillation from a teacher model, including inputting the same input image into the teacher model in a frozen state and the lightweight student model to be trained respectively to obtain corresponding softmax probability vectors and ; a weighted total loss of KL divergence and cross-entropy is calculated, and only the weighted total loss is used as a joint loss function to be back-propagated to all parameters of the lightweight student model; after stable convergence of the training, the weights of the lightweight student model are exported in a deployment format to adapt to a local inference environment of a mobile device; wherein during the training, the teacher model does not participate in parameter updating at all and only serves as a source of guidance signals. The training process of the teacher model includes: selecting a MobileNet model as the model structure of the teacher model; using multiple insect images obtained by the Customs Laboratory as a data set, and using standard classification labels at the image level for supervised learning; using cross-entropy as the loss function during training, combining the Adam optimizer and introducing the Warm-up and learning rate decay strategies for optimization; until the accuracy of the teacher model on the validation set is improved to a Top-1 accuracy of not less than 90%, the training is completed. including:

10. Customs real-time universal device, characterized in that, An image input processing module for locally preprocessing the insect image to be identified to obtain a preprocessed image; ​ A lightweight student model is obtained by knowledge distillation from a teacher model, and the lightweight student model comprises: a front-end convolution module configured to perform feature extraction and channel expansion on the preprocessed image to obtain a convolution feature map; a Patch Embedding module configured to divide the convolution feature map into a plurality of image blocks of a fixed size, map each image block to a corresponding Token, and obtain a Token sequence for local self-attention mechanism; a local self-attention mechanism module configured to apply self-attention to a local region of the Token sequence for local self-attention mechanism to model the global relationship of each local region in the image, and obtain a Token sequence for classification; a fully connected classification output module configured to convert and fuse the Token sequence for classification into a global image representation and output a softmax probability vector corresponding to a candidate insect species; a candidate output generation module configured to perform descending order sorting on the softmax probability vector, select the top k categories as candidate results, and output a top-k candidate list, wherein the top-k candidate list comprises confidence degrees corresponding to top-k candidate insect species.

Citation Information

Patent Citations

  • Agricultural pest image recognition method based on CNN few samples

    CN113177612A

  • Fine-grained image classification method based on feature fusion and semantic enhancement

    CN118799646A

  • Pest identification and recognition method and device, electronic equipment and storage medium

    CN119091465A

  • Lightweight ViT based on image feature cutting and cloud edge knowledge distillation

    CN120375050A

Cited By

  • Data processing method, electronic device, storage medium and computer program product

    CN121279458A