A raman spectrum bacteria classification method and system based on contrast learning

By employing contrastive learning and data augmentation techniques, a deep neural network was trained using unlabeled Raman spectroscopy data. This solved the problems of high dependence on labeled data and insufficient generalization performance in existing Raman spectroscopy classification methods, achieving more efficient and accurate bacterial classification.

CN117219176BActive Publication Date: 2026-02-13XIAMEN UNIV +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311073578.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-24
Publication Date
2026-02-13
Estimated Expiration
2043-08-24

AI Technical Summary

Technical Problem

Existing Raman spectroscopy-based bacterial classification methods require a large amount of labeled data for training, which is costly, and the models have limited generalization performance, making them unsuitable for different instruments and diverse detection tasks.

Method used

We employ a self-supervised learning approach, particularly contrastive learning, using unlabeled Raman spectral data for pre-training. We then construct a self-supervised task through a contrastive learning strategy, extract spectral features, and combine data augmentation techniques to generate new training samples, thereby optimizing the deep neural network model.

Benefits of technology

It reduces the need for labeled data, improves the model's generalization performance and adaptability, lowers training costs, and enhances the accuracy and robustness of spectral classification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117219176B_ABST
    Figure CN117219176B_ABST
Patent Text Reader

Abstract

The application discloses a Raman spectrum bacterial classification method and system based on contrast learning, and comprises the following steps: a data preprocessing step, in which original Raman spectra in a pre-training data set, a re-training data set and a test data set are subjected to denoising, background removal and normalization processing; a data enhancement step, in which the pre-processed pre-training data set is subjected to enhancement processing through random spectrum segment zeroing or Gaussian noise adding operation, and a pre-training data sample pair is constructed; a model pre-training step, in which a deep neural network is trained based on the data-enhanced pre-training data set by using contrast learning, and a pre-training model is obtained; a model re-training step, in which the pre-training model with an added classification layer is adjusted by using the pre-processed re-training data set, and a trained classification model is obtained; and a model testing step, in which the pre-processed test data set is input into the trained classification model, and a Raman spectrum bacterial classification result is obtained. The application improves the spectrum classification efficiency and accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of spectral classification technology, specifically to a Raman spectroscopy-based bacterial classification method and system based on contrastive learning. Background Technology

[0002] For elderly and frail patients and in large-scale bacterial infection events, rapid and accurate identification of bacterial pathogens is crucial for rapid treatment and improved patient survival. Traditional bacterial identification methods, such as culture and nucleic acid-based amplification, suffer from low sensitivity, high cost, and slow processing time. Rapid identification methods for bacterial pathogens still require further development. Raman spectroscopy, as a non-destructive analytical technique, can rapidly obtain the biochemical characteristics of individual bacteria. Combined with machine learning techniques, it can provide an automated, rapid, and accurate classification scheme, effectively detecting subtle spectral features of bacterial pathogens.

[0003] Existing methods mostly involve collecting spectral samples and labeling them with corresponding bacterial pathogen categories, then using the data as a training set to train machine learning algorithms. After training, the model can be applied to identify the category of Raman test samples. For example, ResNet is used to achieve rapid pathogen identification [1], scale-adaptive neural networks are used for bacterial identification [2], and lightweight convolutional neural networks are used for bacterial classification [3]. However, these methods have limitations. First, they usually require a large amount of labeled data for training, which is costly. Second, the scope of this high-cost model is limited, and it is only applicable to known datasets and specified instruments. This means that when facing new detection tasks, diverse instruments, or spectral sources, existing data and machine learning models cannot be directly reused, and additional costs and time are required to re-collect data and retrain the model. The human, material, and time costs brought by a large amount of standard data affect the scalability and economy of the method.

[0004] To overcome these limitations and achieve stronger model generalization performance when facing Raman spectral data from different instruments or different detection tasks, it is necessary to make full use of existing data resources and enhance the model's ability to cope with diverse data. This patent applies self-supervised algorithms to spectral classification tasks and explores new methods that can effectively utilize the inherent characteristics of data to better solve the Raman spectral data classification problem. Self-supervised learning is a learning method that does not require human labels for supervision. By utilizing the inherent structure and information of the data itself, it automatically generates appropriate labels or tasks to achieve meaningful feature learning and data representation. Currently, self-supervised learning methods have shown wide application in many other fields. For example, in the field of computer vision, self-supervised learning methods are used for image [4], object detection [5], and other tasks. In the field of natural language processing, self-supervised learning methods are used for text classification [6], machine translation [7], and other tasks. Therefore, self-supervised learning provides a new approach to breaking through the limitations of supervised learning in Raman spectral classification: by mining potential feature representations from a large amount of unlabeled raw data, a more flexible and generalizable feature learning and data classification method is achieved. This not only reduces the complexity of parameter adjustment and the need for a large amount of labeled data, but also reduces costs and time constraints. At the same time, self-supervised learning can also utilize the inherent structure and features of the data to train by automatically generating supervision signals, improving the model's generalization and adaptability.

