Near infrared spectrum background drift deduction method and system and storage medium

By automatically identifying and subtracting the background drift of near-infrared spectroscopy equipment using the 1D-ResNet18 network and Grad-CAM algorithm, the problem of decreased measurement accuracy caused by spectral background drift of the equipment is solved, and efficient and stable spectral data analysis is achieved.

CN120831337APending Publication Date: 2025-10-24CHINA TOBACCO ZHEJIANG IND CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511111525.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-08
Publication Date
2025-10-24

AI Technical Summary

Technical Problem

Existing near-infrared spectroscopy equipment is prone to spectral background drift after prolonged use, leading to decreased measurement accuracy and deviations in analysis results. Traditional calibration methods cannot meet the requirements for real-time processing.

Method used

A spectral recognition model based on the 1D-ResNet18 network is adopted, which combines the attention mechanism and the Grad-CAM algorithm to automatically learn background drift features, identify and subtract key sensitive wavelength points, and screen stable wavelength points through an adaptive threshold mechanism to build a deep learning model for spectral background drift subtraction.

Benefits of technology

It significantly improves the accuracy and stability of spectral data, reduces operation and maintenance costs, meets the rapid response requirements of industrial online real-time monitoring, and enhances the practicality and reliability of the equipment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120831337A_ABST
    Figure CN120831337A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of spectrum detection of near-infrared equipment, in particular to a near-infrared spectrum background drift deduction method and system and a storage medium, and the method comprises the steps: obtaining spectrum data of a white background plate of the near-infrared equipment; preprocessing the spectral data to serve as training data; constructing a spectrum recognition model; training the spectrum recognition model by adopting the training data; based on the trained spectrum identification model, obtaining model prediction values of background spectrums of different dates; according to the model prediction value, an algorithm is adopted to generate wavelength importance curves of the background spectrums of the different dates; according to the wavelength importance curve, wavelength points needing to be deducted are selected and deducted. According to the embodiment of the invention, by combining the 1D-ResNet18 network of the attention mechanism, a complex background drift mode can be effectively captured, key sensitive wavelength points causing drift are accurately positioned and deducted, and the classification accuracy is remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of spectral detection technology of near-infrared equipment, and in particular to a method and system for deducting near-infrared spectral background drift and a storage medium. BACKGROUND

[0002] Online near-infrared (NIR) equipment is widely used in industrial real-time monitoring and analysis due to its high efficiency and non-destructive characteristics. This type of equipment can quickly and accurately analyze the composition of materials or samples by acquiring their spectral data, and has been widely used in food, chemical, pharmaceutical, environmental monitoring and other industries. Near-infrared equipment analyzes the composition of samples by collecting the reflectance spectrum of the substance in the near-infrared band, and has the advantages of no need to contact the sample, fast analysis, low cost, etc., and is an important tool for realizing industrial automation control and quality assurance. When collecting spectra, NIR equipment usually uses a white background plate as a reference. The white background plate is usually made of inorganic materials and has high reflectivity and stable optical performance, which can effectively reflect near-infrared light and ensure that the equipment can measure under relatively consistent lighting conditions. In theory, after reasonable calibration, the NIR equipment should keep the white background plate spectrum consistent under the same environmental conditions at different time periods, so as to ensure that the spectral data collected by the equipment is accurate and reliable, and avoid deviations in the measurement results caused by equipment errors.

[0003] However, as the use time of the equipment increases, the performance of the equipment will degrade, resulting in a decrease in its stability and accuracy. Equipment aging, hardware wear and tear, changes in environmental factors (such as temperature and humidity, air pressure changes, etc.), and adjustments to detection conditions can all cause changes in the optical components of the equipment, thereby affecting the stability of the white background plate spectrum. Specifically, during the spectral acquisition process of the NIR equipment, due to factors such as changes in the state of the equipment, aging of the optical components, etc., differences may occur in the white background plate spectrum, resulting in a so-called "spectral background drift" phenomenon. This drift phenomenon not only affects the measurement accuracy of the equipment, but also can cause deviations in subsequent analysis results, especially in industrial production processes, which can lead to lax quality control and poor product consistency. Therefore, how to effectively deduct the background drift and restore the accuracy of the spectral data has become a technical problem that needs to be solved in the current online monitoring of NIR equipment. Traditional solutions mainly rely on periodic calibration of the equipment or environmental compensation techniques, such as calibration with standard substances or compensation of the output data of the equipment according to known environmental changes. Although these methods have solved the equipment error problem to some extent, they still have some limitations, especially in situations where the state of the equipment needs to be handled in real time, manual intervention and periodic calibration cannot meet the demand for rapid response.

[0004] In recent years, with the rapid development of machine learning and deep learning technology, data-driven background drift correction methods have gradually attracted attention. This kind of method can significantly improve the stability of the device and the accuracy of the data by establishing a background drift model, using advanced algorithms to monitor and correct the spectral background of the device in real time, and no longer relying on manual calibration. Because the spectral background drift usually has nonlinear characteristics, the traditional linear model is difficult to effectively capture its change rule, so in practical application, more efficient and nonlinear problem processing models are needed to solve this problem. SUMMARY

[0005] One of the purposes of the present application is to provide a near-infrared spectral background drift deduction method, system and storage medium to solve the technical problem of low accuracy, stability and reliability of the background drift model in the prior art.

