Lightweight cotton disease and pest identification method based on attention mechanism and transfer learning

By combining attention mechanism and transfer learning, multi-scale convolution and model pruning technologies are adopted, the problems of inaccurate identification and high resource consumption in existing cotton pest recognition technologies are solved, and the effect of high-precision and rapid identification of cotton pests and diseases in the natural environment is achieved.

CN119863702APending Publication Date: 2025-04-22XINJIANG UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411926234.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-24
Publication Date
2025-04-22

AI Technical Summary

Technical Problem

The existing cotton pest identification technology has problems such as inaccurate identification, large resource consumption and single feature extraction scale, making it difficult to effectively identify cotton pests and diseases in the natural environment.

Method used

A lightweight recognition method based on attention mechanism and transfer learning is adopted to reduce model parameters and improve recognition accuracy through multi-scale convolution, RE-intensive blocks, model pruning and MFGA attention mechanisms, so that the model can be deployed in resource-constrained environments.

Benefits of technology

It realizes high-precision and rapid identification of cotton pests and diseases in natural environments, reduces the number of model parameters, improves the deployment capabilities of the model on portable devices, and enhances the attention to key characteristics of cotton pests and diseases.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119863702A_ABST
    Figure CN119863702A_ABST
Patent Text Reader

Abstract

The invention provides a lightweight cotton disease and insect pest recognition method based on an attention mechanism and transfer learning for cotton disease and insect pest images. According to the method, DenseNet121 is taken as a basic model, a new lightweight cotton disease and insect pest recognition model REM-DNet is constructed, and multi-scale convolution is introduced to replace the first-layer 7 * 7 convolution of the basic model, so that the capturing capability of information of different scales is enhanced; in order to reduce model parameters, facilitate deployment and construction of an RE-dense block and an LAMP pruning method in a resource-constrained environment to simplify a network structure and parameter quantity, and propose RReLU6 to relieve the problems of numerical distortion and neuron inactivation so as to facilitate deployment of the model on portable equipment; in order to make up precision loss possibly caused by pruning, an MFGA mechanism is constructed, and in combination with a transfer learning strategy, attention of the model to key disease features is enhanced. According to the method, the recognition accuracy is improved, model parameters are reduced, the method is more suitable for being deployed in portable equipment, and the application requirement of cotton disease and pest recognition in an actual scene can be well met.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer vision in deep learning, and in particular to a lightweight cotton pest and disease identification method based on attention mechanism and transfer learning. Background Art

[0002] Cotton is a very important textile fiber, accounting for about 35% of the world's annual fiber demand. At the same time, the cotton industry is an important economic pillar for many countries, providing farmers with a stable source of income. According to the monitoring of the China Crop Pest and Disease Monitoring Network and the analysis of expert consultations, it is expected that major crop diseases and insect pests will re-occur in 2024. China is expected to have an area of ​​2.33 billion mu, an increase of 26.2% and 18.4% over the actual area in 2023 and the past five years, respectively, posing a threat to more than 70% of crop production areas.

[0003] At present, farmers identify cotton pests and diseases mostly through experience or by inviting experts. However, experience-based methods often have the risk of inaccurate identification, which may lead to incorrect use of pesticides and have adverse effects on crop growth and yield. Although inviting experts to identify pests and diseases is highly professional, it often has problems of time lag and high cost. Misdiagnosis or late discovery may lead to the misuse and abuse of pesticides, which will not only pollute the land, but may also cause pests and diseases to develop resistance, posing a serious threat to agricultural production and environmental protection. Therefore, it is particularly important to identify cotton pests and diseases early and accurately.