[0005] Based on the idea and method of self-supervised learning, contrastive learning is used as a way to train self-supervised tasks by comparing the similarities and differences between samples. Although contrastive learning based on the idea of self-supervised learning has not been widely applied in Raman spectral classification, its potential application prospects are worth exploring. Through contrastive learning, more efficient spectral feature representations can be learned from unlabeled raw data, providing a new direction for breaking through the limitations of supervised learning in Raman spectral classification. Spectra of different classes show obvious differences, while spectra of the same class are similar. Contrastive learning can fully utilize this inter-class difference and intra-class similarity to construct self-supervised tasks for Raman spectra, enabling neural networks to obtain more discriminative features and enhancing their generalization performance. Contrastive learning does not require labeled data and is suitable for large-scale unlabeled spectral data. It can handle classification problems in a more flexible and efficient way, maximize information training, improve performance, and reduce labeling costs. In the subsequent retraining phase, this method can also be effectively extended to specific classification tasks to enhance the model's generalization ability, thereby achieving better classification results. [1] Ho, CS., Jean, N., Hogan, C.A. et al. Rapid identification of pathogenic bacteria using Raman spectroscopy and deep learning. Nat Commun 10, 4927 (2019).

[0006] [2] Deng L, Zhong Y, Wang M, et al. Scale-Adaptive Deep Model for Bacterial Raman Spectra Identification. IEEE J BIOMED HEALTH 26, 1, 369-378, (2022).

[0007] [3] Zhou B, Tong Y, Zhang R, et al. RamanNet: a lightweight convolutional neural network for bacterial identification based on Raman spectra. RSC ADVANCES 12, 40, (2022).

[0008] [4] Chen, T.; Kornblith, S.; Norouzi, M, et al. A simple framework for contrastive learning of visual representations. ICML, 13-18, 1597-1607, (2020).

[0009] [5] Tian, Y.; Krishnan, D.; Isola, P. Contrastive multiview coding. ECCV, 23-28, 776-794, (2020).

[0010] [6] Radford A, Kim J W, Hallacy C, et al. Learning transferable visual models from natural language supervision, International conference on machine learning. PMLR, 8748-8763, (2021).

[0011] [7] Lafuente B, Downs R T, Yang H, et al. The power of databases: the RRUFF project. In: Highlights in Mineralogical Crystallography, T Armbruster and R M Danisi, eds. Berlin, Germany, W. De Gruyter, 1-30, (2015). SUMMARY

[0012] The application provides a Raman spectrum bacterial classification method and system based on contrast learning, which utilizes a large-scale unlabeled Raman spectrum dataset, combines a contrast learning method and a training strategy, can effectively extract and utilize information in the spectrum data, and improves spectrum classification efficiency and precision.

[0013] The application adopts the following technical solutions:

[0014] In one aspect, a Raman spectrum bacterial classification method based on contrast learning comprises:

[0015] A data preprocessing step is performed to denoise, remove background and normalize the original Raman spectrum in a pre-training dataset, a re-training dataset and a test dataset; wherein the pre-training dataset is composed of unlabeled spectrum data, and the re-training dataset is composed of labeled spectrum data;

[0016] A data enhancement step is performed to enhance the pre-processed pre-training dataset spectrum by random spectrum segment zeroing or Gaussian noise adding operation to obtain a data-enhanced pre-training dataset;

[0017] A model pre-training step is performed to train a deep neural network based on the data-enhanced pre-training dataset using a contrast learning strategy, optimize the model using a contrast loss function, and obtain a pre-training model;

[0018] A model re-training step is performed to adjust the pre-training model with an added classification layer using the pre-processed re-training dataset to obtain a trained classification model;

[0019] A model testing step is performed to input the pre-processed test dataset into the trained classification model to obtain a Raman spectrum bacterial classification result.

[0020] Preferably, the data preprocessing step specifically comprises the following steps:

[0021] (1) Denoising each original Raman spectrum;

[0022] (2) Background removal operation is performed on each denoised Raman spectrum, a background model is fitted and subtracted from the original spectrum, and the spectrum signal is retained;

[0023] (3) Normalization is performed on each background-removed Raman spectrum, and the intensity range of the spectrum is mapped to a consistent interval [0, 1].

[0024] Preferably, the random spectrum segment zeroing operation is as follows:

[0025] A one-dimensional vector x is used to record the Raman signal intensity; let a set of preprocessed Raman spectrum data be a data set X = {x i |i = 1, 2, …, N}, where N represents the number of Raman spectrum samples contained in the data set, x i represents the i-th preprocessed Raman spectrum.

[0026] For each preprocessed Raman spectrum sample x i , a Raman shift sequence with a length of is randomly taken, and the Raman signal intensity in the segment is set to zero; where L represents the sequence length of the Raman spectrum, i.e., each Raman spectrum has L Raman signals.