[0006] To achieve the above purpose, the embodiments of the present application provide a near-infrared spectral background drift deduction method, comprising: Obtaining the spectral data of the white background plate of the near-infrared device; Pretreating the spectral data as training data; Constructing a spectral recognition model; Training the spectral recognition model using the training data; Based on the trained spectral recognition model, obtaining the model prediction value of the background spectrum of different dates; According to the model prediction value, generating the wavelength importance curve of the background spectrum of different dates using an algorithm; According to the wavelength importance curve, selecting the wavelength points to be deducted and performing deduction.

[0007] Optionally, constructing a spectral recognition model comprises: Constructing a spectral recognition model based on a 1D-ResNet18 network, including an input layer, a convolution layer, a batch normalization layer, a max pooling layer, a residual module, a global average pooling layer, and a full connection layer. The convolution layer, batch normalization layer, max pooling layer, residual module, global average pooling layer, and full connection layer are sequentially connected to the input layer. The residual module includes a first residual block, a second residual block, and a third residual block connected in sequence.

[0008] Optionally, the first residual block comprises a first convolutional layer, a first attention module, a first batch normalization layer, a first activation function, a second convolutional layer, a second attention module, a second batch normalization layer, a residual learning layer, and a second activation function, one end of the first convolutional layer is connected to the output end of the max-pooling layer, the first attention module, the first batch normalization layer, the first activation function, the second convolutional layer, the second attention module, and the second batch normalization layer are sequentially connected after the first convolutional layer, a first end of the residual learning layer is connected to the second batch normalization layer, a second end of the residual learning is connected to the output end of the max-pooling layer, one end of the second activation function is connected to a third end of the residual learning layer, and the other end of the second activation function serves as an output end of the first residual block.

[0009] Optionally, the third residual block comprises a first residual block and a shortcut connection residual block connected in sequence, wherein the shortcut connection residual block comprises a first convolutional layer, a first attention module, a first batch normalization layer, a first activation function, a second convolutional layer, a second attention module, a second batch normalization layer, a residual learning layer, a second activation function, and a shortcut connection, the first attention module, the first batch normalization layer, the first activation function, the second convolutional layer, the second attention module, and the second batch normalization layer are sequentially connected after the first convolutional layer, one end of the first convolutional layer is connected to the output end of the corresponding first residual block, one end of the shortcut connection is connected to the output end of the corresponding first residual block, a first end of the residual learning layer is connected to the second batch normalization layer, a second end of the residual learning is connected to the other end of the shortcut connection, one end of the second activation function is connected to a third end of the residual learning layer, and the other end of the second activation function serves as an output end of the third residual block.

[0010] Optionally, training the spectrum recognition model using the training data comprises: dividing the training data into a training set, a validation set, and a test set in proportion; performing a data augmentation operation on the training set; inputting the processed training set into the spectrum recognition model to obtain a prediction probability of each category; calculating a value of a loss function according to the prediction probability; updating the weights of the spectrum recognition model using an optimizer according to the value of the current loss function; calculating a validation accuracy based on the validation set; determining whether the validation accuracy has not been improved for N consecutive rounds; completing the training when it is determined that the validation accuracy has not been improved for N consecutive rounds; If it is determined that the verification accuracy rate has been improved for N consecutive rounds, the process returns to the step of inputting the processed training data into the spectrum recognition model to obtain the predicted probability of each category.

[0011] Optionally, calculating a value of a loss function according to the predicted probability includes: Calculate the loss function value according to formula (1): , (1) in, is the loss function value, is the standard cross entropy loss, is the penalty coefficient, Wavelength calculated for the model The weight of It is a set of background drift high-incidence wavelength points determined based on historical equipment operation and maintenance data.

[0012] Optionally, generating wavelength importance curves of the background spectra on different dates using an algorithm according to the model prediction value includes: Obtaining the gradient of the characteristic graph of the model prediction value versus the background spectra of the different date numbers; The importance weight of each channel is calculated according to formula (2), , (2) in, For the Feature map pairs The importance weight of is the wavelength point length of the characteristic graph, is the position of the wavelength point, Classification of spectral recognition models The prediction score of For the The feature map is located in the space The activation value at ; Generate activation map according to formula (3), , (3) in, is the activation map, For the feature maps; The activation map is normalized and superimposed with the spectral curve to generate a thermal map.

[0013] Optionally, selecting wavelength points to be deducted and performing the deduction according to the wavelength importance curve includes: Calculating the mean and standard deviation of all wavelength point weights according to the wavelength importance curve; set the dynamic threshold value according to formula (4), , (4) wherein, is the dynamic threshold value, is the mean of all wavelength point weights, is the standard deviation of all wavelength point weights, is an adjustable factor; filter out wavelength points to be deducted according to the dynamic threshold value; take the white background spectrum of the current date as the reference spectrum, deduct the wavelength points to be deducted, and reconstruct the spectrum of the remaining wavelength points; calculate the norm error of the reconstructed spectrum and the reference spectrum; determine whether the norm error is less than a preset error threshold; in the case where it is determined that the norm error is less than the preset error threshold, confirm that the deduction under the current value is effective; in the case where it is determined that the norm error is greater than or equal to the preset error threshold, adjust the value, and return to the step of setting the dynamic threshold value according to formula (4).

[0014] On the other hand, the present application also provides a near-infrared spectrum background drift deduction system, which comprises a processor configured to perform the method of any one of the above.

[0015] In another aspect, the present application also provides a computer readable storage medium having instructions stored thereon, which, when executed by a processor, implement the method of any one of the above.

