Spectral recognition method and device based on reconstructed prototype guidance, equipment and storage medium

By using a prototype-guided spectral recognition method, which utilizes reconstructed networks and feature prototypes, high-precision recognition of known categories and effective rejection of unknown categories are achieved. This solves the problem of unreliability in open-scene recognition of deep learning spectral recognition methods and improves the robustness and reliability of recognition.

CN122435359APending Publication Date: 2026-07-21TSINGHUA UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
TSINGHUA UNIVERSITY
Filing Date
2026-06-11
Publication Date
2026-07-21

Smart Images

  • Figure CN122435359A_ABST
    Figure CN122435359A_ABST
Patent Text Reader

Abstract

The application provides a spectrum recognition method and device based on reconstruction prototype guidance, equipment and storage medium, relating to the technical field of spectrum recognition. The method comprises: obtaining a training spectrum sample of a known category; inputting the training spectrum sample into a reconstruction network to obtain a reconstructed spectrum; splicing the reconstructed spectrum and the original spectrum to construct a discriminative spectrum pair; inputting the discriminative spectrum pair into a feature extractor to extract a latent feature representation; setting a feature prototype for each known category, generating a classification prediction based on the distance between the latent feature and the feature prototype; optimizing the reconstruction network, the feature encoder and the feature prototype according to the reconstruction difference and the classification difference to obtain a spectrum recognition model; inputting a spectrum sample to be recognized into the model to obtain a classification recognition result indicating the known category or the unknown category. The application only uses known category training, which can realize high-precision recognition of the known category and effective rejection of the unknown category, and is suitable for open scenes such as clinical diagnosis and food safety detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of spectral recognition technology, and in particular to a spectral recognition method, apparatus, device and storage medium based on reconstructed prototype guidance. Background Technology

[0002] With the rapid development of modern medical and health technologies and biological detection technologies, the demand for rapid, reliable, and non-invasive detection technologies is becoming increasingly urgent. Molecular vibrational spectroscopy (such as Raman spectroscopy and infrared spectroscopy) can obtain vibrational and rotational information of substances through the interaction of light and molecules, reflecting the chemical composition and molecular structure characteristics of samples. It is known as the molecular fingerprint of substances and has important application value in disease diagnosis, pathogen detection, and biomarker analysis.

[0003] The development of deep learning technology has led to widespread attention being paid to spectral recognition methods based on deep neural networks. These methods can automatically learn multi-level, non-linear feature representations from raw spectral data, outperforming traditional methods in terms of noise robustness and recognition accuracy. However, most existing deep learning spectral recognition methods are based on the closed-set assumption, meaning that test samples are assumed to come from categories known during training. Under this assumption, the model allocates the entire feature space to known categories, without reserving a discrimination space for unknown categories.

[0004] In practical applications, the above assumptions are often difficult to meet. For example, novel pathogens or variant strains not included in the training data may appear in clinical diagnosis; unknown chemical contaminants may be encountered in food safety testing. In such cases, existing methods lack effective mechanisms for handling unknown categories, easily misclassifying unknown samples as known categories with similar characteristics, leading to unreliable identification results, or even misdiagnosis or safety incidents.

[0005] Therefore, how to effectively detect and reject unknown categories while maintaining the accuracy of known category recognition is a technical problem that urgently needs to be solved in this field. Summary of the Invention

[0006] The purpose of this application is to provide a spectral recognition method, apparatus, device, and storage medium based on reconstructed prototype guidance, which can effectively detect and reject unknown spectral samples that did not appear during the training phase while maintaining high recognition accuracy for known category spectral samples, thereby adapting to the spectral recognition needs in open scenarios.

[0007] To solve the above-mentioned technical problems, this application is implemented as follows: A first aspect of this application discloses a spectral recognition method based on reconstructed prototype guidance, the method comprising: Acquire training spectral samples of known categories, wherein the training spectral samples are spectral data collected for substances of known categories; The training spectral samples are input into the reconstruction network for reconstruction processing to obtain the reconstructed spectrum; The reconstructed spectrum is spliced ​​with the training spectral sample to construct a discriminative spectral pair; The discriminative spectral pair is input into the feature extractor to extract latent feature representations; For each known category, a learnable feature prototype is set, and a classification prediction result is generated based on the distance between the latent feature representation and each feature prototype; wherein, the feature prototype is used to characterize the central position of the corresponding known category in the feature space; Based on the reconstruction difference between the reconstructed spectrum and the training spectrum sample, and the classification difference between the classification prediction result and the true label, the reconstruction network, the feature extractor, and the feature prototype are jointly optimized to obtain a spectral recognition model. The spectral sample to be identified is input into the spectral recognition model to obtain the classification and recognition result; the classification and recognition result is used to indicate whether the spectral sample to be identified belongs to a known category or an unknown category.

[0008] Optionally, the reconstruction network employs an autoencoder structure, including an encoder and a decoder; the training spectral samples are input into the reconstruction network for reconstruction processing to obtain the reconstructed spectrum, including: The training spectral samples are mapped to the latent feature space by an encoder to obtain intermediate latent features; The reconstructed spectrum is obtained by reconstructing the training spectral samples using the intermediate latent features through a decoder.

[0009] Optionally, the discriminative spectrum is input to the feature extractor to extract latent feature representations, including: A gradient-stopping operation is performed on the reconstructed spectral portion of the discriminative spectral pair; The discriminative spectral pairs after the gradient stopping operation are input into the feature extractor to extract the latent feature representation.

