A DebNet intelligent classification method based on fluorescence pesticide residue detection
Through the DebNet intelligent classification method, combined with fluorescence spectrometer and deep learning technology, the problems of insufficient classification accuracy and high cost in traditional fluorescence spectroscopy analysis methods are solved, and fast, lossless and low-cost pesticide residue detection is achieved, which is suitable for large-scale sample detection.
Patent Information
- Application Number
- CN202510236068.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-28
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2045-02-28
AI Technical Summary
Traditional fluorescence spectroscopy analysis methods have problems such as low classification accuracy, insufficient sample data, complex data processing and high cost in pesticide residue detection. It is difficult to effectively distinguish different types of pesticides and are not suitable for large-scale rapid detection.
DebNet intelligent classification method is adopted, combining fluorescence spectrometer detection, data preprocessing, data augmentation and hybrid neural network models (including convolutional neural networks, long and short-term memory networks and self-attention modules), and pesticide classification is optimized through data augmentation and feature extraction, reducing detection costs and improving accuracy.
Fast, lossless and low-cost pesticide residue detection is achieved, which significantly improves classification accuracy and model generalization capabilities, is suitable for large-scale sample detection, and reduces manual intervention and equipment costs.
Smart Images

Figure CN120107686B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of pesticide residue detection, and in particular relates to a DebNet intelligent classification method based on fluorescence pesticide residue detection. Background Art
[0002] The widespread use of pesticides is crucial for improving agricultural production efficiency, but it also poses a threat to the environment and human health. Therefore, the detection and classification of pesticide residues are crucial for ensuring food safety and environmental protection. Traditional pesticide detection methods, such as gas chromatography and high-performance liquid chromatography, while accurate, are cumbersome, time-consuming, and sample-destructive. In recent years, fluorescence spectroscopy, as a rapid, non-destructive, and low-cost detection method, has been widely used in the field of pesticide residue detection.
[0003] However, traditional fluorescence spectroscopy analysis methods still face problems such as low classification accuracy, insufficient sample data, and complex hyperspectral data processing, which are mainly reflected in: Insufficient classification accuracy: The feature overlap and similarity of fluorescence spectral data lead to frequent misjudgments in the classification process of traditional methods, making it difficult to effectively distinguish different types of pesticides; Overfitting problem: Existing machine learning methods, especially when the sample size is small, are prone to overfitting, resulting in poor model generalization ability; High data processing complexity: Traditional methods have high requirements for the preprocessing of spectral data, and most methods require complex manual intervention, which limits their automated application; High cost: Traditional pesticide residue detection methods usually require expensive equipment and long detection cycles, which are not suitable for large-scale rapid detection. Summary of the Invention
[0004] In view of the above shortcomings in the prior art, the purpose of the present invention is to provide a DebNet intelligent classification method based on fluorescence pesticide residue detection, which can improve classification accuracy, reduce sample requirements, simplify data processing procedures, and reduce detection costs.
[0005] To achieve the above objectives, the present invention provides a DebNet intelligent classification method based on fluorescence pesticide residue detection, comprising the following steps:
[0006] S1. Detecting pesticide samples using a fluorescence spectrometer to obtain one-dimensional spectral data of the pesticide samples;
[0007] S2. Preprocessing the spectral data, including filtering and denoising, correcting the baseline drift of the spectrum, and normalization;
[0008] S3, performing data enhancement on the preprocessed spectral data, the enhancement methods include linear interpolation, noise injection, spectral shift and spectrum clipping;
[0009] S4. Build a hybrid neural network model including input layer, convolution layer, pooling layer, LSTM layer, self-attention module, fully connected layer and output layer, which is the DebNet model;
[0010] S5. Train the DebNet model based on the enhanced spectral data. The training process includes forward propagation and backpropagation.
[0011] S6. Use the trained DebNet model to classify and identify the spectral data of the sample to be tested.
[0012] As a preferred embodiment of the present invention, in the aforementioned S1, the fluorescence spectrometer used has a measurement range of 300-500 nm, a sampling interval of 0.5 nm, an excitation wavelength set to 280 nm, and one-dimensional spectral data in the form of an array of wavelength-fluorescence intensity.
[0013] As a preferred embodiment of the present invention, in S2, the preprocessing process is to first calculate the signal-to-noise ratio (SNR) of the spectral data and shield the wavelength range where SNR is less than 3. Then, the spectral data is denoised using a Savitz-Ky-Golay filter to remove noise and smooth the spectrum. Then, an adaptive iterative reweighted penalized least squares algorithm is applied to correct the baseline drift of the spectrum. Finally, Min-max normalization is used to standardize all data to the range of [0, 1] to ensure that the fluorescence intensity between different samples does not interfere with the DebNet model.
[0014] As a preferred embodiment of the present invention, in the preprocessing process, an adaptive spectral segment weighted fusion method is set after the normalization step to further perform preprocessing, specifically including:
[0015] Step 1: Divide the normalized spectral data into several sub-bands of fixed length, each sub-band is 10 nm long;
[0016] Step 2: Calculate the local signal-to-noise ratio (LSNR) for each sub-band and dynamically assign weights based on the LSNR. The weight calculation formula is:
[0017] ;
[0018] Where, is the weight of the z-th sub-band; is a learnable parameter; U is the total number of sub-bands, and u is the index of the sub-band; 、 are the LSNRs of the zth and uth sub-bands respectively;
[0019] Step 3: Perform feature fusion on the weighted sub-bands through a one-dimensional convolution layer with a convolution kernel size of 1×1 and an output channel number of 32.
[0020] Step 4: Perform residual connection on the fused features and the original spectral data to generate the final optimized preprocessed data.
[0021] As a preferred solution of the present invention, in S3, the data enhancement method is specifically as follows:
[0022] Linear interpolation: Linear interpolation is performed on samples with the same label. Two spectral datasets sharing the same label are randomly selected for each operation. Interpolation is implemented by generating two random numbers ranging from 0 to 1 and ensuring that their sum is equal to 1. These two random numbers are then multiplied by the corresponding spectral data and added together to obtain a new interpolated sample.
[0023] Noise injection: Adding a Gaussian signal to the original spectrum to simulate random noise;
[0024] Spectral shift: Randomly select the shift direction, including positive or negative, and uniformly sample the shift amount within the range of ±0.2nm. The shifted spectrum is resampled using the cubic spline interpolation algorithm.
[0025] Spectrum clipping: Randomly select wavelength positions and set the corresponding spectral signal intensity value to zero at the selected wavelength position to simulate spectral missing or abnormal conditions in the measurement.
[0026] As a preferred solution of the present invention, in the S4, the specific architecture of the DebNet model includes 4 convolutional layers, 4 pooling layers, 1 LSTM layer, 1 self-attention module, 2 fully connected layers, and the final output layer uses the Softmax function for multi-classification;
[0027] The LeakyReLU activation function is used after the convolutional layer to prevent the gradient vanishing problem; a maximum pooling layer is set after each of the first three convolutional layers, and a global average pooling layer is set after the last convolutional layer; the LSTM layer contains 100 hidden units to capture the time series characteristics of the spectral data and generate a global time-dependent representation; the self-attention module is used to optimize feature selection and enhance the ability to focus on key features; the two fully connected layers have 128 and 64 neurons respectively to further extract features, and regularization techniques are used to prevent overfitting;
[0028] A batch normalization layer is set after each convolutional layer and fully connected layer to improve training speed and stability; the self-attention module includes a fully connected layer 1, a ReLU activation layer, a fully connected layer 2, and a Softmax layer, which are set in sequence.
[0029] As a preferred embodiment of the present invention, the process of obtaining the output of the DebNet model is as follows:
[0030] After the enhanced spectral data is input into the convolution layer, the LeakyReLU activation function is used, which is expressed as:
[0031] ;
[0032] Where, Represents the LeakyReLU activation function; x represents the input signal; a is a coefficient between 0 and 1, which is used to control the output slope when x is negative;
[0033] The calculation formula of the one-dimensional structure convolution kernel used in the convolution layer is:
[0034] ;
[0035] Where, Represents the value of the feature map output after convolution at position i; is the value of the input signal at position i+m; is the weight parameter of the convolution kernel at position m; b is the bias term used to adjust the convolution output; M is the size of the convolution kernel;
[0036] The maximum pooling layer is set after the first three convolutional layers, and the maximum pooling method is used for sampling, which is expressed as:
[0037] ;
[0038] Where, It represents the value of the jth feature map at position l after the hth convolution layer and the maximum pooling layer; l is the size of the convolution kernel; max represents the maximum pooling operation, which selects the maximum value from the given input; and Represents the two adjacent values at position j in the feature map output by the h-th convolutional layer;
[0039] The global average pooling layer is set after the last convolutional layer, and its calculation formula is:
[0040] ;
[0041] Where y represents the output value of the global average pooling layer; H and W represent the height and width of the feature map respectively; Represents the value of position (p, q) in the feature map, p represents the index on the height dimension of the feature map, and q represents the index on the width dimension of the feature map;
[0042] After multiple layers of convolution and maximum pooling operations, the extracted sample features are processed by the global average pooling layer to reduce the dimensionality of the feature map and convert it into a fixed-size vector representation. The feature vector is then flattened into a one-dimensional vector and input into the LSTM layer.
[0043] The features output from the LSTM layer are further input into the self-attention module. The fully connected layer 1 of the self-attention module maps the features output by the LSTM to a low-dimensional attention space with the number of neurons set to 100. Then, nonlinear mapping is introduced through the ReLU activation function to improve the flexibility of feature selection. Feature weights are then generated from the low-dimensional attention space through the fully connected layer 2 with the number of neurons also set to 100. Finally, the generated weights are normalized by the Softmax function in the self-attention module so that the sum of the weights is 1, which weights the importance of different features. The generated attention weights are then multiplied element-by-element with the features output by the LSTM to highlight key features and suppress irrelevant information.
[0044] The features optimized by the self-attention module are input into two fully connected layers with 128 and 64 neurons respectively, and the dropout ratios are 0.5 and 0.3 respectively to prevent overfitting;
[0045] The Softmax activation function is used in the final output layer to achieve the probability prediction of the pesticide category, and the number of neurons in the output layer is 4.
[0046] As a preferred embodiment of the present invention, in the DebNet model, a multi-scale temporal feature extraction unit is further provided between the LSTM layer and the self-attention module. The unit is composed of a parallel temporal convolutional network (TCN) branch and a bidirectional gated recurrent unit (BiGRU) branch, wherein:
[0047] The TCN branch adopts a dilated causal convolution structure, which includes three convolutional layers with dilation rates of 1, 2, and 4, and a convolution kernel size of 3 in each layer, which is used to capture the multi-scale local temporal dependencies of the spectral sequence;
[0048] The BiGRU branch contains 50 forward GRU units and 50 reverse GRU units, which are used to extract bidirectional long-range temporal features;
[0049] The output features of TCN and BiGRU are dynamically integrated through the gated fusion mechanism. The fusion formula is:
[0050] ;
[0051] Where, Represents the feature output after fusion; Represents the Sigmoid function; is a learnable parameter matrix used to adjust the weights of input features; Represents the output features of TCN; Represents the output features of BiGRU; Indicates concatenating the output features of TCN and BiGRU; Represents element-wise multiplication.
[0052] As a preferred embodiment of the present invention, in S5, the training process is as follows: in the forward propagation, convolution, pooling, LSTM, self-attention module and fully connected layer are calculated in sequence to finally generate a predicted value, and the loss function is calculated using the true value; in the back propagation, the weights of each layer of the DebNet model are updated by calculating the gradient; the training continues until the loss function value converges to a minimum, and the final training result is output; the dynamic hard example mining loss function is used in the back propagation, which is expressed as:
[0053] ;
[0054] Where, is the dynamic hard example mining loss value; N is the total number of samples in the batch, n represents one of the samples; K is the total number of pesticide categories, k represents one of the categories; is the probability that the nth sample is predicted to be the kth class; Indicates the historical batch The exponential moving average of is the focusing coefficient; is the true label predicted by the nth sample; ln represents the natural logarithm.
[0055] As a preferred solution of the present invention, in the S5, during training, the loss function is reduced by the Adam optimization algorithm, and the cosine annealing scheduler is integrated to dynamically adjust the learning rate, wherein the Adam optimization algorithm parameters are set to: the exponential decay rate of the first-order moment estimate The exponential decay rate of the second-order moment estimate is 0.9 is 0.999, the numerical stability parameter is 10 -7 ; Learning rate is 0.001;
[0056] Cosine annealing learning rate The calculation formula is:
[0057] ;
[0058] In the formula, the number of cycles t is set to 100; the minimum learning rate is set to ;The maximum learning rate is set to ;
[0059] To speed up the convergence of the model, the training samples were divided into multiple batches, and the number of batch samples was set to 128. The training samples, that is, the enhanced spectral data, were randomly divided into three parts: 70% of the spectral data was used as a training set; 10% of the spectral data was used as a validation set to adjust the neuron weight parameters during the back-propagation training process; and 20% of the spectral data was used as a test set to test the performance of the trained network model.
[0060] After the training is completed, four evaluation indicators, namely precision, recall, F1 score and accuracy, are used to measure the classification performance of the DebNet model.
[0061] The algorithm involved in the present invention can be executed by an electronic device, which includes a memory, a processor, and a computer program stored in the memory and capable of running on the processor. The above-mentioned algorithm calculation is realized by executing the software through the processor.
[0062] The beneficial effects of the present invention are:
[0063] High Efficiency: Compared to traditional pesticide residue detection methods (such as gas chromatography and liquid chromatography), this method combines fluorescence spectroscopy with deep learning technology to rapidly classify and identify pesticides, significantly improving detection efficiency. By introducing a multi-layer convolutional network (CNN) and a time series analysis module (LSTM), it further optimizes feature extraction and processing capabilities, making it suitable for rapid testing of large samples, significantly improving timeliness and meeting the needs of modern rapid monitoring.
[0064] Nondestructive Testing: Fluorescence spectroscopy is a nondestructive testing method that not only does not damage pesticide samples but is also suitable for multiple analyses and sample preservation. This makes it ideal for applications where sample integrity is critical. Furthermore, spectral data acquisition does not rely on complex chemical reagents or expensive equipment, effectively reducing experimental operating costs.
[0065] High Classification Accuracy: By employing a hybrid model of a one-dimensional convolutional neural network (1D-CNN) and LSTM, this method extracts multidimensional features from fluorescence spectral data. Combined with a self-attention module, it performs weighted optimization of key features, significantly improving pesticide classification accuracy. This hybrid model is particularly effective in distinguishing different pesticide types when spectral data overlaps and classification is challenging, addressing the inaccuracy of traditional methods.
[0066] Strong Adaptability: This paper utilizes data augmentation techniques (including linear interpolation, noise injection, and spectral cropping) to expand the sample size and enhance the model's robustness. These techniques not only improve the model's generalization capabilities but also, combined with the self-attention module, enable it to adapt to diverse and emerging pesticide samples, offering excellent flexibility and scalability.
[0067] Low Cost: Compared to traditional chemical analysis methods, this method requires simpler equipment, primarily relying on a fluorescence spectrometer and computer equipment, significantly reducing initial investment and operating costs. Furthermore, automated data processing and model training processes reduce manual intervention and operating time, further reducing costs.
[0068] Broad Application Prospects: This method is not only suitable for detecting various pesticide residues but also has strong scalability and can be applied to the classification and identification of other chemical substances, particularly those with similar spectral characteristics. By incorporating time series feature extraction (LSTM) and attention mechanisms from deep learning, this method has broad application potential in complex sample classification and large-scale detection scenarios, and is widely applicable in fields such as environmental monitoring and food safety. BRIEF DESCRIPTION OF THE DRAWINGS
[0069] Figure 1 It is a schematic diagram of the process of the present invention;
[0070] Figure 2 It is a schematic diagram of the back propagation process in the present invention;
[0071] Figure 3 It is a schematic structural diagram of the DebNet model in the present invention;
[0072] Figure 4 It is a schematic diagram of the confusion matrix during verification of the present invention;
[0073] Figure 5 Schematic diagram of the accuracy curve during verification of the present invention;
[0074] Figure 6 Schematic diagram of the loss curve during verification of the present invention. DETAILED DESCRIPTION
[0075] The embodiments of the present invention are further described below with reference to the accompanying drawings: Example
[0076] like Figure 1 As shown, a DebNet intelligent classification method based on fluorescence pesticide residue detection includes the following steps:
[0077] S1. Detecting pesticide samples using a fluorescence spectrometer to obtain one-dimensional spectral data of the pesticide samples;
[0078] S2. Preprocessing the spectral data, including filtering and denoising, correcting the baseline drift of the spectrum, and normalization;
[0079] S3, performing data enhancement on the preprocessed spectral data, the enhancement methods include linear interpolation, noise injection, spectral shift and spectrum clipping;
[0080] S4. Build a hybrid neural network model including input layer, convolution layer, pooling layer, LSTM layer, self-attention module, fully connected layer and output layer, which is the DebNet model;
[0081] S5. Train the DebNet model based on the enhanced spectral data. The training process includes forward propagation and backpropagation.
[0082] S6. Use the trained DebNet model to classify and identify the spectral data of the sample to be tested.
[0083] In S1, the measurement range of the fluorescence spectrometer used is 300-500 nm, the sampling interval is 0.5 nm, the excitation wavelength is set to 280 nm, and the one-dimensional spectral data is in the array form of wavelength-fluorescence intensity.
[0084] In S2, the preprocessing process is to first calculate the signal-to-noise ratio (SNR) of the spectral data and screen out the low-quality wavelength range (e.g., 300-320 nm) with SNR < 3. Then, the spectral data is denoised using a Savitz-Ky-Golay filter (polynomial degree = 3, filter length = 7) to remove noise and smooth the spectrum. Then, an adaptive iterative reweighted penalized least squares algorithm is applied to correct the baseline drift of the spectrum. Finally, Min-max normalization is used to standardize all data to the range of [0, 1] to ensure that the fluorescence intensity of different samples does not interfere with the DebNet model.
[0085] The SNR is calculated using a dynamic wavelength selection algorithm, a standard deviation method, a peak height method, a wavelet transform, a Fourier transform, or a filtering method, preferably a dynamic wavelength selection algorithm.
[0086] Sufficient training data allows the neural network to fully learn the internal characteristics of the data, enhance the generalization ability and robustness of the model, and minimize overfitting. It is difficult to obtain a large number of fluorescence spectrum samples by manpower alone, so this embodiment uses data augmentation methods to expand the number of samples.
[0087] In S3, the data enhancement method is as follows:
[0088] Linear interpolation: Linear interpolation is performed on samples with the same label. Two spectral datasets sharing the same label are randomly selected for each operation. Interpolation is implemented by generating two random numbers ranging from 0 to 1 and ensuring that their sum is equal to 1. These two random numbers are then multiplied by the corresponding spectral data and added together to obtain a new interpolated sample.
[0089] Noise injection: A Gaussian signal is added to the original spectrum to simulate random noise, with a mean of 0 and a standard deviation of 0.01;
[0090] Spectral shifting: To address wavelength calibration deviation issues with fluorescence spectrometers, wavelength shifting is performed on the raw spectral data. The shift direction is randomly selected, either positive or negative, and the shift amount is uniformly sampled within the ±0.2nm range (e.g., +0.15nm or -0.18nm). The shifted spectrum is then resampled using a cubic spline interpolation algorithm.
[0091] Spectrum clipping: Randomly select wavelength positions and set the corresponding spectral signal intensity value to zero at the selected wavelength position to simulate spectral missing or abnormal conditions in the measurement.
[0092] Data augmentation improves the model's adaptability to different detection conditions and incomplete data.
[0093] In S4, the specific architecture of the DebNet model includes 4 convolutional layers, 4 pooling layers, 1 LSTM layer, 1 self-attention module, and 2 fully connected layers. The final output layer uses the Softmax function for multi-classification. The convolution kernel sizes used in the 4 convolutional layers are 7x1, 3x1, 3x1, and 3x1, respectively. The number of convolution kernels in each layer is 32, 64, 128, and 256, respectively.
[0094] Among them, the LeakyReLU activation function is used after the convolution layer to prevent the gradient disappearance problem; the maximum pooling layer is set after the first three convolution layers, and the global average pooling layer is set after the last convolution layer; the LSTM layer contains 100 hidden units to capture the time series characteristics of spectral data and generate a global time-dependent representation; the self-attention module is used to optimize feature selection and enhance the ability to focus on key features; the two fully connected layers have 128 and 64 neurons respectively to further extract features, and regularization techniques are used to prevent overfitting.
[0095] The structural diagram of the DebNet model is as follows Figure 3 As shown, the output part corresponds to Table 1.
[0096] In the DebNet model, a batch normalization layer is set after each convolutional layer and fully connected layer to improve training speed and stability; the self-attention module includes the fully connected layer 1, ReLU activation layer, fully connected layer 2 and Softmax layer set in sequence.
[0097] The process of obtaining output of DebNet model is as follows:
[0098] After the enhanced spectral data is input into the convolution layer, the LeakyReLU activation function is used, which is expressed as:
[0099] ;
[0100] Where, Represents the LeakyReLU activation function; x represents the input signal; a is a coefficient between 0 and 1, which is used to control the output slope when x is negative;
[0101] The calculation formula of the one-dimensional structure convolution kernel used in the convolution layer is:
[0102] ;
[0103] Where, Represents the value of the feature map output after convolution at position i; is the value of the input signal at position i+m; is the weight parameter of the convolution kernel at position m; b is the bias term used to adjust the convolution output; M is the size of the convolution kernel;
[0104] The maximum pooling layer is set after the first three convolutional layers, and the maximum pooling method is used for sampling, which is expressed as:
[0105] ;
[0106] Where, It represents the value of the jth feature map at position l after the hth convolution layer and the maximum pooling layer; l is the size of the convolution kernel; max represents the maximum pooling operation, which selects the maximum value from the given input; and Represents the two adjacent values at position j in the feature map output by the h-th convolutional layer;
[0107] The global average pooling layer is set after the last convolutional layer, and its calculation formula is:
[0108] ;
[0109] Where y represents the output value of the global average pooling layer; H and W represent the height and width of the feature map respectively; Represents the value of position (p, q) in the feature map, p represents the index on the height dimension of the feature map, and q represents the index on the width dimension of the feature map;
[0110] After multiple layers of convolution and maximum pooling operations, the extracted sample features are processed by the global average pooling layer to reduce the dimensionality of the feature map and convert it into a fixed-size vector representation. The feature vector is then flattened into a one-dimensional vector and input into the LSTM layer.
[0111] The features output from the LSTM layer are further input into the self-attention module. The fully connected layer 1 of the self-attention module maps the features output by the LSTM to a low-dimensional attention space with the number of neurons set to 100. Then, nonlinear mapping is introduced through the ReLU activation function to improve the flexibility of feature selection. Feature weights are then generated from the low-dimensional attention space through the fully connected layer 2 with the number of neurons also set to 100. Finally, the generated weights are normalized by the Softmax function in the self-attention module so that the sum of the weights is 1, which weights the importance of different features. The generated attention weights are then multiplied element-by-element with the features output by the LSTM to highlight key features and suppress irrelevant information.
[0112] The features optimized by the self-attention module are input into two fully connected layers with 128 and 64 neurons respectively, and the dropout ratios are 0.5 and 0.3 respectively to prevent overfitting;
[0113] The Softmax activation function is used in the final output layer to achieve the probability prediction of the pesticide category, and the number of neurons in the output layer is 4.
[0114] In S5, the training process is to calculate the convolution, pooling, LSTM, self-attention module and fully connected layer in sequence in the forward propagation, and finally generate the predicted value, and use the true value to calculate the loss function; Figure 2 As shown in the figure, in the back propagation, the weights of each layer of the DebNet model are updated by calculating the gradient; the training continues until the loss function value converges to the minimum and the final training result is output; the dynamic hard example mining loss function is used in the back propagation, which is expressed as:
[0115] ;
[0116] Where, is the dynamic hard example mining loss value; N is the total number of samples in the batch, n represents one of the samples; K is the total number of pesticide categories, k represents one of the categories; is the probability that the nth sample is predicted to be the kth class; Indicates the historical batch The exponential moving average of is the focusing coefficient; is the true label predicted by the nth sample (in one-hot encoding form, with a value of 0 or 1); ln represents the natural logarithm;
[0117] During training, the loss function is reduced using the Adam optimization algorithm, and the cosine annealing scheduler is integrated to dynamically adjust the learning rate. The Adam optimization algorithm parameters are set to: the exponential decay rate of the first-order moment estimate The exponential decay rate of the second-order moment estimate is 0.9 is 0.999, the numerical stability parameter is 10 -7 ; Learning rate is 0.001;
[0118] Cosine annealing learning rate The calculation formula is:
[0119] ;
[0120] In the formula, the number of cycles t is set to 100; the minimum learning rate is set to ;The maximum learning rate is set to ;
[0121] To speed up the convergence of the model, the training samples were divided into multiple batches, and the number of batch samples was set to 128. The training samples, that is, the enhanced spectral data, were randomly divided into three parts: 70% of the spectral data was used as a training set; 10% of the spectral data was used as a validation set to adjust the neuron weight parameters during the back-propagation training process; and 20% of the spectral data was used as a test set to test the performance of the trained network model.
[0122] After the training is completed, four evaluation indicators, namely precision, recall, F1 score and accuracy, are used to measure the classification performance of the DebNet model.
[0123] After making predictions on the test set, the model performance was evaluated using four evaluation metrics: precision, recall, F1 score, and accuracy. This fully reflects the model's effectiveness in identifying different pesticide types, ensuring that the model has high classification accuracy and strong generalization capabilities in practical applications. For example, in a specific detection task, based on the intelligent classification method of this embodiment, the final performance data is as follows:
[0124] Table 1 Performance data table
[0125]
[0126] At the same time, the loss value curve, accuracy curve and confusion matrix are plotted to evaluate the performance of the model in the pesticide classification task, such as Figure 4-Figure 6 As shown, it can be seen that this model has a good classification effect. Example
[0127] This embodiment further includes the following improvements based on embodiment 1:
[0128] During the preprocessing process, an adaptive spectral segmentation weighted fusion method is set after the normalization step for further preprocessing, specifically including:
[0129] Step 1: Divide the normalized spectral data into several sub-bands of fixed length, each sub-band is 10 nm long;
[0130] Step 2: Calculate the local signal-to-noise ratio (LSNR) for each sub-band and dynamically assign weights based on the LSNR. The weight calculation formula is:
[0131] ;
[0132] Where, is the weight of the z-th sub-band; is a learnable parameter; U is the total number of sub-bands, and u is the index of the sub-band; 、 are the LSNRs of the zth and uth sub-bands respectively;
[0133] Step 3: Perform feature fusion on the weighted sub-bands through a one-dimensional convolution layer with a convolution kernel size of 1×1 and an output channel number of 32.
[0134] Step 4: Perform residual connection on the fused features and the original spectral data to generate the final optimized preprocessed data.
[0135] The sub-band weights are automatically optimized through end-to-end training to suppress interference in low signal-to-noise ratio areas while enhancing feature expression in high signal-to-noise ratio areas.
[0136] In the DebNet model, a multi-scale temporal feature extraction unit is set between the LSTM layer and the self-attention module. This unit consists of a parallel temporal convolutional network (TCN) branch and a bidirectional gated recurrent unit (BiGRU) branch, where:
[0137] The TCN branch adopts a dilated causal convolution structure, which includes three convolutional layers with dilation rates of 1, 2, and 4, and a convolution kernel size of 3 in each layer, which is used to capture the multi-scale local temporal dependencies of the spectral sequence;
[0138] The BiGRU branch contains 50 forward GRU units and 50 reverse GRU units, which are used to extract bidirectional long-range temporal features;
[0139] The output features of TCN and BiGRU are dynamically integrated through the gated fusion mechanism. The fusion formula is:
[0140] ;
[0141] Where, Represents the feature output after fusion; Represents the Sigmoid function; is a learnable parameter matrix used to adjust the weights of input features; Represents the output features of TCN; Represents the output features of BiGRU; Indicates concatenating the output features of TCN and BiGRU; Represents element-wise multiplication.
[0142] The fused features are input into the self-attention module, which improves the model's ability to identify complex spectral patterns by jointly optimizing multi-scale temporal features and attention mechanism.
Claims
1. A DebNet intelligent classification method based on fluorescence pesticide residue detection, characterized in that The following steps are involved: S1. Detecting pesticide samples using a fluorescence spectrometer to obtain one-dimensional spectral data of the pesticide samples; S2. Preprocessing the spectral data, including filtering and denoising, correcting the baseline drift of the spectrum, and normalization; S3, performing data enhancement on the preprocessed spectral data, the enhancement methods include linear interpolation, noise injection, spectral shift and spectrum clipping; S4. Build a hybrid neural network model including input layer, convolution layer, pooling layer, LSTM layer, self-attention module, fully connected layer and output layer, namely DebNet model. The specific architecture of DebNet model includes 4 convolution layers, 4 pooling layers, 1 LSTM layer, 1 self-attention module, 2 fully connected layers, and the final output layer uses Softmax function for multi-classification; A multi-scale temporal feature extraction unit is also set between the LSTM layer and the self-attention module. This unit consists of a parallel temporal convolutional network (TCN) branch and a bidirectional gated recurrent unit (BiGRU) branch. The output features of the TCN and BiGRU are dynamically integrated through a gated fusion mechanism. S5. Train the DebNet model based on the enhanced spectral data. The training process includes forward propagation and backpropagation. S6. Use the trained DebNet model to classify and identify the spectral data of the sample to be tested.
2. The DebNet intelligent classification method based on fluorescence pesticide residue detection according to claim 1, characterized in that: In the above-mentioned S1, the measurement range of the fluorescence spectrometer used is 300-500 nm, the sampling interval is 0.5 nm, the excitation wavelength is set to 280 nm, and the one-dimensional spectrum data is in the array form of wavelength-fluorescence intensity.
3. The DebNet intelligent classification method based on fluorescence pesticide residue detection according to claim 1, characterized in that: In S2, the preprocessing process is as follows: first, the signal-to-noise ratio (SNR) of the spectral data is calculated, and the wavelength range with SNR < 3 is shielded. Then, the spectral data is denoised using a Savitz-Ky-Golay filter to remove noise and smooth the spectrum. Then, an adaptive iterative reweighted penalized least squares algorithm is applied to correct the baseline drift of the spectrum. Finally, Min-max normalization is used to standardize all data to the range of [0, 1] to ensure that the fluorescence intensity between different samples does not interfere with the DebNet model.
4. The DebNet intelligent classification method based on fluorescence pesticide residue detection according to claim 3 is characterized in that: During the preprocessing process, an adaptive spectral segmentation weighted fusion method is set after the normalization step for further preprocessing, specifically including: Step 1: Divide the normalized spectral data into several sub-bands of fixed length, each sub-band is 10 nm long; Step 2: Calculate the local signal-to-noise ratio (LSNR) for each sub-band and dynamically assign weights based on the LSNR. The weight calculation formula is: ; Where, is the weight of the z-th sub-band; is a learnable parameter; U is the total number of sub-bands, and u is the index of the sub-band; 、 are the LSNRs of the zth and uth sub-bands respectively; Step 3: Perform feature fusion on the weighted sub-bands through a one-dimensional convolution layer with a convolution kernel size of 1×1 and an output channel number of 32. Step 4: Perform residual connection on the fused features and the original spectral data to generate the final optimized preprocessed data.
5. The DebNet intelligent classification method based on fluorescence pesticide residue detection according to claim 1, characterized in that: In the aforementioned S3, the data enhancement method is specifically as follows: Linear interpolation: Linear interpolation is performed on samples with the same label. Two spectral datasets sharing the same label are randomly selected for each operation. Interpolation is implemented by generating two random numbers ranging from 0 to 1 and ensuring that their sum is equal to 1. These two random numbers are then multiplied by the corresponding spectral data and added together to obtain a new interpolated sample. Noise injection: Adding a Gaussian signal to the original spectrum to simulate random noise; Spectral shift: Randomly select the shift direction, including positive or negative, and uniformly sample the shift amount within the range of ±0.2nm. The shifted spectrum is resampled using the cubic spline interpolation algorithm. Spectrum clipping: Randomly select wavelength positions and set the corresponding spectral signal intensity value to zero at the selected wavelength position to simulate spectral missing or abnormal conditions in the measurement.
6. The DebNet intelligent classification method based on fluorescence pesticide residue detection according to claim 1, characterized in that: In the S4 described above, the LeakyReLU activation function is used after the convolution layer to prevent the gradient vanishing problem; a maximum pooling layer is set after each of the first three convolution layers, and a global average pooling layer is set after the last convolution layer; the LSTM layer contains 100 hidden units to capture the time series characteristics of the spectral data and generate a global time-dependent representation; the self-attention module is used to optimize feature selection and enhance the ability to focus on key features; the two fully connected layers have 128 and 64 neurons respectively to further extract features, and regularization techniques are used to prevent overfitting; A batch normalization layer is set after each convolutional layer and fully connected layer to improve training speed and stability; the self-attention module includes a fully connected layer 1, a ReLU activation layer, a fully connected layer 2, and a Softmax layer, which are set in sequence.
7. The DebNet intelligent classification method based on fluorescence pesticide residue detection according to claim 6, characterized in that: The process of obtaining the output of the DebNet model is as follows: After the enhanced spectral data is input into the convolution layer, the LeakyReLU activation function is used, which is expressed as: ; Where, represents the LeakyReLU activation function; x represents the input signal; a is a coefficient between 0 and 1 that controls the output slope when x is negative; The calculation formula of the one-dimensional structure convolution kernel used in the convolution layer is: ; Where, Represents the value of the feature map output after convolution at position i; is the value of the input signal at position i+m; is the weight parameter of the convolution kernel at position m; b is the bias term used to adjust the convolution output; M is the size of the convolution kernel; The maximum pooling layer is set after the first three convolutional layers, and the maximum pooling method is used for sampling, which is expressed as: ; Where, It represents the value of the jth feature map at position l after the hth convolution layer and the maximum pooling layer; l is the size of the convolution kernel; max represents the maximum pooling operation, which selects the maximum value from the given input; and Represents the two adjacent values at position j in the feature map output by the h-th convolutional layer; The global average pooling layer is set after the last convolutional layer, and its calculation formula is: ; Where y represents the output value of the global average pooling layer; H and W represent the height and width of the feature map respectively; Represents the value of position (p, q) in the feature map, p represents the index on the height dimension of the feature map, and q represents the index on the width dimension of the feature map; After multiple layers of convolution and maximum pooling operations, the extracted sample features are processed by the global average pooling layer to reduce the dimensionality of the feature map and convert it into a fixed-size vector representation. The feature vector is then flattened into a one-dimensional vector and input into the LSTM layer. The features output from the LSTM layer are further input into the self-attention module. The fully connected layer 1 of the self-attention module maps the features output by the LSTM to a low-dimensional attention space with the number of neurons set to 100. Then, nonlinear mapping is introduced through the ReLU activation function to improve the flexibility of feature selection. Feature weights are then generated from the low-dimensional attention space through the fully connected layer 2 with the number of neurons also set to 100. Finally, the generated weights are normalized by the Softmax function in the self-attention module so that the sum of the weights is 1, which weights the importance of different features. The generated attention weights are then multiplied element-by-element with the features output by the LSTM to highlight key features and suppress irrelevant information. The features optimized by the self-attention module are input into two fully connected layers with 128 and 64 neurons respectively, and the dropout ratios are 0.5 and 0.3 respectively to prevent overfitting; The Softmax activation function is used in the final output layer to achieve the probability prediction of the pesticide category, and the number of neurons in the output layer is 4.
8. The DebNet intelligent classification method based on fluorescence pesticide residue detection according to claim 7, characterized in that: In the DebNet model: The TCN branch adopts a dilated causal convolution structure, which includes three convolutional layers with dilation rates of 1, 2, and 4, and a convolution kernel size of 3 in each layer, which is used to capture the multi-scale local temporal dependencies of the spectral sequence; The BiGRU branch contains 50 forward GRU units and 50 reverse GRU units, which are used to extract bidirectional long-range temporal features; The output features of TCN and BiGRU are dynamically integrated through the gated fusion mechanism. The fusion formula is: ; Where, Represents the feature output after fusion; Represents the Sigmoid function; is a learnable parameter matrix used to adjust the weights of input features; Represents the output features of TCN; Represents the output features of BiGRU; Indicates concatenating the output features of TCN and BiGRU; Represents element-wise multiplication.
9. The DebNet intelligent classification method based on fluorescence pesticide residue detection according to claim 1, characterized in that: In the aforementioned S5, the training process is as follows: in the forward propagation, convolution, pooling, LSTM, self-attention module and fully connected layer are calculated in sequence to finally generate a predicted value, and the loss function is calculated using the true value; in the backward propagation, the weights of each layer of the DebNet model are updated by calculating the gradient; The training continues until the loss function converges to a minimum and the final training result is output. The dynamic hard example mining loss function is used in back propagation and is expressed as: ; Where, is the dynamic hard example mining loss value; N is the total number of samples in the batch, and n represents one of the samples; K is the total number of pesticide categories, and k represents one of the categories; is the probability that the nth sample is predicted to be the kth class; Indicates the historical batch The exponential moving average of is the focusing coefficient; is the true label predicted by the nth sample; ln represents the natural logarithm.
10. The DebNet intelligent classification method based on fluorescence pesticide residue detection according to claim 1, characterized in that: In the above S5, during training, the loss function is reduced by the Adam optimization algorithm, and the cosine annealing scheduler is integrated to dynamically adjust the learning rate, wherein the Adam optimization algorithm parameters are set to: the exponential decay rate of the first-order moment estimate The exponential decay rate of the second-order moment estimate is 0.9 is 0.999, the numerical stability parameter is 10 -7 ; Learning rate is 0.001; Cosine annealing learning rate The calculation formula is: ; In the formula, the number of cycles t is set to 100; the minimum learning rate is set to ; The maximum learning rate is set to ; To speed up the convergence of the model, the training samples were divided into multiple batches, and the number of batch samples was set to 128. The training samples, i.e., the enhanced spectral data, were randomly divided into three parts: 70% of the spectral data was used as the training set; 10% of the spectral data is used as a validation set to adjust the neuron weight parameters during the back-propagation training process; 20% of the spectral data is used as a test set to test the performance of the trained network model; After the training is completed, four evaluation indicators, namely precision, recall, F1 score and accuracy, are used to measure the classification performance of the DebNet model.
Citation Information
Patent Citations
Pesticide residue type identification method based on fluorescence spectra
CN113916860A
Crop pesticide residue detection method and system based on convolutional neural network
CN116884512A