[0016] Advantages of the present application: The embodiment of the present application is based on data-driven, and automatically learns the background drift features and identifies sensitive wavelengths by using a deep learning model, without relying on frequent manual calibration or complex environmental parameter measurement compensation. Compared with the traditional technical solution, the operation and maintenance cost is significantly reduced.

[0017] The embodiment of the present application has strong non-linear modeling capability through a deep neural network (especially a 1D-ResNet18 combined with an attention mechanism), which can effectively capture complex background drift patterns. Combined with Grad-CAM and an adaptive threshold mechanism, the key sensitive wavelength points causing drift can be accurately located and deducted, and the classification accuracy is significantly improved.

[0018] The embodiment of the present application inhibits the dependence of the model on the high-occurrence wavelength of historical drift by designing a loss function, and finally only uses stable wavelength points that are not sensitive to drift for modeling, so that the adaptive ability of the analysis model to device state changes and environmental fluctuations is effectively improved, and the long-term reliability and consistency of online monitoring results are ensured.

[0019] The embodiment of the present application has good real-time performance, once the drift feature model is trained and the sensitive wavelength points are determined, the drift deduction operation of subsequent spectral data has high calculation efficiency, and can meet the rapid response demand of industrial online real-time monitoring. The key problem (background drift) restricting the long-term stable operation of the online NIR device is effectively solved, the practicability and reliability of the device are significantly improved, more accurate and stable analysis means are provided for real-time quality control and process monitoring in the food, chemical, pharmaceutical and other industries, and the in-depth application of near-infrared spectroscopy technology in industrial automation is effectively promoted.

[0020] Other features and advantages of the present application will be described in detail in the following specific embodiments. BRIEF DESCRIPTION OF DRAWINGS

[0021] The accompanying drawings are included to provide a further understanding of the embodiments of the present application, and constitute a part of the specification, and are used together with the following specific embodiments to explain the embodiments of the present application, but do not constitute a limitation on the embodiments of the present application. In the drawings: Figure 1 Flowchart of the near-infrared spectral background drift deduction method according to an embodiment of the present application; Figure 2 Framework diagram of the spectral recognition model according to an embodiment of the present application; Figure 3 Framework diagram of the first residual block according to an embodiment of the present application; Figure 4 Framework diagram of the shortcut connection residual block according to an embodiment of the present application; Figure 5 Flowchart of the spectral recognition model training method according to an embodiment of the present application; Figure 6 Flowchart of the wavelength importance curve generation method according to an embodiment of the present application; Figure 7 Flowchart of the wavelength point selection and deduction according to an embodiment of the present application; Figure 8 Online spectrum of a white background plate of a certain near-infrared device on different dates according to an embodiment of the present application; Figure 9Spectra of white background plate on-line denoising according to an embodiment of the present application on different dates of a certain near-infrared device Figure 10 Confidence ellipse of dimension reduction of on-line spectra of white background plate according to an embodiment of the present application on different dates of a certain near-infrared device Figure 11 Schematic diagram of wavelength importance curve according to an embodiment of the present application Figure 12 Schematic diagram of the whole process of spectrum identification model and wavelength importance curve according to an embodiment of the present application DETAILED DESCRIPTION

[0022] The specific embodiments of the embodiments of the present application will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are only used to illustrate and explain the embodiments of the present application, and are not used to limit the embodiments of the present application.

[0023] It should be noted that the acquisition, transmission, storage, use, processing and the like of data in the technical solutions of the present application comply with the relevant provisions of national laws and regulations. In the embodiments of the present application, some existing industry solutions such as software, components, models and the like may be mentioned, which should be considered as exemplary, and the purpose is only to illustrate the feasibility of the implementation of the technical solutions of the present application, but it does not mean that the applicant has or will necessarily use the solution.

[0024] As shown in FIG. 1, it is a flowchart of a background drift deduction method of near-infrared spectrum according to an embodiment of the present application. In the embodiment, the background drift deduction method can include the following steps: Figure 1 Figure 1 In the embodiment, the background drift deduction method can include the following steps: In step S10, the spectral data of the white background plate of the near-infrared device is acquired; In step S11, the spectral data is preprocessed as training data; In step S12, a spectral identification model is constructed; In step S13, the spectral identification model is trained using the training data; In step S14, based on the trained spectral identification model, the model prediction values of the background spectra on different dates are obtained; In step S15, according to the model prediction values, the wavelength importance curve of the background spectra on different dates is generated using an algorithm; In step S16, according to the wavelength importance curve, the wavelength points to be deducted are selected and deducted.

[0025] In the embodiment, the background drift deduction method can include the following steps: Figure 1 ​In the shown method for removing the background drift of near-infrared spectrum, step S10 is used to obtain the spectral data of the white background plate of the near-infrared device. In this embodiment, the online spectral data of the white background plate of the near-infrared device on multiple different dates within the same time period can be obtained. Since the background spectral drift mainly occurs between different dates, the spectral change within a day is relatively small, and therefore it can be assumed that the background spectral change within the same day is not large.

[0026] Step S11 is used to pre-process the spectral data as training data. In this example, the methods for pre-processing the spectral data include but are not limited to denoising, standardization, removal of outliers, etc., to ensure the quality and consistency of the data.

