Crop disease and pest detection method, device, equipment and storage medium

By using a target attention convolutional neural network to detect crop diseases and pests, and by training the model with weighted feature maps and adversarial sample sets, the problem of low efficiency in manual detection is solved, and efficient automated disease and pest detection is achieved.

CN116797537BActive Publication Date: 2025-12-26WUHAN POLYTECHNIC UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310436076.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-04-20
Publication Date
2025-12-26
Estimated Expiration
2043-04-20

AI Technical Summary

Technical Problem

Current technologies rely on manual detection for crop diseases and pests, resulting in low overall detection efficiency.

Method used

A target attention convolutional neural network is used for crop pest and disease detection. By acquiring crop images, the input layer, convolutional layer, attention module, adversarial module and fully connected layer of the target attention convolutional neural network are used to detect pests and diseases, generate weighted feature maps and adversarial sample sets, and train the initial attention convolutional neural network to improve detection efficiency.

Benefits of technology

Pests and diseases can be detected directly from crop images without manual intervention, significantly improving the overall efficiency of crop pest and disease detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116797537B_ABST
    Figure CN116797537B_ABST
Patent Text Reader

Abstract

The application belongs to the technical field of image processing, and discloses a crop disease and pest detection method, device, equipment and storage medium. The method comprises the following steps: acquiring a first crop image; inputting the first crop image into a target attention convolutional neural network to output a disease and pest detection result of the first crop image, wherein the target attention convolutional neural network comprises an input layer, a convolutional layer, an attention module, an adversarial module, a full connection layer and an output layer connected in sequence, the attention module is used for generating a weighted feature map of the first crop image according to a feature map, and the adversarial module is used for generating an adversarial sample set, which is used for training an initial attention convolutional neural network to obtain the target attention convolutional neural network. In the foregoing manner, the disease and pest detection result of the crop can be directly detected according to the crop image.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of image processing, and particularly relates to a crop disease and pest detection method, device and equipment and a storage medium. BACKGROUND

[0002] Disease and pest control is an important task in crop production management, and the premise of control is to detect disease and pest occurrence in time. The traditional crop disease and pest detection method is usually manual work, which completely depends on the subjective experience of people on crops. However, with the development of today's agriculture, the planting mode of farm is more and more popular. In the case of the increase of cultivated land area, the use of manual work will cause the overall detection efficiency to be low. SUMMARY

[0003] The main purpose of the present application is to provide a crop disease and pest detection method, device, equipment and storage medium, which aims to solve the technical problem of low overall detection efficiency of crops caused by manual detection of crop diseases and pests in the prior art.

[0004] To achieve the above purpose, the present application provides a crop disease and pest detection method, which comprises the following steps:

[0005] obtaining a first crop image;

[0006] inputting the first crop image into a target attention convolutional neural network to output a disease and pest detection result of the first crop image, wherein the target attention convolutional neural network comprises an input layer, a convolutional layer, an attention module, an adversarial module, a fully connected layer and an output layer connected in sequence, the attention module is used to generate a weighted feature map of the first crop image according to a feature map, and the adversarial module is used to generate an adversarial sample set, which is used to train an initial attention convolutional neural network to obtain the target attention convolutional neural network.

[0007] Optionally, before the first crop image is input into the target attention convolutional neural network, the method further comprises:

[0008] obtaining a second crop image;

[0009] performing a preprocessing operation on the second crop image to obtain a real sample set;

[0010] training an initial adversarial module in an initial attention convolutional neural network based on the real sample set to generate the adversarial module;

[0011] generating an adversarial sample set through the adversarial module;

[0012] The initial attention convolutional neural network is trained based on the real sample set and the adversarial sample set to obtain a target attention convolutional neural network.

[0013] Optionally, the generating the adversarial sample set by the adversarial module comprises:

[0014] A random real sample is determined from the real sample set, and a random initial adversarial sample corresponding to the random real sample is determined by the adversarial module.

[0015] A distance measure of the random real sample and the random initial adversarial sample is determined.

[0016] The current performance of the adversarial module is determined according to the distance measure.

[0017] Based on the current performance and the random real sample, a random adversarial sample of the random real sample is determined to determine an adversarial sample set corresponding to the real sample set.

[0018] Optionally, the initial adversarial module comprises a generator and a discriminator; wherein,

[0019] The initial adversarial module in the initial attention convolutional neural network is trained based on the real sample set to generate the adversarial module, comprising:

[0020] S201, initializing generator parameters in the initial adversarial module, and initializing discriminator parameters in the initial adversarial module;

[0021] S202, determining a noise sample set, and inputting the noise sample set into the generator to obtain a simulation sample set;

[0022] S203, inputting the simulation sample set and the real sample set into the discriminator to output a first discrimination result, and updating discriminator parameters of the discriminator according to the first discrimination result;

[0023] S204, determining a random simulation sample from the simulation sample set, inputting the random simulation sample into the discriminator to obtain a second discrimination result, and updating generator parameters of the generator according to the second discrimination result;

