Near infrared spectrum quantitative analysis method and equipment based on multi-scale wavelength attention and storage medium

By constructing the multi-scale wavelength attention network MSWANet, the problems of spectral information redundancy and poor model interpretability in near-infrared spectroscopy analysis are solved, achieving high-precision and interpretable end-to-end analysis and improving the model's predictive performance.

CN121565283APending Publication Date: 2026-02-24SHAANXI UNIV OF SCI & TECH
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202511637078.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-10
Publication Date
2026-02-24

AI Technical Summary

Technical Problem

Existing near-infrared spectroscopy analysis suffers from problems such as redundant spectral information, difficulty in extracting key features, and weak model interpretability. There is a lack of end-to-end analysis methods that can perform wavelength adaptive weighting and quantitative prediction within a unified framework.

Method used

A multi-scale wavelength attention network (MSWANet) is constructed, including global and local attention branches. Global attention captures long-range dependencies, while local attention extracts local features and multiplies their weights. The MLP is then used for quantitative prediction, and composite loss and L1 regularization are introduced to optimize the model.

Benefits of technology

It achieves high prediction accuracy and strong model interpretability. By adaptively filtering key wavelength information, it improves the prediction accuracy and generalization ability of the model and can intuitively reveal the chemical significance of key bands.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121565283A_ABST
    Figure CN121565283A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of near infrared spectrum analysis and chemometrics, in particular to a near infrared spectrum quantitative analysis method and device based on multi-scale wavelength attention and a storage medium. Global features and local features of spectrum data are matched by constructing a parallel double-branch multi-scale wavelength attention mechanism; the global branch adopts a full-connection network to capture a long-range dependency relationship between any two wavelengths, the local branch adopts a one-dimensional convolutional network and is specially used for extracting local correlation characteristics with sequence characteristics in the spectral data, and then the weights of the two branches are multiplied and fused to obtain the spectral data. A feature screening mechanism which is harsh than simple addition is constructed, and a key wave band which simultaneously meets global importance and local structural property can be more accurately positioned.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of near-infrared spectroscopy analysis and chemometrics, specifically to a near-infrared spectroscopy quantitative analysis method, device, and storage medium based on multi-scale wavelength attention. Background Technology

[0002] Near-infrared spectroscopy (NIRS) analysis technology has been widely used in pharmaceutical, food, and chemical industries due to its rapid and non-destructive characteristics. However, NIRS data typically contains hundreds to thousands of wavelengths, resulting in significant problems such as information redundancy, multicollinearity, and signal overlap. These issues pose a significant challenge to building robust and accurate quantitative calibration models. Therefore, effectively handling high-dimensional redundant information and extracting key features during the modeling process to improve model accuracy and robustness has become a key technical challenge in this field.

[0003] Traditional quantitative modeling methods, such as partial least squares regression (PLSR), are widely used, but their linear assumptions have limited ability to handle complex nonlinear relationships, and they usually need to be combined with independent feature selection algorithms (such as uninformation variable elimination (UVE) and continuous projection algorithm (SPA)) to optimize performance. This kind of "separate" process, where feature selection and modeling steps are independent of each other, may make it difficult to reach the global optimum due to inconsistent optimization objectives.

[0004] In recent years, while end-to-end deep learning models such as one-dimensional convolutional neural networks (1D-CNN) have shown potential in spectral analysis, capable of automatically learning features and improving modeling accuracy to some extent, standard 1D-CNNs often treat all wavelengths equally when processing input, lacking the ability to focus on key spectral regions. This makes them like a "black box," resulting in poor model interpretability. Although some studies have introduced wavelength attention mechanisms, most of them apply the attention module to the abstract feature map extracted by the convolutional layer, rather than directly to the original wavelength. This still has limited effect on improving model interpretability.