[0027] Step S12 is used to construct a spectral recognition model. In this embodiment, the specific method for constructing the spectral recognition model in this step S12 can be various forms known to those skilled in the art, and in one example of the present application, the spectral recognition model in this step S12 can be based on a 1D-ResNet18 network. Specifically, the framework diagram of the model can be as shown in Figure 2 In this Figure 2 , the spectral recognition model can include an input layer, a convolutional layer, a batch normalization layer, a max-pooling layer, a residual module, a global average pooling layer, a fully connected layer, the convolutional layer, the batch normalization layer, the max-pooling layer, the residual module, the global average pooling layer, and the fully connected layer being sequentially connected after the input layer, and the residual module including a first residual block, a second residual block, and three third residual blocks connected in sequence.

[0028] Further, the present embodiment improves the 1D-ResNet18 network structure by embedding a one-dimensional channel and spatial attention module (1D-CBAM) in the residual block. Specifically, the framework diagram of the first residual block can be as shown in Figure 3 The first residual block includes a first convolutional layer, a first attention module, a first batch normalization layer, a first activation function, a second convolutional layer, a second attention module, a second batch normalization layer, a residual learning layer, and a second activation function, one end of the first convolutional layer is connected to the output end of the max-pooling layer, the first attention module, the first batch normalization layer, the first activation function, the second convolutional layer, the second attention module, and the second batch normalization layer are sequentially connected after the first convolutional layer, the first end of the residual learning layer is connected to the second batch normalization layer, the second end of the residual learning is connected to the output end of the max-pooling layer, one end of the second activation function is connected to the third end of the residual learning layer, and the other end of the second activation function serves as the output end of the first residual block. In this example, the architecture of the second residual block can be the same as that of the first residual block.

[0029] Furthermore, in this example, the third residual block includes a shortcut connection residual block and a first residual block connected in sequence, wherein the frame diagram of the shortcut connection residual block can be as follows: Figure 4 As shown, the shortcut connection residual block includes a first convolutional layer, a first attention module, a first batch normalization layer, a first activation function, a second convolutional layer, a second attention module, a second batch normalization layer, a residual learning layer, a second activation function and a shortcut connection. After the first attention module, the first batch normalization layer, the first activation function, the second convolutional layer, the second attention module, and the second batch normalization layer are sequentially connected in series to the first convolutional layer, one end of the first convolutional layer is connected to the output end of the corresponding first residual block, one end of the shortcut connection is connected to the output end of the corresponding first residual block, the first end of the residual learning layer is connected to the second batch normalization layer, the second end of the residual learning is connected to the other end of the shortcut connection, one end of the second activation function is connected to the third end of the residual learning layer, and the other end of the second activation function serves as the output end of the third residual block.

[0030] Furthermore, both the first attention module and the second attention module include a channel attention branch and a spatial attention branch. The channel attention branch performs global average pooling and maximum pooling on the feature channels, and combines the fully connected layer to learn the channel weights to achieve the reinforcement of the stable feature channels. Specifically, in this example, it can be the input feature map (Dimension , is the number of channels, is the number of spectral wavelength points) for channel-dimensional global average pooling and global max pooling The two pooling results are then fed into the multi-layer perceptron with shared parameters ( , containing one hidden layer), the outputs are added and then activated by the Sigmoid function ( ) Generate channel attention weight vector (Dimension ), which is used to strengthen the feature channels that are more important for background drift modeling. Specifically, in this example, the channel attention weight vector can be calculated according to formula (5): , (5) in, is the one-dimensional spectral feature map of the input residual block (dimension is [ ,L], where is the number of channels, L is the length of the spectral wavelength point), It is a multi-layer perceptron (a fully connected network with one hidden layer) used to perform feature conversion on the pooling results and map the channel features into weight vectors. To perform global maximum pooling of the channel dimension on the feature map F, the maximum value of each channel is calculated, and the output dimension is [ ,1], Sigmoid activation function normalizes the output value to the range of [0,1] and generates channel attention weight; is the output channel attention weight vector (dimension is [ ,1]), which is used to weight the channels of the original feature map (the higher the weight, the more importance the features of the corresponding channel receive).

[0031] In this example, the spatial attention branch can be used to weight the feature map after channel attention. ( represents element-by-element multiplication) to perform average pooling in the channel dimension and max pooling , get two feature maps of dimension [1, L]. Then concatenate them along the channel dimension , dimension ([2, L]), and then a 1×3 one-dimensional convolution layer Extract spatial features and finally generate spatial attention weight vector through Sigmoid activation function (dimension is [C, L]), which is used to focus on the wavelength position that is more sensitive or more stable to background drift. Specifically, in this example, the spatial attention weight vector can be calculated according to formula (6): , (6) in, is the feature map after channel attention weighting (dimension is [C, L], i.e. , is element-wise multiplication); For Perform average pooling in the channel dimension (taking the average along the channel direction), and the output dimension is [1, L]; For Perform maximum pooling along the channel dimension (take the maximum value along the channel direction), and the output dimension is [1, L]; For the feature splicing operation, the average pooling and maximum pooling results are spliced ​​in the channel dimension, and the output dimension is [2, L]; It is a 1×3 one-dimensional convolution operation (padding 1 to keep the wavelength length L unchanged) used to extract the spatial correlation of the wavelength dimension; is a Sigmoid activation function that outputs normalized spatial attention weights (dimension is [1, L]); is the output spatial attention weight vector, which is used to weight the wavelength position of the feature map (the higher the weight, the more attention the feature of the corresponding wavelength point receives).

