Pesticide residue detection method based on Raman spectrum and deep learning and electronic equipment
Through the combination of Raman spectroscopy and deep learning, rapid and accurate analysis of pesticide residue detection is achieved, solving the problems of high detection costs, slow speed and insufficient accuracy in the existing technology, and improving detection efficiency and accuracy.
Patent Information
- Application Number
- CN202510639212.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-19
- Publication Date
- 2025-08-15
- Estimated Expiration
- 2045-05-19
AI Technical Summary
In the prior art, enzyme inhibition methods, chromatography and machine learning have problems such as high detection cost, slow speed, strong professionalism, and insufficient detection accuracy in pesticide residue detection, making it difficult to achieve fast and accurate pesticide residue analysis.
Using Raman spectroscopy combined with deep learning method, the Raman spectral data of the sample to be tested is obtained, and the multimodal fusion deep learning network is used for qualitative analysis, the category probability of pesticide components is output, and the content ratio of pesticide components is output through a deep learning architecture with multi-scale feature fusion is performed to output the content ratio of pesticide components.
It realizes fast and accurate pesticide residue detection, improves detection accuracy and efficiency, solves the error accumulation problem caused by the separation of qualitative and quantitative models in traditional methods, and enhances the ability to identify complex pesticide mixtures.
Smart Images

