Pesticide residue detection method based on raman spectrum and deep learning and electronic device
By combining Raman spectroscopy and deep learning, rapid and accurate detection of pesticide residues has been achieved, solving the problems of slow detection speed and insufficient generalization ability in existing technologies, and providing accurate identification of pesticide components and complex ratio analysis.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HUAZHONG AGRI UNIV
- Filing Date
- 2025-05-19
- Publication Date
- 2026-07-21
AI Technical Summary
In existing technologies, enzyme inhibition methods and chromatographic methods are characterized by high specialization, high cost, and slow detection speed in pesticide residue detection. Machine learning models have insufficient generalization ability when processing complex data, making it difficult to accurately and stably identify pesticide components.
A Raman spectroscopy-based and deep learning-based approach is adopted to predict the category probability of pesticide components through a qualitative analysis model and to perform joint analysis of global and local features using a multimodal fusion deep learning network. The quantitative analysis model performs spectral decomposition and concentration regression through a multi-scale feature fusion deep learning architecture, which solves the error accumulation problem caused by the separation of qualitative and quantitative models in traditional methods.
It enables rapid and accurate detection of pesticide residues, improves the overall efficiency of the detection process, accurately identifies the components of mixtures, and provides a unified analytical framework for complex pesticide formulations, overcoming the detection deficiencies of traditional methods.
Smart Images