[0010] Optionally, classification prediction results are generated based on the distances between the latent feature representations and each feature prototype, including: Calculate the distance between the latent feature representation and each feature prototype to obtain a distance vector; wherein the distance is Euclidean distance or cosine distance; The negative of each element in the distance vector is then input into the Softmax function to convert it into a predicted probability vector for the corresponding category, which serves as the classification prediction result.

[0011] Optionally, based on the reconstruction difference between the reconstructed spectrum and the training spectral samples, and the classification difference between the classification prediction result and the true label, the reconstruction network, the feature extractor, and the feature prototype are jointly optimized, including: Based on the reconstruction difference between the reconstructed spectrum and the training spectrum samples, the reconstruction loss is calculated using the mean squared error loss function. Based on the classification difference between the classification prediction result and the true label, the prototype learning loss is calculated, and the prototype learning loss adopts the cross-entropy loss function. The parameters of the reconstruction network are updated based on the reconstruction loss, and the parameters of the feature extractor and the feature prototype are updated based on the prototype learning loss.

[0012] Optionally, the spectral sample to be identified is input into the spectral recognition model to obtain the classification and recognition result, including: The spectral samples to be identified are sequentially input into the reconstruction network and feature extractor in the spectral recognition model to obtain potential identification features; Calculate the distance between the identified latent feature and each optimized feature prototype, and determine the minimum distance; the minimum distance characterizes the proximity of the spectral sample to be identified to the most similar category among all known categories; If the minimum distance is greater than a preset threshold, the spectral sample to be identified is determined to be of an unknown category; If the minimum distance is not greater than a preset threshold, then the spectral sample to be identified is determined to be a known category corresponding to the minimum distance.

[0013] Optionally, the training spectral samples and the spectral samples to be identified are Raman spectral data or infrared spectral data; the method is applied to edge-end spectral recognition devices.

[0014] A second aspect of this application discloses a spectral recognition device based on a reconstructed prototype, the device comprising: The sample acquisition module is used to acquire training spectral samples of known categories, wherein the training spectral samples are spectral data collected for substances of known categories; The spectral reconstruction module is used to input the training spectral samples into the reconstruction network for reconstruction processing to obtain the reconstructed spectrum; The spectral pair construction module is used to stitch the reconstructed spectrum with the training spectral samples to construct discriminative spectral pairs; The feature extraction module is used to input the discriminative spectral pair into the feature extractor and extract latent feature representations; The result prediction module is used to set a learnable feature prototype for each known category and generate a classification prediction result based on the distance between the latent feature representation and each feature prototype; wherein, the feature prototype is used to characterize the central position of the corresponding known category in the feature space; The model optimization module is used to jointly optimize the reconstruction network, the feature extractor, and the feature prototype based on the reconstruction difference between the reconstructed spectrum and the training spectral samples, and the classification difference between the classification prediction result and the true label, to obtain a spectral recognition model. The category recognition module is used to input the spectral sample to be recognized into the spectral recognition model to obtain the classification recognition result; the classification recognition result is used to indicate whether the spectral sample to be recognized belongs to a known category or an unknown category.

[0015] A third aspect of this application discloses an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of the spectral recognition method based on reconstructed prototype guidance described in the first aspect of this application.

[0016] A fourth aspect of this application discloses a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the spectral recognition method based on reconstructed prototype guidance described in the first aspect of this application.

[0017] A fifth aspect of this application discloses a computer program product, including a computer program that, when executed by a processor, implements the steps of the spectral recognition method based on reconstructed prototype guidance described in the first aspect of this application.

[0018] The embodiments of this application have the following advantages: In this embodiment, the training spectral samples are reconstructed by a reconstruction network, and the reconstructed spectra are spliced ​​with the original training spectral samples to construct discriminative spectral pairs. This makes the known and unknown categories inherently different in reconstruction error, thereby amplifying the distinguishability of the two types of samples in the feature extraction stage and laying the foundation for open set recognition.

[0019] By setting learnable feature prototypes for each known category and generating classification prediction results using the distance between the latent feature representation and the feature prototypes, known category samples form a compact distribution around their respective prototypes in the feature space, with clear boundaries between different categories. At the same time, open spaces are naturally formed between prototypes, which is beneficial for distinguishing and rejecting unknown category samples.

[0020] By jointly optimizing the reconstruction difference and the classification difference, the model can simultaneously achieve high-quality reconstruction of known categories and discriminative classification. The two work together to improve the model, enhancing the sensitivity to unknown categories while ensuring the accuracy of known category recognition, thus avoiding the performance bottleneck caused by a single optimization objective.

[0021] Thus, this method can achieve high-precision identification of known categories and effective detection and rejection of unknown categories using only known category samples for training, improving the robustness and reliability of spectral recognition methods in open scenarios, and is suitable for practical applications such as clinical diagnosis, food safety testing, and environmental monitoring. Attached Figure Description