[0005] CN120579118A discloses a quantitative analysis method for near-infrared spectroscopy based on feature coupling and an adaptive multi-scale residual network. Step 1 involves explicitly calculating the eigenvalues ​​of different wavelengths in a one-dimensional spectrum using four feature coupling methods, expanding the original n spectral features into n*n new features to specifically mine the information hidden in the spectral data. Step 2 involves extracting the first k effective principal components from the data using principal component analysis (PCA) to remove noise and redundant information, providing the model with more refined and information-rich features. Step 3 involves constructing an adaptive multi-scale residual network (AMRNet). To achieve local multi-scale feature extraction, three multi-scale residual blocks are introduced and stacked in AMRNet. (a) Dual-scale convolutional kernels are used to extract features at two scales in parallel, enhancing the ability to represent details; (b) Convolution-based residual connections are used to further improve the nonlinearity of the network and alleviate the gradient vanishing problem; (c) Features extracted in parallel are fused through addition. In step 4, the AMRNet model constructed in step 3 is optimized and trained using a five-fold cross-validation strategy, and regression prediction is performed on the samples of the test set. In step 5, model evaluation metrics including RMSEP, R2, and RPD are established, and the results of applying different feature coupling methods to different datasets are compared. This method first captures the correlation between different wavelength spectra through the feature coupling layer, fuses rich information from different bands to expand effective features, and then constructs a backbone network by stacking multi-scale residual blocks and embeds a feature regulator module to adaptively mine deeply abstract multi-scale features.

[0006] Therefore, there is a lack of an end-to-end analysis method in the existing technology that can integrate adaptive weighting and quantitative prediction of wavelength under a unified framework, and can directly learn the contribution of each wavelength point on the original spectral dimension, thereby achieving both high prediction accuracy and strong model interpretability. Summary of the Invention

[0007] To address the problems of redundant spectral information, difficulty in extracting key features, and poor model interpretability in existing near-infrared spectroscopy analysis techniques, this invention provides a near-infrared spectroscopy quantitative analysis method, device, and storage medium based on multi-scale wavelength attention. This is an end-to-end quantitative analysis method that can automatically and adaptively filter key wavelength information and integrate wavelength selection with quantitative modeling, thereby improving the model's prediction accuracy, generalization ability, and interpretability.

[0008] This invention is achieved through the following technical solution: A near-infrared spectroscopy quantitative analysis method based on multi-scale wavelength attention includes: Near-infrared spectra of the samples were acquired in diffuse reflectance mode; The collected near-infrared spectra are preprocessed to obtain the original one-dimensional spectrum x; A multi-scale wavelength attention network (MSWANet) is constructed, which includes parallel global attention branches and local attention branches. Using the original spectrum x as input, the global attention weight sglobal is obtained by utilizing the global attention branch; Using the original spectrum x as input, the local attention weights slocal are obtained using the local attention branch; The global attention weight sglobal and the local attention weight slocal are multiplied element-wise to generate the composite attention weight s; The composite attention weights s are multiplied element-wise with the original spectrum x to obtain the weighted spectrum x_attended; The weighted spectrum x_attended is input into the MLP multilayer perceptron and combined with a composite loss for quantitative prediction to obtain the predicted value of the target component content.

[0009] Preferably, the acquired near-infrared spectra are preprocessed, including: The acquired near-infrared spectra were sequentially smoothed and normalized using Savitzky-Golay.

[0010] Preferably, the global attention branch has a bottleneck structure, consisting of two fully connected layers.

[0011] Preferably, using the original spectrum x as input, the global attention weight sglobal is obtained using a global attention branch, including: The original spectrum x is first processed by the first fully connected layer for dimensionality reduction, and then restored to the original dimension by the second fully connected layer to obtain the intermediate output; The intermediate output is added to the original input through a residual connection to obtain the global attention logic value; The global attention logical value is generated by the Sigmoid activation function, which produces global attention weights sglobal in the range [0, 1].

[0012] Preferably, the local attention branch includes at least one one-dimensional convolutional layer, which is cascaded with batch normalization and ReLU activation function introduced between the convolutional layers.

[0013] Preferably, taking a one-dimensional spectrum as input, the local attention weights (slocal) are obtained using a local attention branch, including: The original spectrum x passes through all the convolutional layers in sequence, and the output of the last layer is normalized by the sigmoid activation function to obtain the local attention weights slocal.