[0032] Finally, the spatial attention weight is used to perform secondary weighting on to obtain the final enhanced feature map . The feature map highlights the channel and wavelength information that is key to distinguishing different date background spectra (i.e., background drift features). Specifically, in this example, the final enhanced feature map can be obtained according to formula (7): , (7) wherein, is the feature map output by the module (dimension [C, L]); k represents the number of channels; is an element-wise multiplication (first strengthen stable channels through channel weights, and then strengthen stable wavelength points through spatial weights); the output feature map has eliminated invalid interference information and only retains stable features that are key to the classification task, and the batch normalization layer and the activation function of the subsequent input residual block.

[0033] Step S13 is configured to train the spectrum recognition model using the training data. In this embodiment, the specific method of training the spectrum recognition model in this step S13 can be various forms known to those skilled in the art. In one example of the present application, this step S13 can include the steps shown in Figure 5 . In this Figure 5 , the step S13 can include: In step S20, the training data is proportionally divided into a training set, a validation set, and a test set; In step S21, data augmentation is performed on the training set; In step S22, the processed training set is input into the spectrum recognition model to obtain the prediction probability of each category; In step S23, the value of the loss function is calculated according to the prediction probability; In step S24, the weights of the spectrum recognition model are updated using the optimizer according to the value of the current loss function; In step S25, the validation accuracy is calculated based on the validation set; In step S26, it is determined whether the validation accuracy has not improved for N consecutive rounds; In step S27, if it is determined that the validation accuracy has not improved for N consecutive rounds, the training is completed; if it is determined that the validation accuracy has improved for N consecutive rounds, the step of inputting the processed training data into the spectrum recognition model to obtain the prediction probability of each category is returned.

[0034] In this as Figure 5In the illustrated method, step S20 is used to proportionally divide the training data into a training set, a validation set, and a test set. In this example, the training set, the validation set, and the test set can be divided in a ratio of 7:2:1. The training set is used for model learning, the validation set is used to adjust hyperparameters and avoid overfitting, and the test set is used to evaluate the model generalization ability. To enhance the robustness of the model, step S21 is used to perform data enhancement operations on the training set. Specifically, in this example, the collected spectral data can be upsampled, and the wavelength points at the beginning and end of each spectrum that fluctuate sharply can be removed. Then, the processed training set is input to the spectral recognition model through step S22 to obtain the prediction probability of each category. Step S23 is used to calculate the value of the loss function according to the prediction probability. Specifically, in this example, the loss function value can be calculated using formula (1): , (1) wherein, is the loss function value, is the standard cross-entropy loss, is a penalty coefficient, is the weight of the wavelength calculated by the model, is a set of background drift high-risk wavelength points determined according to historical operation and maintenance data of the device. In this example, the value of can be 0.05.

[0035] Step S24 is used to update the weights of the spectral recognition model using an optimizer according to the value of the current loss function. In this example, the Adam optimizer can be used to update the parameters, the initial learning rate is set to 0.001, and the StepLR learning rate decay strategy is combined to multiply the learning rate by 0.1 every several epochs to stabilize the later training process. Step S25 is used to calculate the validation accuracy based on the validation set. Step S26 is used to determine whether the validation accuracy has not improved for N consecutive rounds. In this example, the value of N can be 10. Step S27 performs corresponding processing according to the determination result. In the case where the validation accuracy has not improved for N consecutive rounds, the training is completed; in the case where the validation accuracy has improved for N consecutive rounds, the step of inputting the processed training data to the spectral recognition model to obtain the prediction probability of each category is returned.

[0036] Step S14 is used to obtain the model prediction value of the background spectrum of different dates based on the trained spectral recognition model.

[0037] Step S15 is used to generate wavelength importance curves of background spectra of different dates using an algorithm based on the model prediction value. In this embodiment, the specific method for generating the wavelength importance curve in step S15 can be a variety of forms known to those skilled in the art. In one example of the present invention, step S15 can be to generate wavelength importance curves of different categories (different dates) through the gradient weighted class activation mapping (Grad-CAM) algorithm. Grad-CAM calculates the weight of each wavelength by back-propagating the gradient. The higher the weight, the more sensitive the wavelength band is to the background drift (which is the key to distinguishing spectra of different dates). Grad-CAM reveals the key wavelength points that the model relies on to distinguish the background spectra of different dates. These key wavelength points are precisely the areas that are most sensitive to background drift. This is because the model identifies spectra of different dates (i.e., drift) by the differences in these wavelength points. Therefore, deducting these wavelength points that are highly relied upon by the model means removing the part of the spectrum that is most sensitive to background drift, and the remaining wavelength points are relatively stable and less affected by drift. Specifically, step S15 may include the following: Figure 6 The steps shown in Figure 6 In the step S15, the following steps may be performed: In step S30, the gradient of the characteristic graph of the model prediction value versus the background spectrum of different date numbers is obtained; In step S31, the importance weight of each channel is calculated according to formula (2): , (2) in, For the Feature map for category The importance weight of is the wavelength point length of the characteristic graph, is the position of the wavelength point, Classification of spectral recognition models The prediction score of For the Feature maps at spatial locations The activation value at ; In step S32, an activation map is generated according to formula (3): , (3) in, is the activation map, For the feature maps; In step S33, the activation map is normalized and superimposed with the spectral curve to generate a thermal map.