[0022] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0023] Figure 1 This is a flowchart illustrating the steps of a spectral recognition method based on a reconstructed prototype, as provided in an embodiment of this application. Figure 2 This is an overall architecture diagram of a spectral recognition method based on reconstructed prototype guidance provided in an embodiment of this application; Figure 3 This is a schematic diagram of the structure of a spectral recognition device based on a reconstructed prototype provided in an embodiment of this application; Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0024] To make the above-mentioned objectives, features, and advantages of this application more apparent and understandable, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0025] To address the problem that existing spectral recognition methods, based on the closed-set assumption, struggle to effectively detect unknown categories, this application proposes a spectral recognition method guided by a reconstructed prototype. The technical concept is twofold: First, a reconstruction constraint mechanism is introduced, utilizing a reconstruction network to learn reconstruction only for known category samples. This ensures high-quality reconstruction for known categories and significant reconstruction errors for unknown categories. The original and reconstructed spectra are then concatenated to form discriminative spectral pairs, explicitly amplifying the differences between known and unknown categories in the feature space. Second, a prototype-guided classification strategy is proposed. Learnable feature prototypes are set for each known category. Classification decisions are made by calculating the distance between sample features and each prototype, causing known category features to cluster towards their respective prototypes in a compact distribution. Simultaneously, open space is naturally preserved between prototypes, facilitating the effective rejection of unknown category samples. During training, the reconstruction loss and prototype learning loss are jointly optimized, ensuring the model balances reconstruction quality and discriminative performance for known categories. During testing, the model determines whether a sample is known or unknown based on whether the distance between its features and the nearest prototype exceeds a threshold. In summary, this application achieves high-precision recognition of known categories and effective rejection of unknown categories using only known categories for training, adapting to open scenarios.

[0026] The following description, in conjunction with the accompanying drawings, details the spectral recognition method based on reconstructed prototypes provided in this application, through specific embodiments and application scenarios.

[0027] Reference Figure 1 As shown, Figure 1 This is a flowchart illustrating the steps of a spectral recognition method based on prototype reconstruction guidance provided in an embodiment of this application. Figure 1 As shown, the method may include steps S110 to S170: Step S110: Obtain training spectral samples of known categories, wherein the training spectral samples are spectral data collected for substances of known categories.

[0028] In this step, training spectral samples refer to pre-collected spectral data labeled with categories, such as Raman or infrared spectra of known pathogens, chemical substances, or biomarkers. Each training spectral sample corresponds to a known category (e.g., "E. coli," "glucose," etc.) and is used to train the model, enabling the model to learn the intrinsic characteristics of the known category's spectra.

[0029] Step S120: Input the training spectral samples into the reconstruction network for reconstruction processing to obtain the reconstructed spectrum.

[0030] In this step, the reconstruction network typically employs an autoencoder structure, including an encoder and a decoder. Its task is to encode and then decode the input training spectral samples, attempting to reconstruct a spectrum as consistent as possible with the original input. Because the reconstruction network is trained only on samples of known categories, it can achieve high-quality reconstruction (small reconstruction error) for spectral samples of known categories, while the reconstruction error for spectral samples of known categories will increase significantly.

[0031] Step S130: The reconstructed spectrum is spliced ​​with the training spectral sample to construct a discriminative spectral pair.

[0032] In this step, the training spectral samples and the reconstructed spectra are concatenated along the channel dimension to form discriminative spectral pairs, thus explicitly preserving the reconstructed difference information. For known categories, the reconstructed spectra are very similar to the training spectral samples; for unknown categories, the differences are significant. Therefore, the discriminative spectral pairs formed through this concatenation method can explicitly characterize the reconstructed difference information, thereby effectively widening the distribution difference between known and unknown categories in the feature space and improving the ability to discriminate and reject unknown categories.

[0033] Step S140: Input the discriminative spectral pair into the feature extractor to extract latent feature representations.

[0034] In this step, the feature extractor (also known as the feature encoder) is a deep neural network (such as a convolutional neural network or a multilayer perceptron) responsible for mapping the concatenated discriminative spectral pairs to a low-dimensional feature space, obtaining a latent feature representation. This latent feature representation contains key information about the original training spectral samples and the differences in the reconstructed spectra, which is used for subsequent classification decisions. The specific network structure of the feature extractor can be flexibly designed according to the type of spectral data.

[0035] Step S150: Set a learnable feature prototype for each known category, and generate a classification prediction result based on the distance between the latent feature representation and each feature prototype; wherein, the feature prototype is used to characterize the central position of the corresponding known category in the feature space.

[0036] In this step, the feature prototype is a trainable parameter vector, with one feature prototype corresponding to each known category, initially generated randomly. In the feature space, the feature prototype represents the ideal center point of that category. The distance (such as Euclidean distance or cosine distance) between the latent feature representation and each feature prototype is calculated; the closer the distance, the higher the probability of belonging to that category, thus obtaining the classification prediction result. This distance-based classification models the similarity relationship between sample features and the feature prototypes of the categories, making the known categories form a more compact and clearly defined distribution in the feature space, while naturally preserving open space between feature prototypes, which is beneficial for distinguishing and rejecting samples of unknown categories.

[0037] Step S160: Based on the reconstruction difference between the reconstructed spectrum and the training spectral sample, and the classification difference between the classification prediction result and the true label, jointly optimize the reconstruction network, the feature extractor, and the feature prototype to obtain the spectral recognition model.

[0038] The reconstruction difference can be measured using mean squared error, while the classification difference can be measured using cross-entropy. A joint loss function is constructed based on both, and the parameters of the reconstruction network, feature encoder, and feature prototypes are simultaneously updated using the backpropagation algorithm. This joint optimization enables the model to both reconstruct known samples with high quality and to cluster known sample features towards their respective prototypes, thereby improving discriminative ability.