[0014] Preferably, the MLP (Multilayer Perceptron) consists of two fully connected hidden layers containing ReLU activation functions and a linear output layer, with a Dropout strategy introduced between the hidden layers.

[0015] Preferably, the composite loss consists of a mean squared error loss term and an L1 regularization term for the attention weights s.

[0016] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the method.

[0017] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the method described herein.

[0018] Compared with the prior art, the present invention has the following beneficial effects: This invention presents a near-infrared spectroscopy quantitative analysis method based on multi-scale wavelength attention. This method constructs a parallel dual-branch multi-scale wavelength attention mechanism to match the global and local features of spectral data. This is because, when using near-infrared spectroscopy for detection, certain chemical information may be reflected by multiple regions distributed across the entire spectrum, while a meaningful absorption peak is composed of a series of continuous wavelength points. The global branch uses a fully connected network to capture the long-range dependence between any two wavelengths, while the local branch uses a one-dimensional convolutional network specifically designed to extract local correlation features with sequential characteristics from the spectral data. Then, by multiplying and fusing the weights of the two branches, a more stringent feature selection mechanism than simple addition is constructed, enabling more precise localization of key bands that simultaneously satisfy global importance and local structure.

[0019] This invention introduces a multi-scale wavelength attention mechanism that directly acts on the original spectrum into the model, and combines it with L1 regularization, enabling the model to autonomously learn sparse attention weights. This allows for a more intuitive revelation of the key bands that contribute the most to the prediction, and the identified bands are highly consistent with the verification results of the independent SHAP method and have clear chemical significance, thereby improving the interpretability of the deep learning model.

[0020] Compared to traditional partial least squares regression (PLSR) and standard one-dimensional convolutional neural networks (1D-CNN), this invention jointly optimizes wavelength weighting (selection) and quantitative prediction within a unified deep learning framework. This avoids the inconsistency issues that may arise from separating feature selection and modeling steps in traditional methods, enabling end-to-end analysis from raw spectra to prediction results. Higher prediction set determination coefficients (R²p) and lower root mean square error of prediction (RMSEP) have been achieved in quantitative analysis tasks of multiple target components. Taking the quantitative analysis of baicalin in Antai Wan (a traditional Chinese medicine formula) as an example, the R²p of this invention's method... 2 The p-values ​​and RMSEP were 0.9818 and 0.3319, respectively, which were significantly better than PLSR (0.9684, 0.4376) and 1D-CNN (0.9580, 0.5052). Attached Figure Description

[0021] Figure 1 This is a schematic diagram of the network structure of the MSWANet model proposed in this invention.

[0022] Figure 2 These are the spectra of the Antai Pill sample, where (a) is the original spectrum, (b) is the spectrum after SG smoothing, and (c) is the spectrum after further normalization.

[0023] Figure 3 This is a scatter plot of the prediction set results of the MSWANet model of this invention for baicalin (component 1).

[0024] Figure 4 This is a scatter plot of the prediction results of the 1D-CNN model for baicalin (component 1).

[0025] Figure 5 This is a scatter plot of the PLSR model's prediction set results for baicalin (component 1).

[0026] Figure 6 This is the attention weight distribution diagram learned by the model of this invention for quantitative analysis of ferulic acid.

[0027] Figure 7 This is a distribution map of the average absolute contribution of each wavelength to the prediction of ferulic acid content, calculated using the SHAP method, used to cross-validate the reliability of the attention mechanism. Detailed Implementation

[0028] The following specific embodiments illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification.

[0029] Exemplary embodiments of the present invention will now be described with reference to the accompanying drawings. However, the present invention may be embodied in many different forms and is not limited to the embodiments described herein. These embodiments are provided to fully and completely disclose the invention and to fully convey its scope to those skilled in the art. The terminology used in the exemplary embodiments illustrated in the drawings is not intended to limit the invention. In the drawings, the same units / elements are referred to by the same reference numerals.