[0004] With the development of pattern recognition and artificial intelligence technology, the research on automatic identification of crop pests and diseases using computer vision is increasing. Although the early traditional digital image processing technology has achieved certain results, the background segmentation effect is not good when processing pictures with complex backgrounds or large light changes, and it relies on manual feature extraction, which has a "semantic gap" problem. In recent years, the rise of deep learning technology, especially convolutional neural networks, has brought options for cotton pest and disease identification. Convolutional neural networks can not only directly process original images without background segmentation, but also automatically extract multi-level abstract features, simplify the recognition process, and improve the convenience and automation of operation. However, there are still some problems. First, most of the pest and disease images in the existing public data sets are taken in a controlled laboratory environment, which cannot cope well with the pests and diseases generated in the real environment; second, the parameters of the existing models are relatively large, which often makes it difficult to deploy pest and disease identification models on portable devices; finally, some models still have the problem of single feature extraction scale.

[0005] In summary, this paper studies cotton as a specific object and proposes a lightweight cotton disease and pest identification method based on attention mechanism and transfer learning. On the cotton disease and pest dataset collected in the field, it realizes multi-scale feature extraction while ensuring the accuracy of the model and significantly reducing the number of model parameters, thereby achieving accurate and rapid cotton disease and pest identification. Summary of the invention

[0006] In order to overcome the above-mentioned existing deficiencies, the present invention proposes a lightweight cotton disease and pest identification method based on attention mechanism and transfer learning. The method combines attention mechanism, model pruning and transfer learning to reduce model parameters while ensuring model accuracy, thereby achieving accurate and rapid cotton disease and pest identification.

[0007] In order to achieve the above objectives, the present invention proposes a lightweight cotton pest and disease identification method based on attention mechanism and transfer learning, which comprises the following steps, characterized in that:

[0008] S1 Data Collection: The invention takes cotton pests and diseases as the specific research object, and the research mainly focuses on healthy cotton leaves, cotton Verticillium wilt, cotton brown spot disease, cotton wilt and a type of cotton aphid. Since laboratory data cannot well deal with cotton pests and diseases in the natural environment, 5,770 cotton pest and disease images were collected in Tacheng, Xinjiang Uygur Autonomous Region, China and Changji National Agricultural Center, Xinjiang Uygur Autonomous Region, China;

[0009] S2: Dataset division: The collected data is divided into training set and test set in a ratio of 8:2 to ensure that the model has enough data during training, while retaining some data for evaluating model performance.

[0010] S3: Image preprocessing: Due to the interference in the natural environment, the collected dataset samples are unbalanced. In order to enhance the balance of the data and improve the robustness of the model, the training data is subjected to a variety of enhancements, including image cropping, random grid shuffling, channel shuffling, grid distortion, random noise, random brightness adjustment, and hue saturation adjustment. In addition, before model training and testing, the images in the dataset are adaptively scaled, and each image is adjusted to 256×256 pixels to prevent information loss. This can reduce the size differences of the input images, making it easier for the model to capture and learn image features;

[0011] S4: Model construction: Based on DenseNet121, multi-scale convolution is introduced to replace the first layer 7×7 convolution of the basic model to enhance the ability to capture information of different scales;

[0012] In order to reduce model parameters and facilitate deployment in resource-constrained environments, the network structure and parameter quantity are streamlined by constructing RE-dense blocks and LAMP pruning methods to facilitate model deployment on portable devices;

[0013] In order to compensate for the possible loss of accuracy caused by pruning and effectively deal with the tiny and changeable pest and disease characteristics on cotton leaves, the MFGA mechanism is constructed and combined with the transfer learning strategy to strengthen the model's focus on key disease characteristics.

[0014] S41: First, multi-scale convolution is used to extract features of cotton pests and diseases images at different scales;

[0015] S42: Secondly, the features are input into the RE-dense block, which is composed of multiple R-dense layers stacked together. The standard L-layer convolutional network has L connections, that is, each layer is connected to its previous layer and the next layer, while DenseNet connects all previous layers to all subsequent layers, so the number of connections is:

[0016] If the network consists of L layers, each layer implements a nonlinear change H L (·), where L is the index of the layer. L is the output of the Lth layer, and the formula for the input and output of the R-dense layer is: X L =H L (X0,X1,X2...,X L-1 )