[0039] Step S170: Input the spectral sample to be identified into the spectral recognition model to obtain the classification and recognition result; the classification and recognition result is used to indicate whether the spectral sample to be identified belongs to a known category or an unknown category.

[0040] During the inference phase, the spectral sample to be identified is input into the trained spectral recognition model. The model uses the optimized reconstruction network, feature encoder, and feature prototype to perform forward computation on the sample and output the classification result. This result can indicate whether the sample belongs to a specific class within a known category, or whether it is classified as an unknown category and rejected.

[0041] The technical solution of this embodiment, by combining reconstruction constraints and prototype guidance, achieves high-precision recognition of known categories and effective rejection of unknown categories under the condition of training only with known category samples. Specifically, the reconstruction constraint mechanism amplifies the difference in reconstruction error between known and unknown samples, and the discriminative spectrum explicitly encodes this difference, enhancing the discriminative power of the features; prototype-guided classification enables the known category features to cluster compactly, and the prototypes naturally form an open space, providing a natural basis for rejecting unknown samples; joint optimization ensures the model's balance on both types of tasks, avoiding performance degradation caused by a single objective. Therefore, this method can improve the reliability and robustness of recognition in open scenarios and is suitable for practical applications such as clinical diagnosis, food safety testing, and environmental monitoring.

[0042] In an optional embodiment, the reconstruction network adopts an autoencoder structure, including an encoder and a decoder; the step S120 above, "inputting the training spectral samples into the reconstruction network for reconstruction processing to obtain the reconstructed spectrum," may include steps S120-1 to S120-2: Step S120-1: The training spectral samples are mapped to the latent feature space by the encoder to obtain intermediate latent features.

[0043] The encoder typically consists of several fully connected layers, convolutional layers, or attention modules. Its function is to compress high-dimensional training spectral samples into a low-dimensional latent feature space. This intermediate latent feature (also known as the encoding vector) retains the most essential category-related structural information from the training spectral samples while removing some noise and redundancy. The dimension of the latent feature space is smaller than the length of the original spectrum (training spectral sample), which forces the encoder to learn efficient feature representations.

[0044] For example, the intermediate latent features can be represented as:

[0045] in, This represents the training spectral samples, where L represents the spectral length; Indicates encoder, Represents the learnable parameters of the encoder. This is an intermediate potential feature.

[0046] Step S120-2: The training spectral samples are reconstructed by the decoder based on the intermediate latent features to obtain the reconstructed spectrum.

[0047] The decoder, typically symmetrical to the encoder, progressively decompresses intermediate latent features, ultimately outputting a reconstructed spectrum with the same dimensions as the training spectral samples. The decoder learns the transformation from latent features back to the original data (training spectral samples) space.

[0048] For example, the reconstructed spectrum can be represented as:

[0049] in, Indicates decoder, These represent the learnable parameters of the decoder; This indicates the reconstructed spectrum.

[0050] Because the reconstruction network is trained using only training spectral samples of known categories, it can accurately reconstruct the latent features of known samples, but it is difficult to accurately reconstruct unknown samples outside the distribution, thus resulting in a significant difference in reconstruction error.

[0051] The technical solution of this embodiment compresses high-dimensional spectra into low-dimensional intermediate latent features through an encoder, effectively extracting the main structural information of the data and reducing the subsequent computational complexity. The latent features are reconstructed through a decoder, enabling the model to learn the inherent distribution characteristics of samples of known categories. The symmetrical design of the encoder and decoder facilitates stable training, and the calculation of reconstruction error can be directly used to measure the degree of matching between samples and known categories, providing a reliable basis for distinguishing between known and unknown categories.

[0052] In an optional embodiment, step S140 above, "inputting the discriminative spectral pair into the feature extractor to extract latent feature representations," may include steps S140-1 to S140-2: Step S140-1: Perform a stop gradient operation on the reconstructed spectral portion of the discriminative spectral pair.

[0053] The gradient-stopping operation is a technique to block gradient flow during the backpropagation of a neural network. Specifically, during forward computation, the values ​​of the reconstructed spectrum participate normally in the calculations, but during backpropagation, the gradient is not passed forward to the reconstruction network through the reconstructed spectrum. This means that the classification error will not affect the update of the reconstruction network; the reconstruction network is only supervised by the reconstruction error. The purpose of performing the gradient-stopping operation is to prevent the optimization of subsequent classification modules from interfering with the reconstruction network's learning of the reconstructed spectrum of known categories, thereby ensuring that the reconstruction network can independently and stably learn the intrinsic distribution characteristics of known categories.

[0054] Step S140-2: Input the discriminative spectral pair after the stopping gradient operation into the feature extractor to extract the latent feature representation.

[0055] After the gradient operation is stopped, the discriminative spectral pairs are fed into the feature extractor. The feature extractor performs forward computation as usual, extracting latent feature representations for classification. Since the gradient has been blocked in the reconstructed spectrum part, the gradient updates of the feature extractor and subsequent modules will not affect the parameters of the reconstructed network in reverse, but the values ​​of the reconstructed spectrum still participate in feature extraction, thus preserving the reconstruction difference information.

[0056] For example, the latent features are represented as:

[0057] in, Representation of latent features; For feature extractor, Represents the learnable parameters of the feature extractor; This indicates that the gradient operation has been stopped. This represents the discriminative spectral pair.