[0027] Preferably, the Gaussian noise addition operation is as follows:

[0028] For each preprocessed Raman spectrum sample x i , Gaussian noise with a mean of 0 and a variance randomly in the interval [0.01, 0.05] is randomly added, and then normalized in the interval [0, 1].

[0029] Preferably, the operation of constructing a pair of pre-training samples is as follows:

[0030] (1) Positive and negative sample pair construction. In the preprocessed pre-training data set, two preprocessed Raman spectrum samples x i and x k are randomly selected, x i is taken as a positive sample, and the corresponding positive sample x i+ is obtained after data enhancement, x k is taken as a negative sample, and the corresponding negative sample x k- is obtained after data enhancement, and then a pair of pre-training positive samples and a pair of pre-training negative samples are constructed, and are represented as follows:

[0031] Positive sample pair: {x i , x i+}

[0032] Negative sample pair: {x i , x k-}

[0033] (2) Repeat the above steps to generate multiple positive-negative sample pairs for each pre-processed Raman spectrum sample, and build a set of pre-trained sample pairs for the entire pre-training data set.

[0034] Preferably, the model pre-training step specifically comprises:

[0035] Each constructed pre-training sample pair is input into the encoding layer f(·) of the deep neural network for encoding, wherein the positive sample pair {x i ,x i+} generates a new Raman spectrum representation vector {h x ,h x′}, and the negative sample pair {x i ,x k-} generates a new Raman spectrum representation vector {h x ,h k};

[0036] The Raman spectrum representation vectors generated above are input into the projection layer g(·) respectively, and the positive sample pair obtains corresponding projection vectors {z x ,z x′}, and the negative sample pair obtains projection vectors {z x ,z k};

[0037] A loss function L InfoNCE is introduced, and the neural network is trained to optimize the model parameters by minimizing the loss function to maximize the similarity of the positive sample pair and minimize the similarity of the negative sample pair.

[0038] Preferably, the encoding layer f(·) is composed of a multi-head self-attention mechanism and a hierarchical attention mechanism; and the projection layer g(·) is composed of two fully connected layers.

[0039] Preferably, the InfoNCE loss function is represented as follows:

[0040]

[0041] Wherein, L InfoNCE represents the loss function value; sim is a cosine similarity function; z x ,z x′ represents the projection vector of the positive sample pair; and z k represents the projection vector of the negative sample. , which indicates that the mutual information when k = x is not counted, τ is a set temperature parameter; and N represents the number of Raman spectrum samples contained in the data set.

[0042] The two cosine similarity functions are:

[0043]

[0044]

[0045] Preferably, the retraining model is a classification layer added to the encoder f(·) of the pre-training model as the last layer of the model to optimize the current classification task; in the model retraining step, the convolutional layers of the model are gradually unfrozen, and the hyperparameters are adjusted through the retraining process.

[0046] In another aspect, a Raman spectrum bacterial classification system based on contrast learning includes:

[0047] A data preprocessing module is configured to perform denoising, background removal, and normalization processing on original Raman spectra in a pre-training data set, a re-training data set, and a test data set; wherein the pre-training data set is composed of unlabeled spectrum data, and the re-training data set is composed of labeled spectrum data;

[0048] A data enhancement module is configured to perform enhancement processing on the preprocessed pre-training data set spectrum by randomly setting a spectrum segment to zero or adding Gaussian noise, to obtain a data-enhanced pre-training data set;

[0049] A model pre-training module is configured to train a deep neural network based on the data-enhanced pre-training data set using a contrast learning strategy, to optimize the model using a contrast loss function, and to obtain a pre-training model;

[0050] A model retraining module is configured to adjust the pre-training model with an added classification layer using the preprocessed re-training data set, to obtain a trained classification model;

[0051] A model testing module is configured to input the preprocessed test data set into the trained classification model, to obtain a Raman spectrum bacterial classification result.

[0052] The beneficial effects of the present application are as follows:

[0053] (1) The present application combines Raman spectrum pre-training with contrast learning to fully learn the feature differences in a large amount of unlabeled Raman spectrum data from different instruments and different sample categories; a large amount of unlabeled Raman spectrum data from different instruments and different sample categories is used for pre-training to fully learn and capture the differences and features between different samples in the Raman spectrum data, and more comprehensive feature representation is obtained; the pre-trained model is applied to the Raman spectrum classification of the detection task; the feature extraction capability of the model in this task is further adjusted through retraining to better meet the classification requirements. This combination of pre-training and retraining adjustment can effectively utilize the knowledge learned by the pre-training model on unlabeled data, and improve the performance of the model using contrast learning;

