Few-sample Raman spectrum recognition method and device based on cross-correlation attention

The Raman spectrum data is processed through the cross-correlation attention method to generate features from different perspectives, which solves the problem of low recognition accuracy under small sample data and achieves higher accuracy and efficiency in Raman spectrum recognition.

CN118468142BActive Publication Date: 2024-09-10TSINGHUA UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410917697.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-10
Publication Date
2024-09-10
Estimated Expiration
2044-07-10

AI Technical Summary

Technical Problem

Existing Raman spectrum identification methods based on deep learning have low identification accuracy under small sample data, making it difficult to achieve fast and accurate substance identification.

Method used

Using a method based on cross-correlation attention, the residual network is used to extract features from the query set and the support set, and the query features and support features are processed through the cross-correlation attention module to construct a two-dimensional cross-correlation matrix and attention map to generate different perspectives. The final features below are used to improve the similarity of features of the same category and the difference of features of different categories.

Benefits of technology

It achieves more accurate substance identification under few-sample Raman spectrum data, improves identification accuracy, reduces dependence on a large amount of training data, and can quickly and accurately identify types of gases, liquids and solid substances.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118468142B
    Figure CN118468142B
Patent Text Reader

Abstract

The present application provides a method and device for identifying a small number of Raman spectra based on cross-correlation attention. The method includes: using a residual network to extract features from a query set and a support set to obtain query features and support features, wherein the query set includes query Raman spectra data, and the support set includes support Raman spectra data corresponding to each category; using a cross-correlation attention module to process the query features and support features to obtain final query features and final support features; and determining the category of the query Raman spectra data in the query set based on the similarity between the final query features and the final support features. The method does not require a deep neural network model to learn the features of a large amount of Raman spectra data, but only needs to use a small amount of support Raman spectra data in the support set to identify the category of the query Raman spectra data. In this way, accurate Raman spectra recognition can be achieved under small number of Raman spectra data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of Raman spectrum recognition, and in particular to a method and device for small-sample Raman spectrum recognition based on cross-correlation attention. Background Art

[0002] Raman spectroscopy is an analytical technique based on the principle of Raman scattering. It uses the photon scattering phenomenon caused by molecular vibrations to analyze the frequency shift of scattered light from substances to achieve rapid and non-destructive analysis of different material components. Raman spectroscopy has the advantages of being fast, sensitive and non-destructive, and plays an important role in chemical analysis, industrial production and medical diagnosis.

[0003] Traditional Raman spectroscopy analysis requires manual analysis by practitioners with professional knowledge, which is time-consuming and labor-intensive. The small difference in Raman spectra between different substances and the low signal-to-noise ratio of Raman spectra make the task of Raman spectroscopy identification very difficult. Therefore, a Raman spectroscopy identification method based on deep learning is proposed. As a data-driven method, deep learning needs to learn the spectral distribution of different substances by training a large amount of Raman spectroscopy data, so as to realize the identification of Raman spectra of different substances.

[0004] Although the existing deep learning-based Raman spectroscopy recognition method has a high recognition accuracy, it requires a large amount of data for training, and the recognition accuracy drops sharply with a small amount of sample Raman spectroscopy data. Therefore, how to achieve accurate Raman spectroscopy recognition with a small amount of sample Raman spectroscopy data is a technical problem that needs to be solved urgently. Summary of the invention

[0005] In view of the above problems, the embodiments of the present application provide a method and device for small-sample Raman spectrum recognition based on cross-correlation attention, so as to overcome the above problems or at least partially solve the above problems.

[0006] In a first aspect of an embodiment of the present application, a method for identifying a small number of Raman spectra based on cross-correlation attention is disclosed, the method comprising:

[0007] Using a residual network to extract features from a query set and a support set to obtain query features and support features, the query set includes query Raman spectrum data, and the support set includes support Raman spectrum data corresponding to each category;

[0008] Processing the query feature and the supporting feature using a cross-correlation attention module to obtain a final query feature and a final supporting feature;

[0009] According to the similarity between the final query feature and the final supporting feature, the category of the Raman spectrum data queried in the query set is determined.

[0010] Optionally, the support set includes K supporting Raman spectral data corresponding to N categories respectively;

[0011] The query feature and the supporting feature are processed by a cross-correlation attention module to obtain a final query feature and a final supporting feature, including:

[0012] constructing a two-dimensional cross-correlation matrix based on the cosine similarity between the query feature and the supporting feature;

[0013] Determine, according to the two-dimensional cross-correlation matrix, a first attention map of the query feature and a second attention map of the supporting feature, wherein the first attention map represents an average matching probability of the query feature at a first target position and the supporting feature at different positions, and the second attention map represents an average matching probability of the supporting feature at a second target position and the query feature at different positions;