[0017] Among them, H L (·) is a composite function of batch normalization (BN), activation function (RReLU6), pooling (Pool) or convolution (Conv), and depth-wise separable convolution (DSC) operations.

[0018] S43: In order to better optimize the performance of neural networks in resource-constrained environments such as mobile devices and embedded systems. MobileNetV2 and other networks use ReLU6 to replace the ReLU activation function to help reduce the negative impact of quantization and the data distortion that may occur when converting from floating point to integer. However, there is still the problem of partial neuron inactivation, so the present invention proposes RReLU6 to alleviate these two problems at the same time, reducing neuron inactivation while alleviating the negative impact of quantization and data distortion.

[0019] S44: Subsequently, the model is pruned using the unstructured model pruning method LAMP, which approximates the model-level distortion caused by pruning by rescaling the weights. It can be effectively applied to different types of neural network layers (such as fully connected layers and convolutional layers) without any hyperparameter tuning or heavy computation, and can automatically select layer-wise sparsity while maintaining model performance.

[0020] S45: In order to compensate for the problem of accuracy loss caused by model pruning, the present invention proposes a new multi-scale adaptive attention (MFGA), which aims to enhance the model's feature extraction capability through multi-scale feature fusion and fine information flow regulation.

[0021] Then, after the RE-dense block, the MFGA attention mechanism is added. The specific implementation process of MFGA is as follows:

[0022] (1) The network is divided into three branches according to the channel to simulate the effect of multi-head attention, and 1×1 convolution is used to extract channel information;

[0023] (2) Global Context Transformer (GCT) is introduced to control the competition or cooperation relationship between channels and provide a more refined information flow for subsequent operations;

[0024] (3) The multi-layer perceptron, multi-scale module and channel attention are integrated to extract features of different scales and strengthen the connection and complementarity between features. This module is plug-and-play and can be easily integrated into any convolutional neural network.

[0025] S46: In order to maximize the compensation and enhance the accuracy of the model after pruning, the present invention uses transfer learning to transfer the knowledge learned by the model on the PlantVillage dataset to the dataset of the present invention, so that the model can capture a wider distribution of data features and improve the generalization performance on new tasks.

[0026] S47: Finally, a transition layer is used to connect each RE-dense block. The transition layer includes a batch normalization (BN) layer, an activation function (RReLU6), a 1×1 convolution, and a 2×2 average pooling layer. The number of channels is reduced by a 1×1 convolution layer, and the height and width of the feature map are halved using an average pooling layer with a stride of 2, thereby further reducing the model complexity.

[0027] S5: Model training: The pre-processed images are input into a lightweight cotton pest and disease recognition model based on attention mechanism and transfer learning to extract the image features of cotton pests and diseases;

[0028] S6: Cotton pest and disease identification: Finally, after the output data is processed through the average pooling layer and the linear layer, the classifier will generate the classification result.

[0029] S7: Select 6 types of cotton data and input them into the prediction model, and output the prediction results.

[0030] Compared with the prior art, the present invention has the following beneficial effects:

[0031] (1) The present invention reduces the impact of data imbalance on model performance through data enhancement technology, while enhancing the robustness of the model;

[0032] (2) The present invention uses multi-scale convolution to replace the original 7×7 convolution of the first layer of DenseNet121, enhancing the model's ability to extract features of different scales;

[0033] (3) The present invention improves the model accuracy while reducing model parameters by constructing RE-dense blocks and using model pruning, so that the model can be effectively deployed on portable devices and achieve excellent recognition results;

[0034] (4) The present invention introduces attention mechanism and transfer learning, so that the model can learn the features of other data sets, strengthen the model's attention to the key features of cotton pests and diseases, and ignore unimportant features;