[0058] The technical solution of this embodiment introduces a stopping gradient operation into the reconstructed spectrum part of the discriminative spectral pair, decoupling the optimization objective of the reconstruction network from that of the classification network. This allows the reconstruction network to be guided only by the reconstruction loss, focusing on learning high-quality reconstructions of known class samples. It avoids interference from the backpropagation of the prototype learning loss to the reconstruction network, thus maintaining the effectiveness of the reconstruction error in distinguishing known / unknown classes. At the same time, the numerical values ​​of the reconstructed spectrum still participate in feature extraction, ensuring that the reconstruction difference information in the discriminative spectral pair can be utilized by the feature encoder, achieving a balance between information sharing and training stability.

[0059] In an optional embodiment, step S150 above, "generating classification prediction results based on the distance between the latent feature representations and each feature prototype," may include steps S150-1 to S150-2: Step S150-1: Calculate the distance between the latent feature representation and each feature prototype to obtain a distance vector; wherein the distance is Euclidean distance or cosine distance.

[0060] Specifically, each known category k corresponds to a learnable feature prototype. Calculate the latent feature representation With all feature prototypes The distance between them is used to obtain the distance vector. Each element in the distance vector is the distance between the latent feature representation and a feature prototype. Taking Euclidean distance as an example, the distance between the latent feature representation and the prototype is... The distance between each feature prototype can be represented as... .

[0061] Step S150-2: Negate each element in the distance vector and input it into the Softmax function to convert it into a prediction probability vector for the corresponding category, which is used as the classification prediction result.

[0062] Since smaller distances indicate a closer sample to the feature prototype (higher probability of belonging to that category), and the Softmax function is typically used to handle inputs where higher scores correspond to higher probabilities, we first negate each distance, ensuring that categories with smaller distances receive higher scores. This is then input into the Softmax function, converting it into a predicted probability vector for the corresponding category, i.e.:

[0063] in, Let represent the predicted probability vector of a training spectral sample belonging to the i-th category. This represents the distance between the latent feature and the feature prototype corresponding to the i-th category. Finally, the category with the highest probability is selected as the classification prediction result.

[0064] The technical solution of this embodiment calculates the distance between the latent feature representation and the feature prototype, so that there are naturally uncovered areas between the prototypes, providing a discrimination space for unknown category samples; after negating the distance, it is transformed by Softmax to obtain the probability output, so that the classification result has a clear probabilistic interpretation, which is convenient for subsequent rejection threshold setting and decision fusion.

[0065] In an optional embodiment, step S160 above, "jointly optimizing the reconstruction network, the feature extractor, and the feature prototype based on the reconstruction difference between the reconstructed spectrum and the training spectral samples, and the classification difference between the classification prediction result and the true label," may include steps S160-1 to S160-3: Step S160-1: Calculate the reconstruction loss based on the reconstruction difference between the reconstructed spectrum and the training spectrum sample, wherein the reconstruction difference is expressed using the mean square error loss function.

[0066] For example, reconstruction loss The Mean Squared Error (MSE) loss function is used, and its calculation formula is as follows:

[0067] in, For batch size, To train spectral samples, For reconstructing the spectrum, let L2 norm be denoted. This loss is used only to update the parameters of the reconstruction network (encoder and decoder).

[0068] Step S160-2: Calculate the prototype learning loss based on the classification difference between the classification prediction result and the true label. The prototype learning loss adopts the cross-entropy loss function.

[0069] For example, prototype learning loss The cross-entropy loss function is used, and its calculation formula is as follows:

[0070] in, Represents the actual category label, This represents the predicted probability vector (i.e., the classification prediction result) of the training spectral sample belonging to the i-th category. Cross-entropy loss guides features to cluster towards their corresponding prototypes while simultaneously widening the distance between features of different categories, resulting in a compact and highly separable distribution of known categories in the feature space.

[0071] Step S160-3: Update the parameters of the reconstruction network based on the reconstruction loss, and update the parameters of the feature extractor and the feature prototype based on the prototype learning loss.

[0072] This step employs a joint optimization but parameter decoupling update strategy. Specifically, the reconstruction loss, with its gradient calculated via backpropagation, is used only to update the parameters of the reconstruction network (encoder and decoder) without affecting the feature extractor and feature prototypes. The prototype learning loss, with its gradient calculated via backpropagation, is used to update the parameters of the feature extractor and all learnable feature prototypes. Since a gradient-stopping operation has been performed on the reconstructed spectrum, the gradient of the prototype learning loss is not propagated to the reconstruction network.

[0073] The technical solution adopted in this embodiment effectively drives the reconstruction network to accurately reconstruct known category samples, amplifying the difference between known and unknown reconstruction errors; the cross-entropy prototype learning loss guides known category features to cluster towards their respective prototypes, forming a compact category distribution; the parameter update has a clear division of labor, avoiding training instability caused by gradient competition.

[0074] In an optional embodiment, step S170 above, "inputting the spectral sample to be identified into the spectral identification model to obtain the classification and identification result," may include steps S170-1 to S170-4: Step S170-1: Input the spectral sample to be identified into the reconstruction network and feature extractor in the spectral recognition model in sequence to obtain the potential features for identification.

[0075] During the inference phase, the spectral sample to be identified first passes through a trained reconstruction network to obtain a reconstructed spectrum. Then, the spectral sample to be identified is concatenated with the reconstructed spectrum to form a discriminative spectral pair, which is then input into a feature extractor to extract the latent recognition features of the spectral sample to be identified. These latent recognition features contain the original spectral information (the spectral sample to be identified) and the reconstructed difference information.