[0014] According to the query feature and the first attention map, NK final query features under different perspectives are obtained; and, according to the supporting feature and the second attention map, NK final supporting features under different perspectives are obtained.

[0015] Optionally, the residual network and the cross-correlation attention module constitute a spectrum recognition model, and the spectrum recognition model is trained by the following steps:

[0016] Using the residual network to extract features from a query sample set and a support sample set to obtain query sample features and support sample features, the query sample set includes query sample Raman spectrum data, and the support set includes support sample Raman spectrum data corresponding to each category;

[0017] Processing the query sample features and the support sample features using the cross-correlation attention module to obtain final query sample features and final support sample features;

[0018] Constructing a contrast loss according to the query sample features and the support sample features;

[0019] Constructing a prediction loss according to the final query sample feature, the final support sample feature and the true label;

[0020] According to the contrast loss and the prediction loss, the parameters of the residual network and the cross-correlation attention module are updated, and when the training end condition is met, a trained spectral recognition model is obtained. The trained spectral recognition model learns the mapping relationship from the support set to the query set category.

[0021] Optionally, the query sample set and the support sample set are constructed according to the following steps:

[0022] Randomly select N different categories;

[0023] Select K sample Raman spectrum data from each selected category as support sample Raman spectrum data to obtain a support sample set;

[0024] Selecting sample Raman spectrum data from other sample Raman spectrum data not included in the support sample set as query sample Raman spectrum data to obtain a query sample set.

[0025] Optionally, constructing a contrast loss according to the query sample feature and the support sample feature includes:

[0026] Constructing a triple according to the query sample feature and the supporting sample feature, the triple comprising: an embedded feature, an embedded feature of the same category, and an embedded feature of a different category, the embedded feature comprising the query sample feature and the supporting sample feature;

[0027] The contrast loss is obtained according to the mean square error between the embedded feature and the embedded feature of the same category, and the mean square error between the embedded feature and the embedded feature of the different category.

[0028] Optionally, the true label includes a sample mean query feature and a sample mean support feature of the same category, and a prediction loss is constructed according to the final query sample feature, the final support sample feature and the true label, including:

[0029] Performing a mean operation on the final query sample feature and the final support sample feature to obtain a mean query feature and a mean support feature;

[0030] The prediction loss is obtained according to the cosine similarity between the mean query feature and the mean query feature, and the cosine similarity between the sample mean query feature and the sample mean support feature.

[0031] Optionally, determining the category of the Raman spectrum data to be queried in the query set according to the similarity between the final query feature and the final supporting feature includes:

[0032] Calculating the similarity between the final query feature and the final support feature;

[0033] Normalizing the similarity to obtain the probability of the predicted category;

[0034] The category corresponding to the maximum probability among the predicted category probabilities is determined as the category of the Raman spectrum data to be queried in the query set.

[0035] In a second aspect of the embodiments of the present application, a small number of sample Raman spectroscopy recognition device based on cross-correlation attention is disclosed, the device comprising:

[0036] An extraction module is used to extract features from a query set and a support set using a residual network to obtain query features and support features, wherein the query set includes query Raman spectrum data, and the support set includes support Raman spectrum data corresponding to each category;

[0037] A processing module, used for processing the query feature and the supporting feature by using a cross-correlation attention module to obtain a final query feature and a final supporting feature;

[0038] The determination module is used to determine the category of the Raman spectrum data in the query set according to the similarity between the final query feature and the final supporting feature.

[0039] According to a third aspect of an embodiment of the present application, an electronic device is disclosed, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the small-sample Raman spectrum recognition method based on cross-correlation attention described in the first aspect of the embodiment of the present application are implemented.

[0040] The fourth aspect of the embodiments of the present application discloses a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the small-sample Raman spectrum recognition method based on cross-correlation attention described in the first aspect of the embodiments of the present application are implemented.

[0041] The embodiments of the present application include the following advantages:

[0042] In an embodiment of the present application, a residual network is used to extract features from a query set and a support set to obtain query features and support features, wherein the query set includes query Raman spectral data, and the support set includes support Raman spectral data corresponding to each category; the query features and the support features are processed using a cross-correlation attention module to obtain final query features and final support features; and the category of the query Raman spectral data in the query set is determined based on the similarity between the final query features and the final support features.

[0043] Since the category of the query Raman spectral data is determined based on the Raman spectral data in the support set, there is no need for a deep neural network model (such as a residual network and a cross-correlation attention module) to learn the features of a large amount of Raman spectral data. It is only necessary to use a small amount of supporting Raman spectral data in the support set to identify the category of the query Raman spectral data. In this way, accurate Raman spectral recognition is achieved under few-sample Raman spectral data. In addition, by processing the query features and support features through cross-correlation attention, the query features and support features of the same category are more similar, and the query features and embedded features of different categories are more different, which further improves the accuracy of query Raman spectral data recognition under few-sample Raman spectral data. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0045] Figure 1 It is a flowchart of the steps of a few-sample Raman spectrum recognition method based on cross-correlation attention provided in an embodiment of the present application;