[0024] S205, determining whether the second discrimination result is a preset value;

[0025] S206, if it is determined that the second discrimination result is not the preset value, updating the generator parameters of the generator in step S202 according to the second discrimination result, and updating the discriminator parameters of the discriminator in step S203 according to the first discrimination result, and then repeating steps S202-S206 until it is determined that the second discrimination result is the preset value, and the generative adversarial module is generated.

[0026] Optionally, the updating the discriminator parameters of the discriminator according to the first discrimination result comprises:

[0027] inputting the first discrimination result into an adversarial regularization loss function of the discriminator to obtain a discrimination loss value;

[0028] updating the discriminator parameters of the discriminator according to the discrimination loss value;

[0029] the updating the generator parameters of the generator according to the second discrimination result comprises:

[0030] inputting the second discrimination result into an adversarial regularization loss function of the generator to obtain a generation loss value;

[0031] updating the generator parameters of the generator according to the generation loss value.

[0032] Optionally, the determining the noise sample set and inputting the noise sample set into the generator to obtain the simulation sample set comprises:

[0033] determining a noise sample set and determining a condition information set corresponding to the noise sample set, wherein the noise in the noise sample set and the condition information in the condition information set are one-to-one corresponding;

[0034] inputting the noise sample set and the condition information set into the generator to obtain the simulation sample set.

[0035] Optionally, the attention module is a multi-head attention module, the weighted feature map of the first crop image is obtained by linear transformation of the feature map through the multi-head attention module to obtain query representation, key representation and value representation, each head dot product attention is generated according to the query representation, the key representation and the value representation, the splicing dot product attention is determined according to each head dot product attention, the splicing dot product attention is converted into a splicing attention matrix, and the splicing attention matrix is generated according to the feature map and the splicing attention matrix.

[0036] In addition, in order to achieve the above-mentioned purpose, the present application further provides a crop disease and pest detection device, which comprises:

[0037] an acquisition module, configured to acquire a first crop image;

[0038] The identification module is configured to input the first crop image into a target attention convolutional neural network, and output a disease and pest detection result of the first crop image, wherein the target attention convolutional neural network comprises an input layer, a convolutional layer, an attention module, an adversarial module, a fully connected layer and an output layer connected in sequence, the attention module is configured to generate a weighted feature map of the first crop image according to a feature map, and the adversarial module is configured to generate an adversarial sample set, which is used to train an initial attention convolutional neural network to obtain the target attention convolutional neural network.

[0039] In addition, to achieve the above object, the present application further provides a crop disease and pest detection device, which comprises a memory, a processor and a crop disease and pest detection program stored in the memory and executable on the processor, and the crop disease and pest detection program is configured to implement the steps of the crop disease and pest detection method as described above.

[0040] In addition, to achieve the above object, the present application further provides a storage medium, which stores a crop disease and pest detection program, and the crop disease and pest detection program implements the steps of the crop disease and pest detection method as described above when executed by a processor.

[0041] The crop disease and pest detection method, device, equipment and storage medium provided by the present application can obtain a first crop image, input the first crop image into a target attention convolutional neural network, and output a disease and pest detection result of the first crop image, wherein the target attention convolutional neural network comprises an input layer, a convolutional layer, an attention module, an adversarial module, a fully connected layer and an output layer connected in sequence, the attention module is configured to generate a weighted feature map of the first crop image according to a feature map, and the adversarial module is configured to generate an adversarial sample set, which is used to train an initial attention convolutional neural network to obtain the target attention convolutional neural network. In this way, the disease and pest situation of the crop can be detected without manual operation, the disease and pest detection result of the crop can be directly detected according to the crop image, and the overall detection efficiency of the crop is effectively improved. BRIEF DESCRIPTION OF DRAWINGS

[0042] Figure 1 FIG. 1 is a structural schematic diagram of a crop disease and pest detection device related to a hardware running environment of an embodiment of the present application;

[0043] Figure 2 FIG. 2 is a flowchart of a first embodiment of the crop disease and pest detection method of the present application;

[0044] Figure 3A model architecture diagram of the attention convolutional neural network in the first embodiment of the crop disease and pest detection method of the present application;

[0045] Figure 4 A structure diagram of the attention module in the first embodiment of the crop disease and pest detection method of the present application;

[0046] Figure 5 A flowchart of the second embodiment of the crop disease and pest detection method of the present application;

[0047] Figure 6 A training flowchart of the confrontation module in the second embodiment of the crop disease and pest detection method of the present application;

[0048] Figure 7 A structure block diagram of the first embodiment of the crop disease and pest detection device of the present application.

[0049] The implementation, functional features and advantages of the present application will be further described with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION

[0050] It should be understood that the specific embodiments described herein are intended to explain the present application, but not to limit the present application.

[0051] Reference Figure 1 , Figure 1 A crop disease and pest detection device structure diagram of a hardware running environment related to the embodiment scheme of the present application.