[0030] Unless otherwise stated, the terms used herein (including technical terms) have their common meaning as understood by one of ordinary skill in the art. Furthermore, it is understood that terms defined in commonly used dictionaries should be understood to have a meaning consistent with the context of their relevant field, and not to be interpreted as having an idealized or overly formal meaning.

[0031] The present invention will be further described in detail below with reference to specific embodiments. These descriptions are for explanation purposes only and are not intended to limit the scope of the invention.

[0032] This invention discloses a near-infrared spectroscopy quantitative analysis method based on multi-scale wavelength attention, comprising: Acquisition: Near-infrared spectra of the samples were acquired using a near-infrared spectrometer (such as the SupNIR1500) in diffuse reflectance mode; the spectral scanning range could be set to 1000–1800 nm with a resolution of 1 nm.

[0033] Preprocessing: The acquired near-infrared spectra are preprocessed to obtain a one-dimensional raw spectrum x. Specifically, the acquired near-infrared spectra are preprocessed by Savitzky-Golay (SG) smoothing and normalization. SG smoothing is used to reduce noise and preserve peak shape. Normalization eliminates dimensional differences and baseline drift by mean centering and variance scaling.

[0034] Feature weight extraction: Constructing a multi-scale wavelength attention network MSWANet (e.g.) Figure 1 The multi-scale wavelength attention network MSWANet includes parallel global attention branches and local attention branches. The global attention branch has a bottleneck structure and includes two fully connected layers to capture long-range dependencies between wavelengths. The local attention branch includes at least one one-dimensional convolutional layer, which is cascaded and batch normalization and ReLU activation functions are introduced between the convolutional layers.

[0035] Using the original spectrum x as input, the global attention weight sglobal is obtained using the global attention branch. Specifically: The original spectrum x is first reduced in dimension by the first fully connected layer, and then restored to the original dimension by the second fully connected layer to obtain the intermediate output; for example, the original spectrum x with dimension 800 is first reduced to 160 by a fully connected layer, and then restored to 800 dimensions by another fully connected layer.

[0036] The intermediate output is added to the original input through a residual connection to obtain the global attention logic value; The global attention logical value is generated by the Sigmoid activation function, which produces global attention weights sglobal in the range [0, 1].

[0037] Using the original spectrum x as input, a local attention branch is used to obtain the local attention weights slocal. Specifically, the original spectrum x passes through all convolutional layers sequentially, and the output of the last layer is normalized using a sigmoid activation function to obtain the local attention weights slocal. For example, to extract local features at different scales, cascaded convolutional layers can be used, such as first passing through a convolutional layer with a kernel size of 7, and then passing through a convolutional layer with a kernel size of 5. Batch normalization (BN) and ReLU activation functions can be added between the convolutional layers. The final output is normalized using a sigmoid activation function to obtain the local attention weights slocal. This branch focuses on extracting local structural features between adjacent bands. Attention weight fusion: The global attention weight sglobal and the local attention weight slocal are multiplied element-wise to generate a composite attention weight s. This operation is equivalent to an AND logic gate, where only wavelengths considered important at both the global and local scales are assigned high weights.

[0038] Spectral weighting: The composite attention weights s are multiplied element-wise with the original spectrum x to obtain the weighted spectrum x_attended. This weighting process can enhance the contribution of key spectral features while reducing the interference of irrelevant or noisy information.

[0039] The weighted spectrum x_attended is input into an MLP (Multilayer Perceptron) and quantitative prediction is performed using a composite loss. The MLP consists of two fully connected hidden layers with ReLU activation functions and a linear output layer, with a Dropout policy introduced between the hidden layers.

[0040] The composite loss consists of a mean squared error (MSE) loss term and an L1 regularization term for the attention weights *s*. The MSE term ensures prediction accuracy, while the L1 regularization term encourages the model to learn sparse attention weights, thereby enabling embedded wavelength selection and improving the model's generalization ability. Training is performed using the AdamW optimizer. Introducing an L1 penalty for the attention weights into the loss function guides the model to learn sparse weights from the optimization objective. This is not only an effective regularization method but also fundamentally endows the model with the ability to perform automatic wavelength selection, giving its results good physical interpretability.