Figure CN120490045A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of agricultural technology, and specifically to a pesticide residue detection method and electronic equipment based on Raman spectroscopy and deep learning. Background Art
[0002] Pesticides play a key role in controlling diseases and weeds, but their widespread use has also led to unavoidable food safety and environmental pollution issues. Pesticide residues exceeding the permitted limit in vegetables include carbendazim, acetamiprid, and phorate.
[0003] In recent years, chromatography has been gradually applied to the analysis of pesticide residue components. However, this method is highly specialized and expensive, making it unsuitable for rapid on-site testing and hindering its application and promotion. Methods based on enzyme inhibition have also been used for pesticide residue detection. Although this method has certain practicality, it is still insufficient for identifying complex pesticide samples. Spectral-based methods have become an important approach for pesticide residue analysis due to their fast detection speed and high sensitivity. Traditional methods generally use machine learning to establish prediction models for spectral data, but machine learning models require complex feature engineering, which increases processing costs. At the same time, machine learning has weak expression capabilities for complex patterns and large data sets, and suffers from problems such as insufficient generalization capabilities. Summary of the Invention
[0004] In view of this, the embodiments of the present 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 methods, as well as the problem that machine learning cannot accurately and stably find potential patterns in Raman spectra.
[0005] A first aspect of the embodiments of the present application provides a method for detecting pesticide residues based on Raman spectroscopy and deep learning, comprising:
[0006] Obtaining Raman spectrum data of the sample to be tested;
[0007] Inputting the Raman spectral data into a pre-trained qualitative analysis model to output the category probability of the pesticide components in the sample to be tested;
[0008] Inputting the Raman spectral data into a pre-trained quantitative analysis model to output the content ratio of the pesticide component in the sample to be tested;
[0009] Among them, the qualitative analysis model realizes the joint analysis of global and local spectral features based on the deep learning network of multimodal fusion; the quantitative analysis model realizes spectral decomposition and concentration regression based on the deep learning architecture of multi-scale feature fusion.
[0010] A second aspect of the embodiments of the present application provides a pesticide residue detection device based on Raman spectroscopy and deep learning, comprising:
[0011] An acquisition module is used to obtain Raman spectrum data of the sample to be tested;
[0012] A qualitative analysis module is used to input Raman spectral data into a pre-trained qualitative analysis model and output the category probability of the pesticide components in the sample to be tested;
[0013] A quantitative analysis module is used to input Raman spectral data into a pre-trained quantitative analysis model and output the content ratio of the pesticide component in the sample to be tested;
[0014] Among them, the qualitative analysis model realizes the joint analysis of global and local spectral features based on the deep learning network of multimodal fusion; the quantitative analysis model realizes spectral decomposition and concentration regression based on the deep learning architecture of multi-scale feature fusion.
[0015] A third aspect of an embodiment of the present application provides an electronic device, comprising a processor, a memory, and a computer program stored in the memory and runnable on the processor. When the processor executes the computer program, the electronic device implements the pesticide residue detection method based on Raman spectroscopy and deep learning as provided in the first aspect of the embodiment of the present application.
[0016] A fourth aspect of the embodiments of the present application provides a computer program product, including a computer program. When the computer program is executed, the method according to the first aspect of the embodiments of the present application is executed.
[0017] The first aspect of the embodiment of the present application provides a pesticide residue detection method based on Raman spectroscopy and deep learning, which obtains 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 the pesticide components in the sample to be tested; inputs the Raman spectral data into a pre-trained quantitative analysis model to output the content ratio of the pesticide components in the sample to be tested; wherein, the qualitative analysis model realizes the joint analysis of the global and local features of the spectrum based on a deep learning network of multimodal fusion; the quantitative analysis model realizes spectral decomposition and concentration regression based on a deep learning architecture of multi-scale feature fusion. The multimodal fusion architecture of the qualitative analysis model (joint analysis of global and local features) is used to accurately identify the components of the mixture, solving the problem of insufficient analysis ability of overlapping spectra by 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 analysis framework for complex pesticide ratios, overcomes the error accumulation problem caused by the separation of qualitative and quantitative models in traditional methods, and improves the overall efficiency of the detection process.
[0018] It can be understood that the beneficial effects of the second to fourth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments or descriptions of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0020] Figure 1 This is a flow chart of a pesticide residue detection method based on Raman spectroscopy and deep learning provided in one embodiment of the present application;
[0021] Figure 2 This is the structure diagram of the qualitative detection network Raman-MTNet provided by this application;
[0022] Figure 3 This is a diagram of the residual layer structure in the qualitative detection network provided by this application;
[0023] Figure 4 This is the DWT processing flow in the quantitative detection method provided in this application;
[0024] Figure 5 This is a diagram of the structure of the Raman-WaveNet quantitative detection network provided in this application;
[0025] Figure 6 The DWT branch structure in the quantitative detection network Raman-WaveNet provided in this application;
[0026] Figure 7 The CWT branch structure in the quantitative detection network Raman-WaveNet provided in this application;
[0027] Figure 8 Schematic diagram of the fusion of DWT branch and CWT branch output provided by this application;
[0028] Figure 9 A schematic diagram comparing the qualitative analysis performance of the qualitative detection network provided in this application and different algorithms;
[0029] Figure 10 A schematic diagram comparing the quantitative analysis performance of the quantitative detection network provided in this application and different algorithms;
[0030] Figure 11 Schematic diagram of the structure of a pesticide residue detection device based on Raman spectroscopy and deep learning provided in an embodiment of the present application;
[0031] Figure 12 It is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0032] In the following description, specific details such as specific system structures and techniques are provided for purposes of illustration rather than limitation to facilitate a thorough understanding of the embodiments of the present application. However, it will be apparent to those skilled in the art that the present application may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid obscuring the description of the present application with unnecessary detail.
[0033] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or collections thereof.
[0034] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0035] References to "one embodiment" or "some embodiments" in this specification mean that a particular feature, structure, or characteristic described in conjunction with that embodiment is included in one or more embodiments of the present application. Thus, phrases such as "in one embodiment," "in some embodiments," "in other embodiments," and "in other embodiments" appearing in various places in 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 "including," "comprising," "having," and variations thereof all 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 the embodiment of the present application includes the following steps S101 to S106:
[0037] Step S101: Acquire Raman spectrum data of a sample to be tested.
[0038] In the application, Raman-enhanced biochips were used to collect data on pesticide Raman spectra, collecting a total of 2,500 spectra of single substances and mixed substances of three pesticides: acetamiprid, carbendazim and myclobutanil.
[0039] Step S102: Input the Raman spectrum data into the pre-trained qualitative analysis model, and output the category probability of the pesticide components in the sample to be tested.
[0040] In this application, Raman-MTNet (a qualitative analysis model) is used to qualitatively analyze pesticide residue Raman spectra. Pesticide residue spectral data is input into a trained qualitative analysis network, which outputs the predicted pesticide composition (whether acetamiprid, carbendazim, or myclobutanil are present). This system can detect single pesticide residues as well as identify mixtures of pesticide residues.
[0041] Raman-MTNet is a multi-classification network that classifies different mixtures into distinct categories. Based on the three pesticides used in this study—acetamiprid, carbendazim, and myclobutanil—a total of seven categories were generated: acetamiprid, carbendazim, myclobutanil, acetamiprid + carbendazim, acetamiprid + myclobutanil, and a ternary mixture of the three. Specifically, Raman-MTNet receives 1600 Raman spectra at its input and predicts the output probabilities for the seven categories, with the category corresponding to the highest probability being the predicted category.
[0042] Step S103: inputting the Raman spectrum data into the pre-trained quantitative analysis model to output the content ratio of the pesticide components in the sample to be tested;
[0043] Among them, the qualitative analysis model realizes the joint analysis of global and local spectral features based on the deep learning network of multimodal fusion; the quantitative analysis model realizes spectral decomposition and concentration regression based on the deep learning architecture of multi-scale feature fusion.
[0044] In this application, Raman-WaveNet (a quantitative analysis model) is used to quantitatively analyze pesticide residue Raman spectra. The pesticide residue spectral data is input into a trained quantitative analysis network, which outputs the component content of each pesticide (acetamiprid, carbendazim, and myclobutanil). This allows for the detection of different pesticide levels in the sample.
[0045] The Raman-WaveNet input receives 1600 Raman spectra and outputs the predicted percentage of each substance. In this study, the outputs are the corresponding contents of acetamiprid, carbendazim, and myclobutanil, ranging from 0 to 100%.
[0046] The present embodiment achieves accurate identification of mixture components through a multimodal fusion architecture of the qualitative analysis model (combined analysis of global and local features), addressing the inadequate ability of traditional single feature extraction methods to resolve overlapping spectra. The multiscale feature fusion architecture of the quantitative analysis model (combining spectral decomposition with concentration regression) provides a unified analysis 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, obtaining Raman spectral data of a sample to be tested includes:
[0048] Obtain spectral data of acetamiprid, carbendazim, and myclobutanil as single substances and mixtures;
[0049] The mixture includes binary mixture and ternary mixture, and the binary mixture and ternary mixture include various mixing ratios.
[0050] In the application, in order to obtain the Raman spectrum data of the sample to be tested, the following steps are specifically included:
[0051] Step 1: Data collection experimental design.
[0052] Based on the commonly used pesticides for rapeseed, three typical pesticides, carbendazim, acetamiprid and myclobutanil, were used as research objects for the study. In order to study the composition of pesticide mixtures and their concentration prediction, binary and ternary mixing experimental designs were adopted to generate a total of four different mixing experimental groups. Taking into account that the proportions of components in pesticide mixtures may vary, this study designed multiple groups of mixing experiments based on volume to ensure that the proportions of different pesticides in each mixed solution can be evenly distributed from 0% to 100%. Specifically, three mixing levels were set for each binary mixture, and four mixing levels were set for the ternary mixture, as shown in Table 1:
[0053] Table 1
[0054]
[0055] This design ensures that the relative concentration frequency of each pesticide is evenly distributed, thus providing a stable and comprehensive experimental basis for subsequent component identification and concentration prediction.
[0056] Step 2: Sample preparation
[0057] In this study, the quality of the effective substance was used as an indicator to dilute three commonly used pesticides (acetamiprid, carbendazim and myclobutanil) to prepare a 1000 mg / L standard solution. Based on this standard solution, 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 diluted step by step as spare samples. According to the experimental group designed in step 1, the 10 mg / L solutions of the three pesticides were mixed based on the experimental proportion settings. Taking the mixture of acetamiprid and carbendazim at 30%:70% as an example, 10 ml of mixed solution was prepared. Take 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, mix them, and use a vortex mixer to mix at a speed of 2000 rpm for 3 minutes to obtain a uniform mixture.
[0058] Step 3: Sample testing
[0059] Spectral data acquisition experiments were performed using a laser micro-Raman spectrometer (model DRX3). The spectrometer excitation wavelength was set to 785 nm, the laser power was 30 mW, the integration time was 10 s, the number of integrations was 2, and the spectrum acquisition wavelength range was set to 100 cm-1 to 2000 cm-1.
[0060] This experiment collected spectra of seven different pesticide compositions, including three pure substances, three binary mixtures, and one ternary mixture. 100 samples were collected for each pure substance, and 100 samples were collected for each concentration ratio of each mixture, for a total of 2,500 spectral data points.
[0061] The examples in this application incorporate experimental samples encompassing single substances, binary, and ternary mixtures, covering the full range of possible pesticide residue ratios, ensuring the model's adaptability to diverse mixing scenarios. The inclusion of multiple ratio combinations (such as equal and asymmetric ratios) enhances the model's generalization to dynamic concentration changes in real-world applications, avoiding detection biases 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 pre-processed, specifically including:
[0063] Step S201: Eliminate abnormal data in spectra of the same category.
[0064] In applications, qualitative analysis requires preprocessing, while quantitative analysis does not. Environmental interference and instrumental errors can occur during data acquisition, leading to outliers that significantly impact model learning and prediction. To address this issue, we use the Mahalanobis distance to identify outliers within the same category of spectra. The standard deviation of the Mahalanobis distance is calculated, and the 95th percentile is used as a threshold to remove outliers and delete extreme data.
[0065]
[0066] where d mahal is the Manhattan distance, x is the spectral data vector, μ represents the mean vector of the data set, S -1 Represents the inverse of the covariance matrix of all spectral data.
[0067] Step S202 : enumerate the combination schemes of baseline correction, scatter correction, smoothing denoising and scale normalization, and select the combination scheme with the highest classification accuracy as the preprocessing scheme.
[0068] In this application, we categorize preprocessing methods into four categories: baseline correction, scatter correction, smoothing and denoising, and scale normalization. These methods are enumerated in this order. We then perform qualitative classification accuracy tests on all enumerated methods using the Raman-MTNet network as the base network (this is because the quantitative analysis does not use data preprocessing), and then calculate the classification accuracy of all methods.
[0069] The accuracy of all methods is sorted from large to small, and the optimal preprocessing solution that matches the classification model Raman-MTNet is obtained.
[0070] Step S203: pre-process the remaining data after the elimination using a pre-processing solution.
[0071] The Mahalanobis distance-based outlier removal method in this application embodiment effectively identifies and eliminates anomalous spectral data caused by instrument errors or environmental interference, ensuring the reliability of training data. Enumeration methods are used to screen preprocessing combinations (such as the coordinated optimization of baseline correction and scatter correction) to specifically remove interference factors such as baseline drift and noise, ensuring a high degree of compatibility between the preprocessing process and the model characteristics, thereby improving the robustness of feature extraction.
[0072] In one embodiment, before the pre-processed data is input into the pre-trained qualitative analysis model, data enhancement is also included, specifically:
[0073] At least one operation of Gaussian noise, random baseline drift, and random scaling is performed on the Raman spectrum data to obtain enhanced data with an increased data volume.
[0074] In the application, the training, validation, and test sets of Raman-MTNet are split in a ratio of 6:2:2. Data augmentation is performed on the training data, quadrupling the training set's data size to improve the model's robustness and prediction accuracy. The training, validation, and test data are first preprocessed using the preprocessing scheme. The data augmentation described above is then used 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 original Raman spectrum file and calculate the spectrum amplitude as a reference indicator for data enhancement. A larger amplitude corresponds to a larger Gaussian noise, random baseline drift, and random scaling.
[0077] Randomly select n methods (1≤n≤3) among adding Gaussian noise, random baseline drift and random scaling, and enhance the original pesticide residue spectral data in the order of selection;
[0078] The training data is enhanced 3 times, that is, the training data is expanded to 4 times the original data volume;
[0079] The original data and the noise-enhanced data are combined and used as the training set to input the model for training.
[0080]
[0081] Among them, y(t) represents the original spectrum, y aug represents the enhanced spectrum, ε represents Gaussian noise, a represents the scaling factor of random scaling, and b(t) represents the baseline drift.
[0082] This embodiment incorporates a multi-strategy data augmentation method using Gaussian noise, baseline drift, and random scaling to simulate signal fluctuations and device biases that may occur in real-world detection, thereby expanding the diversity of training data. By adaptively adjusting the amplitude of the augmentation, the enhanced spectral data is ensured to conform to physical laws, enhancing the model's adaptability to complex real-world scenarios and alleviating overfitting issues in small sample sizes.
[0083] In one embodiment, the qualitative analysis model includes:
[0084] The convolution pre-processing layer is used to perform preliminary feature extraction on the input Raman spectrum 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 pre-processing layer, extracts local features of the spectrum based on a convolutional module with residual connections;
[0086] A global feature extractor, connected to the second output branch of the convolutional pre-processing layer, extracts the global temporal features of the spectrum based on a recurrent neural network;
[0087] The feature fusion network fuses local features with global temporal features and outputs the category probability of the pesticide components in the sample to be tested.
[0088] In applications, such as Figure 2 As shown in the figure, the Raman-MTNet model for qualitative analysis of pesticide residue Raman spectroscopy is a multi-model composite structure. It mainly includes a convolutional pre-processing layer, a local feature extractor, a global feature extractor, and a fusion focusing network of Transformer local information and global information. The original one-dimensional spectral data is used as the input of the overall model. It first enters the convolutional pre-processing layer for feature extraction. The output is divided into two branches and connected to the local feature extractor and the global feature extractor respectively. The outputs of the local feature extractor and the global feature extractor are spliced in the channel dimension and connected to the fusion focusing network of Transformer local information and global information. This part of the output then passes through the fully connected layer and Softmax to output the classification result. As shown in the figure Figure 3 As shown, the local feature extractor uses a convolutional module based on residual connections. This combination of six layers of residual modules continuously expands the model's receptive field and coarse-to-fine feature extraction capabilities. After the six layers of residual modules, the data enters a fully connected layer for dimensionality conversion before being merged with 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] The present embodiment performs preliminary feature dimensionality reduction and abstraction on the spectrum through a convolutional pre-processing layer, separating high-frequency details from low-frequency trend information. The residual convolution module enhances local feature extraction through a multi-layer skip connection structure, capturing pesticide-specific peak features. A bidirectional GRU network models the global temporal dependencies of spectral sequences, capturing distribution patterns across a wide spectral range. A feature fusion network dynamically integrates local and global features through an attention mechanism, improving the accuracy of mixture composition discrimination.
[0090] Raman-MTNet incorporates a BiGRU subnetwork capable of extracting global Raman spectral information 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 also allows the model to focus on key local spectral features. Finally, the Transformer is applied to fuse local and global features, strengthening the modeling of key information within the sequence.
[0091] In one embodiment, the Raman spectral data is input into a pre-trained quantitative analysis model to output the content ratio of the pesticide component in the sample to be tested, including:
[0092] Perform frequency domain feature extraction on Raman spectral data to obtain multi-level frequency domain detail features;
[0093] Extract time-frequency features from Raman spectral data to obtain time-frequency global correlation features;
[0094] The multi-level frequency domain detail features and the time-frequency global correlation features are fused to obtain the fusion features;
[0095] Multi-scale prediction is performed based on the fusion features to obtain the content ratio of pesticide components in the sample to be tested and output it.
[0096] This embodiment uses discrete wavelet transforms to decompose spectral signals from a frequency domain perspective, extracting detailed features across different frequency bands and enhancing sensitivity to trace components. A continuous wavelet transform captures concentration-related dynamic spectral variations 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, addressing the inadequate separation of overlapping peak signals found in traditional methods.
[0097] The embodiment of the present application has significant advantages in analyzing Raman spectra through discrete wavelet transform (DWT), especially when processing signals with noise, background drift, rapid changes or complex frequency components. DWT provides multi-scale, localization, denoising and smoothing capabilities. This study combines DWT to perform a three-level decomposition of the Raman spectrum to obtain corresponding low-frequency and high-frequency signals. In order to analyze the multi-channel data after DWT decomposition, multi-channel information is extracted based on a two-dimensional residual convolutional network, thereby improving the robustness and accuracy of the model. CWT analyzes signals in continuous time and is a time-frequency analysis method. Unlike DWT, CWT provides time and frequency information at the same time. Its advantage is that it can perform multi-resolution analysis of signals and has high resolution for both low-frequency and high-frequency components. CWT captures fine time-frequency features, and DWT provides compact representation. The combination of the two can cover signal features of different resolutions. After the information of the CWT branch and the DWT branch is effectively fused through the intermediate fusion and back-end fusion strategies, the fused features are segmented and then calculated based on the Transformer and multi-scale convolution modules. On the one hand, this strategy can reduce the amount of calculation. On the other hand, the two branches extract long-range attention information and multi-scale features of the sequence respectively, which increases the robustness of the model. Finally, the outputs of the two branches are used to adjust the attention between channels 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] Perform three-level discrete wavelet transform on Raman spectral data to generate multi-level decomposition signals;
[0100] Resample the multi-level decomposition signals and splice the spectral decomposition matrix;
[0101] The spectral decomposition matrix is input into the discrete wavelet transform network to extract multi-level frequency domain detail features.
[0102] In application, Raman-WaveNet, a method for quantitative analysis of pesticide residues by Raman spectroscopy, is a dual-stream deep learning architecture based on discrete wavelet transform and continuous wavelet transform, in which one branch is based on information after discrete wavelet transform and the other branch is based on information after continuous wavelet transform. For the DWT branch using discrete wavelet transform, the original Raman spectrum is used as input, and the DWT decomposition is first 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) Apply the "db4" wavelet to perform a three-level discrete wavelet transform on the original Raman spectrum, and obtain four decomposition signals. The four decomposition signals represent the detail coefficient of the first level decomposition (length 800), the detail coefficient of the second level decomposition (length 400), the detail coefficient of the third level decomposition (length 200), and the approximate coefficient of the third level decomposition (length 200).
[0104] (2) Resample and merge the four decomposition signals of different lengths. Except for the detail coefficients of the first-level decomposition, the other three decomposition signals are resampled to the same length as the detail coefficients of the first-level decomposition (length 800). The four resampled decomposition 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 of the DWT branch, which consists of a feature extraction convolution layer and four cascaded residual convolution layers. The spectral decomposition matrix is used as the input of the feature extraction convolution layer, and after convolution feature extraction and maximum pooling downsampling, the output is connected to the four cascaded residual convolution layers. The cascaded convolution 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 embodiment of the application uses a three-level discrete wavelet transform to decompose the spectrum into multiple levels of approximation and detail coefficients, preserving the effective component information at different resolutions. By resampling the decomposed signal length to a uniform length and splicing it into multi-channel input, the convolutional network can simultaneously explore the correlation between low-frequency principal components and high-frequency detail features, enhancing the model's ability to distinguish weak signals from 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] Perform eight-scale continuous wavelet transform on Raman spectral data to generate wavelet coefficient matrix;
[0109] The wavelet coefficient matrix is input into the continuous wavelet transform network to extract the time-frequency global correlation features.
[0110] In applications, such as Figure 5 、 7 As shown in the figure, the CWT branch, which uses a continuous wavelet transform (CWT), takes the original Raman spectrum as input and first applies the CWT transform to obtain a wavelet coefficient matrix. This wavelet coefficient matrix is then input into the CWT branch for feature extraction. First, the original spectrum is input and decomposed using the "morl" wavelet. The CWT decomposition scale is set to 8, and the input spectrum signal length is 1600. The data dimension of the wavelet coefficient matrix after the CWT transform is [8, 1600]. Next, the wavelet coefficient matrix is used as input for feature extraction in the CWT branch. The CWT branch consists of a convolutional pre-processing layer and four cascaded Mobile-Net blocks. The CWT branch first performs a convolution downsampling and a max pooling downsampling on the wavelet coefficient matrix to align the data dimensions with those of the DWT branch. The output is then connected to four cascaded Mobile-Net blocks, which downsample the spectrum matrix four times and continuously expand the receptive field. The CWT branch is primarily responsible for feature extraction from the wavelet coefficient matrix containing global information.
[0111] This embodiment uses a continuous wavelet transform (CWT) to generate a wavelet coefficient matrix containing both local and global information through multi-scale time-frequency analysis, fully characterizing the spectral dynamics caused by changes in pesticide concentration. A lightweight MobileNet module performs hierarchical feature extraction on the time-frequency matrix, reducing computational complexity while preserving key time-frequency correlation patterns, improving the model's efficiency in analyzing complex mixed systems.
[0112] In one embodiment, the multi-level frequency domain detail features and the time-frequency global correlation features are fused to obtain fused features, including:
[0113] Perform multiple adaptive weight addition fusions on the intermediate layer outputs of the frequency domain detail features and the time-frequency correlation features;
[0114] The output of the frequency domain detail feature is used as the query vector, the output of the time-frequency correlation feature is used as the key-value vector, and the fusion feature is calculated through the attention mechanism.
[0115] In the application, the outputs of both the DWT and CWT branches are feature maps of dimension [1, 50]. Furthermore, the dimensions of each level of the four cascaded residual convolutional layers in the DWT branch correspond one-to-one with the dimensions of each level of the four cascaded Mobile-Net blocks in the CWT branch, enabling 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. Intermediate fusion is performed between the four cascaded residual convolutional layers in the DWT branch and the four cascaded Mobile-Net blocks in the CWT branch, with the output of one level of either the DWT or CWT branch serving as the input for fusion into the other branch. In cross-fusion, the final output of both the DWT and CWT branches serves as the input for cross-fusion, ultimately outputting the fused feature map.
[0116] Intermediate fusion is performed three times. The first fusion integrates the output of the DWT branch through 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 in Figure 2, when fusing the information of the two branches, adaptive weight addition is used for fusion. Taking the first fusion as an example, the layer output of the DWT branch is X DWT , the layer output of the CWT branch is X CWT , the output after adjustment of the weight parameter α1 is The calculation formula is as follows:
[0118]
[0119] For cross fusion, a cross attention backend fusion method is designed to find the attention of the DWT branch information in the CWT branch, and then fuse them into one output. The outputs of the DWT branch and the CWT branch are X DWT 、X CWT , cross attention utilizes X DWT As a query (Query, Q), X CWT As the key (Key, K) and value (Value, V) to calculate the final fusion feature.
[0120] The fused features are first reduced to a one-dimensional format and divided into two subsets along the channel dimension. These are fed into the ASPP branch and the Transformer branch for further feature extraction. Finally, the output features of the ASPP and Transformer branches are adaptively fused using the SE attention mechanism. ASPP, through dilated convolutions with varying dilation rates, excels at capturing multi-scale information in the data. The Transformer, through its self-attention structure, can mine long-range dependencies and capture global context. The collaborative computation of ASPP and Transformer improves the model's representational capabilities and semi-quantitative analysis accuracy. Finally, a fully connected layer outputs the predicted percentage of each substance.
[0121] This embodiment of the application dynamically balances the feature contributions of the frequency domain and time-frequency branches through an intermediate layer adaptive weight fusion strategy, avoiding the subjective bias of manually setting weights. The back-end cross-attention mechanism uses frequency domain features as a guide to focus on key areas of 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 evaluation of the qualitative model uses three metrics, namely recall (Se), precision (PPr), and F1-score. Recall is expressed as the ratio of the number of correctly detected R-peaks (TP) to the number of all true R-peaks.
[0123]
[0124] The precision (PPr) is expressed as the ratio of the number of correctly detected R peaks (TP) to the number of all detected peaks.
[0125]
[0126] F1-Score is a comprehensive evaluation indicator calculated by recall and precision.
[0127]
[0128] Micro Average is used to evaluate the metrics on the overall samples. TP (True Positive), FP (False Positive), and FN (False Negative) represent the number of correctly classified, incorrectly classified, and undetected samples, respectively.
[0129] Four evaluation indicators were used in the qualitative analysis, namely 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 by this application, this method divides the spectral preprocessing methods into four categories, and performs random combination and enumeration to find the optimal preprocessing method. See Table 2 for details:
[0140] Table 2
[0141]
[0142] To identify the optimal preprocessing method, baseline removal, scatter correction, smoothing and denoising, and scaling were performed sequentially. Enumeration yielded 240 different combinations, which were evaluated using the F1 score. Qualitative classification accuracy tests were conducted on all enumerated methods using the Raman-MTNet network as the base network, and the classification accuracy of all methods was statistically analyzed. As shown in Table 3 for the results of the five optimal preprocessing methods, the optimal preprocessing method is polynomial fitting + standard normal transformation + wavelet transformation.
[0143] Table 3
[0144]
[0145]
[0146] In order to further illustrate the prediction performance of the spectral number qualitative and quantitative analysis algorithm provided in this application, seven algorithms, including 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 multi-layer perceptron and sliding window), were compared in the qualitative analysis. Four algorithms, including PLSR (partial least squares regression), RFR (random forest regression), MobileNet-V3 (MobileNet version 3 network) and VGG19 (VGG19 deep convolutional network), were compared in the quantitative analysis. The qualitative analysis results are as follows: Figure 9 As shown in Figure 2, the proposed Raman-MTNet architecture achieved the best prediction effect. The quantitative analysis results are shown in Figure 2. Figure 10 As shown in the figure, the proposed Raman-WaveNet architecture achieves the best prediction effect, which demonstrates the effectiveness and advancement of the proposed qualitative and quantitative methods.
[0147] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean 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] The present application also provides a pesticide residue detection device based on Raman spectroscopy and deep learning, which is used to perform the steps of the above-mentioned 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 in an electronic device, operated by a processor of the electronic device, or it can be the electronic device itself.
[0149] like Figure 11 As shown, the pesticide residue detection device 100 based on Raman spectroscopy and deep learning provided in an embodiment of the present application includes:
[0150] Acquisition module 101, used to obtain Raman spectrum data of the sample to be tested;
[0151] Qualitative analysis module 102, used to input Raman spectrum data into a pre-trained qualitative analysis model and output the category probability of the pesticide components in the sample to be tested;
[0152] The quantitative analysis module 103 is used to input the Raman spectrum data into a pre-trained quantitative analysis model and output the content ratio of the pesticide component in the sample to be tested;
[0153] Among them, the qualitative analysis model realizes the joint analysis of global and local spectral features based on the deep learning network of multimodal fusion; the quantitative analysis model realizes spectral decomposition and concentration regression based on the deep learning architecture of multi-scale feature fusion.
[0154] In application, each module in the pesticide residue detection device based on Raman spectroscopy and deep learning can be a software program module, or can be implemented through different logic circuits integrated in the processor, or can be implemented through multiple distributed processors.
[0155] like Figure 12 As shown, the embodiment of the present application further provides an electronic device 200, including: at least one processor 201 ( Figure 12 Only one processor is shown in the figure), a memory 202, and a computer program 203 stored in the memory 202 and executable on at least one processor 201. When the processor 201 executes the computer program 203, the steps in the above-mentioned various method embodiments are implemented.
[0156] In applications, electronic devices may include, but are not limited to, processors and memories. Those skilled in the art will appreciate that Figure 12 The electronic device is merely an example and does not limit the electronic device. The electronic device may include more or fewer components than shown in the figure, or may include a combination of certain components or different components.
[0157] In applications, the processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0158] In applications, in some embodiments, the memory can be an internal storage unit of an electronic device, such as a hard disk or memory of the electronic device. In other embodiments, the memory can also be an external storage device of the electronic device, such as a plug-in hard disk equipped on the electronic device, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card, etc. Furthermore, the memory can also include both an internal storage unit of the electronic device and an external storage device. The memory is used to store an operating system, application programs, a boot loader (BootLoader), data, and other programs, such as the program code of a computer program. The memory can also be used to temporarily store data that has been output or is about to be output.
[0159] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of this application. Their specific functions and technical effects can be found in the method embodiment section and will not be repeated here.
[0160] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned functions can be distributed and completed by 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 embodiment can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0161] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.
[0162] An embodiment of the present application provides a computer program product, including a computer program. When the computer program product runs on an electronic device, the electronic device can implement the steps in the above-mentioned various method embodiments when executing the computer program product.
[0163] If the integrated unit is implemented in the form of 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, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and when the computer program is executed by the processor, it can implement the steps of the above-mentioned various method embodiments. Among them, the computer program includes computer program code, which can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to the device / electronic device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electric carrier signal, a telecommunication signal and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, a computer-readable medium cannot be an electric carrier signal or a telecommunication signal.
[0164] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant description of other embodiments.
[0165] Those skilled in the art will appreciate that the units and algorithm steps of each example 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 performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel 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 devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of modules or units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0167] Units described as separate components may or may not be physically separate, and 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 these units may 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 the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present application, and should all be included in the scope of protection of the present application.
Claims
1. A method for detecting pesticide residues based on Raman spectroscopy and deep learning, characterized in that: include: Obtaining Raman spectrum data of the sample to be tested; Inputting the Raman spectral data into a pre-trained qualitative analysis model to output the category probability of the pesticide components in the sample to be tested; Inputting the Raman spectral data into a pre-trained quantitative analysis model to output the content ratio of the pesticide component in the sample to be tested; Among them, the qualitative analysis model realizes the joint analysis of global and local spectral features based on the deep learning network of multimodal fusion; the quantitative analysis model realizes spectral decomposition and concentration regression based on the deep learning architecture of multi-scale feature fusion.
2. The pesticide residue detection method based on Raman spectroscopy and deep learning according to claim 1, characterized in that: The obtaining of Raman spectrum data of the sample to be tested comprises: Obtain spectral data of acetamiprid, carbendazim, and myclobutanil as single substances and mixtures; The mixture includes a binary mixture and a ternary mixture, and the binary mixture and the ternary mixture include multiple mixing ratios.
3. The pesticide residue detection method based on Raman spectroscopy and deep learning according to claim 1, characterized in that: Before inputting the Raman spectral data into the pre-trained qualitative analysis model, the method further includes: Eliminate abnormal data in the same category of spectra; Enumerate the combination schemes of baseline correction, scatter correction, smoothing denoising and scale normalization, and select the combination scheme with the highest classification accuracy as the preprocessing scheme; The remaining data after the elimination is preprocessed using the preprocessing scheme.
4. The pesticide residue detection method based on Raman spectroscopy and deep learning according to claim 1, characterized in that: Before inputting the pre-processed data into the pre-trained qualitative analysis model, the method further includes: At least one operation of Gaussian noise, random baseline drift, and random scaling is performed on the Raman spectrum data to obtain enhanced data with an increased data volume.
5. The pesticide residue detection method based on Raman spectroscopy and deep learning according to claim 1, characterized in that: The qualitative analysis model includes: The convolution pre-processing layer is used to perform preliminary feature extraction on the input Raman spectrum 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 pre-processing layer, extracting local features of the spectrum based on a convolutional module with residual connections; A global feature extractor, connected to the second output branch of the convolutional pre-processing layer, extracts global temporal features of the spectrum based on a recurrent neural network; A feature fusion network is used to fuse the local features with the global temporal features and output the category probability of the pesticide components in the sample to be tested.
6. The pesticide residue detection method based on Raman spectroscopy and deep learning according to claim 1, characterized in that: The method of inputting the Raman spectral data into a pre-trained quantitative analysis model and outputting the content ratio of the pesticide component in the sample to be tested includes: Performing frequency domain feature extraction on the Raman spectrum data to obtain multi-level frequency domain detail features; Extracting time-frequency features from the Raman spectral data to obtain time-frequency global correlation features; Fusing the multi-level frequency domain detail features with the time-frequency global correlation features to obtain fused features; Multi-scale prediction is performed based on the fusion features to obtain the content ratio of the pesticide components in the sample to be tested and output it.
7. The method for detecting pesticide residues based on Raman spectroscopy and deep learning according to claim 6, wherein: The frequency domain feature extraction of the Raman spectrum data to obtain multi-level frequency domain detail features includes: Performing a three-level discrete wavelet transform on the Raman spectrum data to generate a multi-level decomposition signal; resampling the multi-level decomposition signals and splicing the spectrum decomposition matrix; The spectral decomposition matrix is input into a discrete wavelet transform network to extract multi-level frequency domain detail features.
8. The method for detecting pesticide residues based on Raman spectroscopy and deep learning according to claim 6, wherein: The extracting time-frequency features from the Raman spectrum data to obtain time-frequency global correlation features includes: Performing an eight-scale continuous wavelet transform on the Raman spectrum data 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.
9. The method for detecting pesticide residues based on Raman spectroscopy and deep learning according to claim 1, wherein: The fusing of the multi-level frequency domain detail features with the time-frequency global correlation features to obtain fused features includes: Performing multiple adaptive weight addition fusion on the intermediate layer outputs of the frequency domain detail features and the time-frequency correlation features; The output of the frequency domain detail feature is used as the query vector, the output of the time-frequency correlation feature is used as the key-value vector, and the fusion feature is calculated through the attention mechanism.
10. An electronic device, characterized in that: The electronic device comprises a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the electronic device implements the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Intelligent library building method for Raman spectrum data
CN113378680A
Substance detection method based on Raman spectrum and image algorithm
CN115389482A
Multi-channel drug fuzzy recognition method and system based on surface enhanced Raman spectroscopy
CN115774008A
Oral cancer multi-task diagnosis system based on Raman spectrum
CN119230089A
New psychoactive substance non-targeted recognition method, product, electronic equipment and device
CN119920304A
Cited By
Infrared spectroscopy-based soybean detection method and system
CN122545420A
Soybean detection method and system based on infrared spectrum
CN122545420B