[0054] (2) The application utilizes large-scale unlabeled Raman spectral data sets, adopts a contrast learning strategy based on a self-supervised learning method, trains the model to distinguish similar and different to-be-tested samples; unlike traditional supervised learning, it does not require a large number of labeled sample data, but through the contrast learning method, it fully utilizes the unlabeled data for pre-training, thereby improving the utilization rate of spectral data, can effectively utilize the existing data set in the Raman spectrum, realizes the improvement of the reusability of the data set; this not only reduces the workload and cost of data labeling, but also promotes the wide application of the data set, and provides a more feasible and efficient solution for spectral data analysis and classification research;

[0055] (3) The application adopts a data enhancement method of random spectral segment zeroing and Gaussian noise adding, generates new training samples to expand the Raman spectral training data set, further enriches the training data set, improves the robustness of the model, reduces the overfitting phenomenon, and can effectively improve the accuracy and generalization ability of spectral material identification and classification.

[0056] The application will be further described in detail in combination with the drawings and examples, but the Raman spectral bacterial classification method and system based on contrast learning of the application is not limited to the examples. BRIEF DESCRIPTION OF DRAWINGS

[0057] Figure 1 The flowchart of the Raman spectral bacterial classification method based on contrast learning of the embodiment of the application;

[0058] Figure 2 The flowchart of the Raman spectral bacterial classification method based on contrast learning of the embodiment of the application;

[0059] Figure 3A schematic diagram of 30 kinds of bacterial spectrum data of the embodiment of the present application (the bacterial names are as follows: C. albicans, C. glabrata, K. aerogenes, E. coli 1, E. coli 2, E. faecium, E. faecalis 1, E. faecalis 2, E. cloacae, K. pneumoniae 1, K. pneumoniae 2, P. mirabilis, P. aeruginosa 1, P. aeruginosa 2, MSSA 1, MSSA 3, MRSA 1-isogenic, MRSA 2, MSSA 2, S. enterica, S. epidermidis, S. lugdunensis, S. marcescens, S. pneumoniae 2, S. pneumoniae 1, S. sanguinis, Group A Strep., Group B Strep., Group C Strep., Group G Strep.);

[0060] Figure 4 A structural block diagram of the Raman spectrum-based bacterial classification system of the embodiment of the present application based on contrast learning. DETAILED DESCRIPTION

[0061] The present application will be further described below through specific embodiments. It should be noted that the specific embodiments described herein are only used to facilitate the description and explanation of the specific embodiments of the present application, and do not limit the present application.

[0062] In order to make the purpose, technical solution of the present application more clear and clear, the present application will be further described below in combination with the drawings and cases. It should be understood that the cases described herein are only used to explain the present application, and do not limit the present application.

[0063] Referring to Figure 1 The Raman spectrum-based bacterial classification method based on contrast learning of the embodiment includes the following steps:

[0064] In the data preprocessing step 101, the original Raman spectrum in the pre-training data set, the re-training data set and the test data set is denoised, background removed and normalized; wherein the pre-training data set is composed of unlabeled spectrum data, and the re-training data set is composed of labeled spectrum data;

[0065] In the data enhancement step 102, the preprocessed pre-training data set spectrum is enhanced by random spectrum segment zeroing or Gaussian noise adding operation to obtain the data enhanced pre-training data set;

[0066] The model pre-training step 103 is based on the pre-training data set after data enhancement, uses a contrast learning strategy to train the deep neural network, uses a contrast loss function to optimize the model, and obtains a pre-training model;

[0067] The model re-training step 104 uses the pre-processed re-training data set to adjust the pre-training model with an added classification layer, and obtains a trained classification model;

[0068] The model testing step 105 inputs the pre-processed test data set into the trained classification model, and obtains a Raman spectrum bacterial classification result.

[0069] Specifically, as shown in Figure 2 , first, the original spectrum is denoised, background removed and normalized by preprocessing, then two similar but different spectra are randomly generated from one spectrum by data enhancement, and a pre-trained positive sample pair {x i ,x i+} and a negative sample pair {x i ,x k-} are constructed. The enhanced spectrum data is input into the encoder f(·) of the deep neural network as the pre-training data set, wherein the positive sample pair {x i ,x i+} generates new Raman spectrum representation vectors {h x ,h x′}, and the negative sample pair {x i ,x k-} generates new Raman spectrum representation vectors {h x ,h k}. The new Raman spectrum representation vectors are input into the projection layer g(·), and the positive sample pair finally obtains corresponding projection vectors {z x ,z x′}, and the negative sample pair obtains projection vectors {z x ,z k}, and the network model is optimized by comparing the similarity between each other. After the model pre-training is completed, the encoder f(·) is used and a classification layer is added, and adjustment and optimization are performed on another small re-training data set with labels, and finally the test data set is tested to obtain the final classification result C.