[0038] In this Figure 6In the illustrated method, step S30 is configured to obtain the gradient of the feature map of the model prediction value with respect to the background spectrum of different dates. Specifically, in this example, the input spectrum data can pass through the 1D-ResNet18 model to obtain the feature map of the last convolutional layer . Then the prediction score of the model for different categories (different dates) , i.e., the linear output before the oftmax layer, represents the preference degree of the model for the category c. Then the target category score is back-propagated to the feature map of the last convolutional layer to calculate the gradient of each channel. Step S31 is configured to perform global average pooling on the gradient in the wavelength dimension to obtain the importance weight of each channel, which is in this example. Step S32 is configured to multiply and sum the weight and the feature map of the corresponding channel to generate the unnormalized activation map . The ReLU activation function is used to set negative values to 0 and retain the part that has a positive contribution to the target category. Since the input is a one-dimensional spectrum, i.e., directly represents the importance distribution of each wavelength point for the classification of the date. The higher the value, the more critical the wavelength point is for distinguishing the background spectrum of the date (i.e., reflecting the date drift feature).

[0039] Step S16 is configured to select the wavelength points to be deducted according to the wavelength importance curve and perform the deduction. In this embodiment, the specific method of step S16 for selecting the wavelength points to be deducted can be various forms known to those skilled in the art. In one example of the present application, step S16 can include the steps as illustrated in Figure 7 . In this Figure 7 , step S16 can include: In step S40, the mean and standard deviation of the weights of all wavelength points are calculated according to the wavelength importance curve; In step S41, the dynamic threshold is set according to formula (4), , (4) wherein, is the dynamic threshold, is the mean of the weights of all wavelength points, is the standard deviation of the weights of all wavelength points, is an adjustable factor; In step S42, the wavelength points to be deducted are selected according to the dynamic threshold; ​In step S43, the white background spectrum of the current date is taken as the reference spectrum, and the wavelength points to be deducted are deducted, and the remaining wavelength points are reconstructed into a spectrum; In step S44, the norm error between the reconstructed spectrum and the reference spectrum is calculated; In step S45, it is judged whether the norm error is less than the preset error threshold; In step S46, if it is judged that the norm error is less than the preset error threshold, it is confirmed that the deduction under the current value is effective; if it is judged that the norm error is greater than or equal to the preset error threshold, the value is adjusted, and the step of setting the dynamic threshold according to formula (4) is returned.

[0040] In the method shown in the Figure 7 , step S40 calculates the mean and standard deviation of all wavelength point weights of the Grad-CAM importance map of the spectrum of a certain date. Step S41 is used to set the dynamic threshold, where is an adjustable factor, which can be set according to the requirement for stability in industrial scenarios. In this example, the value range of can be , and the initial value is 0.5. Step S42 is used to screen out the wavelength points to be deducted. In this example, the wavelength points with importance weight values greater than Threshold can be marked as "drift sensitive wavelengths" to be deducted. Step S43 is used to reconstruct the spectrum. Specifically, in this example, the white background spectrum of the initial calibration day (or the selected reference day) of the device can be taken as the reference. After the current date spectrum is deducted from the sensitive wavelength points screened out in step 3, the remaining wavelength points are used to reconstruct the spectrum . Step S44 is used to calculate the L2 norm error between the reconstructed spectrum and the reference spectrum . Step S45 is used to judge whether the norm error is less than the preset error threshold. In this example, the preset error threshold can be 0.02. Step S46 is used to perform corresponding operations according to the judgment result. In the case where it is judged that the norm error is less than the preset error threshold, it is confirmed that the deduction under the current value is effective; in the case where it is judged that the norm error is greater than or equal to the preset error threshold, the value is adjusted, and the step of setting the dynamic threshold according to formula (4) is returned. In this example, adjusting the value can be to reduce the

[0041] value. By repeating the verification until the error requirement is met, it is ensured that the drift of the deducted spectrum relative to the reference is effectively suppressed.The embodiment of the application also experimentally verifies the above method. Specifically as follows: 1. Data acquisition and preprocessing: Collecting the near-infrared equipment white background plate spectral data from May 13 to May 31 (the white background plate online spectrum of a near-infrared equipment on different dates is shown as follows Figure 8 ), and preprocessing. Among them, the preprocessing includes the following specific steps: up-sampling the collected spectral data, removing the wavelength points with violent fluctuations at the head and tail of each spectrum; adjusting the up-sampled spectral data to (1, 224) size to meet the requirements of the input data based on the 1D-ResNet18 model. The denoised spectrum is shown as follows Figure 9 , the results show that the background spectra on different dates can be effectively distinguished, proving that the equipment indeed has background drift phenomenon during this period. The PCA dimension reduction confidence ellipse of the background spectrum on different dates is drawn as follows Figure 10 , it is found that the spectra on different dates have nonlinear drift.

[0042] 2. Model training: input the preprocessed data into the spectral recognition model for training. Embedding 1D-CBAM module after 1x3 convolution, the input feature map is first weighted by channel attention (strengthening stable channels), and then weighted by spatial attention (strengthening stable wavelength points), and finally the output feature map enters the batch normalization layer. The training uses a customized loss function (β=0.05), Batchsize=64, Epochs=100, Earlystopping (10 epochs without improvement termination). The input layer receives one-dimensional spectral data sequence as input, the length of the input data is 224, and the feature dimension is determined according to the specific spectral characteristics. Extract features through two 1x3 one-dimensional convolution kernels, and then weight them through the 1D-CBAM attention module, and complete the nonlinear mapping with batch normalization (BN) and ReLU activation function. When the main branch changes the feature map dimension, a 1x1 one-dimensional convolution is used to adjust the channel number and size of the input data; when the dimension is unchanged, an identity mapping is used. The result of adding the main branch and the shortcut connection is processed through the ReLU activation function. Max Pooling or Global Average Pooling (GAP) is used to reduce the length of the feature map, reduce the computational complexity, and at the same time preserve important features. The flattened feature map is flattened into a one-dimensional vector, and the feature representation required for classification prediction is generated through the fully connected layer. The output of the fully connected layer is converted into the prediction probability of each class through the Softmax function, and the class with the highest probability is finally output as the result.