[0052] As Figure 1 shown, the crop disease and pest detection device can include a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 can include a display screen (Display), an input unit such as a keyboard (Keyboard), and an optional user interface 1003 can also include a standard wired interface, a wireless interface. The network interface 1004 can optionally include a standard wired interface, a wireless interface (such as a wireless fidelity (Wireless-Fidelity, Wi-Fi) interface). The memory 1005 can be a high-speed random access memory (RAM) memory, or a stable non-volatile memory (Non-Volatile Memory, NVM), such as a magnetic disk memory. The memory 1005 can also be a storage device independent of the aforementioned processor 1001.

[0053] Those skilled in the art can understand that Figure 1 The structure shown in the figure does not constitute a limitation on the crop disease and pest detection device, and can include more or fewer components than the figure, or combine certain components, or different component arrangements.

[0054] As shown in Figure 1 The memory 1005 as a storage medium can include an operating system, a network communication module, a user interface module, and a crop disease and pest detection program.

[0055] In the crop disease and pest detection device shown in Figure 1 In the crop disease and pest detection device shown in The processor 1001 and the memory 1005 in the crop disease and pest detection device of the present application can be arranged in the crop disease and pest detection device, and the crop disease and pest detection program stored in the memory 1005 is called by the processor 1001 to execute the crop disease and pest detection method provided in the embodiments of the present application.

[0056] Based on the above hardware structure, the crop disease and pest detection method embodiments of the present application are proposed.

[0057] Referring to Figure 2 , Figure 2 The flowchart of the first embodiment of the crop disease and pest detection method of the present application is shown.

[0058] In this embodiment, the crop disease and pest detection method comprises the following steps:

[0059] Step S10: Obtain a first crop image.

[0060] It should be noted that the execution subject of the present embodiment can be a computing service device with data processing, network communication and program running functions, such as mobile phones, tablet computers, personal computers, etc., or an electronic device or crop disease and pest detection device capable of realizing the above functions. The present embodiment and the following embodiments will be described taking the crop disease and pest detection device as an example.

[0061] It should be noted that the first crop image refers to an image used to detect crop diseases and pests.

[0062] Step S20: inputting the first crop image into a target attention convolutional neural network to output a disease and pest detection result of the first crop image, wherein the target attention convolutional neural network comprises an input layer, a convolutional layer, an attention module, an adversarial module, a fully connected layer and an output layer connected in sequence, the attention module is configured to generate a weighted feature map of the first crop image according to a feature map, and the adversarial module is configured to generate an adversarial sample set used for training an initial attention convolutional neural network to obtain the target attention convolutional neural network.

[0063] It can be understood that, since the target attention convolutional neural network is a trained network model, the disease and pest of the first crop image can be directly identified.

[0064] In a specific implementation, as shown in FIG. 2, the first crop image can be received by the input layer, and then the image features are extracted by the convolutional layer to obtain a feature map, the feature map is weighted by the attention module to obtain a weighted feature map, the disease and pest detection result is determined according to the weighted feature map by the fully connected layer, and the disease and pest detection result is output by the output layer, wherein the adversarial module is used to generate adversarial samples to improve the generalization ability of the model. Figure 3

[0065] It should be noted that the attention module can guide the model to focus on more valuable local features in the convolutional layer. The calculation process of the attention module is as follows:

[0066] A = σ (W a F + b a )

[0067] In the formula, A represents an attention matrix, F represents a feature map, W a represents the weight of the attention module, b a represents the bias of the attention module, and σ represents an activation function, wherein the activation function is an improved sigmoid activation function, and the specific representation is as follows:

[0068]

[0069] In the formula, k represents a hyperparameter for controlling the shape of the function, and x represents an input value.

[0070] It should be noted that, compared with the traditional sigmoid activation function, the improved sigmoid activation function is derivable in the definition domain, which is very important for calculating the gradient of the model by the back propagation algorithm. Since the improved sigmoid activation function does not need to calculate the exponential function, the calculation efficiency of the improved sigmoid activation function is higher than that of the sigmoid activation function.

[0071] ​In a specific implementation, the attention module can multiply the attention matrix and the feature map to obtain a weighted feature map, and the specific representation of the weighted feature map is as follows:

[0072] G=A⊙F

[0073] In the formula, ⊙ represents element-wise multiplication, A represents the attention matrix, and F represents the feature map.

[0074] In a specific implementation, as shown in Figure 4 , the pre-enhanced feature is obtained after passing through the attention module.

[0075] In an embodiment, the attention module is a multi-head attention module, and the weighted feature map of the first crop image is obtained by linearly transforming the feature map through the multi-head attention module to obtain query representation, key representation and value representation, generating point product attentions of each head according to the query representation, the key representation and the value representation, determining a spliced point product attention according to the point product attentions of each head, converting the spliced point product attention into a spliced attention matrix, and generating the weighted feature map according to the feature map and the spliced attention matrix.

[0076] In a specific implementation, the multi-head attention module first linearly transforms the feature map of the first crop image into three groups of representations of query, key and value, calculates the point product attention of each head, then splices the point product attention of each head into a spliced point product attention, and linearly transforms the spliced point product attention into a spliced attention matrix, and finally multiplies the feature map and the spliced attention matrix to obtain a weighted feature map.