[0046] Figure 2 It is a flowchart of the steps of a spectral recognition model training method provided in an embodiment of the present application;

[0047] Figure 3 This is an overall architecture diagram of a spectral recognition model training method provided in an embodiment of the present application;

[0048] Figure 4 It is a structural schematic diagram of a small sample Raman spectrum recognition device based on cross-correlation attention provided in an embodiment of the present application;

[0049] Figure 5 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0050] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and understandable, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0051] Reference Figure 1 As shown, Figure 1 1 is a flowchart of a method for identifying a small number of Raman spectra based on cross-correlation attention provided by an embodiment of the present application. Figure 1 As shown, a few-sample Raman spectrum recognition method based on cross-correlation attention provided by an embodiment of the present application may include steps S110 to S130:

[0052] Step S110: extracting features from the query set and the support set using a residual network to obtain query features and support features, wherein the query set includes query Raman spectrum data, and the support set includes support Raman spectrum data corresponding to each category.

[0053] In an embodiment of the present application, Raman spectral data is Raman spectral data collected from substances in different forms (such as gas, liquid, solid). Query Raman spectral data refers to Raman spectral data used for category identification, and the query set includes one or more query Raman spectral data. In some embodiments, each time the category of a query Raman spectral data is identified, a residual network is used to extract features from a query Raman spectral data in the query set to obtain query features corresponding to the query Raman spectral data, thereby subsequently determining the category of the query Raman spectral data based on the support set. In other embodiments, the categories of multiple query Raman spectral data can be identified at the same time, and the residual network is used to extract features from multiple query Raman spectral data in the query set to obtain query features corresponding to multiple query Raman spectral data, thereby subsequently determining the categories of multiple query Raman spectral data based on the support set.

[0054] Supported Raman spectral data refers to Raman spectral data with known categories, which is used to determine the category of the query Raman spectral data. The support set includes supported Raman spectral data corresponding to each category, and a category includes at least one or more supported Raman spectral data.

[0055] The residual network refers to a neural network with feature extraction function (for example, the residual network can be a one-dimensional deep residual network ResNet). Using the residual network to extract features from the query set and the support set means that the residual network extracts features from the Raman spectrum data in the query set and the support set respectively to obtain the features of each Raman spectrum data. Specifically, for the query Raman spectrum data in the query set, feature extraction is performed through the residual network to obtain query features; for the support Raman spectrum data in the support set, feature extraction is performed through the residual network to obtain support features.

[0056] Specifically, for a query Raman spectroscopy data and support for Raman spectroscopy data , , where L and C represent the length and number of channels of Raman spectral data respectively. The feature extraction of query set and support set using residual network is expressed as:

[0057] ,

[0058] in, represents the query features, Indicates supported features, Indicates the length of the embedded feature (query feature or support feature), Indicates the number of channels of embedded features (query features or support features), A function representing a residual network (a one-dimensional deep residual network), Represents the parameters of the residual network.

[0059] Step S120: using a cross-correlation attention module to process the query feature and the supporting feature to obtain a final query feature and a final supporting feature.

[0060] In an embodiment of the present application, the cross-correlation attention module refers to a neural network that processes features based on a cross-correlation attention mechanism. Through the cross-correlation attention mechanism, query features and supporting features can be correlated with each other, query features and supporting features of the same category are more similar, and query features and embedded features of different categories are more different.

[0061] Each final query feature is associated with a final supporting feature, and the query features and supporting features are processed based on the cross-correlation attention mechanism to obtain the final query feature from the perspective of the supporting feature, and the final supporting features associated with the final query feature. The support set includes supporting Raman spectral data corresponding to each category, and each supporting Raman spectral data corresponds to a supporting feature, so the supporting features include multiple; each query feature needs to be processed with all supporting features based on the cross-correlation attention mechanism to obtain the final query feature from multiple perspectives, and the final supporting features associated with the final query feature from multiple perspectives. For example, query feature a is processed with supporting feature 1 and supporting feature 2 based on the cross-correlation attention mechanism respectively to obtain the final query feature a1 and the associated final supporting feature 1a, and the final query feature a2 and the associated final supporting feature 2a.

[0062] In an optional embodiment, the support set includes K supporting Raman spectral data corresponding to N categories, that is, there are NK supporting Raman spectral data in the support set, and the query Raman spectral data is classified based on the NK supporting Raman spectral data.