[0070] From the above, the present application constructs three stages of data sets: pre-training data set, re-training data set and test data set. The samples in these data sets come from different instruments and different detection tasks, which can ensure the diversity and generalization ability of the data. Among them, (1) the pre-training data set is constructed based on the training strategy of contrast learning, which contains a large amount of unlabeled spectral data. At the same time, because it comes from different instruments and deals with different detection tasks, the signal-to-noise ratio of the contained samples is also different, so the sample quality allows to exist differences. (2) The re-training data set is used for targeted re-training task of the model after pre-training, to further optimize the model performance. The label information of the samples in this data set is complete. (3) The test data set may be different from the re-training data set in sample source, but it deals with the same detection task. The main purpose of the test data set is to evaluate the classification performance and generalization ability of the re-trained model on new samples. In general, the pre-training data set provides rich spectral data to help the model learn and mine the universality and robustness of deep spectral features. The re-training data set provides labeled samples for specific tasks to optimize the performance of the model on specific classification tasks. The test data set verifies the classification accuracy and generalization ability of the model on unknown samples. By designing these three data sets, the performance of the model of the present application in different data sources, sample quality and annotation conditions is comprehensively evaluated, and the universality and robustness of the model for Raman spectrum are verified.

[0071] In the embodiment, the specific implementation of the data preprocessing step 101 is as follows.

[0072] In the data preprocessing step, first, the original Raman spectrum is denoised (specifically, the polynomial smoothing algorithm is applied to remove noise caused by instrument noise, environmental interference or sampling instability) and background removal operation is performed to improve the spectral quality, reduce the noise interference of the spectral data, enhance the stability and reliability of the spectral data, facilitate better extraction of spectral features subsequently, and reduce the adverse effects of complex matrix environment on subsequent analysis. At the same time, since the training data set contains Raman spectrum samples from different instruments and for different detection tasks (bacterial tasks and other tasks), the sample wavenumbers and signal intensities are inconsistent, in order to unify the subsequent training and improve the classification accuracy of the re-training model, normalization operation is also required. It should be noted that the data preprocessing step is performed on the spectral data sets of the pre-training, re-training and test three steps.

[0073] The original Raman spectrum sample collected on site is usually a set of two-dimensional data, with the horizontal coordinate being the wavenumber and the vertical coordinate being the spectral signal intensity corresponding to the wavenumber. Generally speaking, since the Raman spectrometer instrument acquires spectral data of the same wavenumber, a one-dimensional vector x can be used to record the signal intensity. Assuming that a set of Raman spectrum data to be processed is a data set X = {x i|i=1,2,…,N}, where N represents the number of Raman spectral samples in the dataset. i Let represent the i-th preprocessed Raman spectrum, where t = [t1, t2, ..., t]. L [] represents the Raman shift sequence, where L represents the total length of each spectral sequence, and x... i (t h ) represents the i-th Raman spectrum at t h The Raman signal intensity at wavenumber, h = 1, 2, ..., L. This is determined using the formula... Perform a normalization operation on the samples, where x u For the normalized training samples, x(t) h ) indicates that x is at displacement t h Raman signal intensity, x min and x max Let x represent the minimum and maximum Raman signal strength, respectively. Normalization can ensure uniform signal strength and prevent the characteristics of weak signals from being masked.

[0074] In this embodiment, the data augmentation step 102 is implemented as follows.

[0075] In the data augmentation step, the pre-training dataset is augmented by zeroing out random spectral bands and adding Gaussian noise to generate pre-training sample pairs. This expands the sample size of the pre-training dataset, increases the model's robustness, and improves its generalization ability. Simultaneously, to facilitate the machine learning model's study of the Raman spectral characteristics of various samples, the similarities and differences between different samples are utilized to allow the model to learn more effective and deeper feature representations. The specific data augmentation operations are as follows:

[0076] The operation of zeroing out random spectral segments: For each preprocessed Raman spectrum sample x(t), whose total sequence length is L, randomly select... The Raman shift sequence of length is defined, and the Raman signal intensity of that segment is set to zero. L represents the sequence length of the Raman spectrum, i.e., each Raman spectrum has L Raman signals.

[0077] Gaussian noise addition: For each preprocessed Raman spectrum sample x(t), a Gaussian noise distribution with a mean of 0, a variance between [0.01, 0.05], and a dimension equal to the dimension of the sample sequence is randomly generated and added to x(t). Then, normalization processing is performed in the [0, 1] interval to standardize the data and ensure its reliability.

[0078] By randomly augmenting the input data to generate a pair of similar but not identical samples, the idea of contrastive learning is used to let the model learn how to distinguish the features of different samples and retain the similar features of the same sample, so that the model learns more discriminative features, thereby improving the material recognition and classification ability of Raman spectrum.

[0079] In this embodiment, the specific implementation of the model pre-training step 103 is as follows.

[0080] In the model pre-training step, a contrastive learning method is used to train a deep neural network to learn the high-level feature representation of the augmented spectral data, and a contrastive loss function is used to optimize the model. The deep neural network fuses information of different scales in the spectral data through different size convolution kernels, and highlights important features by weighting different scale features while weakening unimportant features, which helps to improve the model's attention to key spectral information and improve the performance of spectral recognition.

