A cotton disease recognition method in complex background based on salient object detection
By building a cotton disease recognition model based on significance target detection, using feature coding and multi-head attention mechanism to extract cotton disease characteristics, the problem of low recognition accuracy in complex backgrounds is solved, and cotton disease with high accuracy and stability is achieved Identify.
Patent Information
- Application Number
- CN202411140040.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-20
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2044-08-20
AI Technical Summary
The existing cotton disease recognition methods are not very accurate in complex backgrounds, and have high professional knowledge requirements, poor interpretability of feature extraction modules, high computing power and data costs, making it difficult to build a complete data set.
Using a method based on significance target detection, a cotton disease recognition model is built, including feature encoding module, mask decoding module, feature transformation module and identification and decoding module. Cotton disease characteristics are extracted through jump connection and multi-head attention mechanism, and exponential moving average is used. Methods smooth model parameters and optimize multitasking loss function to improve recognition accuracy and robustness.
High-accuracy cotton disease recognition in complex backgrounds is achieved, reducing the impact of background noise, independently extracting features, and improving model stability and robustness.
Smart Images

Figure CN118658150B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of cotton disease recognition, and in particular relates to a cotton disease recognition method under a complex background based on significant target detection. Background Art
[0002] Cotton diseases are one of the major challenges facing the global cotton industry, including cotton leafhoppers, cotton spider mites, and fall armyworms. These diseases affect the health of cotton leaves, thereby weakening the ability to photosynthesize, which has a negative impact on cotton growth and may even lead to reduced cotton yields or death. Early detection and diagnosis of cotton diseases is crucial to maintaining cotton yield and quality. Through automatic diagnosis technology for cotton diseases, farmers can take appropriate prevention and control measures at the early stage of the disease, which helps reduce the impact of diseases on cotton growth and increase cotton yields and agricultural sustainability.
[0003] Therefore, cotton disease detection has become one of the key issues that need to be solved urgently. With the help of modern technologies, including image recognition and sensor technology, accurate monitoring and early warning of cotton diseases can be achieved, providing farmers with more scientific and efficient agricultural management methods and promoting the sustainable development of the cotton industry.
[0004] Manual observation is the main way to identify cotton diseases in modern times, and this method is mainly based on experience. The application of computer vision technology has brought new possibilities for disease detection, greatly improving the speed and accuracy of detection, while reducing manual intervention and helping to reduce costs. The advantage of cotton pest identification based on machine learning technology over manual observation is that it can artificially establish identification features of cotton pests and realize automatic detection. Traditional machine learning methods such as support vector machines, self-organizing feature maps, and nearest neighbor classification have all achieved the purpose of cotton disease identification.
[0005] However, because these methods require high professional knowledge and need to manually construct features, the recognition accuracy is not satisfactory. Therefore, this limitation restricts its widespread application in intelligent disease recognition. With the continuous enhancement of computer performance and the continuous evolution of deep learning algorithms, deep learning methods are rapidly emerging and becoming a dominant trend. Deep learning can learn cotton disease characteristics under the dual drive of data models, so it is superior in accuracy and robustness. For example, a scholar used a deep learning network based on the LeNet architecture to classify banana leaf diseases, and a scholar used convolutional neural networks and transfer learning methods to identify crop diseases.
[0006] These methods have greatly improved the accuracy of crop pest identification. However, in actual use, the same disease image will still lead to different recognition results due to different shooting backgrounds. Common solutions include: building more complex data sets, designing more advanced feature extraction modules, and avoiding backgrounds through object detection and cropping. However, these methods all have their own problems: building a completely complete data set is difficult and costly; the design of feature extraction modules has poor interpretability and the effect is not intuitive; the object detection and cropping methods require high computing power and high data costs.
[0007] Therefore, a cotton disease recognition method under complex background based on salient target detection is proposed in the present invention. Summary of the invention
[0008] In view of the above technical problems, the present invention provides a cotton disease recognition method under complex background based on significant target detection.
[0009] The technical solution adopted by the present invention to solve the technical problem is:
[0010] A method for identifying cotton diseases in a complex background based on salient target detection, the method comprising the following steps:
[0011] S100: Build a cotton disease recognition model, including feature encoding module, mask decoding module, feature transformation module and recognition decoding module;
[0012] S200: Obtain a cotton disease dataset, input it into a feature encoding module, and extract semantic features of the cotton image and disease features with background noise;
[0013] S300: inputting the semantic features of the cotton image into a mask decoding module, which obtains a mask highlighting the foreground through a stepwise upsampling decoding process by skipping the feature encoding module;
[0014] S400: inputting the mask into a feature transformation module to obtain transformed mask features;
[0015] S500: Input the cotton disease features with background noise and the transformed mask features into a recognition and decoding module, and the recognition and decoding module integrates the foreground information in the mask features and the extracted cotton disease information with background noise to perform pest detection and obtain a recognition result;
[0016] S600: updating the parameters of the cotton disease recognition model according to the recognition result and the preset loss function, and in the parameter updating process, using the exponential moving average method to smooth the updating process of the model parameters to obtain an updated cotton recognition model;
[0017] S700: Acquire real-time cotton disease images, input them into the updated cotton recognition model, and obtain cotton disease recognition results.
[0018] Preferably, the feature encoding module in S200 includes 6 Unet-Block structures of different scales and dimensions, namely encoding U-B1, encoding U-B2, encoding U-B3, encoding U-B4, encoding U-B5 and encoding U-B6. The cotton disease image is first obtained by U-B1 to obtain a first feature, the first feature is copied and retained, the first feature is input into U-B2 to obtain a second feature, the second feature is copied and retained, the second feature is input into U-B3 to obtain a third feature, the third feature is copied and retained, the third feature is input into U-B4 to obtain a fourth feature, the fourth feature is copied and retained, the fourth feature is input into U-B5 to obtain a fifth feature, the fifth feature is copied and retained, the fifth feature is input into U-B6 to fuse with the fifth feature to obtain a sixth feature, and the sixth feature is copied and retained; wherein, the first to sixth features contain semantic features of cotton images of different dimensions, and the sixth feature also contains disease features with background noise.
[0019] Preferably, the mask decoding module in S300 includes 5 Unet-Block structures of different scales and dimensions, namely decoding U-B5, decoding U-B4, decoding U-B3, decoding U-B2 and decoding U-B1. The features obtained after each decoding UB are fused with the features obtained by the corresponding encoding UB through a jump connection; wherein, the sixth feature is input to decoding U-B5, the feature output by decoding U-B5 is fused with the fourth feature input by encoding U-B5 and input to decoding UB4, the feature output by decoding U-B4 is fused with the third feature input by encoding U-B4 and input to decoding UB3, the feature output by decoding U-B3 is fused with the second feature input by encoding U-B3 and input to decoding UB2, the feature output by decoding U-B2 is fused with the first feature input by encoding U-B2 and input to decoding UB1, and decoding UB1 outputs a mask highlighting the foreground.
[0020] Preferably, the feature transformation module in S400 includes a sigmoid function, a convolution layer, a view layer, a softmax function and a linear layer connected in sequence, and the mask feature is input into the feature transformation module, and the feature transformation module changes the cotton leaf mask into a processable visual token containing cotton leaf foreground information.
[0021] Preferably, the recognition and decoding module in S500 includes a multi-head attention mechanism, a multi-layer perceptron and a fully connected layer, the multi-layer perceptron includes a first linear layer, an activation layer, random inactivation and a second linear layer, the multi-head attention mechanism is used to encode the sixth feature and the processable visual token through a hidden information matrix to distinguish the foreground and background of the cotton diseased leaves, the output features of the multi-head attention mechanism are residually connected with the processable visual token and then input into the multi-layer perceptron, the multi-layer perceptron is used to extract and transform the cotton diseases with background noise in the input features through layer-by-layer transfer of multiple linear layers and nonlinear transformation of the activation function, so as to learn the deep features of the cotton diseases in the input features, the features output by the multi-layer perceptron are residually connected with the input features of the multi-layer perceptron and then input into the fully connected layer, and the fully connected layer outputs the cotton disease recognition result.
[0022] Preferably, when the input patch sequence is the sixth feature and the processable visual token, the calculation formula of the multi-head attention mechanism is as follows:
[0023] ;
[0024] ;
[0025] ;
[0026] ;
[0027] ;
[0028] ;
[0029] in, Represents processable visual information containing foreground information token , Represents a rich semantic feature of cotton diseases Feature 6 , represents the dimension of vector K, , , is a learnable parameter matrix, Q represents the query, which contains the weight information assigned to the foreground and background of the cotton disease image, K represents the key, and V represents the value, both of which come from the sixth feature, which contains the cotton disease image information. represents the transposed matrix of the K matrix, softmax represents the normalization process, represents the weight matrix.
[0030] Preferably, the preset loss function is specifically:
[0031] ;
[0032] ;
[0033] ;
[0034] in, , is a trainable parameter, which is learned by , Dynamically adjust the weights of the two tasks, is the regularization term, , To constrain, is the loss function for salient object detection, is the disease identification loss function, N is the sample point, is the true label of the i-th pixel, which takes a value of 0 or 1. is the predicted probability that the i-th pixel output by the model is the foreground, is the number of sample classifications, is the true category of sample i, is the predicted probability distribution of the model for sample i.
[0035] Preferably, in S600, the updating process of the model parameters is smoothed using an exponential moving average method, including:
[0036] Use the exponential moving average method to obtain the shadow weight, specifically:
[0037] ;
[0038] in, is the model weight at time t, is the shadow weight at time t, is the shadow weight at time t-1, is the weighted weight value interval;
[0039] Smooth the update process of model parameters according to shadow weights.
[0040] The above-mentioned cotton disease recognition method under complex background based on salient target detection has the following beneficial effects:
[0041] First, the mask can be fully utilized to optimize the extraction process of disease features; second, the influence of the background of the cotton disease image can be weakened during the recognition process, thereby improving the recognition accuracy; third, the network of the present invention is an end-to-end trainable network, which can autonomously extract the required features through learning during training; fourth, a dimensionally balanced dynamic multi-task loss adjustment method is used to optimize the training process of the multi-task model; fifth, the exponential moving average technology is used to optimize the model parameters and improve the robustness of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 It is a flow chart of a cotton disease recognition method under a complex background based on significant target detection in one embodiment of the present invention;
[0043] Figure 2 This is an overall framework diagram of a cotton disease recognition model in one embodiment of the present invention;
[0044] Figure 3 This is a structural diagram of a feature coding module in one embodiment of the present invention;
[0045] Figure 4 A structural diagram of a mask decoding module in one embodiment of the present invention;
[0046] Figure 5 This is a structural diagram of a feature transformation module in one embodiment of the present invention;
[0047] Figure 6 This is a structural diagram of an identification and decoding module in one embodiment of the present invention. DETAILED DESCRIPTION
[0048] In order to enable those skilled in the art to better understand the technical solution of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings.
[0049] In one embodiment, Figure 1 As shown, a cotton disease recognition method under complex background based on salient target detection comprises the following steps:
[0050] S100: Build a cotton disease recognition model, including feature encoding module, mask decoding module, feature transformation module and recognition decoding module;
[0051] S200: Obtain a cotton disease dataset, input it into a feature encoding module, and extract semantic features of the cotton image and disease features with background noise;
[0052] S300: inputting the semantic features of the cotton image into a mask decoding module, which obtains a mask highlighting the foreground through a stepwise upsampling decoding process by skipping the feature encoding module;
[0053] S400: inputting the mask into a feature transformation module to obtain transformed mask features;
[0054] S500: Input the cotton disease features with background noise and the transformed mask features into a recognition and decoding module, and the recognition and decoding module integrates the foreground information in the mask features and the extracted cotton disease information with background noise to perform pest detection and obtain a recognition result;
[0055] S600: updating the parameters of the cotton disease recognition model according to the recognition result and the preset loss function, and in the parameter updating process, using the exponential moving average method to smooth the updating process of the model parameters to obtain an updated cotton recognition model;
[0056] S700: Acquire real-time cotton disease images, input them into the updated cotton recognition model, and obtain cotton disease recognition results.
[0057] Specifically, the cotton disease recognition model is called UHC-NET network, and its overall block diagram is as follows Figure 2 As shown. The UHC-NET network is mainly composed of four modules: feature encoding module, mask decoding module, feature transformation module and recognition decoding module. First, the cotton disease image is input into the feature encoding module to extract the semantic features of the cotton image and the disease features with background noise; then the semantic features of the extracted cotton image enter the mask decoding module, and the mask features that highlight the foreground are obtained through decoding processes such as upsampling; the extracted cotton disease features with background noise and the transformed mask features are simultaneously input into the recognition decoding module, and the recognition decoding module integrates the foreground information in the mask features and the extracted cotton disease information with background noise to complete pest recognition. By making full use of the mask that highlights the foreground information, the influence of the background of the cotton disease image in the recognition process is weakened, and the accuracy of cotton disease recognition under complex backgrounds is improved. At the same time, a scale-balanced dynamic multi-task loss is designed, and the exponential moving average technology is used to make the multi-task model trained to the optimal state while having stronger stability. The process of the proposed UHC-NET network is as follows:
[0058] 1) First, cotton disease images are used to capture relevant information of cotton diseases at different scales through N series-connected Unet structures. The first N-1 features are used as semantic segmentation features, and the Nth feature is also used as cotton disease information features;
[0059] 2) Secondly, all features are input into the mask decoding module through skip connections, and the multi-scale semantic information is used to accurately locate the diseased area, thereby extracting the foreground information of cotton diseases and completing the corresponding transformation to obtain the mask features;
[0060] 3) Finally, the generated mask features are input into the recognition decoding module as query Q. The recognition decoding module extracts foreground features from the cotton disease information features with background noise through query matching, and further completes the recognition of cotton diseases.
[0061] In one embodiment, the feature encoding module in S200 includes 6 Unet-Block structures of different scales and dimensions, namely encoding U-B1, encoding U-B2, encoding U-B3, encoding U-B4, encoding U-B5 and encoding U-B6. The cotton disease image is first obtained by U-B1 to obtain a first feature, copy and retain the first feature, input the first feature into U-B2 to obtain a second feature, copy and retain the second feature, input the second feature into U-B3 to obtain a third feature, copy and retain the third feature, input the third feature into U-B4 to obtain a fourth feature, copy and retain the fourth feature, input the fourth feature into U-B5 to obtain a fifth feature, copy and retain the fifth feature, input the fifth feature into U-B6 to fuse with the fifth feature to obtain a sixth feature, and copy and retain the sixth feature; wherein, the first to sixth features contain semantic features of cotton images of different dimensions, and the sixth feature also contains disease features with background noise.
[0062] Specifically, the feature encoding module is built on the basis of Unet-Block (UB) of Unet structure, which can extract multi-dimensional cotton disease semantic features from the input image. Figure 3 As shown in the figure, there are a total of 6 UBs that make up the feature encoding module. The cotton disease image first passes through U-B1 to obtain feature 1, and feature 1 is copied and retained while passing through U-B2. Similarly, the extracted features pass through U-B3, U-B4, U-B5, and U-B6 in turn, retaining feature 2, feature 3, feature 4, feature 5, and feature 6.
[0063] In one embodiment, the mask decoding module in S300 includes 5 Unet-Block structures of different scales and dimensions, namely decoding U-B5, decoding U-B4, decoding U-B3, decoding U-B2 and decoding U-B1. The features obtained after each decoding UB are fused with the features obtained by the corresponding encoding UB through a jump connection; wherein, the sixth feature is input to decoding U-B5, the feature output by decoding U-B5 is fused with the fourth feature input by encoding U-B5 and input to decoding UB4, the feature output by decoding U-B4 is fused with the third feature input by encoding U-B4 and input to decoding UB3, the feature output by decoding U-B3 is fused with the second feature input by encoding U-B3 and input to decoding UB2, the feature output by decoding U-B2 is fused with the first feature input by encoding U-B2 and input to decoding UB1, and decoding UB1 outputs a mask highlighting the foreground.
[0064] Specifically, the mask decoding module has a similar structure to the feature encoding module, but has opposite functions. The feature decoding module is also built on the basis of UB, and is composed of U-B5, U-B4, U-B3, U-B2, and U-B1. At the same time, the features obtained after decoding each UB are fused with the features obtained by encoding the corresponding UB through jump connections. The main function of the feature encoding module is to extract the semantic features of cotton images in different dimensions. The feature map will continue to decrease as the depth of the model increases and the number of channels increases. The mask decoding module reduces the number of channels and restores the feature map to the original input image size through operations such as convolution and upsampling.
[0065] The features restored by the mask decoding module are fused with the encoder's features 1, 2, 3, 4, 5, and 6 to obtain more global and local contextual information of cotton leaves. This helps improve the model's understanding of the overall structure and local features of the image. These features are restored to the original cotton image resolution by stepwise upsampling (deconvolution or upsampling operations). This helps preserve the texture, edge, and other detail information in the cotton leaf surface. By restoring the details of the image from high-level abstract features, the model's reconstruction and segmentation performance of cotton images is improved, making it more semantically and visually accurate. This encoding-decoding structure is particularly useful in the cotton leaf image segmentation task because it can capture both global and local information, enabling the model to better understand the semantic structure of the image. The feature encoding module and the mask decoding module form a salient object detection network that can obtain a salient segmentation mask map of the cotton leaf surface under a complex background.
[0066] In one embodiment, the feature transformation module in S400 includes a sigmoid function, a convolution layer, a view layer, a softmax function and a linear layer connected in sequence, and the mask feature is input into the feature transformation module, and the feature transformation module transforms the cotton leaf mask into a processable visual token containing cotton leaf foreground information.
[0067] Specifically, the feature encoding module can obtain feature 6 containing rich semantic features of cotton diseases, and the mask decoding module can detect the cotton leaf foreground saliency mask. First, the foreground mask is characterized, and the feature transformation module structure is as follows: Figure 5 As shown in the figure, it is composed of volume, view, linear and other operations. The foreground mask is converted into a processable visual token containing the foreground information of the cotton leaf surface through the feature transformation module.
[0068] In one embodiment, the recognition and decoding module in S500 includes a multi-head attention mechanism, a multi-layer perceptron and a fully connected layer. The multi-layer perceptron includes a first linear layer, an activation layer, random inactivation and a second linear layer. The multi-head attention mechanism is used to encode the sixth feature and the processable visual token through a hidden information matrix to distinguish the foreground and background of the cotton diseased leaves. The output features of the multi-head attention mechanism are residually connected with the processable visual token and then input into the multi-layer perceptron. The multi-layer perceptron is used to extract and transform the cotton diseases with background noise in the input features through layer-by-layer transfer of multiple linear layers and nonlinear transformation of the activation function to learn the deep features of the cotton diseases in the input features. The features output by the multi-layer perceptron are residually connected with the input features of the multi-layer perceptron and then input into the fully connected layer. The fully connected layer outputs the cotton disease recognition result.
[0069] Specifically, a set of Multi-Head Self-Attention (MSA), Multilayer Perceptron (MLP) and the final fully connected layer for classification constitute the recognition decoding module, the structure is as follows Figure 6 As shown. Under the guidance of the processable visual token containing foreground information, the recognition and decoding module extracts the cotton disease related information in feature 6, weakens the background related information, and achieves the purpose of identifying cotton diseases in complex backgrounds. The recognition and decoding module can encode cotton disease features and tokens through the hidden information matrix, distinguish the foreground and background of cotton diseased leaves, and avoid the influence of complex environments when extracting features. This helps to improve the robustness of the model and improve the recognition accuracy of cotton diseases in complex backgrounds.
[0070] In one embodiment, when the input patch sequence is the sixth feature and a processable visual token, the calculation formula of the multi-head attention mechanism is as follows:
[0071] ;
[0072] ;
[0073] ;
[0074] ;
[0075] ;
[0076] ;
[0077] in, Represents processable visual information containing foreground information token , Represents a rich semantic feature of cotton diseases Feature 6 , represents the dimension of vector K, , , is a learnable parameter matrix, Q represents the query, which contains the weight information assigned to the foreground and background of the cotton disease image, K represents the key, and V represents the value, both of which come from the sixth feature, which contains the cotton disease image information. represents the transposed matrix of the K matrix, softmax represents the normalization process, represents the weight matrix.
[0078] Specifically, by calculating the similarity between the Q (query) matrix and the K (key) matrix, the weight distribution of the information in feature 6 is achieved, so as to strengthen the foreground information of the image and weaken the background information. The above steps implement a single-head attention mechanism, in which multiple attention mechanisms are used to process different feature information. Finally, by splicing the results of the multi-way attention mechanism together and applying the multi-head self-attention mechanism (MSA), Represents the weight matrix, and the concatenated matrix can be linearly transformed. The model can collaboratively learn the information extracted by different attention mechanisms.
[0079] The main function of the multi-layer perceptron structure in the recognition and decoding module is to extract and transform cotton disease features. It learns the deep features of the input cotton disease image through layer-by-layer transmission of multiple linear layers and nonlinear transformation of activation functions. Finally, the cotton disease results are output through the fully connected layer. In addition, methods such as residual connection and normalization technology are used to further improve the performance of the MLP structure in the recognition and decoding module.
[0080] This further strengthens the model's ability to integrate feature 6 and token information. In this way, the model more effectively utilizes mask information and disease information to achieve the purpose of identifying diseases in complex backgrounds in a more comprehensive way.
[0081] In one embodiment, the preset loss function is specifically:
[0082] ;
[0083] ;
[0084] ;
[0085] in, , is a trainable parameter, which is learned by , Dynamically adjust the weights of the two tasks, is the regularization term, , To constrain, is the loss function for salient object detection, is the disease identification loss function, N is the sample point, is the true label of the i-th pixel, which takes a value of 0 or 1. is the predicted probability that the i-th pixel output by the model is the foreground, is the number of sample classifications, is the true category of sample i, is the predicted probability distribution of the model for sample i.
[0086] Specifically, the model is a multi-task model for significant target detection and cotton disease recognition. The multi-task model is usually trained jointly to achieve end-to-end recognition of the model. This method can make the model pay more attention to the tasks that contribute more to the overall performance through automatic learning weights, thereby improving the robustness of the model. The above preset loss function ensures that the contributions of the two tasks are reasonably considered in the loss calculation. The above improvements ensure that the significant target detection task and the cotton disease recognition task are jointly trained to the optimal balance state.
[0087] In one embodiment, the updating process of the model parameters is smoothed using the exponential moving average method in S600, including:
[0088] Use the exponential moving average method to obtain the shadow weight, specifically:
[0089] ;
[0090] in, is the model weight at time t, is the shadow weight at time t, is the shadow weight at time t-1, is the weighted weight value interval;
[0091] Smooth the update process of model parameters according to shadow weights.
[0092] Specifically, Exponential Moving Average (EMA) is a method for optimizing deep learning models, and its main purpose is to smooth the update process of model parameters. The present invention intends to use the exponential moving average method to reduce the noise of parameter updates in the cotton pest classification model and improve the stability of the model. EMA performs a weighted average of the historical gradients of the parameters, paying more attention to the most recent gradient information, thereby updating the model parameters more smoothly during training.
[0093] Further, The weighted weight value range is generally 0.9-0.999. During the model training process, the shadow weight is not trained, and it is updated according to the shadow weight of the previous time and the model weight of the current stage. The exponential moving average makes the model pay more attention to the recent gradient information, while retaining a certain degree of historical information, making the model parameters smoother and improving the stability and generalization ability of the cotton disease recognition model in complex backgrounds.
[0094] The above-mentioned cotton disease recognition method under complex background based on salient target detection has the following beneficial effects:
[0095] First, the mask can be fully utilized to optimize the disease feature extraction process; second, the influence of the cotton disease image background can be weakened in the recognition process to improve the recognition accuracy; third, the network of the present invention is an end-to-end trainable network, which can autonomously extract the required features through learning during training; fourth, a dimensional balanced dynamic multi-task loss adjustment method is used to optimize the training process of the multi-task model; fifth, the exponential moving average technology is used to optimize the model parameters to improve the model robustness.
[0096] The above is a detailed introduction to a cotton disease identification method under a complex background based on significant target detection provided by the present invention. This article uses specific examples to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the core idea of the present invention. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present invention, the present invention can also be improved and modified, and these improvements and modifications also fall within the scope of protection of the claims of the present invention.
Claims
1. A cotton disease recognition method under complex background based on salient target detection, characterized in that: The method comprises the following steps: S100: Build a cotton disease recognition model, including feature encoding module, mask decoding module, feature transformation module and recognition decoding module; S200: Obtain a cotton disease dataset, input it into a feature encoding module, and extract semantic features of the cotton image and disease features with background noise; The feature encoding module in S200 includes 6 Unet-Block structures of different scales and dimensions, namely, encoding U-B1, encoding U-B2, encoding U-B3, encoding U-B4, encoding U-B5 and encoding U-B6. The cotton disease image first obtains the first feature through U-B1, copies and retains the first feature, inputs the first feature into U-B2 to obtain the second feature, copies and retains the second feature, inputs the second feature into U-B3 to obtain the third feature, copies and retains the third feature, inputs the third feature into U-B4 to obtain the fourth feature, copies and retains the fourth feature, inputs the fourth feature into U-B5 to obtain the fifth feature, copies and retains the fifth feature, inputs the fifth feature into U-B6 to fuse with the fifth feature to obtain the sixth feature, and copies and retains the sixth feature; wherein, the first to sixth features contain semantic features of cotton images of different dimensions, and the sixth feature also contains disease features with background noise; S300: inputting the semantic features of the cotton image into a mask decoding module, which obtains a mask highlighting the foreground through a stepwise upsampling decoding process by skipping the feature encoding module; S400: inputting the mask into a feature transformation module to obtain transformed mask features; The feature transformation module in S400 includes a sigmoid function, a convolution layer, a view layer, a softmax function and a linear layer connected in sequence, and the mask feature is input into the feature transformation module, and the feature transformation module transforms the cotton leaf mask into a processable visual token containing cotton leaf foreground information; S500: Input the cotton disease features with background noise and the transformed mask features into a recognition and decoding module, and the recognition and decoding module integrates the foreground information in the mask features and the extracted cotton disease information with background noise to perform pest detection and obtain a recognition result; S600: updating the parameters of the cotton disease recognition model according to the recognition result and the preset loss function, and in the parameter updating process, using the exponential moving average method to smooth the updating process of the model parameters to obtain an updated cotton recognition model; S700: obtaining a real-time cotton disease picture, inputting it into an updated cotton recognition model, and obtaining a cotton disease recognition result; The recognition and decoding module in S500 includes a multi-head attention mechanism, a multi-layer perceptron and a fully connected layer. The multi-layer perceptron includes a first linear layer, an activation layer, random inactivation and a second linear layer. The multi-head attention mechanism is used to encode the sixth feature and the processable visual token through a hidden information matrix to distinguish the foreground and background of the cotton diseased leaves. The output features of the multi-head attention mechanism are residually connected with the processable visual token and then input into the multi-layer perceptron. The multi-layer perceptron is used to extract and transform the cotton diseases with background noise in the input features through layer-by-layer transfer of multiple linear layers and nonlinear transformation of the activation function to learn the deep features of the cotton diseases in the input features. The features output by the multi-layer perceptron are residually connected with the input features of the multi-layer perceptron and then input into the fully connected layer. The fully connected layer outputs the cotton disease recognition results.
2. The method according to claim 1, characterized in that The mask decoding module in S300 includes 5 Unet-Block structures of different scales and dimensions, namely decoding U-B5, decoding U-B4, decoding U-B3, decoding U-B2 and decoding U-B1. The features obtained after each decoding UB are fused with the features obtained by the corresponding encoding UB through jump connections; among them, the sixth feature is input to decoding U-B5, the feature output by decoding U-B5 is fused with the fourth feature input by encoding U-B5 and input into decoding U-B4, the feature output by decoding U-B4 is fused with the third feature input by encoding U-B4 and input into decoding U-B3, the feature output by decoding U-B3 is fused with the second feature input by encoding U-B3 and input into decoding U-B2, the feature output by decoding U-B2 is fused with the first feature input by encoding U-B2 and input into decoding U-B1, and decoding U-B1 outputs a mask highlighting the foreground.
3. The method according to claim 2, characterized in that When the input patch sequence is the sixth feature and the processable visual token, the calculation formula of the multi-head attention mechanism is as follows: ; ; ; ; ; ; in, Represents a processable visual token containing foreground information, Indicates feature 6 that contains rich semantic features of cotton diseases, represents the dimension of vector K, , , is a learnable parameter matrix, Q represents the query, which contains the weight information assigned to the foreground and background of the cotton disease image, K represents the key, and V represents the value, both of which come from the sixth feature, which contains the cotton disease image information. represents the transposed matrix of the K matrix, softmax represents the normalization process, represents the weight matrix.
4. The method according to claim 3, characterized in that The preset loss function is: ; ; ; in, , is a trainable parameter, which is learned by , Dynamically adjust the weights of the two tasks, is the regularization term, , To constrain, is the loss function for salient object detection, is the disease recognition loss function, N is the total number of pixels, is the true label of the i-th pixel, which takes a value of 0 or 1. is the predicted probability that the i-th pixel output by the model is the foreground, is the number of sample classifications, is the true category of sample i, is the predicted probability distribution of the model for sample i.
5. The method according to claim 4, characterized in that The updating process of the model parameters using the exponential moving average method in S600 includes: Use the exponential moving average method to obtain the shadow weight, specifically: ; in, is the model weight at time t, is the shadow weight at time t, is the shadow weight at time t-1, is the weighted weight value interval; Update model parameters according to shadow weights to smooth the update process.