[0076] Step S170-2: Calculate the distance between the identified potential feature and each optimized feature prototype, and determine the minimum distance; the minimum distance characterizes the proximity of the spectral sample to be identified to the most similar category among all known categories.

[0077] In this step, the distance between the identified latent features and the feature prototypes of each known category obtained during the training phase is calculated. The distance metric can be Euclidean distance or cosine distance. A set of distance values ​​is obtained after calculation, and the minimum value is found from this set.

[0078] Step S170-3: If the minimum distance is greater than a preset threshold, the spectral sample to be identified is determined to be of an unknown category.

[0079] The preset threshold is a predetermined constant used to distinguish between known and unknown categories. The preset threshold can be flexibly adjusted according to the actual application scenario. In scenarios with high safety requirements (such as medical diagnosis), a lower threshold can be set to reduce the risk of missed diagnoses, while in scenarios with high accuracy requirements, a higher threshold can be set to reduce false alarms.

[0080] When the minimum distance is greater than the preset threshold, it indicates that the spectral sample to be identified is far away from the feature prototypes of all known categories in the feature space. That is, the spectral sample to be identified is also significantly different from the closest known category. Therefore, it is determined that the sample does not belong to any known category and belongs to an unknown category.

[0081] Step S170-4: If the minimum distance is not greater than a preset threshold, then the spectral sample to be identified is determined to be a known category corresponding to the minimum distance.

[0082] When the minimum distance is not greater than a preset threshold, it indicates that the spectral sample to be identified is sufficiently close to the feature prototype of a certain known category in the feature space. Therefore, the sample is determined to belong to the known category corresponding to that feature prototype. The specific category label is the category corresponding to the minimum distance. At this time, the model outputs the specific category name or identifier.

[0083] The technical solution of this embodiment uses a trained feature prototype as a reference center for known categories, which can complete open set recognition without additional training of a classifier; it achieves effective rejection of unknown categories by means of a distance threshold, while retaining the high-precision recognition capability of known categories; the threshold is adjustable to adapt to the security requirements of different scenarios.

[0084] In one optional embodiment, the training spectral samples and the spectral samples to be identified are Raman spectral data or infrared spectral data; the method is applied to an edge-end spectral recognition device.

[0085] In this embodiment, edge-end spectral recognition devices refer to computing devices located close to the data source, such as portable Raman spectrometers, handheld infrared detectors, and embedded spectral analysis modules. These devices offer advantages such as low latency, low bandwidth consumption, and data privacy protection. This method has low computational complexity, making it suitable for deployment on resource-constrained edge devices to achieve real-time, on-site spectral recognition. In practical applications, offline training can be performed using training spectral samples of known categories to obtain a spectral recognition model. During on-site testing, the device collects the spectral samples to be recognized, calls the spectral recognition model to complete forward computation and rejection determination, without needing to transmit data to the cloud, thus ensuring real-time performance and data security.

[0086] like Figure 2 As shown, Figure 2This is an overall architecture diagram of a spectral recognition method based on prototype reconstruction guidance provided in this application embodiment. Specifically, the overall process of this solution can be divided into a training phase and a testing phase.

[0087] Training Phase: Training spectral samples of known categories are acquired and input into the reconstruction network (including encoder and decoder). The reconstruction network encodes and decodes the input training spectral samples, outputting reconstructed spectra. The mean squared error between the training spectral samples and the reconstructed spectra is calculated as the reconstruction loss. Simultaneously, the training spectral samples and the reconstructed spectra are concatenated (cat) along the channel dimension to form discriminative spectral pairs, and a gradient-stopping operation is performed on the reconstructed spectral portion to prevent prototype learning loss from interfering with the optimization of the reconstruction network. Subsequently, the discriminative spectral pairs are input into the feature extractor to extract latent feature representations. A learnable feature prototype is set for each known category, and the distance between the latent feature representation and each feature prototype is calculated. The negative distance is converted into a classification prediction probability vector by Softmax, and the cross-entropy loss is calculated with the true label as the prototype learning loss. Finally, the reconstruction loss and the prototype learning loss are added to form the joint loss. The parameters of the reconstruction network, feature extractor, and feature prototypes are jointly optimized through backpropagation, enabling the reconstruction network to reconstruct known spectra with high quality, while allowing known category features to cluster towards their respective prototypes, naturally forming open spaces between prototypes.

[0088] Testing Phase: The spectral sample to be identified is input into the trained reconstruction network and feature extractor to obtain potential features for identification. The distance between this feature and all known class prototypes is calculated, and the minimum distance is found. If the minimum distance is greater than a preset threshold, it is determined to be an unknown category and rejected; otherwise, it is determined to be a known category corresponding to the minimum distance.

[0089] This method amplifies the difference between known and unknown samples by reconstructing constraints and achieves open set classification through prototype guidance. The synergy of these two approaches enables the model to reliably identify known categories and effectively reject unknown categories in open scenarios by training only with known categories.