[0043] 3. Wavelength importance analysis and deduction: based on the classification results generated by the above model, the Grad-CAM method is used to generate the wavelength importance curve of the background spectrum on different dates (as shown in Figure 11As shown, different colors on the curve represent the importance of different wavebands, and the color determines which wavelengths contribute more to the model prediction, for example, if red contributes more, then the red wavelength points are excluded), and the adaptive threshold mechanism is used to screen the drift-sensitive wavelengths to be deducted. Specifically as follows: (1) Calculate the Grad-CAM weight of the spectrum on May 13th to May 31st every day and , take , and generate a threshold value by ; (2) Screen the wavelength points with a large weight greater than the threshold value (such as wavelength points 191, 192, 193, and 190 on May 13th); (3) Take the spectrum on May 13th as the reference , and verify the error of the reconstructed daily spectrum after deduction to ensure <0.02, and finally determine the wavelength point set to be deducted (see the bottom of Table 1).

[0044] Table 1 Characteristic wavelengths of different dates of background spectrum of a near-infrared device and drift-sensitive wavelength points to be deducted

[0045] Table 2 Comparison of accuracy of near-infrared spectrum-based brand classification model before and after background drift deduction

[0046] As shown in Table 2, the classification accuracy after background drift deduction by the embodiment of the present application is greatly improved, which verifies the effectiveness of the method of the embodiment of the present application. Figure 12 The whole process of obtaining the wavelength importance curve through the Grad-CAM after the spectrum is identified by the spectrum recognition model. By integrating the 1D-CBAM attention mechanism to enhance the drift feature extraction capability of the model, customizing the loss function to guide the model to focus on stable features, using the Grad-CAM to accurately locate the drift-sensitive wavelengths, and using the adaptive threshold to realize stable wavelength screening, the near-infrared spectrum background drift can be efficiently and automatically deducted, and the accuracy, stability and robustness of the online monitoring model can be significantly improved. This method is suitable for food, chemical, pharmaceutical and other industrial scenes that require high-precision, high-stability online near-infrared analysis.

[0047] On the other hand, the present application also provides a near-infrared spectrum background drift deduction system, which comprises a processor configured to perform the method of any one of the above.

[0048] In still another aspect, the present application also provides a computer readable storage medium, having stored thereon instructions which, when executed by a processor, implement any of the above method.

[0049] Advantages of the present application: The embodiment of the present application is based on data driving, and automatically learns background drift features and identifies sensitive wavelengths by using a deep learning model, without relying on frequent manual calibration or complex environmental parameter measurement compensation, thereby significantly reducing operation and maintenance costs compared with traditional technical solutions.

[0050] The embodiment of the present application has strong non-linear modeling capability by using a deep neural network (especially 1D-ResNet18 combined with an attention mechanism), and can effectively capture complex background drift patterns. Combined with Grad-CAM and an adaptive threshold mechanism, the key sensitive wavelength points causing drift can be accurately located and deducted, and the classification accuracy is significantly improved.

[0051] The embodiment of the present application suppresses the dependence of the model on the history drift high-frequency wavelength by designing a loss function, and finally only uses stable wavelength points that are not sensitive to drift for modeling, thereby effectively improving the adaptability of the analysis model to device state changes and environmental fluctuations, and guaranteeing the long-term reliability and consistency of online monitoring results.

[0052] The embodiment of the present application has good real-time performance, and once the drift feature model is trained and the sensitive wavelength points are determined, the drift deduction operation of subsequent spectral data has high calculation efficiency, which can meet the rapid response requirements of industrial online real-time monitoring. The key problem (background drift) that restricts the long-term stable operation of online NIR equipment is effectively solved, the practicability and reliability of the equipment are significantly improved, more accurate and stable analysis means are provided for real-time quality control and process monitoring in the food, chemical, pharmaceutical and other industries, and the in-depth application of near-infrared spectroscopy in industrial automation is effectively promoted.

[0053] Those skilled in the art will appreciate that embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage, etc.) containing computer-usable program code.

[0054] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0055] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0056] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0057] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.

[0058] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0059] Computer-readable media includes permanent and non-permanent, movable and non-movable media that can implement information storage by any method or technology. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette, magnetic tape disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information accessible to a computing device. According to the definition herein, computer-readable media does not include transitory media such as modulated data signals and carriers.

[0060] It should also be noted that the terms "comprising", "containing", or any other variant thereof are intended to cover non-exclusive inclusions, so that a process, method, article or apparatus that includes a list of elements does not only include those elements, but also includes other elements not explicitly listed, or further includes elements inherent in such a process, method, article or apparatus. Without more limitations, the element defined by the statement "comprising a" does not exclude the presence of additional identical elements in the process, method, article or apparatus that includes the element.

[0061] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application can have various modifications and changes. Any modification, equivalent replacement, improvement, etc. within the spirit and principle of the present application shall be included in the scope of claims of the present application.

Claims