[0041] Taking Antai Pill as an example, the MSWANet model in this invention and other models (1DCNN model, PLSR model) were used to perform quantitative analysis of three different chemical components in Antai Pill. Figure 2 The effects of spectral preprocessing are demonstrated: Figure 2 (a) shows the original spectra of 107 samples of Ante-Tai Pills, with obvious baseline drift and noise. Figure 2(b) is the spectrum after Savitzky–Golay (SG) smoothing, where high-frequency noise is suppressed; Figure 2 (c) The spectrum after further standardization based on SG smoothing. The data is mean centered and variance scaled to effectively eliminate dimensional differences and inconsistencies in baseline levels.

[0042] Quantitative analysis of three different chemical components in Antai Pill using the MSWANet model: Raw materials: 21 batches of Antai Pills, totaling 107 samples.

[0043] Spectral acquisition parameters: A SupNIR1500 spectrometer was used, with a scanning range of 1000–1800 nm and a resolution of 1 nm. The average of 32 scans was taken.

[0044] Model network structure parameters: Input layer: Spectral data of dimension (None, 800).

[0045] Global branch: The number of neurons in the fully connected layer is 160 and 800 respectively, and the activation function is ReLU.

[0046] Local branches: The first convolutional layer has 16 kernels and a size of 7; the second convolutional layer has 1 kernel and a size of 5. Both are padded with 'same'.

[0047] The regression head (MLP) has 200 and 100 neurons in the two hidden layers, respectively, with a dropout rate of 0.5 and a ReLU activation function. The output layer has 1 neuron and a linear activation function.

[0048] Model training parameters: Optimizer: AdamW Learning rate: 0.0005 ~ 0.005, preferably 0.001.

[0049] Weight decay: 0.001 ~ 0.05, preferably 0.01.

[0050] Batch size: 8 ~ 32, preferably 16.

[0051] Number of iterations: 200 ~ 600, preferably 500.

[0052] The L1 regularization coefficient λL1: 0.0001 ~ 0.01, is an adjustable hyperparameter.

[0053] Experimental Results: This method was used to quantitatively analyze three components in Antai Pill: baicalin, scutellarin, and ferulic acid. The coefficient of determination (R²) of the prediction set was [not specified]. 2The p) values ​​were 0.9818, 0.9894, and 0.9817, respectively; the root mean square error of prediction (RMSEP) were 0.3319, 1.8279, and 0.0372, respectively.

[0054] The results of the model in this invention are compared with those of other models, as follows: In terms of performance comparison, as shown in Table 1, in the quantitative analysis of the three quality control index components (components 1, 2, and 3) in Antai Pill, the MSWANet model proposed in this invention, compared with the PLSR and 1D-CNN models, has a higher R-value. 2 MSWANet has the highest p-value and the lowest RMSEP. For example, in the prediction of component 2, MSWANet's RMSEP is 1.8279, which is much lower than PLSR's 3.5164 and 1D-CNN's 2.7435. Figure 3 , 4 The scatter plot of 5 also visually shows that MSWANet's predicted points are more closely clustered around the diagonal of y=x.

[0055] To verify the necessity of the multi-scale design, ablation experiments were conducted (as shown in Table 2). The results show that models containing only local branches or only global branches perform worse than the complete MSWANet model combining both. This demonstrates that the synergistic effect of global and local branches is indispensable for achieving optimal prediction accuracy, thus verifying the rationality of the method design in this invention.

[0056] Table 1. Comparison of evaluation metrics for MSWANet model, 1DCNN model and PLSR model

[0057] Table 2 Ablation Experiment