[0063] Specifically, the query feature and the supporting feature are processed by a cross-correlation attention module to obtain a final query feature and a final supporting feature, including steps A1 to A3:

[0064] Step A1: construct a two-dimensional cross-correlation matrix based on the cosine similarity between the query feature and the supporting feature.

[0065] In the embodiment of the present application, the cosine similarity between each pair of query features and supporting features is calculated as an element in the two-dimensional cross-correlation matrix. For example, query feature b, supporting feature 3, supporting feature 4, and supporting feature 5 can constitute three pairs of features, that is, query feature b and supporting feature 3 can be used as a pair of features, query feature b and supporting feature 4 can be used as a pair of features, and query feature b and supporting feature 5 can be used as a pair of features.

[0066] For example, a two-dimensional cross-correlation matrix is ​​represented as:

[0067] ,

[0068] in, represents a two-dimensional cross-correlation matrix, represents the query features, Indicates supported features, Indicates the length of the embedded feature (query feature or support feature), Indicates the number of channels of embedded features (query features or support features), represents the location of the query feature, represents the location of the supporting features, Represents the cosine similarity between two features.

[0069] Step A2: According to the two-dimensional cross-correlation matrix, determine the first attention map of the query feature and the second attention map of the supporting feature, the first attention map represents the average matching probability of the query feature at the first target position and the supporting feature at different positions, and the second attention map represents the average matching probability of the supporting feature at the second target position and the query feature at different positions.

[0070] In the embodiment of the present application, the first attention map and the second attention map display the related content between the query feature and the supporting feature.

[0071] For example, the first attention map and the second attention map are respectively expressed as:

[0072] ,

[0073] in, represents the first attention map, represents the second attention map, Expressed as the temperature coefficient, The value of exist Position and support features The average matching probability of a position, The value indicates that the supported feature exist Location and query features The average matching probability of a position, Indicates the traversal position of the query feature, Indicates the traversal position of the supporting features, represents a two-dimensional cross-correlation matrix.

[0074] Step A3: According to the query feature and the first attention map, obtain NK final query features under different perspectives; and, according to the supporting feature and the second attention map, obtain NK final supporting features under different perspectives.

[0075] For example, the final query features and the final support features are expressed as:

[0076] ,

[0077] in, represents the final query feature, Indicates the final support features, The value of exist Position and support features The average matching probability of a position, The value indicates that the supported feature exist Location and query features The average matching probability of a position.

[0078] In the embodiment of the present application, the association between the query feature and the support feature is further enhanced by the attention map to obtain the final query feature and the final support feature. The support set includes K supporting Raman spectral data corresponding to N categories, that is, there are NK supporting samples in the support set. For each query feature, the cross-correlation attention mechanism will generate the final query features under NK different perspectives. ; At the same time, obtain the final supporting features of the associated query feature semantics , which is the final support features under NK different perspectives.

[0079] Step S130: determining the category of the Raman spectrum data queried in the query set according to the similarity between the final query feature and the final supporting feature.

[0080] In the embodiment of the present application, the final query feature and the final supporting feature of the same category are more similar, so the category of the queried Raman spectrum data is determined according to the similarity between the final query feature and the final supporting feature. The similarity between the final query feature and the final supporting feature can be cosine similarity, or other information that can characterize the similarity between the two features, which is not limited in the present application.

[0081] In some optional embodiments, determining the category of the Raman spectroscopy data in the query set according to the similarity between the final query feature and the final supporting feature includes steps B1 to B3:

[0082] Step B1: Calculate the similarity between the final query feature and the final support feature.

[0083] Step B2: normalize the similarity to obtain the probability of the predicted category.

[0084] Step B3: determining the category corresponding to the maximum probability among the predicted category probabilities as the category of the Raman spectrum data to be queried in the query set.

[0085] In the embodiment of the present application, the final query feature includes NK final query features under different viewing angles, the final supporting features include NK final supporting features under different viewing angles, each final query feature is associated with a final supporting feature, and in order to better compare the similarity between each pair of final query features and final supporting features, the similarity is normalized, and the normalized similarity is used as the probability of the predicted category. Thus, the category corresponding to the maximum probability is determined as the category of the queried Raman spectrum data.

[0086] Through the above implementation process, since the category of the query Raman spectral data is determined based on the Raman spectral data in the support set, there is no need for the deep neural network model (such as the residual network and the cross-correlation attention module) to learn the features of a large amount of Raman spectral data. It is only necessary to use a small amount of supporting Raman spectral data in the support set to identify the category of the query Raman spectral data. In this way, accurate Raman spectral recognition is achieved under the condition of few-sample Raman spectral data. In addition, the query features and support features are processed through cross-correlation attention, so that the query features and support features of the same category are more similar, and the query features and embedded features of different categories are more different, which further improves the accuracy of query Raman spectral data recognition under the condition of few-sample Raman spectral data.