[0090] It is understood that the spectral recognition method based on reconstructed prototypes provided in this application can be widely applied to substance detection and identification tasks in various open scenarios. Specifically, in clinical diagnostic scenarios, this method can be used for rapid pathogen detection. For example, by training a model using Raman spectroscopy of known common pathogens (such as Escherichia coli and Staphylococcus aureus), when a novel or variant strain not included in the training library appears in the test sample, the model can accurately identify known strains and reject unknown strains, avoiding antibiotic abuse or delayed treatment due to misjudgment. In food safety testing scenarios, this method can be used for screening harmful substances in food. For example, by training a model using Raman / infrared spectroscopy of known common pesticides or additives, when an unknown pollutant is detected, the model issues an alarm signal, prompting further testing and reducing food safety risks. In environmental monitoring scenarios, this method can be used for identifying pollutants in water or air. For example, by training a model using the spectral characteristics of known common pollutants, unknown chemical components can be effectively distinguished and prompt for verification, improving the level of monitoring automation. In addition, this method requires little computation and is suitable for edge deployment. It can be integrated into portable spectrometers, handheld detection devices, or embedded analysis modules to meet the needs of real-time on-site detection.

[0091] This application also provides a spectral recognition device based on reconstructed prototype guidance, referring to... Figure 3 As shown, Figure 3 This is a schematic diagram of a spectral recognition device based on a reconstructed prototype-guided approach, provided in an embodiment of this application. The device includes: The sample acquisition module 310 is used to acquire training spectral samples of known categories, wherein the training spectral samples are spectral data collected for substances of known categories; The spectral reconstruction module 320 is used to input the training spectral samples into the reconstruction network for reconstruction processing to obtain the reconstructed spectrum; The spectral pair construction module 330 is used to splice the reconstructed spectrum with the training spectral sample to construct a discriminative spectral pair; Feature extraction module 340 is used to input the discriminative spectral pair into the feature extractor to extract latent feature representations; The result prediction module 350 is used to set a learnable feature prototype for each known category and generate a classification prediction result based on the distance between the latent feature representation and each feature prototype; wherein, the feature prototype is used to characterize the central position of the corresponding known category in the feature space; The model optimization module 360 ​​is used to jointly optimize the reconstruction network, the feature extractor, and the feature prototype based on the reconstruction difference between the reconstructed spectrum and the training spectral samples, and the classification difference between the classification prediction result and the true label, to obtain a spectral recognition model. The category recognition module 370 is used to input the spectral sample to be recognized into the spectral recognition model to obtain the classification recognition result; the classification recognition result is used to indicate whether the spectral sample to be recognized belongs to a known category or an unknown category.

[0092] In an optional embodiment, the reconstruction network employs an autoencoder structure, including an encoder and a decoder; the spectral reconstruction module 320 is specifically used for: The training spectral samples are mapped to the latent feature space by an encoder to obtain intermediate latent features; The reconstructed spectrum is obtained by reconstructing the training spectral samples using the intermediate latent features through a decoder.

[0093] In an optional embodiment, the feature extraction module 340 is specifically used for: A gradient-stopping operation is performed on the reconstructed spectral portion of the discriminative spectral pair; The discriminative spectral pairs after the gradient stopping operation are input into the feature extractor to extract the latent feature representation.

[0094] In an optional embodiment, the result prediction module 350 is specifically used for: Calculate the distance between the latent feature representation and each feature prototype to obtain a distance vector; wherein the distance is Euclidean distance or cosine distance; The negative of each element in the distance vector is then input into the Softmax function to convert it into a predicted probability vector for the corresponding category, which serves as the classification prediction result.

[0095] In an optional embodiment, the model optimization module 360 ​​is specifically used for: Based on the reconstruction difference between the reconstructed spectrum and the training spectrum samples, the reconstruction loss is calculated using the mean squared error loss function. Based on the classification difference between the classification prediction result and the true label, the prototype learning loss is calculated, and the prototype learning loss adopts the cross-entropy loss function. The parameters of the reconstruction network are updated based on the reconstruction loss, and the parameters of the feature extractor and the feature prototype are updated based on the prototype learning loss.

[0096] In an optional embodiment, the category identification module 370 is specifically used for: The spectral samples to be identified are sequentially input into the reconstruction network and feature extractor in the spectral recognition model to obtain potential identification features; Calculate the distance between the identified latent feature and each optimized feature prototype, and determine the minimum distance; the minimum distance characterizes the proximity of the spectral sample to be identified to the most similar category among all known categories; If the minimum distance is greater than a preset threshold, the spectral sample to be identified is determined to be of an unknown category; If the minimum distance is not greater than a preset threshold, then the spectral sample to be identified is determined to be a known category corresponding to the minimum distance.

[0097] In one optional embodiment, the training spectral samples and the spectral samples to be identified are Raman spectral data or infrared spectral data; the method is applied to an edge-end spectral recognition device.

[0098] It is understood that the spectral recognition device based on reconstructed prototype guidance in the embodiments of this application can realize the spectral recognition method based on reconstructed prototype guidance in the above embodiments. The spectral recognition device based on reconstructed prototype guidance has the same advantages as the spectral recognition method based on reconstructed prototype guidance in the prior art, and will not be repeated here.

[0099] This application also provides an electronic device, see embodiments thereof. Figure 4 , Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. For example... Figure 4 As shown, the electronic device 400 includes a memory 410 and a processor 420. The memory 410 and the processor 420 are connected via a bus for communication. The memory 410 stores a computer program that can run on the processor 420 to implement the steps of the spectral recognition method based on reconstructed prototype guidance described in the embodiments of this application.

[0100] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the spectral recognition method based on reconstructed prototype guidance described in this application.

[0101] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the spectral recognition method based on reconstructed prototype guidance described in this application.

[0102] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

[0103] This application describes embodiments of methods and apparatus according to flowchart illustrations and / or block diagrams. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0104] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0105] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0106] Although preferred embodiments of the present application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present application.