Figure CN120490045B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of agricultural technology, specifically to a pesticide residue detection method and electronic device based on Raman spectroscopy and deep learning. Background Technology
[0002] Pesticides play a crucial role in controlling diseases and weeds, but their widespread use has also brought unavoidable food safety and environmental pollution problems. Among the pesticides found in vegetables with excessive residues are carbendazim, acetamiprid, and phorate.
[0003] In recent years, chromatography has been increasingly applied to the component analysis of pesticide residues. However, this method suffers from high technical requirements and costs, making it unsuitable for rapid on-site detection and hindering its application and promotion. Enzyme inhibition-based methods have also been used for pesticide residue detection. While these methods have some practicality, they fall short in identifying complex pesticide samples. Spectroscopic methods, due to their speed and high sensitivity, have become an important approach for pesticide residue analysis. Traditional methods typically rely on machine learning to build predictive models for spectral data. However, machine learning models require complex feature engineering, increasing processing costs. Furthermore, machine learning has limited ability to represent complex patterns and large datasets, exhibiting insufficient generalization capabilities. Summary of the Invention
[0004] In view of this, embodiments of this application provide a pesticide residue detection method and electronic device based on Raman spectroscopy and deep learning, which can solve the detection defects of enzyme inhibition methods and chromatography, as well as the problem that machine learning cannot accurately and stably find potential modes in Raman spectroscopy.
[0005] The first aspect of this application provides a pesticide residue detection method based on Raman spectroscopy and deep learning, comprising:
[0006] Obtain the Raman spectral data of the sample to be tested;
[0007] The Raman spectroscopy data is input into a pre-trained qualitative analysis model, which outputs the class probability of pesticide components in the sample to be tested.
[0008] The Raman spectroscopy data is input into a pre-trained quantitative analysis model, which outputs the content ratio of pesticide components in the sample to be tested.
[0009] The qualitative analysis model is based on a multimodal fusion deep learning network to achieve joint analysis of global and local spectral features; the quantitative analysis model is based on a multi-scale feature fusion deep learning architecture to achieve spectral decomposition and concentration regression.
[0010] A second aspect of this application provides a pesticide residue detection device based on Raman spectroscopy and deep learning, comprising:
[0011] The acquisition module is used to acquire the Raman spectral data of the sample to be tested;
[0012] The qualitative analysis module is used to input Raman spectroscopy data into a pre-trained qualitative analysis model and output the category probability of pesticide components in the sample to be tested.
[0013] The quantitative analysis module is used to input Raman spectroscopy data into a pre-trained quantitative analysis model and output the content ratio of pesticide components in the sample to be tested.
[0014] The qualitative analysis model is based on a multimodal fusion deep learning network to achieve joint analysis of global and local spectral features; the quantitative analysis model is based on a multi-scale feature fusion deep learning architecture to achieve spectral decomposition and concentration regression.
[0015] A third aspect of this application provides an electronic device including a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the electronic device enables the pesticide residue detection method based on Raman spectroscopy and deep learning as provided in the first aspect of this application.
[0016] A fourth aspect of this application provides a computer program product including a computer program that, when run, causes the method described in the first aspect of this application to be performed.
[0017] The first aspect of this application provides a pesticide residue detection method based on Raman spectroscopy and deep learning. This method acquires Raman spectral data of the sample to be tested; inputs the Raman spectral data into a pre-trained qualitative analysis model to output the category probability of pesticide components in the sample; and inputs the Raman spectral data into a pre-trained quantitative analysis model to output the content ratio of pesticide components in the sample. The qualitative analysis model uses a multi-modal fusion deep learning network to achieve joint analysis of global and local spectral features; the quantitative analysis model uses a multi-scale feature fusion deep learning architecture to achieve spectral decomposition and concentration regression. The multi-modal fusion architecture of the qualitative analysis model (joint analysis of global and local features) enables accurate identification of mixture components, solving the problem of insufficient analytical capability for overlapping spectra in traditional single-feature extraction methods. The multi-scale feature fusion architecture of the quantitative analysis model (combination of spectral decomposition and concentration regression) provides a unified analytical framework for complex pesticide formulations, overcoming the error accumulation problem caused by the separation of qualitative and quantitative models in traditional methods, and improving the overall efficiency of the detection process.
[0018] It is understood that the beneficial effects of the second to fourth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is a schematic flowchart of a pesticide residue detection method based on Raman spectroscopy and deep learning provided in an embodiment of this application;
[0021] Figure 2 This is a structural diagram of the Raman-MTNet qualitative detection network provided in this application;
[0022] Figure 3 The residual layer structure diagram in the qualitative detection network provided in this application;
[0023] Figure 4 The DWT processing flow in the quantitative detection method provided in this application;
[0024] Figure 5 This is a structural diagram of the Raman-WaveNet quantitative detection network provided in this application;
[0025] Figure 6 The DWT branch structure in the Raman-WaveNet quantitative detection network provided in this application;
[0026] Figure 7 The CWT branch structure in the Raman-WaveNet quantitative detection network provided in this application;
[0027] Figure 8 A schematic diagram illustrating the fusion of DWT and CWT branch outputs provided in this application;
[0028] Figure 9 A schematic diagram comparing the qualitative analysis performance of the qualitative detection network provided in this application with that of different algorithms;
[0029] Figure 10 A schematic diagram comparing the quantitative detection network provided in this application with the quantitative analysis performance of different algorithms;
[0030] Figure 11 This is a schematic diagram of the structure of the pesticide residue detection device based on Raman spectroscopy and deep learning provided in the embodiments of this application;
[0031] Figure 12 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0032] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.
[0033] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.
[0034] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0035] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0036] like Figure 1 As shown, the pesticide residue detection method based on Raman spectroscopy and deep learning provided in this application includes the following steps S101 to S106:
[0037] Step S101: Obtain the Raman spectral data of the sample to be tested.
[0038] In the application, Raman-enhanced biochips were used to collect Raman spectra data of pesticides, collecting a total of 2,500 spectra of single substances and mixtures of three pesticides: acetamiprid, carbendazim, and cyproconazole.
[0039] Step S102: Input the Raman spectroscopy data into the pre-trained qualitative analysis model and output the category probability of pesticide components in the sample to be tested.
[0040] In this application, Raman-MTNet (a qualitative analysis model) is used for qualitative analysis of pesticide residue Raman spectra. The pesticide residue spectral data is input into the trained qualitative analysis network, which outputs the predicted pesticide components (whether acetamiprid, carbendazim, or cyproconazole are present). This method can detect both single pesticide residues and identify mixtures of pesticide residues.
[0041] Raman-MTNet is a multi-classification network that treats different mixtures as different categories. Based on the three pesticides used in this study—acetamiprid, carbendazim, and cyproconazole—a total of seven categories were generated: acetamiprid, carbendazim, cyproconazole, acetamiprid + carbendazim, acetamiprid + cyproconazole, and a ternary mixture of the three. Specifically, Raman-MTNet receives 1600 Raman spectra as input, performs predictions, and outputs the probabilities of seven categories, selecting the category corresponding to the highest probability as the predicted category.
[0042] Step S103: Input the Raman spectroscopy data into the pre-trained quantitative analysis model and output the content ratio of pesticide components in the sample to be tested.
[0043] Among them, the qualitative analysis model is based on a multimodal fusion deep learning network to achieve joint analysis of global and local spectral features; the quantitative analysis model is based on a multi-scale feature fusion deep learning architecture to achieve spectral decomposition and concentration regression.
[0044] In this application, Raman-WaveNet (a quantitative analysis model) is used to quantitatively analyze the Raman spectra of pesticide residues. The pesticide residue spectral data are input into the trained quantitative analysis network, which outputs the content of each pesticide (acetamiprid, carbendazim, and cyproconazole). This allows for the detection of different pesticide contents in the tested sample.
[0045] The Raman-WaveNet input receives 1600 Raman spectra, and after model prediction, outputs the percentage content of each substance. In this study, the output is the corresponding content of acetamiprid, carbendazim, and cyproconazole, ranging from 0% to 100%.
[0046] This application's embodiments achieve accurate identification of mixture components through a multimodal fusion architecture (joint analysis of global and local features) of the qualitative analysis model, solving the problem of insufficient analytical capability for overlapping spectra in traditional single feature extraction methods. The multi-scale feature fusion architecture (combination of spectral decomposition and concentration regression) of the quantitative analysis model provides a unified analytical framework for complex pesticide formulations, overcoming the error accumulation problem caused by the separation of qualitative and quantitative models in traditional methods, and improving the overall efficiency of the detection process.
[0047] In one embodiment, acquiring the Raman spectral data of the sample to be tested includes:
[0048] Obtain spectral data of acetamiprid, carbendazim, and cyproconazole as single substances and mixtures;
[0049] The mixtures include binary mixtures and ternary mixtures, and the binary and ternary mixtures include various mixing ratios.
[0050] In application, to obtain the Raman spectral data of the sample to be tested, the following steps are specifically included:
[0051] Step 1: Data Acquisition Experiment Design.
[0052] Based on commonly used pesticides for rapeseed, this study focuses on three typical pesticides: carbendazim, acetamiprid, and cyproconazole. To investigate the composition and concentration prediction of pesticide mixtures, binary and ternary mixing experimental designs were employed, resulting in four different mixing experimental groups. Considering the potential variation in the component ratios within the pesticide mixtures, multiple mixing experiments were designed based on volume to ensure a uniform distribution of different pesticide proportions from 0% to 100% in each mixed solution. Specifically, three mixing levels were set for each binary mixture, while four mixing levels were set for the ternary mixture, as detailed in Table 1.
[0053] Table 1
[0054]
[0055] This design ensures a uniform distribution of the relative concentration frequency of each pesticide, thus providing a stable and comprehensive experimental basis for subsequent component identification and concentration prediction.
[0056] Step 2, Sample Preparation
[0057] This study used the mass of the active ingredient as an indicator, and prepared 1000 mg / L standard solutions by diluting three commonly used pesticides (acetamiprid, carbendazim, and cyprodinil). Based on these standard solutions, sample solutions with concentrations of 100 mg / L, 10 mg / L, 1 mg / L, 0.1 mg / L, and 0.01 mg / L were further serially diluted to prepare sample solutions as backup samples. Following the experimental group designed in step 1, the three pesticides were mixed according to the experimental ratio based on the 10 mg / L solutions. Taking a 30%:70% mixture of acetamiprid and carbendazim as an example, 10 ml of mixed solution was prepared. 3 ml (30% of the total volume) of 10 g / ml acetamiprid sample solution and 7 ml (70% of the total volume) of 10 g / ml carbendazim sample solution were mixed and vortexed at 2000 rpm for 3 minutes to obtain a homogeneous mixture.
[0058] Step 3, Sample Testing
[0059] The spectral data acquisition experiment was conducted using a laser micro Raman spectrometer (model DRX3). The excitation wavelength of the spectrometer was set to 785 nm, the laser power to 30 mW, the integration time to 10 s, the number of integrations to 2, and the spectral acquisition wavelength range to 100 cm⁻¹ to 2000 cm⁻¹.
[0060] This experiment collected the spectra of pesticides with seven different components, including three pure substances, three binary mixtures, and one ternary mixture. Data was collected from 100 samples for each pure substance and from 100 samples for each concentration ratio of each mixture, for a total of 2500 spectral data points.
[0061] This application's embodiments utilize experimental samples designed to cover single substances, binary, and ternary mixtures, encompassing the full range of possible pesticide residues and ensuring the model's adaptability to different mixing scenarios. The introduction of multiple ratio combinations (such as equal and asymmetric ratios) enhances the model's generalization ability to dynamic concentration changes in real-world applications, avoiding detection bias caused by limited training data.
[0062] In one embodiment, before inputting the Raman spectral data into the pre-trained qualitative analysis model, the Raman spectral data is preprocessed, specifically including:
[0063] Step S201: Remove abnormal data from the same category of spectra.
[0064] In applications, qualitative analysis requires preprocessing, while quantitative analysis does not. This is because environmental interference and instrument errors during data acquisition can lead to outliers, which significantly impact model learning and prediction. To address this issue, outliers within the same class of spectra are identified based on Mahalanobis distance. The standard deviation of the Mahalanobis distance is calculated, and outliers are removed using the 95th percentile as a threshold, thus eliminating extreme data.
[0065]
[0066] Where d mahal Let S be the Manhattan distance, x be the spectral data vector, μ be the mean vector of the dataset, and S be the mean vector of the dataset. -1 It represents the inverse of the covariance matrix of all spectral data.
[0067] Step S202: Enumerate the combination schemes of baseline correction, scattering correction, smoothing and denoising and scale standardization, and select the combination scheme with the highest classification accuracy as the preprocessing scheme.
[0068] In the application, preprocessing methods are categorized into four types: baseline correction, scattering correction, smoothing and denoising, and scale normalization, and enumerated in that order. Qualitative classification accuracy tests are performed on all enumerated methods using Raman-MTNet as the base network (because no data preprocessing was used in the quantitative analysis), and the classification accuracy of all methods is statistically analyzed.
[0069] The accuracy of all methods is sorted from highest to lowest to obtain the optimal preprocessing scheme that matches the classification model Raman-MTNet.
[0070] Step S203: Preprocess the remaining data after removal using a preprocessing scheme.
[0071] The outlier removal method based on Mahalanobis distance in this application can effectively identify and eliminate abnormal spectral data caused by instrument errors or environmental interference, ensuring the reliability of training data. The enumeration method for selecting preprocessing combinations (such as the synergistic optimization of baseline correction and scattering correction) specifically removes interference factors such as baseline drift and noise, making the preprocessing process highly compatible with model characteristics and improving the robustness of feature extraction.
[0072] In one embodiment, before inputting the preprocessed data into the pre-trained qualitative analysis model, data augmentation is also included, specifically:
[0073] By performing at least one of Gaussian noise, random baseline shift, and random scaling on Raman spectral data, enhanced data with increased data volume is obtained.
[0074] In the application, the ratio of the training, validation, and test sets in Raman-MTNet is 6:2:2. Data augmentation is performed on the training data, increasing the size of the training set by four times to improve the robustness and prediction accuracy of the model. First, the training, validation, and test data are preprocessed using a preprocessing scheme. Then, the aforementioned data augmentation is applied to partition the dataset and augment the training set. Finally, the Raman-MTNet model is trained.
[0075] In the application, three enhancement methods are designed: Gaussian noise, random baseline drift, and random scaling. The specific process is as follows:
[0076] Read the raw Raman spectrum file and calculate the spectral amplitude as a data augmentation reference. A larger amplitude corresponds to greater Gaussian noise, random baseline drift, and random scaling.
[0077] n methods (1≤n≤3) among adding Gaussian noise, random baseline drift and random scaling are randomly selected and used to enhance the original pesticide residue spectral data in the order of selection.
[0078] The training data was augmented three times, that is, the training data was expanded to four times the original data volume;
[0079] The original data and the noise-enhanced data are combined and used as the training set input to train the model.
[0080]
[0081] Where y(t) represents the original spectrum, y aug ε represents the enhanced spectrum, a represents the Gaussian noise, b(t) represents the scaling factor for random scaling, and b(t) represents the baseline drift.
[0082] This application's embodiments integrate a multi-strategy data augmentation method that incorporates Gaussian noise, baseline drift, and random scaling to simulate signal fluctuations and device biases that may exist in actual detection, thereby expanding the diversity of training data. By adaptively adjusting the augmentation amplitude, it ensures that the augmented spectral data conforms to physical laws, enhances the model's adaptability to complex real-world scenarios, and alleviates overfitting problems under small sample conditions.
[0083] In one embodiment, the qualitative analysis model includes:
[0084] The convolutional preprocessing layer is used to perform preliminary feature extraction on the input Raman spectral data to obtain the first output branch and the second output branch.
[0085] A local feature extractor, connected to the first output branch of the convolutional preprocessing layer, extracts local spectral features based on the convolutional module with residual connections.
[0086] A global feature extractor, connected to the second output branch of the convolutional preprocessing layer, extracts global temporal features of the spectrum based on a recurrent neural network;
[0087] The feature fusion network fuses local features and global temporal features to output the class probability of pesticide components in the sample to be tested.
[0088] In applications, such as Figure 2 As shown, the Raman-MTNet model for qualitative analysis of pesticide residues using Raman spectroscopy is a multi-model composite structure. It mainly includes a convolutional preprocessing layer, a local feature extractor, a global feature extractor, and a Transformer network that fuses and focuses local and global information. The original one-dimensional spectral data serves as the input to the overall model, first entering the convolutional preprocessing layer for feature extraction. The output is divided into two branches, connecting to the local and global feature extractors respectively. The outputs of the local and global feature extractors are concatenated along their channel dimensions and then connected to the Transformer network that fuses and focuses local and global information. This output then passes through a fully connected layer and a Softmax layer to output the classification result. Figure 3 As shown, the local feature extractor uses convolutional modules based on residual connections. Through a combination of six residual modules, the receptive field of the model is continuously expanded, enhancing its coarse-to-fine feature extraction capability. After passing through the six residual modules, the model enters a fully connected layer for dimensionality transformation, which is then used to merge the output of the global feature extractor. The global feature extractor is responsible for extracting global information from the entire pesticide residue Raman spectral signal and consists of a single bidirectional GRU layer.
[0089] This application's embodiments perform preliminary feature reduction and abstraction on the spectrum through a convolutional preprocessing layer, separating high-frequency details and low-frequency trend information. The residual convolution module enhances local feature extraction capabilities through a multi-layer skip connection structure, capturing pesticide-specific peak features; a bidirectional GRU network models the global temporal dependencies of the spectral sequence, capturing distribution patterns across a wide spectral band. The feature fusion network dynamically integrates local and global features through an attention mechanism, improving the accuracy of mixture component discrimination.
[0090] Raman-MTNet employs a BiGRU subnetwork capable of extracting global information from Raman spectra and a residual convolutional network capable of extracting local information. Leveraging the BiGRU's ability to perceive global information, the model learns the overall distribution patterns of Raman spectra for different pesticide categories. The residual convolutional network allows the model to simultaneously focus on key local spectral features. Finally, a Transformer is applied to fuse local and global features, enhancing the modeling of crucial information within the sequence.
[0091] In one embodiment, Raman spectroscopy data is input into a pre-trained quantitative analysis model, which outputs the content ratio of pesticide components in the sample to be tested, including:
[0092] Frequency domain features were extracted from Raman spectral data to obtain multi-level frequency domain detail features;
[0093] Time-frequency features were extracted from Raman spectroscopy data to obtain global time-frequency correlation features;
[0094] Multi-level frequency domain detail features and time-frequency global correlation features are fused to obtain fused features;
[0095] Multi-scale prediction based on fusion features is used to obtain and output the content ratio of pesticide components in the sample to be tested.
[0096] This application's embodiments decompose spectral signals from a frequency domain perspective using discrete wavelet transform, extracting detailed features from different frequency bands and enhancing sensitivity to trace components; continuous wavelet transform captures the dynamic spectral variation patterns related to concentration through time-frequency analysis. A multi-scale feature fusion strategy combines frequency domain details with time-frequency correlation information to achieve refined analysis of mixed pesticide concentration gradients, solving the problem of insufficient signal separation in overlapping peak regions using traditional methods.
[0097] This application's embodiments demonstrate significant advantages in Raman spectroscopy analysis using Discrete Wavelet Transform (DWT), particularly when processing signals with noise, background drift, rapidly changing, or complex frequency components. DWT offers multi-scale, localization, denoising, and smoothing capabilities. This study combines DWT with a three-level decomposition of the Raman spectrum to obtain corresponding low-frequency and high-frequency signals. To analyze the multi-channel data after DWT decomposition, a two-dimensional residual convolutional network is used to extract multi-channel information, thereby improving the model's robustness and accuracy. Convolutional Wavelet Transform (CWT) analyzes signals in continuous time, a time-frequency analysis method. Unlike DWT, CWT provides both time and frequency information simultaneously. Its advantage lies in its ability to perform multi-resolution signal analysis, offering high resolution for both low-frequency and high-frequency components. CWT captures fine time-frequency features, while DWT provides a compact representation; combining the two can cover signal features at different resolutions. After effectively fusing the information from the CWT and DWT branches through intermediate and back-end fusion strategies, the fused features are segmented, and then computation is performed based on Transformer and multi-scale convolutional modules. This strategy reduces computational cost. On the other hand, the two branches extract long-range attention information and multi-scale features of the sequence respectively, increasing the robustness of the model. Finally, the outputs of the two branches are adjusted for inter-channel attention using SE attention, focusing on important channels and reducing redundant information.
[0098] In one embodiment, frequency domain feature extraction is performed on Raman spectral data to obtain multi-level frequency domain detail features, including:
[0099] A three-level discrete wavelet transform is performed on the Raman spectral data to generate a multi-level decomposed signal;
[0100] The multi-level decomposed signals are resampled and spliced together to form a spectral decomposition matrix;
[0101] The spectral decomposition matrix is input into a discrete wavelet transform network to extract multi-level frequency domain detail features.
[0102] In applications, Raman-WaveNet, a method for quantitative analysis of pesticide residues using Raman spectroscopy, is a two-stream deep learning architecture based on discrete wavelet transform (DWT) and continuous wavelet transform (CWT). One branch is based on information from the discrete wavelet transform, and the other on information from the CWT. For the DWT branch using DWT, the original Raman spectrum is used as input. First, DWT decomposition is applied to obtain the spectral decomposition matrix, and then the spectral decomposition matrix is input into the DWT branch for feature extraction. Figure 4 , 6 As shown, the DWT decomposition steps are as follows:
[0103] (1) The original Raman spectrum was subjected to a 3-level discrete wavelet transform using the “db4” wavelet to obtain 4 decomposed signals. The 4 decomposed signals represent the detail coefficients of the first-level decomposition (800), the detail coefficients of the second-level decomposition (400), the detail coefficients of the third-level decomposition (200), and the approximation coefficients of the third-level decomposition (200);
[0104] (2) Resample and merge the four decomposed signals of different lengths. Except for the detail coefficients of the first-level decomposition, the other three decomposed signals are resampled to the same length (800) as the detail coefficients of the first-level decomposition. The four resampled decomposed signals are spliced according to the first dimension to obtain a spectral decomposition matrix of size [4,800].
[0105] (3) The spectral decomposition matrix of size [4,800] is used as the input to the DWT branch. The DWT branch consists of a feature extraction convolutional layer and four cascaded residual convolutional layers. The spectral decomposition matrix is used as the input to the feature extraction convolutional layer. After convolutional feature extraction and max pooling downsampling, the output is connected to the four cascaded residual convolutional layers. The cascaded convolutional layers downsample the spectrum four times and continuously expand the receptive field. The DWT branch is mainly responsible for feature extraction from the multi-channel spectral decomposition matrix.
[0106] This application's embodiments decompose the spectrum into multiple levels of approximations and detail coefficients using a three-level discrete wavelet transform, preserving effective component information at different resolutions. By resampling to unify the decomposed signal length and concatenating it into a multi-channel input, the convolutional network can simultaneously mine the correlation between low-frequency principal components and high-frequency detail features, enhancing the model's ability to distinguish weak signals and noise interference.
[0107] In one embodiment, time-frequency feature extraction is performed on Raman spectral data to obtain time-frequency global correlation features, including:
[0108] An eight-scale continuous wavelet transform is performed on the Raman spectral data to generate a wavelet coefficient matrix;
[0109] The wavelet coefficient matrix is input into a continuous wavelet transform network to extract time-frequency global correlation features.
[0110] In applications, such as Figure 5 , 7 As shown, for the CWT branch using continuous wavelet transform, the original Raman spectrum is used as input. First, the CWT transform is applied to obtain the wavelet coefficient matrix, and then the wavelet coefficient matrix is input into the CWT branch for feature extraction. First, after the original spectrum is input, the "Moll" wavelet is applied for CWT decomposition, where the scale of the CWT decomposition is set to 8, the length of the input spectral signal is 1600, and the data dimension of the wavelet coefficient matrix after CWT transform is [8, 1600]. Next, the wavelet coefficient matrix is used as input to the CWT branch for feature extraction. The CWT branch consists of a convolutional preprocessing layer and four cascaded Mobile-Net blocks. The CWT branch first performs one convolutional downsampling and one max-pooling downsampling on the wavelet coefficient matrix to make the data dimension consistent with the dimension of the DWT branch. The output is connected to the four cascaded Mobile-Net blocks to perform four downsamplings on the spectral matrix and continuously expand the receptive field. The CWT branch is mainly responsible for feature extraction from the wavelet coefficient matrix containing global information.
[0111] This application's embodiments generate a wavelet coefficient matrix containing local and global information through continuous wavelet transform and multi-scale time-frequency analysis, fully characterizing the spectral dynamics caused by pesticide concentration changes. A lightweight MobileNet module performs hierarchical feature extraction on the time-frequency matrix, reducing computational complexity while preserving key time-frequency correlation patterns, thus improving the model's analytical efficiency for complex mixed systems.
[0112] In one embodiment, multi-level frequency domain detail features and time-frequency global correlation features are fused to obtain fused features, including:
[0113] The intermediate layer output of the frequency domain detail features and time-frequency correlation features is fused by multiple adaptive weight additions.
[0114] The fused features are calculated using the output of frequency domain detail features as the query vector and the output of time-frequency correlation features as the key vector, through an attention mechanism.
[0115] In the application, the outputs of both the DWT and CWT branches are feature maps with dimensions [1, 50]. Furthermore, the dimensions of each level in the four cascaded residual convolutional layers of the DWT branch correspond one-to-one with the dimensions of each level in the four cascaded Mobile-Net blocks of the CWT branch, facilitating data fusion between the two branches. Intermediate fusion and cross-fusion strategies are designed between the CWT and DWT branches to promote a more robust understanding of the data by the model. Intermediate fusion occurs between the four cascaded residual convolutional layers of the DWT branch and the four cascaded Mobile-Net blocks of the CWT branch, using the output of one level of either the DWT or CWT branch as input to the other branch. Cross-fusion uses the final outputs of both the DWT and CWT branches as input, ultimately outputting a fused feature map.
[0116] The intermediate fusion process is performed three times. The first fusion integrates the output of the DWT branch after the first residual layer into the corresponding size feature map of the CWT branch. The second fusion integrates the output features of the second Mobile-Net block of the CWT branch into the corresponding size feature map of the DWT branch. The third fusion integrates the output features of the third residual layer of the DWT branch into the corresponding size feature map of the CWT branch.
[0117] like Figure 8 As shown, adaptive weight addition is used for fusing information from the two branches. Taking the first fusion as an example, the layer output of the DWT branch at this time is X. DWT The layer output of the CWT branch is X. CWT The output after adjustment by the weight parameter α1 is The calculation formula is as follows:
[0118]
[0119] For cross-attention fusion, a backend fusion method is designed to find the attention of DWT branch information in the CWT branch, thereby fusing them into a single output. The outputs of the DWT branch and the CWT branch are X, respectively. DWT X CWT Cross attention utilizes X DWT As a query (Q), X CWT The final fused features are calculated using keys (K) and values (V).
[0120] The fused features are first reduced to a one-dimensional format and then divided into two subsets along the channel dimension. These subsets are input into the ASPP branch and the Transformer branch, respectively, for further feature extraction. Finally, the output features of the ASPP and Transformer branches are adaptively fused using a SE attention mechanism. ASPP, through dilated convolutions with different dilation rates, excels at capturing multi-scale information in the data. The Transformer, with its self-attention structure, can mine long-range dependencies and capture global contextual information. The collaborative computation of ASPP and Transformer improves the model's representational ability and semi-quantitative analysis accuracy. Finally, a fully connected layer outputs the percentage prediction results for each substance.
[0121] This application's embodiments dynamically balance the feature contributions of the frequency domain and time-frequency branches through an intermediate layer adaptive weight fusion strategy, avoiding subjective biases caused by manually setting weights. The back-end cross-attention mechanism, guided by frequency domain features, focuses on key regions in the time-frequency features, achieving feature complementarity and information enhancement, improving the effectiveness of multimodal feature fusion, and enhancing the stability and accuracy of quantitative prediction.
[0122] The performance of the qualitative model was evaluated using three metrics: recall (Se), precision (PPr), and F1-score. Recall is expressed as the ratio of the number of correctly detected R-peaks (TP) to the total number of true R-peaks.
[0123]
[0124] Precision (PPr) is expressed as the ratio of the number of correctly detected R peaks (TP) to the total number of detected peaks.
[0125]
[0126] F1-Score is a comprehensive evaluation metric calculated using recall and precision.
[0127]
[0128] Micro averages are used to evaluate the overall sample. TP (true positive), FP (false positive), and FN (false negative) represent the number of correctly classified, misclassified, and undetected samples, respectively.
[0129] The qualitative analysis used four evaluation indicators: root mean square error, mean absolute error, coefficient of determination, and relative deviation ratio.
[0130] Root mean square error (RMSE).
[0131]
[0132] Mean Absolute Error (MAE)
[0133]
[0134] Coefficient of determination R 2 (R-Square).
[0135]
[0136] Relative Percent Difference (RPD).
[0137]
[0138] In the four evaluation index formulas, y i Represents the true value. represents the predicted value, and m represents the total number of predicted samples.
[0139] To further illustrate the spectral data preprocessing method provided in this application, this method categorizes spectral preprocessing methods into four main types and randomly combines them using an enumeration method to find the optimal preprocessing method. See Table 2 for details:
[0140] Table 2
[0141]
[0142] To validate the optimal preprocessing method, the following steps were performed sequentially: baseline elimination, scatter correction, smoothing and denoising, and scale scaling. Based on an enumeration method, 240 different combinations were generated, and these combinations were evaluated using F1 scores. Qualitative classification accuracy tests were conducted on all enumerated methods using Raman-MTNet as the base network, and the classification accuracy of all methods was statistically analyzed. As shown in Table 3, the optimal preprocessing method is polynomial fitting + standard normal transform + wavelet transform.
[0143] Table 3
[0144]
[0145]
[0146] To further illustrate the predictive performance of the qualitative and quantitative spectral analysis algorithms provided in this application, the qualitative analysis compared seven algorithms: decision tree, support vector machine, random forest, K-nearest neighbor, PACE (a Raman spectral classification method with local and global strategies), ResNet-Bacteria (a pathogen spectral classification method based on ResNet), and RamanNet (a Raman spectral classification method based on multilayer perceptron and sliding window). The quantitative analysis compared four algorithms: PLSR (partial least squares regression), RFR (random forest regression), MobileNet-V3 (MobileNet version 3), and VGG19 (VGG19 deep convolutional network). The qualitative analysis results are as follows: Figure 9 As shown, the proposed Raman-MTNet architecture achieves the best prediction performance. Quantitative analysis results are as follows: Figure 10 As shown, the proposed Raman-WaveNet architecture achieves the best prediction results, demonstrating the effectiveness and advancement of the proposed qualitative and quantitative methods.
[0147] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0148] This application also provides a pesticide residue detection device based on Raman spectroscopy and deep learning, used to perform the steps described in the embodiments of the pesticide residue detection method based on Raman spectroscopy and deep learning. The pesticide residue detection device based on Raman spectroscopy and deep learning can be a virtual device within an electronic device, run by the processor of the electronic device, or it can be the electronic device itself.
[0149] like Figure 11 As shown in the embodiment of this application, the pesticide residue detection device 100 based on Raman spectroscopy and deep learning includes:
[0150] The acquisition module 101 is used to acquire the Raman spectral data of the sample to be tested;
[0151] The qualitative analysis module 102 is used to input Raman spectroscopy data into a pre-trained qualitative analysis model and output the category probability of pesticide components in the sample to be tested.
[0152] The quantitative analysis module 103 is used to input Raman spectroscopy data into a pre-trained quantitative analysis model and output the content ratio of pesticide components in the sample to be tested.
[0153] The qualitative analysis model is based on a multimodal fusion deep learning network to achieve joint analysis of global and local spectral features; the quantitative analysis model is based on a multi-scale feature fusion deep learning architecture to achieve spectral decomposition and concentration regression.
[0154] In applications, the modules in a pesticide residue detection device based on Raman spectroscopy and deep learning can be software program modules, or they can be implemented through different logic circuits integrated in a processor, or they can be implemented through multiple distributed processors.
[0155] like Figure 12 As shown, this application embodiment also provides an electronic device 200, including: at least one processor 201 ( Figure 12 The diagram shows only one processor, memory 202, and computer program 203 stored in memory 202 and executable on at least one processor 201. When processor 201 executes computer program 203, it implements the steps in the various method embodiments described above.
[0156] In applications, electronic devices may include, but are not limited to, processors and memory. Those skilled in the art will understand that... Figure 12 This is merely an example of an electronic device and does not constitute a limitation on the electronic device. It may include more or fewer components than shown, or a combination of certain components, or different components.
[0157] In applications, the processor can be a Central Processing Unit (CPU), but it can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor.
[0158] In applications, memory can be an internal storage unit of an electronic device in some embodiments, such as a hard drive or RAM. In other embodiments, memory can be an external storage device of the electronic device, such as a plug-in hard drive, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card. Furthermore, memory can include both internal and external storage units of the electronic device. Memory is used to store operating systems, applications, bootloaders, data, and other programs, such as program code for computer programs. Memory can also be used to temporarily store data that has been output or will be output.
[0159] It should be noted that the information interaction and execution process between the above-mentioned devices / units are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, and they will not be repeated here.
[0160] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0161] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps described in the various method embodiments above.
[0162] This application provides a computer program product, including a computer program, which, when run on an electronic device, enables the electronic device to perform the steps described in the various method embodiments above.
[0163] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. A computer-readable medium can include at least: any entity or device capable of carrying computer program code to a device / electronic device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electrical carrier signals or telecommunication signals.
[0164] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0165] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0166] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0167] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0168] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. A pesticide residue detection method based on Raman spectroscopy and deep learning, characterized in that, include: Obtain the Raman spectral data of the sample to be tested; The Raman spectroscopy data is input into a pre-trained qualitative analysis model, which outputs the probability of the pesticide component category in the sample to be tested. The Raman spectroscopy data is input into a pre-trained quantitative analysis model, which outputs the content ratio of pesticide components in the sample to be tested. The qualitative analysis model is based on a multimodal fusion deep learning network to achieve joint analysis of global and local spectral features; the quantitative analysis model is based on a multi-scale feature fusion deep learning architecture to achieve spectral decomposition and concentration regression. The qualitative analysis model includes: The convolutional preprocessing layer is used to perform preliminary feature extraction on the input Raman spectral data to obtain the first output branch and the second output branch. A local feature extractor, connected to the first output branch of the convolutional preprocessing layer, extracts local spectral features based on the convolutional module with residual connections. A global feature extractor, connected to the second output branch of the convolutional preprocessing layer, extracts global temporal features of the spectrum based on a recurrent neural network; A feature fusion network fuses the local features and the global temporal features to output the category probability of pesticide components in the sample to be tested. The step of inputting Raman spectroscopy data into a pre-trained quantitative analysis model and outputting the content ratio of pesticide components in the sample to be tested includes: Frequency domain features are extracted from the Raman spectral data to obtain multi-level frequency domain detail features; Time-frequency features are extracted from the Raman spectral data to obtain global time-frequency correlation features; The multi-level frequency domain detail features and the time-frequency global correlation features are fused to obtain fused features; Based on the fusion features, multi-scale prediction is performed to obtain and output the content ratio of pesticide components in the sample to be tested; The frequency domain feature extraction of the Raman spectral data yields multi-level frequency domain detail features, including: The Raman spectral data are subjected to a three-level discrete wavelet transform to generate a multi-level decomposed signal; The multi-level decomposed signals are resampled and spliced together to form a spectral decomposition matrix; The spectral decomposition matrix is input into a discrete wavelet transform network to extract multi-level frequency domain detail features; The step of extracting time-frequency features from the Raman spectral data to obtain global time-frequency correlation features includes: The Raman spectral data are subjected to an eight-scale continuous wavelet transform to generate a wavelet coefficient matrix; The wavelet coefficient matrix is input into a continuous wavelet transform network to extract time-frequency global correlation features; The process of fusing the multi-level frequency domain detail features with the time-frequency global correlation features to obtain fused features includes: The intermediate layer output of the frequency domain detail features and the time-frequency correlation features is fused by multiple adaptive weight additions. Using the output of the frequency domain detail features as the query vector and the output of the time-frequency correlation features as the key vector, the fused features are calculated through an attention mechanism.
2. The pesticide residue detection method based on Raman spectroscopy and deep learning as described in claim 1, characterized in that, The acquisition of Raman spectral data of the sample to be tested includes: Obtain spectral data of acetamiprid, carbendazim, and cyproconazole as single substances and mixtures; The mixture includes binary mixtures and ternary mixtures, and the binary mixtures and ternary mixtures include a variety of mixing ratios.
3. The pesticide residue detection method based on Raman spectroscopy and deep learning as described in claim 1, characterized in that, Before inputting the Raman spectroscopy data into the pre-trained qualitative analysis model, the following steps are also included: Remove outlier data from the same category of spectra; Enumerate the combinations of baseline correction, scatter correction, smoothing and denoising and scale standardization, and select the combination with the highest classification accuracy as the preprocessing scheme. The preprocessing scheme is used to preprocess the remaining data after the removal.
4. The pesticide residue detection method based on Raman spectroscopy and deep learning as described in claim 3, characterized in that, Before inputting the preprocessed data into the pre-trained qualitative analysis model, the process also includes: By performing at least one of Gaussian noise, random baseline shift, and random scaling on Raman spectral data, enhanced data with increased data volume is obtained.
5. An electronic device comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it causes the electronic device to implement the method as described in any one of claims 1-4.