[0081] Through the contrastive learning method, the similarity and difference features of the spectral data can be effectively extracted, thereby improving the accuracy of spectral material recognition and classification. Specifically, the augmented spectral data is input into the encoder f(·) of the deep neural network as the pre-training data set. For the same sample, different perturbed samples generated by data augmentation technology belong to positive samples, i.e. {x i ,x i+}, and for different sample data, the augmented samples belong to negative samples, i.e. {x i ,x k-}.

[0082] Each Raman spectrum can be regarded as a one-dimensional vector, so this embodiment uses a one-dimensional deep neural network to train it. In order to better extract and retain spectral information, the encoding layer f(·) of this embodiment is composed of multi-head self-attention mechanism and hierarchical attention mechanism. Multi-head self-attention mechanism is used to capture the information interaction between adjacent elements, which is a commonly used attention mechanism in neural networks. It maps the input sequence to multiple subspaces and processes them in parallel to extract different aspects of information, and interacts and integrates information between different heads to improve the expression and learning ability of the model. In order to fuse the local and global information of the spectral data, the network model also introduces hierarchical attention mechanism, which interacts and integrates information between different levels, and weights and fuses features of different levels to obtain more rich semantic information and improve the modeling effect. After encoding the Raman spectrum, a new Raman spectrum representation is generated (positive sample pair spectrum representation {h x ,h x′}, and negative sample pair spectrum representation {h x ,h k}), then input to the projection layer g(·) (consisting of two fully connected layers), to obtain the final output result (positive sample pair output {z)). x ,z x′}, negative sample pairs output {z x ,z k}) and compare their similarity. This embodiment uses cosine similarity to calculate the output result {z x ,z x′} and {z x ,z k The similarity between} is calculated using the cosine similarity function, as follows:

[0083]

[0084]

[0085] To optimize the feature representations learned by the model, the InfoNCE loss function is used to optimize the model parameters. This is achieved by quantifying the dependency between two vectors and maximizing the mutual information between positive and negative samples to train the neural network. Specifically, for a given sample, it is used as an "anchor." Positive samples are generated from the same sample using different data augmentation methods, while negative samples are generated from other samples using different data augmentation methods. Anchors and positive samples form positive sample pairs, and anchors and negative samples form negative sample pairs. For each positive-negative sample pair, the mutual information between the anchor and the positive / negative samples is calculated by calculating the cosine similarity, thus constructing the loss function. To minimize the loss function and optimize neural network training, the InfoNCE loss function is used to calculate the model loss. This loss function aims to improve the model's feature representation ability by minimizing the distance between the anchor and the positive sample in the feature space and maximizing the distance between the anchor and the negative sample. The formula is as follows:

[0086]

[0087] Among them, L InfoNCE Represents the loss function value; sim is the cosine similarity function; z x ,z x′ z represents the projection vector of the positive sample pair; k Represents the projection vector of the negative sample; This indicates that the mutual information when k=x is not taken into account, τ is the set temperature parameter; N represents the number of Raman spectral samples in the dataset;

[0088] By iteratively optimizing the training process, the loss function is minimized, enabling the neural network to better learn the feature representation of the samples. Since the pre-training dataset does not contain labels, the model training will optimize the model parameters based on the differences and similarities between samples. Such an optimization process helps to improve the performance and generalization ability of the model.

[0089] In this embodiment, the specific implementation of the model retraining step 104 is as follows.

[0090] In the model retraining step, the pre-trained model in the model pre-training step is specifically retrained using a small, labeled retraining dataset to achieve further optimization. A classification layer is added as the last layer of the model based on the encoder f(·) of the pre-trained model to optimize the current classification task. The process of model retraining is to gradually unfreeze the convolutional layers of the model and adjust the model to better adapt to the characteristics of the current task, achieve a balance between contrastive learning and retraining, and make the model better adapt to the new dataset, improving the generalization ability of the model.

[0091] In this embodiment, the specific implementation of the model testing step 105 is as follows.

[0092] In the model testing step, the performance and accuracy of the model are verified by predicting and evaluating the test set. Specifically, the actual clinical bacterial Raman spectrum samples are used as the samples of the test dataset, which are input into the classification model trained by the model retraining step S104. The model judges whether the output result of the sample is consistent with the true label, and calculates the accuracy and reliability of the model.

[0093] The classification method of this embodiment will be verified by experiments as follows.

[0094] The dataset used in this embodiment is shown in Table 1 and is divided into three parts: pre-training dataset, retraining dataset, and test dataset.

[0095] In the pre-training phase, the Raman spectra of the pre-training dataset come from two different public datasets (without using sample labels): (1) The RRUFF dataset comes from 5 instruments, totaling 8494 mineral Raman spectrum data; (2) The Bacteria dataset comes from 2 instruments, using 6000 bacterial Raman spectrum samples cultured in the laboratory (denoted as Bacteria-1).