[0035] (5) The data set used in the present invention is collected in a natural environment, so that the trained model has strong anti-interference ability and robustness, and can better meet the actual needs of cotton pest and disease identification in a natural environment. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] Figure 1 It is an overall flow chart of a lightweight cotton pest and disease identification method based on attention mechanism and transfer learning according to a specific embodiment of the present invention;

[0037] Figure 2 A sample graph of cotton pests and diseases collected in a lightweight cotton pest and disease identification method based on an attention mechanism and transfer learning according to a specific implementation of the present invention;

[0038] Figure 3 A before-and-after comparison diagram of data enhancement of a lightweight cotton pest and disease identification method based on attention mechanism and transfer learning according to a specific embodiment of the present invention;

[0039] Figure 4 A structural diagram of a multi-scale convolution of a lightweight cotton pest and disease identification method based on attention mechanism and transfer learning in a specific embodiment of the present invention;

[0040] Figure 5 A schematic diagram of a lightweight cotton pest and disease identification method RReLU6 based on attention mechanism and transfer learning according to a specific embodiment of the present invention;

[0041] Figure 6 A structural diagram of a deep separable convolution in a lightweight cotton pest and disease identification method based on an attention mechanism and transfer learning according to a specific implementation of the present invention;

[0042] Figure 7 An R-dense layer structure diagram of a lightweight cotton pest and disease identification method based on attention mechanism and transfer learning according to a specific implementation method of the present invention;

[0043] Figure 8 A flowchart of model pruning in a lightweight cotton pest and disease identification method based on attention mechanism and transfer learning in a specific embodiment of the present invention;

[0044] Fig. 9 A flowchart of transfer learning in a lightweight cotton pest and disease identification method based on attention mechanism and transfer learning in a specific embodiment of the present invention;

[0045] Fig.10 This is a structural diagram of the MFGA attention mechanism of a lightweight cotton pest and disease identification method based on attention mechanism and transfer learning in a specific implementation manner of the present invention. DETAILED DESCRIPTION

[0046] In order to make the purpose, technical scheme and advantages of the present invention more clear, the present invention will be further described in conjunction with examples below, but it is not intended to limit the present invention. Figure 1 -10 Provide a detailed explanation of this technical solution.

[0047] In the present invention, see Figure 1 As shown, the present invention proposes a lightweight cotton pest and disease identification method based on attention mechanism and transfer learning, the steps comprising:

[0048] S1: Dataset collection: Field collection of cotton pest and disease datasets;

[0049] S11: In Tacheng Prefecture and Changji National Agricultural Center in Xinjiang Uygur Autonomous Region, China, 5770 images of cotton pests and diseases were collected, including 1016 images of healthy cotton leaves, 1457 images of cotton Verticillium wilt, 1136 images of cotton brown spot, 1061 images of cotton wilt, 497 images of cotton aphids, and 602 images of cotton red leaf and stem blight. Figure 2 Sample images of cotton pests and diseases are shown;

[0050] S2: Dataset division: The collected cotton pest and disease dataset is divided into training set and test set;

[0051] S21: Divide the collected cotton pest and disease dataset into a training set and a test set in a ratio of 8:2;

[0052] S3: Image preprocessing: Perform image enhancement on the training set images before training;

[0053] S31: Use data augmentation methods to balance the number distribution of samples in different categories, ensuring that the number of sample images in each of the six categories is at least 1,200. Use the Albumentations data augmentation method, such as shearing, random grid shuffling, channel shuffling, grid distortion, random noise, and random brightness, etc., to enhance the original 5,770 images to 7,200; Figure 3 The figure shows the quantity comparison chart before and after data augmentation.

[0054] S4: Model construction: Build a lightweight cotton pest and disease identification model based on the attention mechanism and transfer learning;

[0055] S41: Replace the first-layer 7×7 convolution of DenseNet121 with a multi-scale convolution, Figure 4 The figure shows the structure of the multi-scale convolution;