1. A method for background drift removal of near infrared spectroscopy, characterized in that, The deduction method comprises: acquiring spectral data of a near-infrared equipment white background plate; preprocessing the spectral data as training data; constructing a spectral recognition model; training the spectral recognition model using the training data; based on the trained spectral recognition model, acquiring model prediction values of background spectra of different dates; based on the model prediction values, generating a wavelength importance curve of the background spectra of different dates using an algorithm; based on the wavelength importance curve, selecting wavelength points to be deducted and performing deduction.

2. The deduction method of claim 1, wherein, Constructing a spectral recognition model comprises: constructing a spectral recognition model based on a 1D-ResNet18 network, including an input layer, a convolution layer, a batch normalization layer, a max pooling layer, a residual module, a global average pooling layer, and a full connection layer, the convolution layer, the batch normalization layer, the max pooling layer, the residual module, the global average pooling layer, and the full connection layer being sequentially connected to the input layer, and the residual module comprising a first residual block, a second residual block, and a third residual block connected in sequence.

3. The deduction method of claim 2, wherein, The first residual block comprises a first convolution layer, a first attention module, a first batch normalization layer, a first activation function, a second convolution layer, a second attention module, a second batch normalization layer, a residual learning layer, and a second activation function, one end of the first convolution layer being connected to an output end of the max pooling layer, the first attention module, the first batch normalization layer, the first activation function, the second convolution layer, the second attention module, and the second batch normalization layer being sequentially connected to the first convolution layer, a first end of the residual learning layer being connected to the second batch normalization layer, a second end of the residual learning being connected to the output end of the max pooling layer, one end of the second activation function being connected to a third end of the residual learning layer, and the other end of the second activation function being an output end of the first residual block.

4. The deduction method of claim 2, wherein, The third residual block comprises a first residual block and a shortcut connection residual block connected in sequence, wherein the shortcut connection residual block comprises a first convolution layer, a first attention module, a first batch normalization layer, a first activation function, a second convolution layer, a second attention module, a second batch normalization layer, a residual learning layer, a second activation function, and a shortcut connection, the first attention module, the first batch normalization layer, the first activation function, the second convolution layer, the second attention module, and the second batch normalization layer being sequentially connected to the first convolution layer, one end of the first convolution layer being connected to an output end of a corresponding first residual block, one end of the shortcut connection being connected to the output end of the corresponding first residual block, a first end of the residual learning layer being connected to the second batch normalization layer, a second end of the residual learning being connected to the other end of the shortcut connection, one end of the second activation function being connected to a third end of the residual learning layer, and the other end of the second activation function being an output end of the third residual block.

5. The deduction method of claim 1, wherein, Training the spectral recognition model using the training data comprises: dividing the training data into a training set, a validation set, and a test set in proportion; performing a data enhancement operation on the training set; inputting the processed training set into the spectrum recognition model to obtain a prediction probability of each category; calculating a value of a loss function according to the prediction probability; updating weights of the spectrum recognition model using an optimizer according to the value of the current loss function; calculating a verification accuracy rate based on the verification set; judging whether the verification accuracy rate has not been improved for N consecutive rounds; completing the training when it is judged that the verification accuracy rate has not been improved for N consecutive rounds; returning to inputting the processed training data into the spectrum recognition model to obtain a prediction probability of each category when it is judged that the verification accuracy rate has been improved for N consecutive rounds.

6. The deduction method of claim 5, wherein, calculating a value of a loss function according to the prediction probability includes: calculating the value of the loss function according to formula (1), ,(1) wherein, is a loss function value, is a standard cross-entropy loss, is a penalty coefficient, is a wavelength calculated by the model weight, is a background drift high-risk wavelength point set determined according to device historical operation and maintenance data statistics.

7. The deduction method of claim 1, wherein, generating a wavelength importance curve of the background spectrum of the different dates using an algorithm according to the model prediction value includes: obtaining a gradient of a feature map of the background spectrum of the different dates according to the model prediction value; calculating an importance weight of each channel according to formula (2), ,(2) wherein, is the importance weight of the th feature map for the class, is the wavelength point length of the feature map, is the position of the wavelength point, is the prediction score of the spectral recognition model for the class, is the activation value of the th feature map at the spatial position .​​ generating an activation map according to formula (3), ,(3) wherein, is an activation map, is a first feature map; normalizing the activation map and superimposing the spectrum curve to generate a heat map.

8. The deduction method of claim 1, wherein, selecting and removing the wavelength points to be removed according to the wavelength importance curve includes: calculating a mean value and a standard deviation of all wavelength point weights according to the wavelength importance curve; setting a dynamic threshold according to formula (4), ,(4) wherein, is a dynamic threshold, is the mean of all wavelength point weights, is the standard deviation of all wavelength point weights, is an adjustable factor; screening out the wavelength points to be removed according to the dynamic threshold; taking the white background spectrum of the current date as a reference spectrum, removing the wavelength points to be removed, and reconstructing the spectrum of the remaining wavelength points; calculating a norm error between the reconstructed spectrum and the reference spectrum; judging whether the norm error is less than a preset error threshold; In a case where it is judged that the norm error is smaller than a preset error threshold, it is confirmed that the current value is valid for deduction. In a case where it is judged that the norm error is greater than or equal to a preset error threshold, adjusting value, returning to the step of setting the dynamic threshold according to formula (4).

9. A near infrared spectroscopy background drift subtraction system, comprising: the system includes a processor configured to execute the method of any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that, the computer readable storage medium stores instructions, and when the instructions are executed by the processor, the method of any one of claims 1 to 8 is implemented. the computer readable storage medium stores instructions, and when the instructions are executed by the processor, the method of any one of claims 1 to 8 is implemented.