[0077] In a specific implementation, for each head, the input feature map F is linearly transformed into query Q i , key K i and value V i , specifically:

[0078]

[0079]

[0080]

[0081] In the formula, and are the query, key and value weight matrices of the i-th head, respectively, and are the corresponding bias terms.

[0082] In a specific implementation, the point product attention is calculated for each head (head):

[0083] A i =Attention(Q i , K i , V i )

[0084] In a specific implementation, the attention results of all heads are spliced to obtain a spliced dot product attention:

[0085] A concat =Concat(A1, A2, …, A h )

[0086] In a specific implementation, the spliced result is subjected to a linear transformation to obtain a final output, that is, a spliced attention matrix:

[0087] A output =W o A concat +b o

[0088] In the formula, W o and b o are an output weight matrix and a bias term.

[0089] In this embodiment, replacing the original attention module with a multi-head self-attention module can make the model more fine when paying attention to local features of different scales and semantic levels, thereby improving the performance of crop disease and pest detection.

[0090] The embodiment obtains a first crop image; inputs the first crop image into a target attention convolutional neural network, and outputs a disease and pest detection result of the first crop image, wherein the target attention convolutional neural network comprises an input layer, a convolutional layer, an attention module, an adversarial module, a fully connected layer and an output layer connected in sequence, the attention module is used for generating a weighted feature map of the first crop image according to a feature map, and the adversarial module is used for generating an adversarial sample set, the adversarial sample set is used for training an initial attention convolutional neural network to obtain the target attention convolutional neural network. In the above manner, the disease and pest situation of the crop does not need to be detected by manual operation, the disease and pest detection result of the crop can be directly detected according to the crop image, and the overall detection efficiency of the crop is effectively improved.

[0091] Reference Figure 5 , Figure 5 is a flowchart of a second embodiment of a crop disease and pest detection method.

[0092] Based on the first embodiment, the crop disease and pest detection method of the embodiment further comprises, before the step S10:

[0093] Step S101: obtaining a second crop image.

[0094] It should be noted that the second crop image refers to an image used to train the initial attention convolutional neural network, and the second crop image includes multiple crop images.

[0095] Step S102: performing a preprocessing operation on the second crop image to obtain a real sample set.

[0096] In a specific implementation, the preprocessing operation includes cropping, rotating, scaling, and data enhancement. The cropping is to remove irrelevant areas and background information in the image and only leave crop leaves. The rotating is to rotate the leaves to a horizontal or vertical direction to facilitate subsequent processing. The scaling is to scale the leaves to the same size to ensure that the model has robustness to images of different scales. The data enhancement is to expand the training data set through random cropping, rotating, reversing, and the like to improve the generalization ability of the model.

[0097] Step S103: training an initial adversarial module in the initial attention convolutional neural network based on the real sample set to generate the adversarial module.

[0098] In an embodiment, as shown in FIG. 1, the initial adversarial module includes a generator and a discriminator. Figure 6

[0099] The training of the initial adversarial module in the initial attention convolutional neural network based on the real sample set to generate the adversarial module includes:

[0100] S201: initializing generator parameters in the initial adversarial module, and initializing discriminator parameters in the initial adversarial module.

[0101] S202: determining a noise sample set, and inputting the noise sample set into the generator to obtain a simulated sample set.

[0102] S203: inputting the simulated sample set and the real sample set into the discriminator to output a first discrimination result, and updating discriminator parameters of the discriminator according to the first discrimination result.

[0103] S204: determining a random simulated sample from the simulated sample set, inputting the random simulated sample into the discriminator to obtain a second discrimination result, and updating generator parameters of the generator according to the second discrimination result.

[0104] S205: determining whether the second discrimination result is a preset value.

[0105] ​S206, if it is determined that the second discrimination result is not the preset value, updating the generator parameter of the generator in step S202 according to the second discrimination result, and updating the discriminator parameter of the discriminator in step S203 according to the first discrimination result, and then repeating steps S202-S206 until it is determined that the second discrimination result is the preset value, and the generative adversarial module is generated.

[0106] It should be noted that the initial generative adversarial module refers to the untrained generative adversarial module, and the generative adversarial module refers to the trained generative adversarial module.

[0107] It should be noted that the generator and the discriminator for generating the adversarial sample can be used for game playing. The task of the generator in the generative adversarial module is to generate challenging adversarial samples, and the task of the discriminator is to determine whether the input sample is an adversarial sample.

[0108] It can be understood that updating the discriminator parameter of the discriminator according to the first discrimination result is to input the first discrimination result into the loss function of the discriminator to obtain a discrimination loss value, so as to update the discriminator parameter of the discriminator according to the discrimination loss value; and updating the generator parameter of the generator according to the second discrimination result is to input the second discrimination result into the loss function of the generator to obtain a generation loss value, so as to update the generator parameter of the generator according to the generation loss value.

[0109] It should be noted that the preset value is set in advance, and when the second discrimination result is the preset value, it can be considered that the generative adversarial module converges.