[0107] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.

[0108] The above provides a detailed description of a spectral identification method, apparatus, device, and storage medium based on reconstructed prototype guidance provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A spectral recognition method based on prototype reconstruction guidance, characterized in that, include: Acquire training spectral samples of known categories, wherein the training spectral samples are spectral data collected for substances of known categories; The training spectral samples are input into the reconstruction network for reconstruction processing to obtain the reconstructed spectrum; The reconstructed spectrum is spliced ​​with the training spectral sample to construct a discriminative spectral pair; The discriminative spectral pair is input into the feature extractor to extract latent feature representations; For each known category, a learnable feature prototype is set, and a classification prediction result is generated based on the distance between the latent feature representation and each feature prototype; wherein, the feature prototype is used to characterize the central position of the corresponding known category in the feature space; Based on the reconstruction difference between the reconstructed spectrum and the training spectrum sample, and the classification difference between the classification prediction result and the true label, the reconstruction network, the feature extractor, and the feature prototype are jointly optimized to obtain a spectral recognition model. The spectral sample to be identified is input into the spectral recognition model to obtain the classification and recognition result; the classification and recognition result is used to indicate whether the spectral sample to be identified belongs to a known category or an unknown category.

2. The method according to claim 1, characterized in that, The reconstructed network adopts an autoencoder structure, including an encoder and a decoder; The training spectral samples are input into the reconstruction network for reconstruction processing to obtain the reconstructed spectrum, including: The training spectral samples are mapped to the latent feature space by an encoder to obtain intermediate latent features; The reconstructed spectrum is obtained by reconstructing the training spectral samples using the intermediate latent features through a decoder.

3. The method according to claim 1, characterized in that, The discriminative spectral pair is input into the feature extractor to extract latent feature representations, including: A gradient-stopping operation is performed on the reconstructed spectral portion of the discriminative spectral pair; The discriminative spectral pairs after the gradient stopping operation are input into the feature extractor to extract the latent feature representation.

4. The method according to claim 1, characterized in that, Based on the distance between the latent feature representations and each feature prototype, classification prediction results are generated, including: Calculate the distance between the latent feature representation and each feature prototype to obtain a distance vector; wherein the distance is Euclidean distance or cosine distance; The negative of each element in the distance vector is then input into the Softmax function to convert it into a predicted probability vector for the corresponding category, which serves as the classification prediction result.

5. The method according to claim 4, characterized in that, Based on the reconstruction difference between the reconstructed spectrum and the training spectrum samples, and the classification difference between the classification prediction result and the true label, the reconstruction network, the feature extractor, and the feature prototype are jointly optimized, including: Based on the reconstruction difference between the reconstructed spectrum and the training spectrum samples, the reconstruction loss is calculated using the mean squared error loss function. Based on the classification difference between the classification prediction result and the true label, the prototype learning loss is calculated, and the prototype learning loss adopts the cross-entropy loss function. The parameters of the reconstruction network are updated based on the reconstruction loss, and the parameters of the feature extractor and the feature prototype are updated based on the prototype learning loss.

6. The method according to claim 1, characterized in that, The spectral sample to be identified is input into the spectral recognition model to obtain the classification and recognition results, including: The spectral samples to be identified are sequentially input into the reconstruction network and feature extractor in the spectral recognition model to obtain potential identification features; Calculate the distance between the identified latent feature and each optimized feature prototype, and determine the minimum distance; the minimum distance characterizes the proximity of the spectral sample to be identified to the most similar category among all known categories; If the minimum distance is greater than a preset threshold, the spectral sample to be identified is determined to be of an unknown category; If the minimum distance is not greater than a preset threshold, then the spectral sample to be identified is determined to be a known category corresponding to the minimum distance.

7. The method according to any one of claims 1-6, characterized in that, The training spectral samples and the spectral samples to be identified are Raman spectral data or infrared spectral data; the method is applied to edge-end spectral recognition devices.

8. A spectral recognition device based on prototype reconstruction guidance, characterized in that, include: The sample acquisition module is used to acquire training spectral samples of known categories, wherein the training spectral samples are spectral data collected for substances of known categories; The spectral reconstruction module is used to input the training spectral samples into the reconstruction network for reconstruction processing to obtain the reconstructed spectrum; The spectral pair construction module is used to stitch the reconstructed spectrum with the training spectral samples to construct discriminative spectral pairs; The feature extraction module is used to input the discriminative spectral pair into the feature extractor and extract latent feature representations; The result prediction module is used to set a learnable feature prototype for each known category and generate a classification prediction result based on the distance between the latent feature representation and each feature prototype; wherein, the feature prototype is used to characterize the central position of the corresponding known category in the feature space; The model optimization module is used to jointly optimize the reconstruction network, the feature extractor, and the feature prototype based on the reconstruction difference between the reconstructed spectrum and the training spectral samples, and the classification difference between the classification prediction result and the true label, to obtain a spectral recognition model. The category recognition module is used to input the spectral sample to be recognized into the spectral recognition model to obtain the classification recognition result; the classification recognition result is used to indicate whether the spectral sample to be recognized belongs to a known category or an unknown category.

9. 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, it implements the steps of the spectral recognition method based on reconstructed prototype guidance as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The readable storage medium stores a program or instructions that, when executed by a processor, implement the steps of the spectral recognition method based on reconstructed prototype guidance as described in any one of claims 1-7.