[0058] like Figure 4 As shown, the attention weights learned by the model exhibit significant sparsity, with weight peaks concentrated in a few regions such as 1100-1150 nm and 1380-1420 nm. These regions are highly correlated with the overtone absorption regions of phenolic hydroxyl groups, carboxyl OH groups, and aromatic ring CH stretching vibrations in components such as ferulic acid, and have clear chemical significance. Meanwhile, as... Figure 5 As shown, the contribution distribution obtained from SHAP analysis is highly consistent with the attention weight distribution, cross-validating the reliability of the present invention in identifying key bands.

[0059] The present invention also discloses a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the method.

[0060] The present invention also discloses a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the method described herein.

[0061] The above description is merely a preferred embodiment of the present invention and is not intended to limit the technical solution of the present invention in any way. Those skilled in the art should understand that, without departing from the spirit and principles of the present invention, the technical solution can be modified and replaced in several simple ways, and these modifications and replacements are all within the scope of protection covered by the claims.

Claims

1. A near-infrared spectroscopy quantitative analysis method based on multi-scale wavelength attention, characterized in that, include: Near-infrared spectra of the samples were acquired in diffuse reflectance mode; The collected near-infrared spectra are preprocessed to obtain the original one-dimensional spectrum x; A multi-scale wavelength attention network (MSWANet) is constructed, which includes parallel global attention branches and local attention branches. Using the original spectrum x as input, the global attention weight sglobal is obtained by utilizing the global attention branch; Using the original spectrum x as input, the local attention weights slocal are obtained using the local attention branch; The global attention weight sglobal and the local attention weight slocal are multiplied element-wise to generate the composite attention weight s; The composite attention weights s are multiplied element-wise with the original spectrum x to obtain the weighted spectrum x_attended; The weighted spectrum x_attended is input into the MLP multilayer sensor and combined with a composite loss for quantitative prediction to obtain the predicted content of the target component.

2. The near-infrared spectroscopy quantitative analysis method based on multi-scale wavelength attention according to claim 1, characterized in that, The acquired near-infrared spectra were preprocessed, including: The acquired near-infrared spectra were sequentially processed using Savitzky-Golay smoothing and normalization.

3. The near-infrared spectroscopy quantitative analysis method based on multi-scale wavelength attention according to claim 2, characterized in that, The global attention branch has a bottleneck structure, consisting of two fully connected layers.

4. The near-infrared spectroscopy quantitative analysis method based on multi-scale wavelength attention according to claim 3, characterized in that, Using the original spectrum x as input, the global attention weights sglobal are obtained using the global attention branch, including: The original spectrum x is first processed by the first fully connected layer for dimensionality reduction, and then restored to the original dimension by the second fully connected layer to obtain the intermediate output; The intermediate output is added to the original input through a residual connection to obtain the global attention logic value; The global attention logical value is generated by the Sigmoid activation function, which produces global attention weights sglobal in the range [0, 1].

5. The near-infrared spectroscopy quantitative analysis method based on multi-scale wavelength attention according to claim 1, characterized in that, The local attention branch consists of at least two one-dimensional convolutional layers, which are cascaded and batch normalization and ReLU activation functions are introduced between them.

6. The near-infrared spectroscopy quantitative analysis method based on multi-scale wavelength attention according to claim 1, characterized in that, Using a one-dimensional spectrum as input, the local attention weights (slocal) are obtained through a local attention branch, including: The original spectrum x passes through all the convolutional layers in sequence, and the output of the last layer is normalized by the sigmoid activation function to obtain the local attention weights slocal.

7. The near-infrared spectroscopy quantitative analysis method based on multi-scale wavelength attention according to claim 1, characterized in that, The MLP (Multilayer Perceptron) consists of two fully connected hidden layers with ReLU activation functions and a linear output layer, with a Dropout policy introduced between the hidden layers.

8. The near-infrared spectroscopy quantitative analysis method based on multi-scale wavelength attention according to claim 1, characterized in that, The composite loss consists of a mean squared error loss term and an L1 regularization term for the attention weights s.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1 to 8.

10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 8.

Citation Information

Patent Citations

  • Near infrared spectrum quantitative analysis method based on feature coupling and adaptive multi-scale residual network

    CN120579118A