[0110] In a specific implementation, the training of the generative adversarial module is optimized by using a stochastic gradient (SGD) method, and the loss function is a cross-entropy loss. In the training process, first, the generator parameter is fixed, then the discriminator parameter is updated to minimize L D , and then the discriminator parameter is fixed, and then the generator parameter is updated to minimize L G This process is repeated until the generative adversarial module converges.

[0111] In a specific implementation, the loss function between the generator and the discriminator can be defined as:

[0112] L G = -kog(D(G(z)))

[0113] L D = -kog(D(x))-kog(1-D(G(z)))

[0114] In the formula, z represents random noise, x represents a real sample, G(z) is an adversarial sample generated by the generator, D(x) is the judgment result of the discriminator on the real sample, and D(G(z)) is the judgment result of the discriminator on the generated adversarial sample.

[0115] It can be understood that the training processes of the generator and the discriminator compete with each other, and finally make the generator generate high-quality adversarial samples, thereby improving the generalization ability of the model.

[0116] In an embodiment, the determination of the noise sample set and the input of the noise sample set into the generator to obtain the simulation sample set comprises:

[0117] The noise sample set is determined, and a condition information set corresponding to the noise sample set is determined, wherein the noise in the noise sample set and the condition information in the condition information set one-to-one correspond;

[0118] The noise sample set and the condition information set are input into the generator to obtain the simulation sample set.

[0119] It should be noted that when the adversarial module generates adversarial samples, the generator not only accepts random noise z, but also receives condition information cs as input. The goal of the generator is to generate adversarial samples that match the condition information cs. At the same time, when the discriminator judges real samples and adversarial samples, it will also judge according to the condition cs. In this way, the generator and the discriminator in the adversarial module can better adapt to the condition information in the training process, thereby improving the detection performance of the model.

[0120] In a specific implementation, the input of the generator G is (z, cs), and the output adversarial sample is

[0121]

[0122] In a specific implementation, the input of the discriminator D is (x, cs), and the output is the probability that the sample x is a real sample D(x, cs):

[0123] D(x, cs) = P(y = 1 | x, cs)

[0124] It can be understood that when the adversarial training of the model is performed, the real sample, the adversarial sample and the corresponding condition information are input into the discriminator, and the loss function is calculated according to the output of the discriminator. Subsequently, the parameters of the generator and the discriminator are updated using the gradient descent method to minimize the loss function. By introducing conditional generative adversarial networks (abbreviated as CGANs), additional condition information is integrated into the adversarial training process, which can make the model better adapt to the condition information such as the type and growth stage of crops in the training process, thereby improving the performance of crop disease and pest detection.

[0125] In the embodiment, the conditional generative adversarial network technology is combined, the condition information such as crop types and growth stages is fully utilized, the model is better adapted to the conditions in the training process, and therefore the performance of crop disease and pest detection is improved.

[0126] In an embodiment, the updating the discriminator parameter of the discriminator according to the first discrimination result comprises:

[0127] The updating the discriminator parameter of the discriminator according to the first discrimination result comprises:

[0128] The first discrimination result is input into an adversarial regularization loss function of the discriminator to obtain a discrimination loss value;

[0129] The discriminator parameter of the discriminator is updated according to the discrimination loss value;

[0130] The updating the generator parameter of the generator according to the second discrimination result comprises:

[0131] The second discrimination result is input into an adversarial regularization loss function of the generator to obtain a generation loss value;

[0132] The generator parameter of the generator is updated according to the generation loss value.

[0133] In a specific implementation, the adversarial regularization loss function of the discriminator and the adversarial regularization loss function of the generator are as follows:

[0134] L D =-kogD(x)-kog(1-D(G(z)))+α·||D(x)-D(G(z))||;

[0135] L G =-logD(G(z))+λ·||G(z)-x||+γ·||D(G(z))-c||;

[0136] In the formula, z represents random noise, x represents a real sample, G(z) is an adversarial sample generated by the generator, D(x) is a judgment result of the discriminator on the real sample, D(G(z)) is a judgment result of the discriminator on the adversarial sample, γ represents a regularization coefficient, c is a constant used to represent an expected value of the distance between the generator and the discriminator, λ is a regularization coefficient, and ||·|| represents an L1 or L2 norm.

[0137] In a specific implementation, appropriate regularization coefficients and constants can be selected according to different specific tasks and data sets.

[0138] In the embodiment, the loss function based on adversarial regularization can maximize the judgment ability of the discriminator for the real data and the adversarial samples generated by the generator, while punishing the discriminator for the distance between the real data and the adversarial samples generated by the generator being too large, so as to improve the training stability and generation effect of the GAN, avoid the problem of mode collapse, and make the samples generated by the generator more diversified and real.

[0139] Step S104: generating an adversarial sample set through the adversarial module.

[0140] In an embodiment, the generating of the adversarial sample set through the adversarial module comprises:

[0141] determining a random real sample from the real sample set and determining a random initial adversarial sample corresponding to the random real sample through the adversarial module;