[0096] In the retraining and testing phases, the Raman spectral data is typically used for different detection tasks, and in this case, we use bacterial Raman spectral samples collected from real cases from the Bacteria dataset (denoted as Bacteria-2 and Bacteria-3, respectively). It is particularly noted that although Raman spectra from the Bacteria dataset are used in different phases, there is no overlap between them. Through such data settings, the generalization ability and performance stability of the model can be effectively verified, and its classification accuracy can be evaluated. This experimental setup ensures the diversity and generalization ability of the data and fully considers the characteristics of different instruments, sample sources, and categories. Therefore, the experimental results are reliable and credible, and can effectively prove the effectiveness and advantages of the present application in Raman spectral analysis.

[0097] Table 1 Raman spectral data used in the experiment

[0098]

[0099] The bacterial spectral data used in this experiment is shown in Figure 3 .

[0100] The hyperparameters used to train the network model in this experiment are as follows: the number of training epochs is 300, the number of samples per iteration (BatchSize) is 512, the initial learning rate is 0.003, and the weight decay is set to 0.0001. Gradient descent is optimized using the Adam optimizer, which can more efficiently perform gradient descent. During training, the settings of these hyperparameters will directly affect the performance and training speed of the model. Therefore, reasonable settings need to be made according to the specific dataset and task. Since the size of the learning rate will affect the convergence speed and final performance of the model during training, this experiment uses a cosine annealing strategy to optimize the neural network training process to ensure that there is enough learning rate in the early training period to quickly converge, and there is a small enough learning rate in the later training period to obtain better generalization performance, prevent the model from falling into a local optimal solution, and thus improve the generalization performance of the model.

[0101] The classification accuracy is used as an indicator to evaluate the performance of the model in this experiment, which is usually represented as the proportion of the number of correctly classified samples to the total number of samples. In the classification task, the more samples that are correctly classified, the higher the accuracy, and the stronger the classification ability of the model, and the overall accuracy calculation formula is In the test set of 30 bacterial sample categories, the experiment can achieve an overall accuracy of 81.6%.

[0102] In summary, the present application proves that the efficiency and accuracy of Raman spectrum substance identification can be improved by making full use of a large amount of unlabeled Raman spectrum data, and the research process of Raman spectrum substance identification self-supervised learning is promoted.

[0103] Referring to Figure 4 As shown in the embodiment, the Raman spectrum bacteria classification system based on contrast learning also includes:

[0104] The data preprocessing module 401 is configured to perform denoising, background removal and normalization processing on the original Raman spectrum in the pre-training data set, the re-training data set and the test data set; wherein the pre-training data set is composed of unlabeled spectrum data, and the re-training data set is composed of labeled spectrum data;

[0105] The data enhancement module 402 is configured to perform enhancement processing on the preprocessed pre-training data set spectrum by random spectrum segment zeroing or Gaussian noise adding operation to obtain the data enhanced pre-training data set;

[0106] The model pre-training module 403 is configured to train the deep neural network based on the data enhanced pre-training data set using the contrast learning strategy, optimize the model using the contrast loss function, and obtain the pre-training model;

[0107] The model re-training module 404 is configured to adjust the pre-training model with an added classification layer using the preprocessed re-training data set to obtain a trained classification model;

[0108] The model test module 405 is configured to input the preprocessed test data set into the trained classification model to obtain a Raman spectrum bacteria classification result.

[0109] The specific implementation of the Raman spectrum bacteria classification system based on contrast learning is the same as the Raman spectrum bacteria classification method based on contrast learning, and the embodiment will not be repeated.

[0110] It should be understood that those skilled in the art can make improvements and changes according to the above description, and all these improvements and changes shall belong to the protection scope of the appended claims of the present application.

Claims

1. A method for Raman spectral bacterial classification based on contrastive learning, characterized in that, Comprise: Data preprocessing step, the original Raman spectrum in the pre-training data set, re-training data set and test data set is denoised, background removed and normalized; wherein, the pre-training data set is composed of unlabeled spectral data, the re-training data set is composed of labeled spectral data; Data enhancement step, the preprocessed pre-training data set spectrum is enhanced by random spectrum segment zero or Gaussian noise addition operation, and the data enhanced pre-training data set is obtained; Model pre-training step, based on the data enhanced pre-training data set, the deep neural network is trained by using contrast learning strategy, the model is optimized by using contrast loss function, and the pre-training model is obtained; Model retraining step, the pre-training model with classification layer is adjusted by using the preprocessed re-training data set, and the trained classification model is obtained; Model test step, the preprocessed test data set is input into the trained classification model, and the Raman spectrum bacterial classification result is obtained; The model pre-training step, specifically comprises: inputting each constructed pre-training sample pair into an encoding layer of a deep neural network encoding, wherein positive sample pairs generate a new Raman spectrum representation vector and negative sample pairs generate a new Raman spectrum representation vector ; The generated Raman spectrum characterization vectors are respectively input into the projection layer , the positive sample pair obtains a corresponding projection vector , the negative sample pair obtains a projection vector ; A loss function L is introduced InfoNCE The neural network is trained to optimize the model parameters by minimizing the loss function to maximize the similarity of positive sample pairs and minimize the similarity of negative sample pairs.