[0087] In practical applications, if the Raman spectral data is the collected Raman spectral data of a gas, the type of gas can be quickly and accurately identified through the method provided in the embodiment of the present application.

[0088] In the embodiment of the present application, the residual network and the cross-correlation attention module constitute a spectral recognition model, which learns the mapping relationship from the support set to the query set category, so that the spectral recognition model can determine the category of the query Raman spectral data based on the Raman spectral data in the support set. The training method of the spectral recognition model is described in detail below.

[0089] First, the spectral recognition model training task is explained.

[0090] The few-sample Raman spectroscopy recognition method based on cross-correlation attention proposed in the embodiment of the present application uses the known category Training data Optimize and then evaluate the unknown classes on the test set Test data Moreover, the categories in the training set are completely different from those in the test set. Both the training set and the test set consist of multiple sets, each of which contains a query set. and a support set , where N is the category contained in the support set, K is the number of samples contained in each category. Such a few-sample classification task is called an N-class K-sample task, that is, there are NK supporting sample Raman spectral data in the support set.

[0091] During the spectral recognition model training process, a set (support sample set and query sample set) is randomly extracted from the training data iteratively, and the spectral recognition model is trained to learn the mapping relationship from the support set to the query set category. During testing, the spectral recognition model classifies the test sample into one of the N categories to which the support set belongs in the test data.

[0092] Reference Figure 2 As shown, Figure 2 1 is a flowchart of a spectrum recognition model training method provided in an embodiment of the present application. Specifically, the spectrum recognition model is trained through the following steps S210 to S250:

[0093] Step S210: extracting features from the query sample set and the support sample set using the residual network to obtain query sample features and support sample features, wherein the query sample set includes query sample Raman spectrum data, and the support set includes support sample Raman spectrum data corresponding to each category.

[0094] In the embodiment of the present application, the residual network extracts features from the sample Raman spectrum data in the query sample set and the support sample set based on the current parameters, thereby obtaining features corresponding to each sample Raman spectrum data. Specifically, for the query sample Raman spectrum data in the query sample set, the residual network extracts features to obtain query sample features; for the support sample Raman spectrum data in the support sample set, the residual network extracts features to obtain support sample features.

[0095] Specifically, the query sample set and the support sample set are constructed according to the following steps: randomly selecting N different categories; selecting K sample Raman spectrum data from each selected category as support sample Raman spectrum data to obtain a support sample set; selecting sample Raman spectrum data from other sample Raman spectrum data that are not included in the support sample set as query sample Raman spectrum data to obtain a query sample set.

[0096] Step S220: Utilize the cross-correlation attention module to process the query sample features and the support sample features to obtain final query sample features and final support sample features.

[0097] In the embodiment of the present application, the cross-correlation attention module processes the query sample features and the support sample features based on the current parameters to obtain the final query sample features and the final support sample features. Through the cross-correlation attention mechanism, the query sample features of the same category are more similar to the support sample features, and the query sample features of different categories are more different from the support sample features.

[0098] Step S230: constructing a contrast loss according to the query sample features and the support sample features.

[0099] In an embodiment of the present application, for the query sample features and support sample features obtained in step S210, a contrastive learning method is used to enhance the discriminability between features of different categories. Specifically, the embedded features of the same category (query sample features, support sample features) are as similar as possible, while the embedded features of different categories are as different as possible, so that the residual network can learn more discriminative features through contrast loss.

[0100] Specifically, a contrast loss is constructed according to the query sample features and the support sample features, including: constructing a triplet according to the query sample features and the support sample features, the triplet including: an embedded feature, an embedded feature of the same category, and an embedded feature of a different category, the embedded feature including the query sample feature and the support sample feature; and obtaining a contrast loss according to a mean square error between the embedded feature and the embedded feature of the same category, and a mean square error between the embedded feature and the embedded feature of the different category.

[0101] For example, the triple is represented as ,in, represents the embedded features, Represented as and embedded features Embedding features of the same category, Represented as and embedded features Embedding features of different categories. The contrast loss is expressed as:

[0102] ,

[0103] in, represents the contrast loss, Indicates the maximum value operation. represents the mean square error, is the minimum embedding distance between positive and negative samples.

[0104] It is understandable that step S230 may be executed after step S210 or after step S220, and this application does not limit this.

[0105] Step S240: construct a prediction loss according to the final query sample features, the final support sample features and the true label.

[0106] In an embodiment of the present application, the category prediction probability of the query sample Raman spectral data is obtained by calculating the similarity between the final query sample features and the final support sample features, and the prediction loss is constructed by the difference between the category prediction category probability and the true label.