[0142] determining a distance measure of the random real sample and the random initial adversarial sample;

[0143] determining a current performance of the adversarial module according to the distance measure;

[0144] determining a random adversarial sample of the random real sample based on the current performance and the random real sample, so as to determine an adversarial sample set corresponding to the real sample set.

[0145] It should be noted that the random real sample refers to any sample in the real sample set, and each real sample in the real sample set needs to generate a corresponding adversarial sample according to the current performance of the model. Specifically, the upper limit δ of the distance measure can be updated according to the performance of the adversarial module at the current stage; when the model performance of the adversarial module improves, the value of δ is reduced to generate more challenging adversarial samples; when the model performance of the adversarial module decreases, the value of δ is increased to generate relatively weak adversarial samples.

[0146] In a specific implementation, the back propagation method and the gradient descent algorithm are used to generate the adversarial sample with the current model parameters and the real sample as inputs:

[0147]

[0148] In the formula, ∈ is the strength of the adversarial perturbation, L(θ, x, y) is the loss function value of the model under the current parameter θ, and y is the real label of the real sample.

[0149] In a specific implementation, the value of ∈ is adjusted according to the performance of the model on the validation set. For example, when the performance of the model on the validation set does not improve significantly after continuous training for several rounds, the value of ∈ is appropriately increased to make the generated adversarial samples more challenging.

[0150] It should be noted that the adaptive adversarial training uses a dynamically adjusted adversarial sample generation strategy, which can automatically adjust the strength of the adversarial sample according to the performance of the model in the training process. Specifically, in the training process, for each real sample x, a corresponding adversarial sample and the distance measure between the two is calculated According to the performance of the model at the current stage, the upper limit of the distance measure δ is updated, when the model performance of the adversarial module improves, the value of δ is reduced, and more challenging adversarial samples are generated; when the model performance of the adversarial module decreases, the value of δ is increased, and relatively weak adversarial samples are generated.

[0151] In this embodiment, through adaptive adversarial training, the model can adapt to adversarial samples of different strengths in the training process, thereby better improving the generalization ability and robustness of the model.

[0152] Step S105: training the initial attention convolutional neural network based on the real sample set and the adversarial sample set to obtain a target attention convolutional neural network.

[0153] In this embodiment, the second crop image is obtained; the second crop image is preprocessed to obtain a real sample set; the initial adversarial module in the initial attention convolutional neural network is trained based on the real sample set to generate the adversarial module; an adversarial sample set is generated through the adversarial module; and the initial attention convolutional neural network is trained based on the real sample set and the adversarial sample set to obtain a target attention convolutional neural network. Through the above manner, the model is trained by the adversarial sample set generated by the adversarial module and the real sample set, which can enable the model to learn features adversarially in the training process, thereby improving the generalization ability.

[0154] In addition, the present embodiment further provides a storage medium having a crop disease and pest detection program stored thereon, and the crop disease and pest detection program is executed by a processor to implement the steps of the crop disease and pest detection method as described above.

[0155] Reference Figure 7 , Figure 7 is a structural block diagram of the first embodiment of the crop disease and pest detection device of the present application.

[0156] As Figure 7 shown, the crop disease and pest detection device provided by the present embodiment comprises:

[0157] The acquisition module 10 is configured to acquire a first crop image.

[0158] The recognition module 20 is configured to input the first crop image into a target attention convolutional neural network, and output a disease and pest detection result of the first crop image, wherein the target attention convolutional neural network comprises an input layer, a convolutional layer, an attention module, an adversarial module, a full connection layer and an output layer connected in sequence, the attention module is configured to generate a weighted feature map of the first crop image according to a feature map, and the adversarial module is configured to generate an adversarial sample set, and the adversarial sample set is used for training an initial attention convolutional neural network to obtain the target attention convolutional neural network.

[0159] It should be understood that the above is only an example, and the technical solutions of the present application do not constitute any limitation. In specific applications, those skilled in the art can set up as needed, and the present application does not limit this.

[0160] The embodiment obtains a first crop image; inputs the first crop image into a target attention convolutional neural network, and outputs a disease and pest detection result of the first crop image, wherein the target attention convolutional neural network comprises an input layer, a convolutional layer, an attention module, an adversarial module, a full connection layer and an output layer connected in sequence, the attention module is configured to generate a weighted feature map of the first crop image according to a feature map, and the adversarial module is configured to generate an adversarial sample set, and the adversarial sample set is used for training an initial attention convolutional neural network to obtain the target attention convolutional neural network. In the above manner, the disease and pest situation of the crop can be detected without manual operation, the disease and pest detection result of the crop can be directly detected according to the crop image, and the overall detection efficiency of the crop is effectively improved.

[0161] In an embodiment, the obtaining module 10 is further configured to:

[0162] obtain a second crop image;

[0163] perform a preprocessing operation on the second crop image to obtain a real sample set;

[0164] train an initial adversarial module in an initial attention convolutional neural network based on the real sample set to generate the adversarial module;

