Crop seed disease intelligent diagnosis method and system and storage medium
Patent Information
- Application Number
- CN202610740737.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-27
- Publication Date
- 2026-09-11
AI Technical Summary
[0004]为了解决现有技术中自注意力计算复杂度高、冗余背景特征干扰明显、矩阵秩难以动态适配、特征融合缺乏稀疏约束以及低置信度样本易误诊的问题,本发明提出农作物种子病害智能诊断方法、系统及存储介质
Smart Images

Figure CN122737573A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of disease identification, and in particular relates to intelligent diagnostic methods, systems and storage media for crop seed diseases. Background Technology
[0002] Agriculture is the foundation of the national economy, and crop seeds are directly related to crop yield, quality, and national food security. During seed breeding, storage, and distribution, seeds are susceptible to various diseases. If diseased seeds are planted in the field, they can cause widespread disease outbreaks, resulting in severe agricultural economic losses. Traditional manual and biochemical testing methods generally suffer from long testing cycles, low efficiency, and difficulty in meeting the demands of high-throughput real-time testing. With the development of computer vision and deep learning technologies, image-based intelligent diagnostic technology can automatically extract minute lesions, color variations, and complex texture features from the seed surface, enabling rapid and non-destructive assessment of seed health.
[0003] In recent years, the Transformer architecture, with its excellent global context modeling capabilities, has been increasingly applied to the field of intelligent diagnosis of crop seed diseases. By dividing seed images into multiple image patches and introducing a self-attention mechanism, Transformer can capture the long-distance dependency between local lesion features and the overall seed morphology. However, standard multi-head self-attention mechanisms have high computational complexity, lack effective low-rank compression of the query matrix, and the key matrix is easily mixed with background features of healthy regions and redundant noise, resulting in high model computational overhead and affecting the stability of feature expression. Existing models often struggle to dynamically adjust the matrix rank based on the energy distribution of the input feature covariance, limiting the model's adaptive expression ability for complex and variable disease features. Existing feature fusion processes lack constraints on the sparsity of features in the current layer, easily causing invalid information to be blindly transmitted in deeper layers of the network. At the same time, in the final classification decision stage, existing methods often directly output classification results based on the highest predicted probability, ignoring the uncertainty reflected by the information entropy of the probability distribution. When faced with ambiguous lesions or atypical disease samples, they lack a rejection and verification mechanism based on adaptive thresholds, easily leading to misdiagnosis and failing to meet the high reliability requirements for disease diagnosis in actual agricultural production. Summary of the Invention
[0004] To address the problems of high computational complexity of self-attention, significant interference from redundant background features, difficulty in dynamically adapting matrix rank, lack of sparsity constraints in feature fusion, and easy misdiagnosis of low-confidence samples in existing technologies, this invention proposes an intelligent diagnostic method, system, and storage medium for crop seed diseases.
[0005] In the first aspect, the present invention proposes an intelligent diagnostic method for crop seed diseases, comprising the following steps: Crop seed images are acquired and preprocessed to obtain images to be diagnosed; the images to be diagnosed are divided into image blocks, which are then linearly mapped and positionally encoded before being input into an improved Transformer encoder; In the improved Transformer encoder, the query matrix is decomposed along the channel dimension into the product of a first low-rank factor matrix and a second low-rank factor matrix. The first low-rank factor matrix is reweighted using row vectors with scaling factors generated based on the input feature mean and variance, while the second low-rank factor matrix is shared across all attention heads. The base rank is determined based on the cumulative energy curve of the normalized eigenvalues of the input feature covariance matrix, and the decomposed dynamic rank is calculated by combining the integer rank offset obtained from the previous layer's attention entropy mapping and the preset maximum limit rank. The key matrix is subjected to block hard thresholding shrinkage, and the elements whose absolute values within a block are less than the absolute values of the block mean and the weighted sum of the block's standard deviation are set to zero to obtain a sparsified key matrix. The dot product of the low-rank query matrix reconstructed from the first and second low-rank factor matrices and the sparsified key matrix is calculated. The attention weights are calculated using a Softmax function with a temperature coefficient that is inversely adjusted with the dynamic rank, and multiplied with the value matrix. The results are then fused with the previous layer's features via gated residual connections. The improved Transformer encoder's final layer output is fed into the classification head. The weighted value of the preset baseline probability plus the normalized probability distribution information entropy is used as the adaptive threshold. When the highest probability is greater than the adaptive threshold, the corresponding disease category is determined; otherwise, it is marked as pending review.
[0006] In a second aspect, the present invention proposes an intelligent diagnostic system for crop seed diseases, comprising the following modules: The acquisition module is used to acquire crop seed images and preprocess them to obtain the image to be diagnosed; the image to be diagnosed is divided into image blocks, which are then linearly mapped and positionally encoded before being input into the improved Transformer encoder; The attention calculation module, in the improved Transformer encoder, decomposes the query matrix along the channel dimension into the product of a first low-rank factor matrix and a second low-rank factor matrix. The first low-rank factor matrix is reweighted using row vectors with scaling factors generated based on the input feature mean and variance, while the second low-rank factor matrix is shared across all attention heads. The base rank is determined based on the cumulative energy curve of the normalized eigenvalues of the input feature covariance matrix, and the dynamic rank of the decomposed matrix is calculated by combining the integer rank offset obtained from the previous layer's attention entropy mapping and the preset maximum limit rank. The key matrix is subjected to block hard thresholding shrinkage, and the elements whose absolute values within a block are less than the absolute values of the block mean and the weighted sum of the standard deviations of the block are set to zero to obtain a sparse key matrix. The dot product of the low-rank query matrix reconstructed from the first and second low-rank factor matrices and the sparse key matrix is calculated. The attention weights are calculated using a Softmax function with a temperature coefficient that is inversely adjusted with the dynamic rank, and multiplied with the value matrix. Finally, the attention weights are fused with the previous layer features via gated residual connections. The diagnostic module is used to send the output of the improved Transformer encoder's final layer into the classification head. It uses a weighted value of a preset baseline probability plus the information entropy of the normalized probability distribution as an adaptive threshold. When the highest probability is greater than the adaptive threshold, the corresponding disease category is determined; otherwise, it is marked as pending review.
[0007] In a third aspect, the present invention also proposes a computer-readable storage medium on which a computer program is stored, the computer program implementing the method described in the first aspect when executed by a processor.
[0008] This invention decomposes the query matrix in the Transformer encoder into two low-rank factor matrices, with the second matrix shared across all attention heads, reducing the number of model parameters and redundant computation. By reweighting the first low-rank factor matrix based on input feature statistics and combining the cumulative energy curve of eigenvalues with the entropy value of the previous layer's attention, the decomposition rank is determined, facilitating the extraction of key disease information as needed and improving processing efficiency while maintaining recognition performance. Furthermore, a block-based hard thresholding shrinkage process is applied to the key matrix to obtain a sparse key matrix, reducing background noise and redundant interference. Combined with a calculation method that adjusts the temperature coefficient inversely with rank, the distribution of attention weights becomes more reasonable and stable. Gated residual connections constrained by the proportion of non-zero elements control the effective fusion of cross-layer features, reducing the propagation of noisy features in deep networks. A flexible threshold determination mechanism based on probability distribution information entropy is introduced in the classification stage, which can reasonably distinguish between confirmed and pending samples based on the uncertainty of the prediction results, helping to reduce the risk of misdiagnosis in complex disease situations and improving the accuracy, computational efficiency, and robustness of intelligent seed disease diagnosis. Attached Figure Description
[0009] Figure 1A flowchart for an intelligent diagnostic method for crop seed diseases; Figure 2 This is a schematic diagram of different block hard thresholds. Detailed Implementation
[0010] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.
[0011] This embodiment provides an intelligent diagnostic method for crop seed diseases, such as... Figure 1 As shown, it includes the following steps: Step 1: Acquire crop seed images and preprocess them to obtain the image to be diagnosed; divide the image to be diagnosed into image blocks, and after linear mapping and position encoding, input them into the improved Transformer encoder.
[0012] For example, RGB images of crop seeds are acquired, and the images are uniformly adjusted to a standard size of 224×224 pixels using a bilinear interpolation algorithm. The image pixel values are then normalized by subtracting the three-channel mean of the ImageNet preset dataset and dividing by the three-channel standard deviation to obtain the image to be diagnosed.
[0013] The image to be diagnosed is cut into 196 independent image patches without overlap, with a stride of 16×16 pixels and a window size. For each image patch, it is flattened into a one-dimensional tensor in spatial dimension and then input into a linear projection layer to map the feature dimension of each image patch to 768 dimensions. A learnable position encoding tensor with the same dimension as the feature sequence is instantiated as an absolute position encoding. This position encoding tensor is added element-wise to the linearly mapped image patch feature sequence. A learnable class token tensor with a dimension of 768 is concatenated at the zero-index start position of the sequence to construct a complete sequence feature with a tensor shape of batch size × 197 × 768, which is then input into the improved Transformer encoder.
[0014] In one possible embodiment, the acquisition and preprocessing of crop seed images to obtain the image to be diagnosed includes: RGB optical images of crop seeds are acquired, and Gaussian smoothing filters are used to denoise the images. The denoised image is uniformly scaled and mapped to a preset fixed pixel size using a bilinear interpolation algorithm. Calculate the mean gray value of each color channel in the scaled image, and then perform center-zeroing by subtracting the mean gray value of the corresponding channel from each pixel in the image to obtain the preprocessed image to be diagnosed.
[0015] After acquiring the RGB optical image of the crop seeds, the kernel size is first applied. Spatial standard deviation A two-dimensional Gaussian smoothing filter with a value of 1.2 is used to perform convolution operations on the three-channel image. This process helps to suppress high-frequency noise and random interference generated during sensor acquisition by calculating the weighted average of the center pixel and its neighboring pixels. The smoothed pixel values are maintained as 8-bit unsigned integers, ranging from 0 to 255.
[0016] A bilinear interpolation algorithm is used to calculate pixel values at non-integer coordinates in the target grid. This involves performing linear interpolation in two directions using the four nearest known pixels from the original image, scaling the smoothed, irregularly sized image to a fixed pixel size of 224×224 pixels. After size normalization, the RGB color channels of the scaled image are traversed, and the grayscale values of 50176 pixels in each channel are accumulated and divided by the total number of pixels to obtain the global color mean. For example, in a certain test, the mean vectors for the three channels were 123.68, 116.78, and 103.94, respectively. Channel-level nulling is then performed, using a broadcast mechanism to subtract the corresponding channel mean from the grayscale values of all pixels in each channel, shifting the data distribution mean to near zero. This ultimately generates a standardized diagnostic image matrix with dimensions of 224×224×3, converted to 32-bit floating-point data. This operation reduces the overall color shift caused by different lighting conditions and helps accelerate the gradient descent convergence speed of the subsequent Transformer model.
[0017] The improved Transformer network model takes a preprocessed image to be diagnosed as input and outputs a set of predicted probability values for each disease category. The network structure includes an image slice embedding module, a multi-layered cascaded improved Transformer encoder module, and a multilayer perceptron classification head. The image slice embedding module segments the input image to be diagnosed into multiple small patches and maps them to a one-dimensional feature vector sequence. The improved Transformer encoder module utilizes a dynamic low-rank attention module and block sparsity processing to model the spatial relationships between feature vectors within the sequence and update the features. The multilayer perceptron classification head maps the updated feature vector sequence to the category dimension and combines it with a normalized exponential activation function to obtain the final predicted probability distribution.
[0018] Step 2: In the improved Transformer encoder, the query matrix is decomposed along the channel dimension into the product of a first low-rank factor matrix and a second low-rank factor matrix. The first low-rank factor matrix is reweighted using row vectors with scaling factors generated based on the input feature mean and variance. The second low-rank factor matrix is shared by all attention heads. The base rank is determined based on the cumulative energy curve of the normalized eigenvalues of the input feature covariance matrix, and the decomposed dynamic rank is calculated by combining the integer rank offset obtained from the previous layer's attention entropy mapping and the preset maximum limit rank. The key matrix is subjected to block hard thresholding shrinkage, and the elements whose absolute values within a block are less than the absolute values of the block mean and the weighted sum of the standard deviations of the block are set to zero to obtain a sparse key matrix. The dot product of the low-rank query matrix reconstructed from the first low-rank factor matrix and the second low-rank factor matrix and the sparse key matrix is calculated. The attention weights are calculated using a Softmax function with a temperature coefficient that is inversely adjusted with the dynamic rank, and multiplied with the value matrix. The results are then fused with the previous layer features via gated residual connections.
[0019] In the forward propagation process of the improved Transformer encoder, the covariance matrix of the input sequence features in the channel dimension is calculated for a single sample feature. The eigenvalues of the covariance matrix are solved and arranged in descending order. The eigenvalues are accumulated item by item in descending order, and the result of each step of accumulation is divided by the sum of all eigenvalues to obtain the normalized eigenvalue cumulative energy curve.
[0020] Traverse the curve to find the number of cumulative terms corresponding to the first cumulative energy value greater than or equal to a threshold, such as 0.9, and use this as the baseline rank of the current layer. If the current layer is the second layer or deeper of the improved Transformer encoder, obtain the multi-head attention weight matrix of the previous layer, calculate the Shannon information entropy corresponding to each query position along the key sequence dimension, and average the information entropy of each attention head and each query position to obtain the average attention entropy of the previous layer. Divide the average attention entropy of the previous layer by the natural logarithm of the sequence length N to obtain the normalized attention entropy. Multiply the normalized attention entropy by the preset rank offset upper limit and round down to obtain the integer offset. Add the baseline rank to the integer offset and use the preset maximum limit rank to truncate the upper limit to obtain the dynamic rank, so that the dynamic rank is not less than one and not greater than the maximum limit rank.
[0021] The input features are dimensionality-reduced and mapped to generate a first low-rank factor matrix and a second low-rank factor matrix, where the second low-rank factor matrix shares memory weights among all attention heads without being split into separate heads. The mean and variance tensors of the input features in the channel dimension are calculated separately, and the two are concatenated in the channel dimension and input into a two-layer fully connected network to generate a scaling factor tensor corresponding to the sequence position. The scaling factor is used to perform weighted multiplication on each row vector of the first low-rank factor matrix through element-wise multiplication to complete the reweighting. For the key matrix generated by linear mapping, it is divided into multiple sub-matrix blocks of a preset size or number in the sequence length dimension. The absolute value of the elements in each matrix block is calculated, and the mean and standard deviation of the elements in the block are obtained respectively.
[0022] The aforementioned scaling factor tensor is activated by the sigmoid function, and the global mean is obtained as the weighting factor. The absolute value of the mean within the block is added to the product of the weighting factor and the standard deviation within the block as the dynamic threshold within the block. Elements within the matrix block whose absolute value is less than the dynamic threshold are assigned a value of zero to obtain the sparse bond matrix.
[0023] The matrix product of the first low-rank factor matrix and the second low-rank factor matrix is calculated to reconstruct the low-rank query matrix of the full dimension. The dot product of the reconstructed low-rank query matrix and the transpose of the sparse bond matrix is calculated. When calculating the attention weights, a reverse adjustment temperature coefficient based on dynamic rank is constructed. Specifically, the initial temperature coefficient is obtained, the ratio of the dynamic rank to the maximum limit rank is calculated as the adjustment range, the initial temperature coefficient is subtracted from the adjustment range and limited to above the preset lower limit to obtain the dynamic temperature coefficient, the dot product result is divided by the dynamic temperature coefficient and then input into the softmax function to calculate the attention weight distribution matrix, and the weight matrix is multiplied by the value matrix generated by linear mapping to obtain the attention output features.
[0024] The number of non-zero elements in the sparse bond matrix is counted and divided by the total number of elements to obtain a scalar of the proportion of non-zero elements. This scalar of proportion is concatenated with the attention output feature along the feature dimension and then input into a single-layer linear network. A sigmoid activation function is added to generate a gating coefficient vector with values between 0 and 1. This gating coefficient vector is then used to perform element-wise weighted summation of the attention output feature and the original input feature, and the gating residual connection is fused to complete the update of the current layer's features.
[0025] In one possible embodiment, the block-based hard-threshold shrinkage of the bond matrix, which involves setting the elements within a block whose absolute value is less than the absolute value of the block's mean and the weighted sum of the block's standard deviation to zero, yields a sparser bond matrix. The generated scaling factor is mapped to the interval between zero and one using the Sigmoid function, and the arithmetic mean of all mapped values is calculated and used as the weighting factor. The key matrix is divided into multiple independent matrix blocks along the spatial dimension using the slicing operation; For each matrix block, calculate the arithmetic mean of all elements within the block and the standard deviation, which reflects the degree of data dispersion. The independent shrinkage hard threshold of the matrix block is calculated by multiplying the weighting coefficients by the standard deviation of the matrix block and adding the absolute value of the arithmetic mean of the matrix block. Iterate through the elements within each matrix block, and determine whether the absolute value of the original element is less than the shrinkage hard threshold of the corresponding matrix block. If it is less, force the element to be set to zero; otherwise, leave it unchanged. Reconstruct and merge all processed matrix blocks to obtain the sparse bond matrix.
[0026] When determining the dynamic weighting coefficients, the sequence position scaling coefficient vector of length N generated by the first low-rank factor reweighting network in the preceding step is extracted and substituted element-wise into the Sigmoid activation function as an input variable, nonlinearly compressing and mapping the unbounded real values to an open interval of zero to one. Subsequently, all mapped activation values are summed and divided by the total number of sequence positions N to calculate the global arithmetic mean. For example, the mean parameter calculated in the experiment is equal to 0.45, which is used as the weighting coefficient for threshold determination. When processing the dense bond matrix, its tensor shape is assumed to be N×dk. If the sequence length N equals 197 and the attention head dimension dk equals 64, memory slicing is used to cut it into four non-overlapping sub-matrix blocks along the sequence space dimension. The independent dimensions of the first three matrix blocks are 49×64, and the independent dimension of the last matrix block is 50×64, achieving isolation and analysis of local features. Entering the block-based hard thresholding shrinkage calculation stage, each of the above-defined local matrix blocks is traversed in parallel, and the number of floating-point values contained in each matrix block is counted. For the m-th matrix block, the arithmetic mean and unbiased standard deviation of all floating-point numbers within it are calculated statistically. For example, if the arithmetic mean of a certain local block is found to be -0.12 and the standard deviation is 0.88, a shrinkage hard threshold corresponding to this block is constructed using a dynamic truncation formula. This is achieved by adding the absolute value of the arithmetic mean to the product of the weighting coefficient and the standard deviation, and substituting this into the aforementioned values to calculate the hard threshold, which is 0.516. Figure 2 The diagram shows the hard thresholds for different blocks.
[0027] After determining the hard threshold, a tensor masking operation is initiated. The absolute values of elements within each matrix block are extracted and compared. If the absolute value of an element is less than the previously calculated shrinkage hard threshold, its underlying memory value is rewritten to 0.0; otherwise, the original value remains unchanged. After all blocks have undergone local sparse truncation, they are reconstructed into a complete 197×64 sparse bond matrix according to the reverse logic of slicing, thereby reducing weak activation interference caused by background noise.
[0028] In one possible embodiment, determining the basic rank based on the cumulative energy curve of the normalized eigenvalues of the input feature covariance matrix includes: Calculate the mean of the input feature vector in each dimension, and subtract the corresponding mean from the input feature vector to obtain the centered feature matrix; The input feature covariance matrix is obtained by multiplying the transpose of the centered feature matrix by itself. Singular value decomposition is performed on the input feature covariance matrix, and all feature values are extracted and arranged in descending order of numerical value to form the target sequence. Based on the target sequence, the eigenvalues are accumulated one-way item by item and divided by the sum of the eigenvalues in the sequence to plot the cumulative energy curve of the generated normalized eigenvalues; The cumulative energy curve is verified step by step, and the number of cumulative terms corresponding to the first time the cumulative energy exceeds the preset proportional threshold is recorded. This number of cumulative terms is determined as the basic rank for low-rank decomposition.
[0029] Suppose that the input feature tensor of the current layer of the improved Transformer encoder, after reconstruction and flattening, is represented as a two-dimensional feature matrix of dimension N×D, where N is the sequence length (e.g., if divided into 196 image blocks plus classification feature labels, N equals 197), and D is the feature channel dimension (e.g., D is preset to 768). Traversing along the sequence dimension N, the arithmetic mean of each channel dimension is calculated to generate a mean vector of length D. Then, matrix broadcasting is used to subtract this mean vector from all feature vectors in the original feature matrix, constructing a centered feature matrix X that eliminates translation bias. Matrix multiplication is then performed to calculate the product of the transpose matrix and itself, resulting in a positive semi-definite input feature covariance matrix of dimension D×D, which represents the second-order statistical correlation of each feature channel dimension.
[0030] Singular value decomposition is performed on the covariance matrix to extract D non-negative real eigenvalues, which are then sorted in monotonically descending order of value to construct the target sequence of eigenvalues. The target sequence is traversed, and the cumulative energy at step k is defined as the sum of the first k largest eigenvalues divided by the sum of all D eigenvalues. The discrete data points are connected to generate a monotonically increasing, normalized eigenvalue cumulative energy curve that asymptotically approaches 1.0.
[0031] The cumulative energy value is monitored and calculated item by item, and a preset proportion threshold parameter is set to 0.90. The loop terminates when the current cumulative energy is detected to be greater than or equal to 0.90 for the first time, and the current number of accumulated items k is extracted. For example, in actual measurement, when k equals 64, it accounts for 90.5% of the total energy. This positive integer is designated as the basic integer rank in the low-rank decomposition and recorded as the basic rank. .
[0032] In one possible embodiment, the dynamic rank of the decomposition is calculated by combining the integer rank offset obtained from the previous layer's attention entropy mapping and the preset maximum limit rank, including: If the current layer is the first layer of the improved Transformer encoder, then the base rank will be... The current layer's dynamic rank is determined after truncation by a preset maximum rank limit. If the current layer is the second layer or a deeper layer, the attention weight matrix output by the previous layer is obtained. The Shannon information entropy corresponding to each query position is calculated along the key sequence dimension, and the information entropy of each attention head and each query position is averaged to obtain the average attention entropy of the previous layer. The average attention entropy of the previous layer is divided by the natural logarithm of the sequence length N to obtain the normalized attention entropy. Then, the normalized attention entropy is multiplied by the preset rank offset upper limit and rounded down to obtain the integer offset. The basic rank with integer offset The rank is obtained by adding the rank and truncating it using preset minimum and maximum rank limits. ,Right now ,in It represents the maximum restricted rank.
[0033] In one possible embodiment, calculating the attention weights using a Softmax function with a temperature coefficient inversely adjusted by the dynamic rank includes: Get the dynamic rank of the current layer and the pre-set maximum rank limit; Calculate the ratio of the dynamic rank to the maximum restricted rank, and use the quotient as the adjustment range for the current layer; Obtain the initial temperature coefficient set by the system, subtract the adjustment range from the initial temperature coefficient, compare it with the preset lower limit of the temperature, and take the maximum value of the two to obtain the dynamic temperature coefficient that adaptively adjusts with the dynamic rank. The initial attention score matrix is obtained by multiplying the low-rank query matrix reconstructed from the first low-rank factor matrix and the second low-rank factor matrix with the transpose of the sparse bond matrix. Divide each value in the initial attention score matrix by the dynamic temperature coefficient, and then apply the Softmax function along the preset dimension to perform exponential normalization calculation to obtain the attention weight distribution.
[0034] Retrieve the dynamic rank variable of the current layer determined by the previous steps. For example, if the current dynamic rank is measured to be 24 in the deep layers of the network, extract the maximum limit rank preset parameter that limits the model's memory boundary from the configuration file. Usually, the empirical upper limit value of the maximum limit rank is set to 64.
[0035] The percentage of dynamic rank to maximum restricted rank is obtained by performing floating-point division. The resulting quotient is defined as the adjustment range reflecting the complexity of the feature space representation. Based on the previous value, the adjustment range is 24 / 64, which equals 0.375. The default initial temperature coefficient is obtained based on the attention head dimension. Taking the square root of the head dimension 64, the initial temperature coefficient is 8.0. The calculated adjustment range is subtracted from this initial temperature coefficient, ensuring that the result is not lower than the preset lower limit, to generate the dynamic temperature coefficient specific to this network layer. The dynamic temperature coefficient is calculated to be 7.625. This ensures that when the dynamic rank increases, leading to an increase in feature abundance, the temperature coefficient decreases accordingly, which helps to enhance the discriminative ability of subsequent attention weights.
[0036] In the forward computation of matrix multiplication, the first low-rank factor matrix and the second low-rank factor matrix undergo matrix multiplication to reconstruct the corresponding low-rank approximate query matrix, such as a 197×64 matrix. This matrix is then subjected to batch tensor multiplication with the transpose of the pre-truncated sparse key matrix, outputting a dense initial attention score matrix of size 197×197. To reduce the impact of abnormally large values on the exponential normalization result, a global tensor scalar division is performed on the score matrix, scaling all values by the calculated dynamic temperature coefficient. Normalization is then performed along the specified key sequence feature dimension of the matrix, smoothly mapping the original real-domain scores to a non-negative probability tensor with a single-row sum of 1.0, outputting a 197×197 attention weight distribution matrix reflecting the correlation dependencies between various feature patches of seed diseases.
[0037] Step 3: Send the output of the improved Transformer encoder's last layer into the classification head. Use the weighted value of the preset baseline probability plus the normalized probability distribution information entropy as the adaptive threshold. When the highest probability is greater than the adaptive threshold, determine the corresponding disease category; otherwise, mark it as pending review.
[0038] The category token feature tensor located at the zero index position in the output sequence of the last layer of the improved Transformer encoder is extracted and fed into the classification head, which is composed of a LayerNorm layer and a Linear layer concatenated. The category token feature tensor is linearly mapped by the classification head to the unnormalized logical values corresponding to various crop seed diseases.
[0039] The softmax function is used to convert the logical values into probability distribution tensors representing the prediction confidence levels of various diseases; the highest probability value in the probability distribution tensor is obtained. Based on this probability distribution tensor, the natural logarithm of the probability of each category is calculated. The probability distribution tensor is multiplied element-wise by its natural logarithm tensor, the sum is taken, and the negative number is used to obtain the probability distribution information entropy. Then, the probability distribution information entropy is divided by the natural logarithm of the number of categories to obtain the normalized probability distribution information entropy.
[0040] For example, a preset baseline probability constant is set to 0.85, and a preset constant multiplier is set to 0.15. An adaptive threshold floating-point number is calculated by adding the normalized information entropy to 0.85 and the product of 0.15. The highest probability value is compared with the adaptive threshold. When the highest probability value is greater than the calculated adaptive threshold, the category index corresponding to the highest probability is obtained, and the specific crop seed disease category name is determined and output according to the pre-loaded dictionary mapping table. If the condition judgment result is that the highest probability is not greater than the adaptive threshold, the diagnosis result string variable of the seed image is assigned the status of pending review, and the storage function is triggered to save the tensor data and the original image to the specified hard disk directory for human expert intervention.
[0041] In one possible embodiment, the step of using a weighted value of a preset baseline probability plus the information entropy of the normalized probability distribution as the adaptive threshold includes: Obtain the set of predicted probability values for each disease category output by the classification head for the current image to be diagnosed, and extract the maximum probability value in the set as the highest probability; Calculate the Shannon information entropy of the current output probability distribution based on the set of predicted probability values; Divide the Shannon information entropy by the natural logarithm of the number of categories to obtain the normalized information entropy. Calculate the product of the preset constant multiplier and the normalized information entropy, and set the sum of the preset baseline probability and the product as the adaptive threshold for the diagnosis of the current sample. The system compares whether the highest probability is greater than an adaptive threshold. If it is, the disease category corresponding to the highest probability is output as the diagnosis result; if it is not, the image is marked as a low-confidence sample to be reviewed.
[0042] After the feature vector of the crop seed image to be diagnosed is processed by the fully connected classification head module and Softmax normalization, a complete set of predicted probability values is output for multiple predefined possible categories, such as five categories including healthy, Fusarium head blight, and smut.
[0043] By traversing the probability set and performing a maximum value retrieval operation, the extreme values are extracted and recorded as the highest probability of the current image. For example, in a real-world test case, the maximum classification probability of a certain image was predicted to be 0.92, and the label was Fusarium head blight. To quantify the network's built-in confidence and model uncertainty in this inference result, all five probability distribution values are substituted into the formula to calculate the Shannon information entropy. When the prediction distribution is relatively concentrated and the uncertainty is low, the calculated information entropy is, for example, equal to 0.30. Entering the dynamic threshold adjudication stage, the configured judgment standard parameters are loaded, i.e., the empirical preset baseline probability is equal to 0.85, and the preset constant multiplier parameter for smoothing adjustment is equal to 0.15. Since the number of categories is 5, dividing the information entropy 0.30 by ln5 yields a normalized information entropy of approximately 0.186; the product of the constant multiplier and the normalized information entropy is approximately 0.028. By adding this product to the preset baseline probability, an adaptive threshold of approximately 0.878 is generated for this specific single sample characteristic.
[0044] The highest probability of 0.92 is compared with the dynamically calculated adaptive threshold of 0.878. Since the former is greater than the latter, the diagnosis is valid, and the Fusarium head blight label corresponding to this probability is output as a valid intelligent diagnosis result. If the highest classification probability of the test case fails to exceed the threshold warning line due to noise or other interference, a review mark is generated. Instead of outputting a forced classification result, the original images of the batch are isolated, saved, and marked with attributes, and then transferred to the human expert review queue for processing.
[0045] The experiment utilized a self-built image database of crop seed diseases for validation, containing a total of 600 high-resolution optical images, categorized into five core types including healthy crops and Fusarium head blight. The dataset was divided into training, validation, and test sets in an 8:1:1 ratio. The global batch size for network training was set to 128, and the model parameter optimizer employed the adaptive momentum algorithm. The base learning rate was initialized to 0.05%, supplemented by a cosine annealing learning rate decay strategy, resulting in 200 full-data iteration cycles. The experimental evaluation metrics were set as the overall accuracy on the test set, the number of floating-point operations performed by the model, and the end-to-end inference time per sample. The experimental model and data are shown in Table 1.
[0046] Table 1 It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments in this specification are not limited to the described order of actions, because according to the embodiments in this specification, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the embodiments in this specification.
[0047] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0048] The preferred embodiments disclosed above are merely illustrative of this specification. The optional embodiments do not exhaustively describe all details, nor do they limit the invention to the specific implementations described. Clearly, many modifications and variations can be made based on the embodiments described herein. These embodiments are selected and specifically described in this specification to better explain the principles and practical applications of the embodiments, thereby enabling those skilled in the art to better understand and utilize this specification. This specification is limited only by the claims and their full scope and equivalents.
Claims
1. A method for intelligent diagnosis of crop seed diseases, characterized in that, Includes the following steps: Crop seed images are acquired and preprocessed to obtain images to be diagnosed; the images to be diagnosed are divided into image blocks, which are then linearly mapped and positionally encoded before being input into an improved Transformer encoder; In the improved Transformer encoder, the query matrix is decomposed along the channel dimension into the product of a first low-rank factor matrix and a second low-rank factor matrix. The first low-rank factor matrix is reweighted using row vectors with scaling factors generated based on the input feature mean and variance. The second low-rank factor matrix is shared by all attention heads. The base rank is determined based on the cumulative energy curve of the normalized eigenvalues of the input feature covariance matrix, and the decomposed dynamic rank is calculated by combining the integer rank offset obtained from the previous layer's attention entropy mapping and the preset maximum limit rank. The bond matrix is divided into blocks and hard thresholded shrinkage. Elements whose absolute values are less than the absolute values of the block mean and the standard deviation of the block are set to zero to obtain a sparse bond matrix. The dot product of the low-rank query matrix reconstructed from the first low-rank factor matrix and the second low-rank factor matrix and the sparse bond matrix is calculated. The attention weight is calculated using the Softmax function with the temperature coefficient inversely adjusted by the dynamic rank and multiplied with the value matrix. Gated residual connections are fused with features from the previous layer; The improved Transformer encoder's final layer output is fed into the classification head. The weighted value of the preset baseline probability plus the normalized probability distribution information entropy is used as the adaptive threshold. When the highest probability is greater than the adaptive threshold, the corresponding disease category is determined; otherwise, it is marked as pending review.
2. The method according to claim 1, characterized in that, The process of acquiring and preprocessing crop seed images to obtain images for diagnosis includes: RGB optical images of crop seeds are acquired, and Gaussian smoothing filters are used to denoise the images. The denoised image is uniformly scaled and mapped to a preset fixed pixel size using a bilinear interpolation algorithm. Calculate the mean grayscale value of each color channel in the scaled image, and then perform center-zeroing by subtracting the mean grayscale value of the corresponding channel from each pixel in the image to obtain the preprocessed image to be diagnosed.
3. The method according to claim 2, characterized in that, The determination of the basic rank based on the cumulative energy curve of the normalized eigenvalues of the input feature covariance matrix includes: Calculate the mean of the input feature vector in each dimension, and subtract the corresponding mean from the input feature vector to obtain the centered feature matrix; The input feature covariance matrix is obtained by multiplying the transpose of the centered feature matrix by itself. Singular value decomposition is performed on the input feature covariance matrix to extract and arrange all feature values in descending order to form the target sequence. Based on the target sequence, the eigenvalues are accumulated one-way and divided by the sum of the eigenvalues in the sequence to plot the cumulative energy curve of the generated normalized eigenvalues; The cumulative energy curve is approved step by step, and the number of cumulative terms corresponding to the first time the cumulative energy exceeds the preset proportional threshold is recorded. This number of cumulative terms is determined as the basic rank for low-rank decomposition.
4. The method according to claim 1, characterized in that, The block-based hard-threshold shrinkage of the bond matrix, which involves setting the elements within a block whose absolute value is less than the absolute value of the block's mean and the weighted sum of the block's standard deviation to zero, yields a sparser bond matrix, including: The generated scaling factor is mapped to the interval between zero and one using the Sigmoid function, and the arithmetic mean of all mapped values is calculated and used as the weighting factor. The key matrix is divided into multiple independent matrix blocks along the spatial dimension using the slicing operation; For each matrix block, calculate the arithmetic mean of all elements within the block and the standard deviation, which reflects the degree of data dispersion. The independent shrinkage hard threshold of the matrix block is calculated by multiplying the weighting coefficients by the standard deviation of the matrix block and adding the absolute value of the arithmetic mean of the matrix block. Iterate through the elements within each matrix block, and determine whether the absolute value of the original element is less than the shrinkage hard threshold of the corresponding matrix block. If it is less, force the element to be set to zero; otherwise, leave it unchanged. Reconstruct and merge all processed matrix blocks to obtain the sparse bond matrix.
5. The method according to claim 1, characterized in that, The calculation of attention weights using the Softmax function, whose temperature coefficient is inversely adjusted with dynamic rank, includes: Get the dynamic rank of the current layer and the pre-set maximum rank limit; Calculate the ratio of the dynamic rank to the maximum restricted rank, and use the quotient as the adjustment range for the current layer; Obtain the initial temperature coefficient set by the system, subtract the adjustment range from the initial temperature coefficient, compare it with the preset lower limit of the temperature, and take the maximum value of the two to obtain the dynamic temperature coefficient that adaptively adjusts with the dynamic rank. The initial attention score matrix is obtained by multiplying the low-rank query matrix reconstructed from the first low-rank factor matrix and the second low-rank factor matrix with the transpose of the sparse bond matrix. Divide each value in the initial attention score matrix by the dynamic temperature coefficient, and then apply the Softmax function along the preset dimension to perform exponential normalization calculation to obtain the attention weight distribution.
6. The method according to claim 4, characterized in that, The step of using a weighted value of a preset baseline probability plus the information entropy of a normalized probability distribution as the adaptive threshold includes: Obtain the set of predicted probability values for each disease category output by the classification head for the current image to be diagnosed, and extract the maximum probability value in the set as the highest probability; Calculate the Shannon information entropy of the current output probability distribution based on the set of predicted probability values; Divide the Shannon information entropy by the natural logarithm of the number of categories to obtain the normalized information entropy. Calculate the product of the preset constant multiplier and the normalized information entropy, and set the sum of the preset baseline probability and the product as the adaptive threshold for the diagnosis of the current sample. The system compares whether the highest probability is greater than an adaptive threshold. If it is, the disease category corresponding to the highest probability is output as the diagnosis result; if it is not, the image is marked as a low-confidence sample to be reviewed.
7. An intelligent diagnostic system for crop seed diseases, characterized in that, Includes the following modules: The acquisition module is used to acquire crop seed images and preprocess them to obtain the image to be diagnosed; the image to be diagnosed is divided into image blocks, which are then linearly mapped and positionally encoded before being input into the improved Transformer encoder; The attention calculation module is used in the improved Transformer encoder to decompose the query matrix along the channel dimension into the product of a first low-rank factor matrix and a second low-rank factor matrix. The first low-rank factor matrix is reweighted using row vectors with scaling factors generated based on the mean and variance of the input features, and the second low-rank factor matrix is shared by all attention heads. The basic rank is determined based on the cumulative energy curve of the normalized eigenvalues of the input feature covariance matrix, and the dynamic rank of the decomposed matrix is calculated by combining the integer rank offset obtained from the previous layer's attention entropy mapping and the preset maximum limit rank. The bond matrix is divided into blocks and hard thresholded shrinkage. Elements whose absolute values are less than the absolute values of the block mean and the standard deviation of the block are set to zero to obtain a sparse bond matrix. The dot product of the low-rank query matrix reconstructed from the first low-rank factor matrix and the second low-rank factor matrix and the sparse bond matrix is calculated. The attention weight is calculated using the Softmax function with the temperature coefficient inversely adjusted by the dynamic rank and multiplied with the value matrix. Gated residual connections are fused with features from the previous layer; The diagnostic module is used to send the output of the improved Transformer encoder's final layer into the classification head. It uses a weighted value of a preset baseline probability plus the information entropy of the normalized probability distribution as an adaptive threshold. When the highest probability is greater than the adaptive threshold, the corresponding disease category is determined; otherwise, it is marked as pending review.
8. The system according to claim 7, characterized in that, The process of acquiring and preprocessing crop seed images to obtain images for diagnosis includes: RGB optical images of crop seeds are acquired, and Gaussian smoothing filters are used to denoise the images. The denoised image is uniformly scaled and mapped to a preset fixed pixel size using a bilinear interpolation algorithm. Calculate the mean grayscale value of each color channel in the scaled image, and then perform center-zeroing by subtracting the mean grayscale value of the corresponding channel from each pixel in the image to obtain the preprocessed image to be diagnosed.
9. The system according to claim 7, characterized in that, The determination of the basic rank based on the cumulative energy curve of the normalized eigenvalues of the input feature covariance matrix includes: Calculate the mean of the input feature vector in each dimension, and subtract the corresponding mean from the input feature vector to obtain the centered feature matrix; The input feature covariance matrix is obtained by multiplying the transpose of the centered feature matrix by itself. Singular value decomposition is performed on the input feature covariance matrix to extract and arrange all feature values in descending order to form the target sequence. Based on the target sequence, the eigenvalues are accumulated one-way and divided by the sum of the eigenvalues in the sequence to plot the cumulative energy curve of the generated normalized eigenvalues; The cumulative energy curve is approved step by step, and the number of cumulative terms corresponding to the first time the cumulative energy exceeds the preset proportional threshold is recorded. This number of cumulative terms is determined as the basic rank for low-rank decomposition.
10. A computer-readable storage medium storing a computer program thereon, characterized in that, The computer program, when executed by a processor, implements the method as described in any one of claims 1-6.