[0107] Specifically, the true label includes sample mean query features and sample mean support features of the same category. According to the final query sample features, the final support sample features and the true label, a prediction loss is constructed, including: performing a mean operation on the final query sample features and the final support sample features to obtain a mean query feature and a mean support feature; and obtaining a prediction loss according to the cosine similarity between the mean query feature and the mean query feature, and the cosine similarity between the sample mean query feature and the sample mean support feature.

[0108] For example, the prediction loss is expressed as:

[0109] ,

[0110] in, represents the prediction loss, represents the temperature coefficient, represents the mean query feature, represents the mean support feature, Indicates Sample mean query feature, Indicates sample mean support features, N represents the total number of sample mean query features and sample mean support features, Represents the cosine similarity between two features.

[0111] Step S250: According to the contrast loss and the prediction loss, the parameters of the residual network and the cross-correlation attention module are updated, and when the training end condition is met, a trained spectral recognition model is obtained. The trained spectral recognition model learns the mapping relationship from the support set to the query set category.

[0112] In an embodiment of the present application, the contrast loss and the prediction loss are weighted and summed to obtain a final loss value, and the parameters of the residual network and the cross-correlation attention module are updated according to the final loss value.

[0113] For example, the final loss function is expressed as:

[0114] ,

[0115] in, represents the final loss function, and are the weights of the contrast loss function and the prediction loss function, respectively. represents the prediction loss, represents contrast loss.

[0116] For example, Figure 3 This is an overall architecture diagram of a spectral recognition model training method provided by an embodiment of the present application. Specifically, a residual network is used to extract features of the query sample Raman spectral data and the support sample Raman spectral data to obtain query sample features and support sample features, and a contrast loss is constructed through the query sample features and the support sample features; then, the query sample features and the support sample features are processed using a cross-correlation attention module to obtain the final query sample features and the final support sample features; thereby, a prediction loss is constructed based on the final query sample features, the final support sample features and the true label; finally, based on the contrast loss and the prediction loss, the parameters of the residual network and the cross-correlation attention module are updated, and when the training end conditions are met, a trained spectral recognition model is obtained, and the trained spectral recognition model learns the mapping relationship from the support set to the query set category.

[0117] In the embodiments of the present application, in view of the problem that the existing Raman spectrum recognition method lacks feature discriminability, it is proposed to use contrastive learning to enhance the discriminability of the features extracted by the model (such as the residual network), so that the model can better recognize the Raman spectrum. In addition, in order to solve the problem that the existing Raman spectrum recognition method has poor classification performance in the case of few samples, the present application uses meta-learning to perform few-sample Raman spectrum recognition, so that the spectrum recognition model learns the mapping relationship from the support set to the query set category, so that only a small amount of supporting Raman spectrum data in the support set is needed to identify the category of the query Raman spectrum data.

[0118] Unlike the related Raman spectrum recognition algorithm, the method provided in the embodiment of the present application can detect categories that have not been seen in training because the spectrum category is identified based on the mapping relationship from the support set to the query set category. In addition, by processing the query features and the support features through cross-correlation attention, the query features and the support features of the same category are more similar, and the query features and the embedded features of different categories are more different, which further improves the accuracy of query Raman spectrum data recognition under the condition of few sample Raman spectrum data.

[0119] The present application also provides a small sample Raman spectrum recognition device based on cross-correlation attention, referring to Figure 4 As shown, Figure 4 : is a structural schematic diagram of a small sample Raman spectrum recognition device based on cross-correlation attention provided in an embodiment of the present application, the device comprising:

[0120] An extraction module 410 is used to extract features from a query set and a support set using a residual network to obtain query features and support features, wherein the query set includes query Raman spectrum data, and the support set includes support Raman spectrum data corresponding to each category;

[0121] A processing module 420, configured to process the query feature and the supporting feature using a cross-correlation attention module to obtain a final query feature and a final supporting feature;

[0122] The determination module 430 is configured to determine the category of the Raman spectrum data in the query set according to the similarity between the final query feature and the final supporting feature.

[0123] In an optional embodiment, the support set includes K supporting Raman spectral data corresponding to N categories respectively; the processing module includes:

[0124] A correlation matrix construction module, used to construct a two-dimensional cross correlation matrix according to the cosine similarity between the query feature and the supporting feature;

[0125] An attention map determination module is used to determine a first attention map of the query feature and a second attention map of the supporting feature according to the two-dimensional cross-correlation matrix, wherein the first attention map represents an average matching probability of the query feature at a first target position and the supporting feature at different positions, and the second attention map represents an average matching probability of the supporting feature at a second target position and the query feature at different positions;