[0056] S411: The network structure of the multi-scale convolution is composed of 1x1 convolution branch, 3x3 convolution branch, 5x5 convolution branch, and max-pooling branch respectively to replace the original 7×7 convolution, introducing receptive fields of different scales and enhancing the model's ability to capture information of targets at different scales in complex scenes.

[0057] S42: Replace the activation function of the dense layer with RReLU6, and the expression of RReLU6 is:

[0058] where, a i ~U(l,u), l < u and l, u ∈ [0, 1), x is the input. If the input is greater than or equal to 0, take the minimum value between x and 6. If it is less than 0, a randomly drawn from the uniform distribution U(I, u) i makes x smaller. Figure 5 The figure shows the structure diagram of the RReLU6 activation function.

[0059] S43: Replace the second convolutional layer of the dense layer with a depthwise separable convolution, Figure 6 The figure shows the structure diagram of the depthwise separable convolution. The depthwise separable convolution consists of two steps: depthwise convolution DC and pointwise convolution PC. The expression of the depthwise convolution DC is:

[0060] The expression of the pointwise convolution PC is:

[0061] Among them, (i, j) represents the position of the image, z represents the input feature map of the convolutional layer, and W represents the trainable weight matrix. A and B represent the width and height of the input image respectively, and C represents the number of channels.

[0062] The expression of depth-separable convolution DSC is: DSC(W p ,W d ,z) (i,j) =PC (i,j) (W p ,DC (i,j) (W d ,z))

[0063] S44: Thus, a new dense layer R-dense layer is formed, and the structure of the new dense layer is as shown in FIG. Figure 7 As shown, different numbers of R-dense layers form new dense blocks RE-dense blocks, and different RE-dense blocks are connected by transition layers, which consist of a 1×1 convolution and a 2×2 average pooling layer.

[0064] S45: By removing unimportant weights in each layer, while minimizing the impact of pruning on the layer output. For the fully connected layer, the present invention achieves this goal by minimizing the layer output l2 distortion under a given worst-case input signal, and the specific calculation formula is as follows.

[0065] S451: Use ||Wξ-(M⊙W)ξ||2 to calculate the l2-norm distance between the output vectors before and after pruning to measure the impact of pruning on the output. Here, M is a binary mask matrix indicating which weights are retained (1) or removed (0); ||M||0≤κ specifies the maximum number of non-zero elements that can be retained, i.e., the sparsity. ξ is the input. W is the weight tensor, and ⊙ represents element-by-element multiplication.

[0066] S452: Although the layer pruning technique can effectively reduce the number of weights in a single layer, its limitation is that the optimization scope is limited to the current layer, and it is difficult to balance the importance of weights between layers from a global perspective. To overcome this limitation, LAMP extends the concept of layer pruning to the entire model level and proposes a new global pruning strategy, which is calculated as follows:

[0067] in, The total number of non-zero elements in all layers of the model is limited to κ as a global sparsity constraint. (1:d)represents the weight set of all layers in the model, and f() represents the output function of the model. Compared with layer-level pruning, the global pruning method extends the optimization scope to the entire model, so that the sparsity of each layer can be dynamically adjusted according to its actual importance. The LAMP method not only focuses on the importance of weights within each layer, but also uses a global optimization strategy to ensure that the pruned model can maintain the best performance.

[0068] S453: In the process of pruning, the importance score of weights is the key. LAMP proposes a simple and effective scoring method to measure the contribution of weights to model performance. The calculation formula is as follows:

[0069] Where score(u;W) represents the LAMP score of the u-th weight, which measures the importance of the weight in all unpruned connections in its layer. u represents the position index of a specific weight in the weight tensor W. W[u] is the value mapped from index u to the weight tensor W, that is, the value of the u-th weight. ∑ v≥u (W[v]) 2 is the sum of the squares of all weights from index u to the end of the weight tensor, used for normalization (W[v]) 2 , so that the score can reflect the relative importance of the weight in the remaining weights, Figure 8 The process of model pruning is shown.