[0165] generate an adversarial sample set through the adversarial module;

[0166] train the initial attention convolutional neural network based on the real sample set and the adversarial sample set to obtain a target attention convolutional neural network.

[0167] In an embodiment, the obtaining module 10 is further configured to:

[0168] determine a random real sample from the real sample set, and determine a random initial adversarial sample corresponding to the random real sample through the adversarial module;

[0169] determine a distance metric of the random real sample and the random initial adversarial sample;

[0170] determine a current performance of the adversarial module according to the distance metric;

[0171] determine a random adversarial sample of the random real sample based on the current performance and the random real sample, to determine an adversarial sample set corresponding to the real sample set.

[0172] In an embodiment, the initial adversarial module includes a generator and a discriminator; wherein,

[0173] The acquisition module 10 is further configured to:

[0174] The training of the initial adversarial module in the initial attention convolutional neural network based on the real sample set to generate the adversarial module includes:

[0175] S201, initialize the generator parameters in the initial adversarial module, and initialize the discriminator parameters in the initial adversarial module;

[0176] S202, determine a noise sample set, and input the noise sample set into the generator to obtain a simulation sample set;

[0177] S203, input the simulation sample set and the real sample set into the discriminator, output a first discrimination result, and update the discriminator parameters of the discriminator according to the first discrimination result;

[0178] S204, determine a random simulation sample from the simulation sample set, input the random simulation sample into the discriminator to obtain a second discrimination result, and update the generator parameters of the generator according to the second discrimination result;

[0179] S205, determine whether the second discrimination result is a preset value;

[0180] S206, if it is determined that the second discrimination result is not the preset value, after updating the generator parameters of the generator in step S202 according to the second discrimination result and updating the discriminator parameters of the discriminator in step S203 according to the first discrimination result, repeat steps S202-S206 until it is determined that the second discrimination result is the preset value, and generate the adversarial module.

[0181] In an embodiment, the acquisition module 10 is further configured to:

[0182] inputting the first discrimination result into an adversarial regularization loss function of the discriminator to obtain a discrimination loss value;

[0183] updating a discriminator parameter of the discriminator according to the discrimination loss value;

[0184] the updating the generator parameter of the generator according to the second discrimination result comprises:

[0185] inputting the second discrimination result into an adversarial regularization loss function of the generator to obtain a generation loss value;

[0186] updating a generator parameter of the generator according to the generation loss value.

[0187] In an embodiment, the obtaining module 10 is further configured to:

[0188] determine a noise sample set and determine a condition information set corresponding to the noise sample set, wherein the noise in the noise sample set and the condition information in the condition information set are in one-to-one correspondence;

[0189] input the noise sample set and the condition information set into the generator to obtain a simulation sample set.

[0190] In an embodiment, the obtaining module 10 is further configured to:

[0191] The attention module is a multi-head attention module, and the weighted feature map of the first crop image is obtained by linear transformation of the feature map through the multi-head attention module to obtain query representation, key representation and value representation, and each head dot product attention is generated according to the query representation, the key representation and the value representation, and the splicing dot product attention is determined according to each head dot product attention, the splicing dot product attention is converted into a splicing attention matrix, and the splicing attention matrix is generated according to the feature map and the splicing attention matrix.

[0192] It should be noted that the above-described workflow is only illustrative and does not limit the scope of protection of the present application. In actual application, a person skilled in the art can select part or all of them according to actual needs to achieve the purpose of the embodiment scheme, which is not limited here.

[0193] In addition, technical details not described in detail in this embodiment can be referred to the crop disease and pest detection method provided by any embodiment of the present application, which will not be repeated here.

[0194] Moreover, it is to be understood that the phraseology and terminology used herein is for the purpose of description and should not be regarded as limiting. The use of "including" "comprising" or "having" and variations thereof herein is intended to encompass the presence of one or more recited elements or steps and not the exclusion of any other integers or steps. The use of "including", "comprising", "having" and "with" and variations thereof herein is intended to encompass the presence of one or more recited elements or steps and not the exclusion of any other integers or steps.

[0195] The above-mentioned embodiment numbers of the present application are only for description, and do not represent the advantages or disadvantages of the embodiments.

[0196] Those skilled in the art can clearly understand the above-mentioned embodiment methods from the description of the above embodiments, which can be realized by software and necessary general hardware platforms, of course, can also be realized by hardware, but in many cases, the former is a better embodiment. Based on such understanding, the technical solutions of the present application can be embodied in the form of a software product, which is stored in a storage medium (such as a read only memory (ROM) / RAM, a magnetic disk, an optical disk), and includes a plurality of instructions for making a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) execute the methods described in various embodiments of the present application.

[0197] The above is only the preferred embodiment of the present application, and does not limit the patent scope of the present application, and any equivalent structure or equivalent process transformation, or direct or indirect application in other related technical fields, is also included in the patent protection scope of the present application.

Claims