[0126] A final feature module is used to obtain NK final query features under different perspectives based on the query features and the first attention map, and to obtain NK final supporting features under different perspectives based on the supporting features and the second attention map.

[0127] In an optional embodiment, the residual network and the cross-correlation attention module constitute a spectrum recognition model, and the device includes a training module for training the spectrum recognition model, and the training module includes:

[0128] A sample feature extraction module, used to extract features from a query sample set and a support sample set using the residual network to obtain query sample features and support sample features, wherein the query sample set includes query sample Raman spectrum data, and the support set includes support sample Raman spectrum data corresponding to each category;

[0129] A sample feature processing module, used to process the query sample feature and the support sample feature using the cross-correlation attention module to obtain a final query sample feature and a final support sample feature;

[0130] A contrast loss module, used for constructing a contrast loss according to the query sample features and the support sample features;

[0131] A prediction loss module, used to construct a prediction loss according to the final query sample feature, the final support sample feature and the true label;

[0132] A parameter updating module is used to update the parameters of the residual network and the cross-correlation attention module according to the contrast loss and the prediction loss, and obtain a trained spectral recognition model when the training end condition is met. The trained spectral recognition model learns the mapping relationship from the support set to the query set category.

[0133] In an optional embodiment, the training module further includes a set construction module for constructing the query sample set and the support sample set, and the construction module includes:

[0134] Category selection module, used to randomly select N different categories;

[0135] A supporting sample training module is used to select K sample Raman spectrum data from each selected category as supporting sample Raman spectrum data to obtain a supporting sample set;

[0136] The query sample training module is used to select sample Raman spectrum data from other sample Raman spectrum data not included in the support sample set as query sample Raman spectrum data to obtain a query sample set.

[0137] In an optional embodiment, the contrast loss module includes:

[0138] A triplet module, configured to construct a triplet according to the query sample feature and the support sample feature, wherein the triplet includes: an embedded feature, an embedded feature of the same category, and an embedded feature of a different category, wherein the embedded feature includes the query sample feature and the support sample feature;

[0139] The contrast loss submodule is used to obtain the contrast loss according to the mean square error between the embedded feature and the embedded feature of the same category, and the mean square error between the embedded feature and the embedded feature of the different category.

[0140] In an optional embodiment, the true label includes a sample mean query feature and a sample mean support feature of the same category, and the prediction loss module includes:

[0141] A mean operation module, used for performing a mean operation on the final query sample feature and the final support sample feature to obtain a mean query feature and a mean support feature;

[0142] The prediction loss submodule is used to obtain the prediction loss according to the cosine similarity between the mean query feature and the mean query feature, and the cosine similarity between the sample mean query feature and the sample mean support feature.

[0143] In an optional embodiment, the determining module includes:

[0144] A calculation module, used for calculating the similarity between the final query feature and the final support feature;

[0145] A normalization module, used to normalize the similarity to obtain the probability of the predicted category;

[0146] The category determination module is used to determine the category corresponding to the maximum probability among the probabilities of the predicted categories as the category of the Raman spectrum data to be queried in the query set.

[0147] The present application also provides an electronic device, referring to Figure 5 , Figure 5Schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 5 As shown, the electronic device 500 includes: a memory 510 and a processor 520. The memory 510 and the processor 520 are connected via a bus communication. A computer program is stored in the memory 510. The computer program can be run on the processor 520 to implement the steps of the small-sample Raman spectrum recognition method based on cross-correlation attention described in the embodiment of the present application.

[0148] The embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the small-sample Raman spectrum recognition method based on cross-correlation attention described in the embodiment of the present application are implemented.

[0149] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0150] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods and devices 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 the 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 terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal 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.

[0151] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0152] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0153] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.

[0154] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0155] The above is a detailed introduction to a few-sample Raman spectroscopy recognition method and device based on cross-correlation attention provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technicians in this field, according to the ideas of the present application, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A few-sample Raman spectroscopy recognition method based on cross-correlation attention, characterized in that: The method comprises: Using a residual network to extract features from a query set and a support set to obtain query features and support features, the query set includes query Raman spectrum data, and the support set includes support Raman spectrum data corresponding to each category; Processing the query feature and the supporting feature using a cross-correlation attention module to obtain a final query feature and a final supporting feature; Determining the category of the Raman spectrum data queried in the query set according to the similarity between the final query feature and the final supporting feature; The support set includes K supporting Raman spectral data corresponding to N categories respectively; the query feature and the supporting feature are processed by a cross-correlation attention module to obtain a final query feature and a final supporting feature, including: constructing a two-dimensional cross-correlation matrix according to the cosine similarity between the query feature and the supporting feature; Determine, according to the two-dimensional cross-correlation matrix, a first attention map of the query feature and a second attention map of the supporting feature, wherein the first attention map represents an average matching probability of the query feature at a first target position and the supporting feature at different positions, and the second attention map represents an average matching probability of the supporting feature at a second target position and the query feature at different positions; According to the query feature and the first attention map, NK final query features under different perspectives are obtained; and, according to the supporting feature and the second attention map, NK final supporting features under different perspectives are obtained.