2. The Raman spectroscopy-based bacteria classification method based on contrast learning according to claim 1, characterized in that, The data preprocessing step, specifically as follows: (1) each original Raman spectrum is denoised; (2) each denoised Raman spectrum is background removed, the background model is fitted and subtracted from the original spectrum, and the spectrum signal is reserved; (3) Normalization is performed on each background-removed Raman spectrum, and the intensity range of the spectrum is mapped to a consistent interval .

3. The Raman spectroscopy-based bacteria classification method based on contrastive learning according to claim 1, characterized in that, The random spectrum segment zero operation is as follows: Using a one-dimensional vector Recording the Raman signal intensity; Let a set of pre-processed Raman spectrum data be a data set wherein denotes the number of Raman spectrum samples contained in the data set, denotes the i-th pre-processed Raman spectrum; For each pre-processed Raman spectrum sample , randomly take a Raman shift sequence with length of between 1 and 5, and set the intensity of the Raman signals in this segment to zero; wherein, L represents the sequence length of the Raman spectrum, i.e. each Raman spectrum has L Raman signals.

4. The Raman spectroscopy-based bacteria classification method based on contrast learning according to claim 1, wherein, The Gaussian noise addition operation is as follows: For each pre-processed Raman spectrum sample Gaussian noise with mean 0 and variance randomly in interval is added, and then normalized in interval is performed.

5. The Raman spectroscopy-based bacteria classification method based on contrastive learning according to claim 1, wherein, The operation of constructing pre-training sample pair is as follows: (1) Positive and negative sample pair construction, in the preprocessed pre-training data set, randomly select two preprocessed Raman spectrum samples and , the selected as a positive sample, after data enhancement, the corresponding positive sample , the selected as a negative sample, after data enhancement, the corresponding negative sample , and then construct the pre-trained positive sample pair and negative sample pair, as follows: ; ; (2) repeat the above steps to generate multiple positive and negative sample pairs for each preprocessed Raman spectrum sample, and construct a set of pre-training sample pairs for the whole pre-training data set.

6. The Raman spectroscopy-based bacteria classification method based on contrastive learning according to claim 1, wherein, Encoding layer consists of multi-head self-attention mechanism and hierarchical attention mechanism; projection layer consists of two fully connected layers.

7. The Raman spectroscopy-based bacteria classification method based on contrastive learning according to claim 1, wherein, InfoNCE loss function is expressed as follows: ; wherein, represents a loss function value; is a cosine similarity function; , represents a projection vector of a positive sample pair; represents a projection vector of a negative sample; indicates not to count the mutual information when is a mutual information; is a set temperature parameter; represents the number of Raman spectrum samples contained in the data set; Two cosine similarity functions are as follows: ; 。 8. The Raman spectroscopy-based bacteria classification method based on contrast learning according to claim 1, characterized in that, The retrained model is based on an encoder of the pre-trained model and adds a classification layer as the last layer of the model to optimize the current classification task. In the model retraining step, the convolution layer of the model is unfrozen gradually, and the hyperparameters are adjusted through the retraining process.

9. A Raman spectroscopy-based bacteria classification system based on contrastive learning, characterized in that, Comprise: Data preprocessing module, for denoising, background removal and normalization of original Raman spectrum in pre-training data set, re-training data set and test data set; wherein, the pre-training data set is composed of unlabeled spectral data, the re-training data set is composed of labeled spectral data; Data enhancement module, for preprocessed pre-training data set spectrum, through random spectrum segment zero or Gaussian noise addition operation to realize enhancement processing, obtain data enhanced pre-training data set; Model pre-training module, for training deep neural network based on data enhanced pre-training data set by using contrast learning strategy, optimizing model by using contrast loss function, obtaining pre-training model; Model retraining module, for adjusting the pre-training model with classification layer by using the preprocessed re-training data set, obtaining the trained classification model; Model test module, for inputting the preprocessed test data set into the trained classification model, obtaining the Raman spectrum bacterial classification result; The model pre-training module is specifically used for: inputting each of the constructed pre-training sample pairs into an encoding layer of a deep neural network encoding, wherein positive sample pairs generate a new Raman spectrum representation vector and negative sample pairs generate a new Raman spectrum representation vector ; The generated Raman spectrum characterization vectors are respectively input into the projection layer , the positive sample pair obtains a corresponding projection vector , the negative sample pair obtains a projection vector ; A loss function L is introduced InfoNCE The neural network is trained to optimize the model parameters by minimizing the loss function to maximize the similarity of positive sample pairs and minimize the similarity of negative sample pairs.

Citation Information

Patent Citations

  • Raman spectrum classification method based on self-attention mechanism

    CN115130566A

  • Medical image classification method based on federal learning and comparative learning

    CN116563625A