1. A method for detecting a disease or pest of a crop, characterized by, The crop disease and pest detection method comprises: obtaining a first crop image; inputting the first crop image into a target attention convolutional neural network to output a disease and pest detection result of the first crop image, wherein the target attention convolutional neural network comprises an input layer, a convolutional layer, an attention module, an adversarial module, a fully connected layer and an output layer connected in sequence, the attention module is used to generate a weighted feature map of the first crop image according to a feature map, and the adversarial module is used to generate an adversarial sample set used for training an initial attention convolutional neural network to obtain the target attention convolutional neural network; Before the first crop image is input into the target attention convolutional neural network, the method further comprises: obtaining a second crop image; performing a preprocessing operation on the second crop image to obtain a real sample set; training an initial adversarial module in the initial attention convolutional neural network based on the real sample set to generate the adversarial module; generating an adversarial sample set through the adversarial module; training the initial attention convolutional neural network based on the real sample set and the adversarial sample set to obtain the target attention convolutional neural network; the initial adversarial module comprises a generator and a discriminator; wherein the training of the initial adversarial module in the initial attention convolutional neural network based on the real sample set to generate the adversarial module comprises: S201, initializing the generator parameters in the initial adversarial module and initializing the discriminator parameters in the initial adversarial module; S202, determining a noise sample set and inputting the noise sample set into the generator to obtain a simulated sample set; S203, inputting the simulated sample set and the real sample set into the discriminator to output a first discrimination result, and updating the discriminator parameters of the discriminator according to the first discrimination result; S204, determining a random simulated sample from the simulated sample set, inputting the random simulated sample into the discriminator to obtain a second discrimination result, and updating the generator parameters of the generator according to the second discrimination result; S205, determining whether the second discrimination result is a preset value; S206, if it is determined that the second discrimination result is not the preset value, after updating the generator parameters of the generator in the second discrimination result updating step S202 and updating the discriminator parameters of the discriminator in the first discrimination result updating step S203, repeating steps S202-S206 until it is determined that the second discrimination result is the preset value, and generating the adversarial module; the updating of the discriminator parameters of the discriminator according to the first discrimination result comprises: inputting the first discrimination result into an adversarial regularization loss function of the discriminator to obtain a discrimination loss value; updating the discriminator parameters of the discriminator according to the discrimination loss value; the updating of the generator parameters of the generator according to the second discrimination result comprises: inputting the second discrimination result into an adversarial regularization loss function of the generator to obtain a generation loss value; According to the generation loss value, the generator parameter of the generator is updated.

2. The method of claim 1, wherein, The generating of the set of adversarial samples by the adversarial module comprises: A random real sample is determined from the set of real samples, and a random initial adversarial sample corresponding to the random real sample is determined by the adversarial module; A distance measure of the random real sample and the random initial adversarial sample is determined; According to the distance measure, a current performance of the adversarial module is determined; Based on the current performance and the random real sample, a random adversarial sample of the random real sample is determined to determine a set of adversarial samples corresponding to the set of real samples.

3. The method of claim 1, wherein, The determination of the set of noise samples and the input of the set of noise samples into the generator to obtain a set of simulation samples comprises: A set of noise samples is determined, and a set of condition information corresponding to the set of noise samples is determined, wherein the noise in the set of noise samples and the condition information in the set of condition information correspond one-to-one. The set of noise samples and the set of condition information are input into the generator to obtain a set of simulation samples.

4. The method of any one of claims 1 to 3, wherein, The attention module is a multi-head attention module, the weighted feature map of the first crop image is obtained by linear transformation of the feature map through the multi-head attention module to obtain query representation, key representation and value representation, according to the query representation, the key representation and the value representation, the dot product attention of each head is generated, the splicing dot product attention is determined according to the dot product attention of each head, the splicing dot product attention is converted into a splicing attention matrix, and the weighted feature map of the first crop image is generated according to the feature map and the splicing attention matrix.

5. A crop disease and pest detection device characterized by comprising: The device is used to implement the method of claim 1, and the crop disease and pest detection device comprises: An acquisition module is configured to acquire a first crop image. An identification module is configured to input the first crop image into a target attention convolutional neural network to output a disease and pest detection result of the first crop image, wherein the target attention convolutional neural network comprises an input layer, a convolutional layer, an attention module, an adversarial module, a fully connected layer and an output layer connected in sequence, the attention module is configured to generate a weighted feature map of the first crop image according to a feature map, and the adversarial module is configured to generate a set of adversarial samples, which are used to train an initial attention convolutional neural network to obtain the target attention convolutional neural network.

6. A crop disease and pest detection apparatus characterized by comprising: The device comprises a memory, a processor and a crop disease and pest detection program stored on the memory and executable on the processor, and the crop disease and pest detection program is configured to implement the steps of the crop disease and pest detection method according to any one of claims 1 to 4.

7. A storage medium, characterized by The storage medium stores a crop disease and pest detection program, and the crop disease and pest detection program implements the steps of the crop disease and pest detection method according to any one of claims 1 to 4 when executed by a processor.

Citation Information

Patent Citations

  • A scene matching localization method based on an improved region convolution neural network

    CN109543819A

  • KR20210047230A