[0070] S46: After being embedded into the RE-dense block using the MFGA attention mechanism, the structure of the MFGA attention mechanism is as follows Fig. 9 As shown, the calculation process of the MFGA attention mechanism is as follows:

[0071] (1) First, for the input features Figure X ∈R B×C×H×W Perform an average pooling operation, and then use one-dimensional convolution to linearly combine the channels. The calculation formula is as follows: Y split =Conv1D(Avg(X)) Among them, Avg represents the global average pooling operation, and Conv1D is a one-dimensional convolution.

[0072] (2) GCT is used to control the competition or cooperation between channels and improve the sensitivity of the model to key features. The calculation formula of GCT is as follows:

[0073] Where Q is Y split, ∈ is a small constant to avoid division by zero. α is a learnable scaling parameter, γ is a learnable normalization parameter, and β is a learnable bias parameter. Mean represents the mean of the embedding. tanh is the hyperbolic tangent function used to calculate the gating weights.

[0074] (3) Use three parallel modules, MLP, MSC and CA, to capture important feature information at different scales and perform feature fusion to strengthen the connection and complementarity between features. The calculation formula is as follows: Y mjp =W2·R(W1·G+b1)+b2 Y ca =σ(C2·R(C1·(Avg(G)+Max(G)))

[0075] Where G is the output of GCT, Conv1D represents a one-dimensional convolution operation at scale i, N represents the number of scales of multi-scale convolution, and σ represents the Sigmoid activation function. i Represents the weight matrix of the fully connected layer, Max represents the maximum pooling operation, Avg represents the average pooling operation, and R represents the ReLU activation function. i represents the weight matrix of the convolutional layer, b i is the bias corresponding to the fully connected layer.

[0076] (4) The features from different modules are fused through a fully connected layer, and the weights are generated using the Sigmoid activation function. The weights are multiplied by the input feature map to generate the final feature weighted map Y. The calculation formula of Y is as follows:

[0077] Among them, FC is the fully connected layer, ⊕ represents feature concatenation, σ represents the Sigmoid activation function, Y is the generated attention weight, X is the input, represents feature multiplication.

[0078] S47: Transfer learning can help the model learn basic features that are beneficial to the target task through the pre-training stage. Fig.10 The specific process of transfer learning is demonstrated.

[0079] S5: Input the processed images in S3 into the constructed lightweight cotton pest and disease recognition model based on attention mechanism and transfer learning for training;

[0080] S6: Input the test set into the model to test the model accuracy;

[0081] S7: Select cotton pest and disease images to input into the prediction model, and output the cotton pest and disease identification results.

[0082] In summary, the main features of the present invention are:

[0083] (1) The present invention designs an RE-dense block, in which the R-dense layer uses depthwise separable convolution to reduce model parameters, and uses the RReLU6 activation function to solve the problem of partial neuron inactivation caused by ReLU6 and alleviate the distortion problem caused by the RReLU activation function when deployed on portable devices. This design improves model accuracy while reducing parameters, achieving a good balance between model complexity and accuracy;

[0084] (2) The present invention uses multi-scale convolution to replace the 7×7 convolution of the first layer, which reduces the model parameters and increases the receptive field of the model, so that the model can better pay attention to the features of different scales, thereby improving the model accuracy. At the same time, in order to better reduce the number of model parameters, the present invention uses a model pruning method to compress the model and reduce the number of model parameters;

[0085] (3) In order to better balance model parameters and accuracy, the present invention uses transfer learning and MFGA multi-scale adaptive attention mechanism to compensate for the accuracy loss caused by pruning.

[0086] (4) The present invention proposes a lightweight cotton pest and disease identification method based on attention mechanism and transfer learning. This method extracts more information of different scales in the initial stage through multi-scale convolution; uses RE-dense blocks and model pruning to reduce model parameters and improve recognition accuracy; and finally introduces MFGA attention mechanism and transfer learning to make the model pay more attention to important information and ignore unimportant information while increasing model accuracy;

[0087] The embodiments of the present invention are described in detail above with reference to the accompanying drawings, but the present invention is not limited to the above embodiments, and various changes can be made within the knowledge scope of ordinary technicians in the relevant technical field without departing from the purpose of the present invention.

Claims

1. A lightweight cotton pest and disease identification method based on attention mechanism and transfer learning, characterized in that: The following steps are involved: S1: Dataset collection: Field collection of cotton pest and disease data; S2: Dataset division: The collected cotton pest and disease dataset is divided into training set and test set; S3: Image preprocessing: image enhancement of training set images; S4: Model building: Construct a lightweight cotton pest and disease recognition model based on attention mechanism and transfer learning; S5: Model training: input the images processed in step 3 into the cotton pest and disease recognition model for training; S6: Model testing: Test the trained model using the test set; S7: Cotton pest and disease prediction: Use the trained model weights to predict other cotton pest and disease images and output the prediction results.

2. A lightweight cotton pest and disease identification method based on attention mechanism and transfer learning according to claim 1, characterized in that: The cotton pest and disease dataset obtained in step 1 was collected in the field in Tacheng, Xinjiang Uygur Autonomous Region, China and Changji National Agricultural Center, Xinjiang Uygur Autonomous Region, China. These data were collected in real environments and faced challenges with complex backgrounds and different lighting conditions, such as variable field environments and different weather changes. All images were taken using an Android smartphone.

3. A lightweight cotton pest and disease identification method based on attention mechanism and transfer learning according to claim 2, characterized in that: The cotton diseases and insect pests include four diseases and one insect pest, namely healthy cotton leaves, cotton Verticillium wilt, cotton brown spot disease, cotton wilt, cotton red leaf and stem blight and cotton aphids.

4. A lightweight cotton pest and disease identification method based on attention mechanism and transfer learning according to claim 1, characterized in that: The cotton pest and disease dataset in step 2 is divided into a training set and a test set in a ratio of 8:

2.

5. A lightweight cotton pest and disease identification method based on attention mechanism and transfer learning according to claim 1, characterized in that: The image preprocessing in step 3 includes any one of image shearing, random grid shuffling, channel shuffling, grid distortion, random noise, random brightness, random adjustment of hue and saturation, and image data normalization.

6. A lightweight cotton pest and disease identification method based on attention mechanism and transfer learning according to claim 1, characterized in that: In the step 4, building a cotton pest and disease recognition model based on the attention mechanism and deep separable convolution includes using multi-scale convolution to replace the first layer of 7×7 convolution in DenseNet121; replacing the ReLU activation function in the dense layer of DenseNet121 with the RReLU6 activation function, while ensuring efficient operation on portable devices, reducing the inactivation of neurons; replacing the second convolution in the dense layer with a deep separable convolution, thereby constructing a new dense layer: R-dense layer, combining multiple R-dense layers into RE-dense blocks to reduce the number of model parameters; using the LAMP model pruning method to prune the model to reduce the number of model parameters; in order to compensate for the loss of model accuracy after pruning, using transfer learning to migrate the knowledge on the PlantVillage data set to the model constructed by the present invention; finally, constructing the MFGA multi-scale adaptive attention mechanism and embedding it in the RE-dense block to enhance the model's attention to important information.

7. A lightweight cotton pest and disease identification method based on attention mechanism and transfer learning according to claim 5, characterized in that: The initial learning rate is set to 0.01, the weight decay is 0.0001, and the SGD optimizer with momentum 0.9 is used.

8. A lightweight cotton pest and disease identification method based on attention mechanism and transfer learning according to claim 6, characterized in that: Input the test set into the model and output the model test accuracy.

9. A lightweight cotton pest and disease identification method based on attention mechanism and transfer learning according to claim 7, characterized in that: The images of cotton pests and diseases are input into the prediction model, and the recognition results of cotton pests and diseases are output.