2. The method for identifying a small number of Raman spectra based on cross-correlation attention according to claim 1, characterized in that: The residual network and the cross-correlation attention module constitute a spectrum recognition model, and the spectrum recognition model is trained by the following steps: Using the residual network to extract features from a query sample set and a support sample set to obtain query sample features and support sample features, the query sample set includes query sample Raman spectrum data, and the support set includes support sample Raman spectrum data corresponding to each category; Processing the query sample features and the support sample features using the cross-correlation attention module to obtain final query sample features and final support sample features; Constructing a contrast loss according to the query sample features and the support sample features; Constructing a prediction loss according to the final query sample feature, the final support sample feature and the true label; According to the contrast loss and the prediction loss, the parameters of the residual network and the cross-correlation attention module are updated, and when the training end condition is met, a trained spectral recognition model is obtained. The trained spectral recognition model learns the mapping relationship from the support set to the query set category.

3. The method for identifying a small number of Raman spectra based on cross-correlation attention according to claim 2, characterized in that: The query sample set and the support sample set are constructed according to the following steps: Randomly select N different categories; Select K sample Raman spectrum data from each selected category as support sample Raman spectrum data to obtain a support sample set; Selecting sample Raman spectrum data from other sample Raman spectrum data not included in the support sample set as query sample Raman spectrum data to obtain a query sample set.

4. The method for identifying a small number of Raman spectra based on cross-correlation attention according to claim 2, characterized in that: Constructing a contrast loss according to the query sample features and the support sample features, including: Constructing a triple according to the query sample feature and the supporting sample feature, the triple comprising: an embedded feature, an embedded feature of the same category, and an embedded feature of a different category, the embedded feature comprising the query sample feature and the supporting sample feature; The contrast loss is obtained according to the mean square error between the embedded feature and the embedded feature of the same category, and the mean square error between the embedded feature and the embedded feature of the different category.

5. The method for identifying a small number of Raman spectra based on cross-correlation attention according to claim 2, characterized in that: The true label includes the sample mean query feature and the sample mean support feature of the same category. According to the final query sample feature, the final support sample feature and the true label, a prediction loss is constructed, including: Performing a mean operation on the final query sample feature and the final support sample feature to obtain a mean query feature and a mean support feature; The prediction loss is obtained according to the cosine similarity between the mean query feature and the mean query feature, and the cosine similarity between the sample mean query feature and the sample mean support feature.

6. The method for identifying a small number of Raman spectra based on cross-correlation attention according to claim 1, characterized in that: Determining the category of the Raman spectrum data in the query set according to the similarity between the final query feature and the final supporting feature, including: Calculating the similarity between the final query feature and the final support feature; Normalizing the similarity to obtain the probability of the predicted category; The category corresponding to the maximum probability among the predicted category probabilities is determined as the category of the Raman spectrum data to be queried in the query set.

7. A small sample Raman spectrum recognition device based on cross-correlation attention, characterized in that: The device comprises: An extraction module is used to extract features from a query set and a support set using a residual network to obtain query features and support features, wherein the query set includes query Raman spectrum data, and the support set includes support Raman spectrum data corresponding to each category; A processing module, used for processing the query feature and the supporting feature by using a cross-correlation attention module to obtain a final query feature and a final supporting feature; A determination module, used for determining the category of the Raman spectrum data queried in the query set according to the similarity between the final query feature and the final supporting feature; The support set includes K supporting Raman spectral data corresponding to N categories respectively; the processing module includes: A correlation matrix construction module, used to construct a two-dimensional cross correlation matrix according to the cosine similarity between the query feature and the supporting feature; An attention map determination module is used to determine a first attention map of the query feature and a second attention map of the supporting feature according to the two-dimensional cross-correlation matrix, wherein the first attention map represents an average matching probability of the query feature at a first target position and the supporting feature at different positions, and the second attention map represents an average matching probability of the supporting feature at a second target position and the query feature at different positions; A final feature module is used to obtain NK final query features under different perspectives based on the query features and the first attention map, and to obtain NK final supporting features under different perspectives based on the supporting features and the second attention map.

8. An electronic 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, the steps of the small-sample Raman spectrum recognition method based on cross-correlation attention described in any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the small-sample Raman spectrum recognition method based on cross-correlation attention described in any one of claims 1 to 6 are implemented.