Bacteria classification method based on Raman spectrum data and related equipment
By constructing a multi-level tree classification structure and feature extraction network, the problem of low accuracy in bacterial classification by existing Raman spectroscopy technology is solved, and the accuracy of fine-grained classification and the recognition ability of unknown bacterial species are achieved.
Patent Information
- Application Number
- CN202510315699.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-17
- Publication Date
- 2025-07-22
AI Technical Summary
The existing Raman spectroscopy technology is difficult to effectively model the multi-level structure of bacteria in bacterial classification. The existing spectral characteristics and bacterial category labels are single, resulting in low accuracy at the fine-grained classification level.
By constructing a multi-level tree classification structure, the spectrum and category characteristics are extracted using hierarchical graph convolution networks and multi-layer one-dimensional convolution networks, class-aware characteristics are generated, and similarity is calculated through the classification layer to predict the bacterial category probability, and classification model parameters are optimized.
The accuracy of bacterial classification is improved, especially at the fine-grained classification level, the identification accuracy of known bacterial species is enhanced and the probability of determining unknown bacterial species is provided, and the effect of bacterial classification is optimized.
Smart Images

Figure CN120354274A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the technical field of bacterial classification, and in particular to a bacterial classification method based on Raman spectroscopy data and related devices. Background Art
[0002] Traditional bacterial classification methods usually rely on artificial culture and biochemical experiments, which are time-consuming and have high requirements for sample size and reagents. Therefore, there is currently a Raman spectroscopy technique that can compare the generated spectral fingerprints with known bacteria to quickly identify the types of bacteria.
[0003] However, in the actual application process, due to the multi-level structure of bacterial classification, existing methods are difficult to effectively model the hierarchical relationship, and the existing fusion method of spectral features and bacterial class labels is single, ignoring the difference in feature attention at different classification levels, resulting in low accuracy of the existing Raman spectroscopy technique at the fine-grained classification level and affecting the bacterial classification effect. Summary of the Invention
[0004] The embodiments of the present application provide a bacterial classification method based on Raman spectroscopy data and related devices, which can perform class-aware feature encoding on spectral data based on the hierarchical structure of bacterial class labels, improve the feature perception ability of the model at different classification levels, and thus can improve the classification accuracy of bacterial classification at the fine-grained classification level and effectively optimize the bacterial classification effect.
[0005] In a first aspect, the present application provides a bacterial classification method based on Raman spectroscopy data, including: obtaining original spectral data of different types of bacteria within a target wavenumber range and a target resolution; obtaining a plurality of bacterial class labels corresponding to different types of bacteria, and constructing a multi-level tree-like classification structure representing the class membership relationship between the plurality of bacterial class labels; inputting the original spectral data and the multi-level tree-like classification structure into an initial classification model, where the initial classification model includes a plurality of sequentially cascaded feature extraction layers and a classification layer; through the plurality of sequentially cascaded feature extraction layers, performing extraction and fusion of spectral features and class features based on the original spectral data and the multi-level tree-like classification structure to generate a plurality of class-aware features; calculating the similarity between the plurality of class-aware features and a preset prototype feature through the classification layer, and predicting the bacterial class prediction probability corresponding to the original spectral data based on the similarity; optimizing the model parameters of the initial classification model based on the bacterial class prediction probability to obtain an optimized target classification model; inputting the target spectral data of the bacteria to be tested into the target classification model, and determining the target bacterial class of the bacteria to be tested based on the bacterial class prediction probability output by the target classification model.
[0006] In some embodiments, extracting and fusing spectral features and class features based on the original spectral data and the multi-level tree classification structure to generate multiple class-aware features includes: encoding each of the bacterial class labels through a hierarchical graph convolutional network according to the multi-level tree classification structure to generate node features representing class hierarchical relationships; abstracting the original spectral data layer by layer through a multi-layer one-dimensional convolutional network to extract a spectral feature matrix; calculating the attention weights of multiple band features in the spectral feature matrix in the node features, and performing weighted summation on the multiple band features according to the weights to generate class-related perception features.
[0007] In some embodiments, constructing a multi-level tree classification structure representing the class membership relationships between multiple bacterial class labels includes: defining hierarchical labels from coarse-grained to fine-grained according to bacterial taxonomy criteria, where the hierarchical labels include Gram staining results, genus classification, species classification, and strain classification; generating a label hierarchical structure tree according to the hierarchical relationships between the hierarchical labels, and performing hierarchical processing on the multiple bacterial class labels according to the label hierarchical structure tree, such that the bacterial class labels belonging to the child nodes inherit the classification attributes of the bacterial class labels belonging to the parent nodes to construct a multi-level tree classification structure.
[0008] In some embodiments, encoding each of the bacterial class labels through a hierarchical graph convolutional network according to the multi-level tree classification structure to generate node features representing class hierarchical relationships includes: aggregating the features of the bacterial class labels of each node in the tree classification structure through a hierarchical graph convolutional network to obtain the label features of each node; fusing the label features of the parent node and its corresponding child node through a two-way propagation mechanism among multiple nodes to generate node features representing class hierarchical relationships.
[0009] In some embodiments, abstracting the original spectral data layer by layer through a multi-layer one-dimensional convolutional network to extract a spectral feature matrix includes: inputting the original spectral data into a multi-layer one-dimensional convolutional network, such that each layer of the one-dimensional convolutional network performs local feature extraction on the original spectral data through convolutional kernels of different sizes; performing normalization layer integration processing on the band feature sequence output by the last layer in the multi-layer one-dimensional convolutional network to obtain a spectral feature matrix.
[0010] In some embodiments, calculating the attention weights of multiple band features in the spectral feature matrix in the node features, and performing weighted summation on the multiple band features according to the attention weights to generate a perception feature related to the category, includes: for the node features of each category, calculating the correlation scores between each band feature in the spectral feature matrix and the node features respectively; converting the correlation scores into attention weight values through normalization processing, and performing weighted summation on the multiple band features based on the attention weight values to generate a perception feature related to the category.
[0011] In some embodiments, the prototype features include positive sample prototype features and negative sample prototype features. Calculating the similarity between multiple category perception features and preset prototype features through the classification layer, and predicting the bacterial category prediction probability corresponding to the original spectral data based on the similarity, includes: obtaining the positive sample prototype features and negative sample prototype features of a preset plurality of known bacterial species, where the positive sample prototype features are generated by the mean of the sample features of the samples belonging to the known bacterial species in the training samples, and the negative sample prototype features are generated by the mean of the sample features of the samples not belonging to the known bacterial species in the training samples; calculating the positive sample similarity between the category perception feature and the positive sample prototype feature, and the negative sample similarity between the category perception feature and the negative sample prototype feature through the classification layer; taking the ratio of the positive sample similarity to the sum of the positive and negative sample similarities as the bacterial category prediction probability of the original spectral data belonging to the known bacterial species.
[0012] In some embodiments, optimizing the model parameters of the initial classification model based on the bacterial category prediction probability to obtain an optimized target classification model includes: randomly dividing the preset training samples into multiple batches of fixed size, and inputting each batch into the initial classification model in sequence for forward inference and outputting the bacterial category prediction probability; calculating the cross-entropy loss according to the difference between the bacterial category prediction probability and the true label corresponding to the training sample, and updating the model parameters of the initial classification model through the backpropagation algorithm; repeating the iterative training process until the model loss of the initial classification model tends to be stable or reaches the preset maximum number of iterations to obtain the optimized target classification model.
[0013] In some embodiments, determining the target bacterial category of the to-be-detected bacterium based on the predicted probability of the bacterial category output by the target classification model includes: setting a classification threshold for each of the known bacterial species, and performing hierarchical logical constraints on the predicted probability of the bacterial category according to the hierarchical classification structure: if the predicted probability corresponding to the parent node is lower than the classification threshold, the categories corresponding to all its child nodes are automatically marked as invalid; obtaining the predicted probability of each of the known bacterial species respectively based on the predicted probability of the bacterial category output by the target classification model, and comparing the predicted probability of each of the known bacterial species with the classification threshold based on the hierarchical logical constraints; if the predicted probability of any one of the known bacterial species is higher than the classification threshold, it is determined that the to-be-detected bacterium belongs to the known bacterial species; if the predicted probability of each of the known bacterial species is lower than the classification threshold, it is determined that the to-be-detected bacterium belongs to an unknown bacterial species.
[0014] In a second aspect, the present application provides a bacterial classification device based on Raman spectroscopy data, including: a data acquisition module, configured to acquire raw spectral data of different types of bacteria within a target wavenumber range and a target resolution; a hierarchical construction module, configured to acquire a plurality of bacterial category labels corresponding to different types of bacteria, and construct a multi-level tree-like classification structure representing the category belonging relationship between the plurality of bacterial category labels; a data input module, configured to input the raw spectral data and the multi-level tree-like classification structure into an initial classification model, where the initial classification model includes a plurality of cascaded feature extraction layers and a classification layer in sequence; a feature fusion module, configured to extract and fuse spectral features and category features based on the raw spectral data and the multi-level tree-like classification structure through the plurality of cascaded feature extraction layers in sequence, and generate a plurality of category-aware features; a feature classification module, configured to calculate the similarity between the plurality of category-aware features and preset prototype features through the classification layer, and predict the predicted probability of the bacterial category corresponding to the raw spectral data based on the similarity; a model training module, configured to optimize the model parameters of the initial classification model based on the predicted probability of the bacterial category to obtain an optimized target classification model; a model inference module, configured to input the target spectral data of the to-be-detected bacterium into the target classification model, and determine the target bacterial category of the to-be-detected bacterium based on the predicted probability of the bacterial category output by the target classification model.
[0015] In a third aspect, the present application provides an electronic device, including: at least one processor; at least one memory, configured to store at least one program; when at least one of the at least one program is executed by the at least one processor, the method for classifying bacteria based on Raman spectroscopy data according to any item of the first aspect is implemented.
[0016] Fourthly, the present application provides a computer-readable storage medium storing computer-executable instructions for executing the bacterial classification method based on Raman spectroscopy data according to any one of the first aspects.
[0017] According to the embodiments of the present application, a bacterial classification method based on Raman spectroscopy data and related devices have at least the following beneficial effects: By obtaining the original Raman spectroscopy data of bacteria and a multi-level tree-like classification structure and inputting them into an initial classification model, the present application uses a multi-cascade feature extraction layer to extract fused spectral and class features to generate class-aware features, and then calculates the similarity through a classification layer to predict the bacterial classification probability. Based on the predicted probability, the model is optimized to obtain a target classification model. Then, when classifying a to-be-tested bacterium, by inputting the target spectral data, the type of the bacterium can be determined. It can be understood that the present application ensures the standardization of the input data by collecting the original spectral data within a limited target wavenumber range and target resolution. Further, by constructing a multi-level tree-like classification structure to represent the hierarchical relationship of bacterial classification, the model can capture the dependencies and differences between different classification levels. Further, through the sequentially cascaded feature extraction layers in the initial classification model, the spectral data and the hierarchical classification structure are processed simultaneously to extract and fuse spectral features and class features, generating multi-dimensional class-aware features, and calculating the prediction probability based on the similarity between the class-aware features and the preset prototype features. By optimizing the model parameters with the probability, the model can dynamically adjust the feature weights and classification boundaries, improving the recognition accuracy of known bacterial species and providing a probability basis for the determination of unknown bacterial species. Further, by inputting the to-be-tested data into the optimized target classification model and determining the target bacterial type of the to-be-tested bacterium based on the bacterial type prediction probability output by the target classification model, the classification accuracy of the method for classifying bacteria at a fine-grained classification level can be improved, effectively optimizing the bacterial classification effect. Description of the Drawings
[0018] Figure 1 is a flowchart of the bacterial classification method based on Raman spectroscopy data provided by an embodiment of the present application;
[0019] Figure 2 is a schematic diagram of the hierarchical structure of class labels in the bacterial classification method based on Raman spectroscopy data provided by an embodiment of the present application;
[0020] Figure 3 is a flowchart of generating multiple class-aware features in the bacterial classification method based on Raman spectroscopy data provided by an embodiment of the present application;
[0021] Figure 4 is a flowchart of constructing a multi-level tree-like classification structure in the bacterial classification method based on Raman spectroscopy data provided by an embodiment of the present application;
[0022] Figure 5 In a method for classifying bacteria based on Raman spectroscopy data provided by an embodiment of the present application, a flowchart for generating node features representing a category hierarchy relationship;
[0023] Figure 6 In a method for classifying bacteria based on Raman spectroscopy data provided by an embodiment of the present application, a schematic diagram for extracting a spectral feature matrix;
[0024] Figure 7 In a method for classifying bacteria based on Raman spectroscopy data provided by an embodiment of the present application, a flowchart for generating perception features related to categories;
[0025] Figure 8 In a method for classifying bacteria based on Raman spectroscopy data provided by an embodiment of the present application, a flowchart for obtaining an optimized target classification model;
[0026] Figure 9 In a method for classifying bacteria based on Raman spectroscopy data provided by an embodiment of the present application, a schematic diagram for determining a target bacterial category of a to-be-tested bacterium based on Raman spectroscopy data;
[0027] Figure 10 A schematic diagram of the structure of a computer device provided by an embodiment of the present application. Detailed implementation manners
[0028] To make the objectives, technical solutions, and advantages of the present application clearer and more understandable, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0029] In some embodiments, although functional modules are divided in the system schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order from the module division in the system or the flowchart. Terms such as first and second in the specification, claims, and the above-mentioned drawings are used to distinguish similar objects and do not necessarily need to describe a specific order or sequence.
[0030] In addition, unless otherwise clearly specified and limited, the term "connected / linked" should be understood in a broad sense. For example, it can be a fixed connection or a movable connection, or a detachable connection or an inseparable connection, or an integral connection; it can be a mechanical connection, an electrical connection, or can communicate with each other; it can be directly connected, or indirectly connected through an intermediate medium.
[0031] In the description of the embodiments of the present application, the descriptions referring to terms such as "one embodiment / implementation", "another embodiment / implementation" or "certain embodiments / implementations", "in the above embodiments / implementations", etc. mean that the specific features, structures, materials or characteristics described in connection with the embodiments or examples are included in at least two embodiments or implementations disclosed in the present application. In the disclosure of the present application, the schematic expressions of the above terms do not necessarily refer to the same embodiment or implementation. It should be noted that although the logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a sequence different from that in the flowchart.
[0032] Currently, traditional bacterial classification methods usually rely on artificial culture and biochemical experiments, which are time-consuming and require high sample volume and reagents. Therefore, there is currently a Raman spectroscopy technology that can compare the generated spectral fingerprints with known bacteria to achieve rapid identification of bacterial types. However, in the actual application process, due to the multi-level structure of bacterial classification, existing methods are difficult to effectively model the hierarchical relationship, and the existing fusion method of spectral features and bacterial category labels is single, ignoring the difference in feature attention at different classification levels, resulting in low accuracy of the existing Raman spectroscopy technology at the fine-grained classification level and affecting the bacterial classification effect.
[0033] Based on this, the embodiments of the present application provide a bacterial classification method and related devices based on Raman spectral data, which can perform category-aware feature encoding on spectral data based on the hierarchical structure of bacterial category labels, improve the feature perception ability of the model at different classification levels, and thus can improve the classification accuracy of bacterial classification at the fine-grained classification level and effectively optimize the bacterial classification effect.
[0034] The following will further describe the embodiments of the present application with reference to the accompanying drawings.
[0035] Refer to Figure 1 , Figure 1 is a flowchart of a bacterial classification method based on Raman spectral data provided by an embodiment of the present application; in some embodiments, the present application provides a bacterial classification method based on Raman spectral data, including but not limited to the following steps:
[0036] Step S110, obtaining the original spectral data of different types of bacteria within a target wavenumber range and a target resolution;
[0037] Step S120, obtaining multiple bacterial category labels corresponding to different types of bacteria, and constructing a multi-level tree-like classification structure representing the category belonging relationship between the multiple bacterial category labels;
[0038] Step S130, inputting the original spectral data and the multi-level tree classification structure into an initial classification model, wherein the initial classification model includes a plurality of feature extraction layers and classification layers cascaded in sequence;
[0039] Step S140, extracting and fusing spectral features and category features based on the original spectral data and the multi-level tree classification structure through a plurality of sequentially cascaded feature extraction layers, to generate a plurality of category perception features;
[0040] Step S150, calculating the similarity between the plurality of category perception features and the preset prototype features through the classification layer, and predicting the prediction probability of the bacteria category corresponding to the original spectral data based on the similarity;
[0041] Step S160, optimizing the model parameters of the initial classification model based on the bacterial category prediction probability to obtain an optimized target classification model;
[0042] Step S170: input the target spectrum data of the bacteria to be detected into the target classification model, and determine the target bacteria category of the bacteria to be detected based on the bacteria category prediction probability output by the target classification model.
[0043] In some embodiments, the present application obtains the original Raman spectrum data of bacteria and a multi-level tree classification structure and inputs the initial classification model, uses a multi-cascade feature extraction layer to extract the fused spectrum and category features, generates category-aware features, and then calculates the similarity through the classification layer to predict the bacterial classification probability, so as to obtain the target classification model based on the prediction probability optimization model, and then when classifying the bacteria to be tested, the target spectrum data is input to determine the bacterial species.
[0044] Among them, it can be understood that the present application collects raw spectral data by limiting the target wavenumber range and target resolution to ensure the standardization of input data; further, by constructing a multi-level tree classification structure to characterize the hierarchical relationship of bacterial classification, the model can capture the dependencies and differences between different classification levels; further, through the feature extraction layers cascaded in sequence in the initial classification model, the spectral data and the hierarchical classification structure are processed simultaneously, the spectral features and category features are extracted and fused, and multi-dimensional category-aware features are generated. The prediction probability is calculated based on the similarity between the category-aware features and the preset prototype features, and the model parameters are optimized through probability, so that the model can dynamically adjust the feature weights and classification boundaries, improve the recognition accuracy of known bacterial species, and provide a probabilistic basis for the determination of unknown bacterial species; further, the data to be tested is input into the optimized target classification model, and the target bacterial category of the bacteria to be tested is determined based on the bacterial category prediction probability output by the target classification model, thereby improving the classification accuracy of the method for bacterial classification at a fine-grained classification level, and effectively optimizing the bacterial classification effect.
[0045] In some embodiments, it is worth noting that the classification models for bacterial identification using deep learning methods in the past had low accuracy at the fine-grained classification level. In this application, by referring to the multi-level classification model in the text classification task and introducing the label information of bacterial categories, the model focuses on different features at different classification levels, thereby improving the classification accuracy of the overall model. Secondly, the classification generalization is enhanced through prototype vector learning, and the recognition rate of unknown bacterial species is improved.
[0046] In some embodiments, with the data obtained by means of Raman spectroscopy technology, this application can achieve the identification of different types of bacteria and the determination of the categories of unknown types of bacteria. Corresponding to steps S110 to S170, the process of this application covers links such as the acquisition and preprocessing of spectral data, feature extraction and fusion through a deep learning model, and then classification prediction and model optimization.
[0047] Among them, in the data acquisition stage, this application can obtain the original Raman spectral data of different types of bacteria within a specific wavenumber range and resolution. Raman spectral data refers to the molecular vibration information of substances obtained by Raman spectroscopy technology and can reflect the unique molecular structure characteristics of bacteria. At the same time, the corresponding bacterial category labels are collected, and a multi-level tree-like classification structure is constructed. The multi-level tree-like classification structure is a hierarchical data organization form used to represent the subordination relationship between bacterial category labels. From coarse-grained to fine-grained, it helps the model focus on different features at different levels.
[0048] Furthermore, in the data preprocessing and preliminary analysis stage, the collected original spectral data is preprocessed, such as removing noise and performing baseline correction, etc., to improve the data quality. At the same time, the bacterial category labels are encoded to match the spectral data.
[0049] Furthermore, in the model construction and training stage, the preprocessed spectral data and label data are input into the initial classification model. This model is composed of multiple sequentially cascaded feature extraction layers and classification layers. The feature extraction layer is the part of the deep learning model responsible for extracting useful features from the input data. Multiple sequentially cascaded feature extraction layers can gradually abstract and fuse spectral features and category features to generate category-aware features. These features contain both spectral information and category attributes, so as to make full use of the subtle differences in spectral data and the hierarchical information of category labels, enabling the model to learn more discriminative feature representations.
[0050] Further, in the classification and prediction stage, the similarity between the class-aware features and the preset prototype features is calculated through the classification layer. The classification layer is responsible for making further classification decisions based on the extracted features. By calculating the similarity between the class-aware features and the preset prototype features, the prediction probability of the bacterial class corresponding to the original spectral data is predicted. The prototype features are the feature representations preset for each known bacterial class and are usually generated by the feature means of the training samples. Furthermore, the prediction probability of the bacterial class corresponding to the original spectral data can be predicted. This stage not only considers the recognition of known classes but also enhances the recognition ability of unknown-class bacteria through a specific mechanism, strengthening the generalization and robustness of the model.
[0051] Further, in the model optimization and evaluation stage, based on the difference between the prediction probability and the true label, the loss function is used to evaluate the model performance, and the model parameters are optimized through the backpropagation algorithm. Continuous iterative training is carried out until the model reaches the expected classification accuracy and stability, and the optimized target classification model can be obtained, enabling it to more accurately determine the target bacterial class of the bacteria to be measured in practical applications. Furthermore, in the actual application stage, the spectral data of the bacteria to be measured can be input into the optimized target classification model, and the prediction probability output by the model determines the class of the bacteria to be measured.
[0052] Reference Figure 2 , Figure 2 is a schematic diagram of the hierarchical structure of class labels in the bacterial classification method based on Raman spectral data provided by an embodiment of the present application; in some embodiments, as Figure 2 shown, Figure 2 shows a hierarchical structure of bacterial class labels. The above structure is the basis for constructing a multi-level tree-like classification model. In Figure 2 , the root node (Root) is located at the top layer, representing the total set of all bacterial classes. Starting from the root node, it is divided into multiple levels downward in sequence. Each level contains several nodes, and these nodes represent bacterial class labels at different levels. For example, in the second layer, the root node branches out nodes such as C1, C2, etc., which can represent the coarse-grained classification of bacteria, such as the Gram staining result. As the level increases, the degree of fine-grained classification gradually increases. By the L-th layer, nodes such as C K-5 , C K-4 , C K-3etc., can represent specific genus or species classifications; the connection relationship between each node represents the belonging relationship between categories, that is, the sub-category inherits the classification attributes of the parent category. The above multi-level tree-like classification structure can effectively organize bacterial category labels, enabling the model to focus on different features at different levels, thereby improving the accuracy of classification and the ability of fine-grained recognition; it can be understood that in practical applications, through the above hierarchical structure, the model can make classification decisions layer by layer, first making a preliminary classification at the coarse-grained level, and then making a more accurate distinction at the fine-grained level to further achieve accurate prediction of bacterial types.
[0053] In some embodiments, it can be understood that when data is collected, the Raman spectrogram of each sample is recorded within a certain wavenumber range (such as 100 - 3200 cm^-1) and resolution (such as 1 cm^-1). Assume that the original Raman spectrum of the i-th sample is denoted as S i =<A1,A2,…A j ,…,A M >, A j represents the intensity corresponding to the j-th wavenumber point.
[0054] Reference Figure 3 , Figure 3 is a schematic diagram of the hierarchical structure of category labels in the bacterial classification method based on Raman spectroscopy data provided in an embodiment of the present application; in some embodiments, based on the original spectral data and the multi-level tree-like classification structure, spectral features and category features are extracted and fused to generate multiple category-aware features, including but not limited to the following steps:
[0055] Step S310, according to the multi-level tree-like classification structure, encode each bacterial category label through a hierarchical graph convolutional network to generate node features representing the category hierarchical relationship;
[0056] Step S320, layer-by-layer abstract the original spectral data through a multi-layer one-dimensional convolutional network to extract the spectral feature matrix;
[0057] Step S330, calculate the attention weights of multiple band features in the spectral feature matrix in the node features, and perform weighted summation on the multiple band features according to the weights to generate category-related perception features.
[0058] In some embodiments, spectral features, class features are extracted and fused based on the original spectral data and the multi-level tree-like classification structure to generate multiple class-aware features. The specific steps are as follows: First, according to the multi-level tree-like classification structure, each bacterial class label is encoded by a hierarchical graph convolutional network to generate node features representing the hierarchical relationship of the classes. The hierarchical graph convolutional network can capture the hierarchical dependencies between class labels, so that each node feature not only contains its own information, but also fuses the feature information of the parent node and the child node. Second, the original spectral data is abstracted layer by layer through a multi-layer one-dimensional convolutional network to extract a spectral feature matrix. The multi-layer structure of the convolutional network enables the model to extract spectral features from different scales, and each layer of convolutional operation can further abstract the useful information in the data. Further, the attention weights of multiple band features in the spectral feature matrix in the node features are calculated, and the multiple band features are weighted and summed according to the weights to generate class-related perception features. The attention mechanism enables the model to dynamically focus on the importance of different band features in different classes, thereby improving the class discrimination of the feature representation.
[0059] In some embodiments, multiple sequentially cascaded feature extraction layers include an encoding layer, a spectral feature extraction layer, and an attention layer. Among them, the encoding layer is the encoder of the class label, which may include a hierarchical graph convolutional neural network. The hierarchical graph convolutional neural network is used to encode each bacterial class label according to the multi-level tree-like classification structure to generate node features representing the hierarchical relationship of the classes, which can capture the hierarchical dependencies between class labels, so that each node feature not only contains its own information, but also fuses the feature information of the parent node and the child node, providing rich class semantic information for subsequent feature fusion.
[0060] The spectral feature extraction layer is the feature extractor of the Raman spectrum. A multi-layer one-dimensional convolutional network can be used to extract the features of the Raman spectrum to obtain a spectral feature matrix. The multi-layer structure of the convolutional network enables the model to extract spectral features from different scales, and each layer of convolutional operation can further abstract the useful information in the data, gradually extracting the feature vector that can represent the core features of the bacterial Raman spectrum, providing a basis for subsequent feature fusion and classification.
[0061] The attention layer is used to calculate the attention weights of multiple band features in the spectral feature matrix in the node features, and weighted sum the multiple band features according to the weights to generate class-related perception features. The attention mechanism enables the model to dynamically focus on the importance of different band features in different classes, automatically adjust the degree of attention to different bands according to the hierarchical structure of the class label and the distribution of the spectral features, thereby improving the class discrimination of the feature representation, making the generated class-aware features more targeted and effective, and further improving the classification performance of the model.
[0062] It can be understood that the above-mentioned encoding layer, spectral feature extraction layer, and attention layer can perform multi-level feature extraction and fusion methods to utilize the spectral information in the Raman spectral data and the hierarchical information in the class labels, enabling the model to learn richer and more discriminative feature representations.
[0063] Reference Figure 4 , Figure 4 FIG. is a schematic diagram of the hierarchical structure of class labels in the bacterial classification method based on Raman spectral data provided by an embodiment of the present application; in some embodiments, constructing a multi-level tree-like classification structure representing the class membership relationship between multiple bacterial class labels includes, but is not limited to, the following steps:
[0064] Step S410, according to the bacterial taxonomy standard, define hierarchical labels from coarse-grained to fine-grained, where the hierarchical labels include Gram staining results, genus classification, species classification, and strain classification;
[0065] Step S420, generate a label hierarchical structure tree according to the hierarchical relationship between the hierarchical labels, and perform hierarchical processing on multiple bacterial class labels according to the label hierarchical structure tree, so that the bacterial class labels belonging to the child nodes in the multiple bacterial class labels inherit the classification attributes of the bacterial class labels belonging to the parent nodes, in order to construct a multi-level tree-like classification structure.
[0066] In some embodiments, constructing a multi-level tree-like classification structure representing the class membership relationship between multiple bacterial class labels, the specific steps are as follows: First, according to the bacterial taxonomy standard, define hierarchical labels from coarse-grained to fine-grained, where the hierarchical labels include Gram staining results, genus classification, species classification, and strain classification. The above design of hierarchical labels conforms to the scientific system of bacterial classification and can comprehensively cover all levels of bacterial classification; Second, generate a label hierarchical structure tree according to the hierarchical relationship between the hierarchical labels, and perform hierarchical processing on multiple bacterial class labels according to the label hierarchical structure tree, so that the bacterial class labels belonging to the child nodes in the multiple bacterial class labels inherit the classification attributes of the bacterial class labels belonging to the parent nodes, in order to construct a multi-level tree-like classification structure. Furthermore, through the above hierarchical processing, the model can make full use of the hierarchical relationship between classes during the training and prediction processes, improving the accuracy and robustness of classification.
[0067] Reference Figure 5 , Figure 5 FIG. is a schematic diagram of the hierarchical structure of class labels in the bacterial classification method based on Raman spectral data provided by an embodiment of the present application; in some embodiments, according to the multi-level tree-like classification structure, encode each bacterial class label through a hierarchical graph convolutional network to generate node features representing the class hierarchical relationship, including but not limited to the following steps:
[0068] Step S510: Aggregate the feature of the bacterial category label of each node in the tree - shaped classification structure through a hierarchical graph convolutional network to obtain the label feature of each node;
[0069] Step S520: Between multiple nodes, fuse the label feature of the parent node and the label feature of its corresponding child node through a two - way propagation mechanism to generate node features representing the category hierarchical relationship.
[0070] In some embodiments, according to the multi - level tree - shaped classification structure, encode each bacterial category label through a hierarchical graph convolutional network to generate node features representing the category hierarchical relationship. The specific steps are as follows: First, aggregate the feature of the bacterial category label of each node in the tree - shaped classification structure through a hierarchical graph convolutional network to obtain the label feature of each node, so as to utilize the powerful representation ability of the graph convolutional network to aggregate the category label information of each node with the information of its adjacent nodes to form a label feature that can represent the characteristics of the node itself; Further, between multiple nodes, fuse the label feature of the parent node and the label feature of its corresponding child node through a two - way propagation mechanism to generate node features representing the category hierarchical relationship. The above - mentioned two - way propagation mechanism enables the features of the parent node and the child node to influence each other, fully capturing the hierarchical dependence relationship between category labels, so that the generated node features not only contain their own information but also fuse the feature information of the upper and lower levels, providing semantic information for subsequent feature fusion and classification.
[0071] It can be understood that as an encoder of category labels, the feature representation of the \(C_k\) - th node is determined by its parent node \(parent(C_k)\), child nodes \(child(C_k)\), and the feature representation of the previous layer of its own node. \(N(C k )=\{parent(C k ),child(C k ),C k \}, and its calculation formula is as follows:
[0072]
[0073] Among them, \(N(C_k)\) represents the set of the parent node and child nodes of node \(C_k\). Since this category hierarchical structure is a tree - shaped graph, its neighbor nodes are the parent node or child node \(X l-1 \) is the feature representation of the upper - level node, \) is the bias parameter of the \(l\) - th hidden layer, \) is the bias parameter of the input gate of the \(l\) - th layer, \(W l \) is the parameter of the input gate of the \(l\) - th layer, \) is the connection probability matrix between and node \(C k \), where \(X l-1 \in R N×d , W l ∈R d , where d is the dimension of the feature representation. When l = 1, X l-1 is a learnable parameter initialized randomly, where W l , are all learnable parameters, ⊙ represents the dot product, represents the C l th row component of g j , represents th row component of C j , represents the feature representation of the C k th category at layer l. The graph convolutional network can be stacked to improve the model performance. For the convenience of description, a one-layer convolutional neural network is taken in this case for illustration.
[0074] Reference Figure 6 , Figure 6 is a schematic diagram of the hierarchical structure of the class labels in the method for classifying bacteria based on Raman spectroscopy data provided in an embodiment of the present application; in some embodiments, the original spectral data is abstracted layer by layer through a multi-layer one-dimensional convolutional network to extract a spectral feature matrix, including but not limited to the following steps:
[0075] Step S610: Input the original spectral data into the multi-layer one-dimensional convolutional network, so that each layer of the one-dimensional convolutional network extracts local features of the original spectral data through convolutional kernels of different sizes;
[0076] Step S620: Perform normalization layer integration processing on the band feature sequence output by the last layer of the multi-layer one-dimensional convolutional network to obtain a spectral feature matrix.
[0077] In some embodiments, the original spectral data is abstracted layer by layer through a multi-layer one-dimensional convolutional network to extract a spectral feature matrix. The specific steps are as follows: First, input the original spectral data into the multi-layer one-dimensional convolutional network, so that each layer of the one-dimensional convolutional network extracts local features of the original spectral data through convolutional kernels of different sizes. Convolutional kernels of different sizes can capture spectral band features of different widths, thereby extracting local patterns and trends of the spectrum at different scales. As the number of network layers increases, these local features are gradually abstracted into higher-level feature representations. Then, perform normalization layer integration processing on the band feature sequence output by the last layer of the multi-layer one-dimensional convolutional network to obtain a spectral feature matrix. The normalization layer integration processing can adjust the distribution of the feature sequence, making it have more stable statistical characteristics, which is beneficial to subsequent feature fusion and model training. The spectral feature matrix extracted in the above manner not only retains the important information in the original spectral data but also can better characterize the features of the bacterial Raman spectrum, providing a solid foundation for subsequent classification tasks.
[0078] Among them, it can be understood that the multi-layer one-dimensional convolutional network includes a model composed of T convolutional layers and batch normalization layers, and the input sequence S corresponding to the original spectral data i Via, a feature matrix R with an output dimension of N×F i , where F is the number of convolutional kernels in the last convolutional layer.
[0079] Reference Figure 7 , Figure 7 FIG. is a schematic diagram of the hierarchical structure of class labels in the method for classifying bacteria based on Raman spectral data provided by an embodiment of the present application; in some embodiments, calculating the attention weights of multiple band features in the spectral feature matrix in the node features, and performing weighted summation on the multiple band features according to the attention weights to generate perception features related to the category, including but not limited to the following steps:
[0080] Step S710, for the node features of each category, calculate the correlation scores between each band feature in the spectral feature matrix and the node features respectively;
[0081] Step S720, convert the correlation scores into attention weight values through normalization processing, and perform weighted summation on the multiple band features based on the attention weight values to generate perception features related to the category.
[0082] In some embodiments, calculating the attention weights of multiple band features in the spectral feature matrix in the node features, and performing weighted summation on the multiple band features according to the attention weights to generate perception features related to the category, the specific steps are as follows: First, for the node features of each category, calculate the correlation scores between each band feature in the spectral feature matrix and the node features respectively. This step quantifies the degree of correlation between each band feature and the node features through a specific similarity measurement method, such as dot product or cosine similarity. A band feature with a high correlation score means that it has higher discrimination and relevance in this category. Then, convert the correlation scores into attention weight values through normalization processing. The normalization method usually uses the softmax function, so that the sum of all attention weight values is 1, forming a probability distribution. Further, perform weighted summation on the multiple band features based on the attention weight values to generate perception features related to the category. The above weighted summation operation enables the model to automatically adjust its contribution according to the importance of the band features, highlighting the band features that are important for classification, thereby improving the category discrimination and expression ability of the generated perception features.
[0083] In some embodiments, the prototype features include positive sample prototype features and negative sample prototype features. The similarity between multiple class perception features and the preset prototype features is calculated through a classification layer, and the bacterial class prediction probability corresponding to the original spectral data is predicted based on the similarity, including: obtaining the positive sample prototype features and negative sample prototype features of a preset plurality of known bacterial species. The positive sample prototype features are generated by the mean of the sample features belonging to the known bacterial species in the training samples, and the negative sample prototype features are generated by the mean of the sample features not belonging to the known bacterial species in the training samples; calculating the positive sample similarity between the class perception features and the positive sample prototype features, and the negative sample similarity between the class perception features and the negative sample prototype features through the classification layer; taking the ratio of the positive sample similarity to the sum of the positive and negative sample similarities as the bacterial class prediction probability that the original spectral data belongs to the known bacterial species.
[0084] It can be understood that the prototype features include positive sample prototype features and negative sample prototype features. The similarity between multiple class perception features and the preset prototype features is calculated through a classification layer, and the bacterial class prediction probability corresponding to the original spectral data is predicted based on the similarity. The specific steps are as follows: First, obtain the positive sample prototype features and negative sample prototype features of a preset plurality of known bacterial species; the positive sample prototype features are generated by the mean of the sample features belonging to the known bacterial species in the training samples, that is, by averaging all the positive sample feature vectors of each known bacterial species to obtain a vector that can represent the typical features of the bacterial species; the negative sample prototype features are generated by the mean of the sample features not belonging to the known bacterial species in the training samples, which are used to represent unknown bacterial species or background features; then, calculate the positive sample similarity between the class perception features and the positive sample prototype features, and the negative sample similarity between the class perception features and the negative sample prototype features through the classification layer; the calculation of the similarity can adopt methods such as Euclidean distance and cosine similarity to measure the closeness between the perception features and the prototype features; further, take the ratio of the positive sample similarity to the sum of the positive and negative sample similarities as the bacterial class prediction probability that the original spectral data belongs to the known bacterial species; the specific formula can be expressed as: prediction probability = positive sample similarity / (positive sample similarity + negative sample similarity); the above calculation method enables the prediction probability to comprehensively consider the similarity between the perception features and the positive and negative sample prototype features. When the perception features are closer to the positive sample prototype features, the prediction probability is higher, and vice versa, so as to achieve accurate prediction of the bacterial class corresponding to the original spectral data.
[0085] Among them, it can be understood that the construction process of the attention layer can be as follows: Extract the feature representation of class perception:
[0086]
[0087] V = [v1; v2;...; v K
[0088] Among them, The category C obtained by the encoder in the previous step k The final feature representation Is the feature representation of the j-th band point of the i-th sample For the j-th band point in category C k The weight, v k Indicates the feature representation of the i-th sample in category C k When classifying, after passing through the attention layer, a category-aware feature matrix V will be obtained. Among them, V ∈ R K ×d ; It can be understood that the category label is obtained by constructing an encoder through the above steps S510 to S520. d is the dimension of the feature vector. This attention layer will extract the corresponding category-aware feature representation Vk for each category Ck respectively. Combining K Vk together can obtain the feature matrix V.
[0089] Reference Figure 8 , Figure 8 Is a schematic diagram of the hierarchical structure of category labels in the bacterial classification method based on Raman spectroscopy data provided by an embodiment of the present application; in some embodiments, optimizing the model parameters of the initial classification model based on the predicted probability of the bacterial category to obtain an optimized target classification model includes, but is not limited to, the following steps:
[0090] Step S810, randomly divide the preset training samples into multiple batches of fixed size, and input each batch into the initial classification model for forward inference in turn and output the predicted probability of the bacterial category;
[0091] Step S820, calculate the cross-entropy loss according to the difference between the predicted probability of the bacterial category and the true label corresponding to the training sample, and update the model parameters of the initial classification model through the backpropagation algorithm;
[0092] Step S830, repeat the iterative training process until the model loss of the initial classification model tends to be stable or reaches the preset maximum number of iterations to obtain an optimized target classification model.
[0093] In some embodiments, the model parameters of the initial classification model are optimized based on the predicted probability of the bacterial category to obtain the optimized target classification model. The specific steps are as follows: First, the preset training samples are randomly divided into multiple batches of fixed size, and each batch is sequentially input into the initial classification model for forward inference and the predicted probability of the bacterial category is output. The above batch processing method can not only effectively utilize computing resources, but also improve the stability of model parameter updates through the sample diversity within the batch. Then, the cross-entropy loss is calculated according to the difference between the predicted probability of the bacterial category and the true label corresponding to the training sample, and the model parameters of the initial classification model are updated through the backpropagation algorithm. The cross-entropy loss can accurately measure the difference between the model's predicted probability distribution and the true label distribution, and the backpropagation algorithm adjusts the model parameters according to the loss gradient to minimize the prediction error. Further, the training process is repeated iteratively until the model loss of the initial classification model tends to be stable or reaches the preset maximum number of iterations to obtain the optimized target classification model. During the training process, by continuously adjusting the model parameters, the model can gradually learn the complex patterns and features in the data and the associations with the categories, thereby improving the accuracy and robustness of classification.
[0094] Among them, it can be understood that in the case where the input data is the preset labeled bacterial species dataset X, the iterative training process will synchronously update the encoder, convolutional layer, and classification layer. The specific iterative training process can be as follows: Initialize the iteration number step = 0 and set the maximum number of iterations M. Randomly divide the U samples collected into batches with the number of samples per batch being BS; calculate the class label representation X through the encoder of the class label; for each batch of samples, respectively pass through the above convolutional layer, attention layer, and classification layer to obtain the probability p that the sample belongs to all classes; calculate the loss function value of the current batch:
[0095]
[0096] Among them, y i,k is the label information in the training set, y i,k = +1 indicates that the i-th sample belongs to the category C k , y i,k = 0 indicates that the i-th sample does not belong to the category C k . p(y i,k = +1|S i ) is the probability that the model predicts that the i-th sample belongs to the category C k ;
[0097] Update the model parameters according to the gradient descent method:
[0098]
[0099] Among them, θ cis the parameter of the feature extractor, θ h is the encoder parameter of the class label, ε is the learning rate, is the loss function Loss CE The gradient of the parameter θ c is is the loss function Loss CE The gradient of the parameter θ h is
[0100] Furthermore, by repeating the above process of processing the samples of each batch through the above convolutional layer, attention layer and classification layer respectively, calculating the loss function and based on the model parameters, until all batches are iterated and the preset number of loop iterations is reached, the current training process is ended, and the optimized target classification model is obtained.
[0101] Reference Figure 9 , Figure 9 is a schematic diagram of the hierarchical structure of class labels in the bacterial classification method based on Raman spectroscopy data provided by an embodiment of the present application; in some embodiments, determining the target bacterial class of the bacteria to be tested based on the predicted probability of the bacterial class output by the target classification model includes, but is not limited to, the following steps:
[0102] Step S910, set a classification threshold for each known bacterial species, and perform hierarchical logical constraints on the predicted probability of the bacterial class according to the classification hierarchical structure: if the predicted probability corresponding to the parent node is lower than the classification threshold, then all the categories corresponding to its child nodes are automatically marked as invalid;
[0103] Step S920, obtain the predicted probability of each known bacterial species respectively according to the predicted probability of the bacterial class output by the target classification model, and compare the predicted probability of each known bacterial species with the classification threshold based on the hierarchical logical constraints;
[0104] Step S930, if the predicted probability of any known bacterial species is higher than the classification threshold, it is determined that the bacteria to be tested belong to the known bacterial species;
[0105] Step S940, if the predicted probability of each known bacterial species is lower than the classification threshold, it is determined that the bacteria to be tested belong to an unknown bacterial species.
[0106] In some embodiments, the target bacterial category of the bacteria to be tested is determined based on the predicted probability of the bacterial category output by the target classification model. The specific steps are as follows: First, a classification threshold is set for each known bacterial species, and hierarchical logical constraints are imposed on the predicted probability of the bacterial category according to the hierarchical structure; if the predicted probability corresponding to the parent node is lower than the classification threshold, the categories corresponding to all its child nodes are automatically marked as invalid; the above hierarchical logical constraints are based on the hierarchical relationship of bacterial classification to ensure the consistency and rationality of the classification results at the hierarchical level. Then, the predicted probability of each known bacterial species is obtained based on the predicted probability of the bacterial category output by the target classification model, and the predicted probability of each known bacterial species is compared with the classification threshold based on the hierarchical logical constraints; if the predicted probability of any known bacterial species is higher than the classification threshold, it is determined that the bacteria to be tested belong to the known bacterial species; if the predicted probability of each known bacterial species is lower than the classification threshold, it is determined that the bacteria to be tested belong to an unknown bacterial species. Through the above method, the model can not only accurately identify known bacterial species but also effectively discover unknown bacterial species, expanding the application scope and practicality of bacterial classification.
[0107] It can be understood that in the inference process corresponding to steps S910 to S940, the prediction results need to be further processed to meet the hierarchical constraints between categories, specifically as follows: From the training samples, N positive samples and N negative samples are collected for each category, which is a part of the input of the classifier; a rejection probability threshold is set for each category, and the simplest method is to set them all to 0.5; calculate the probability that the sample belongs to various categories. If the predicted probability is less than the rejection probability threshold, it is preliminarily determined that this sample does not belong to this sample; otherwise, it is predicted that this sample belongs to this category; since it is considered that the predicted bacteria may not belong to the existing known bacterial categories, the bacteria of unknown categories are identified through post-processing; starting from the root node, the prediction results of the child nodes are determined layer by layer; if the parent node is predicted to be negative, all child nodes are set to negative. pos positive samples and N neg negative samples, which is a part of the input of the classifier; a rejection probability threshold is set for each category, and the simplest method is to set them all to 0.5; calculate the probability that the sample belongs to various categories. If the predicted probability is less than the rejection probability threshold, it is preliminarily determined that this sample does not belong to this sample; otherwise, it is predicted that this sample belongs to this category; since it is considered that the predicted bacteria may not belong to the existing known bacterial categories, the bacteria of unknown categories are identified through post-processing; starting from the root node, the prediction results of the child nodes are determined layer by layer; if the parent node is predicted to be negative, all child nodes are set to negative.
[0108] It can be conceived that the inference process can be understood as: obtaining the Raman spectral data of the sample Z to be tested; using a convolutional network to extract features to obtain the feature matrix Z; calculating the category-aware feature matrix V; calculating the distance between the perceptual features and the prototype vectors of various categories to obtain the predicted probability; if the probability of the category with the highest predicted probability is greater than 0.5, it is determined that the sample belongs to this category; if the predicted probabilities of all categories are lower than 0.5, the sample is marked as an unknown category and further analyzed; among them, the positive samples and negative samples are part of the formula in the construction process of the above attention layer. The positive samples and negative samples are different in each iteration. When making predictions, it is necessary to determine the positive and negative samples to represent the category. The higher the rejection threshold, the more samples are identified as unknown categories.
[0109] To achieve the above object, a second aspect of the embodiments of the present application provides a bacterial classification device based on Raman spectroscopy data, including: a data acquisition module for acquiring original spectral data of different types of bacteria within a target wavenumber range and a target resolution; a hierarchical construction module for acquiring a plurality of bacterial category labels corresponding to different types of bacteria and constructing a multi-level tree-like classification structure representing the category belonging relationships among the plurality of bacterial category labels; a data input module for inputting the original spectral data and the multi-level tree-like classification structure into an initial classification model, where the initial classification model includes a plurality of cascaded feature extraction layers and a classification layer in sequence; a feature fusion module for extracting and fusing spectral features and category features based on the original spectral data and the multi-level tree-like classification structure through the plurality of cascaded feature extraction layers in sequence to generate a plurality of category-aware features; a feature classification module for calculating the similarity between the plurality of category-aware features and preset prototype features through the classification layer and predicting the bacterial category prediction probability corresponding to the original spectral data based on the similarity; a model training module for optimizing the model parameters of the initial classification model based on the bacterial category prediction probability to obtain an optimized target classification model; and a model inference module for inputting the target spectral data of the bacteria to be measured into the target classification model and determining the target bacterial category of the bacteria to be measured based on the bacterial category prediction probability output by the target classification model.
[0110] Among them, it can be understood that the present application improves the overall accuracy of the model by introducing label information of cell categories into the cell classification modeling process, and uses the prototype learning method to capture the relevance between categories to enhance the classification generalization and improve the recognition rate of unknown bacterial species.
[0111] Some embodiments of the present application provide a computer device. Figure 10 For the structural schematic diagram of the computer device provided in an embodiment of the present application, refer to Figure 10 , the computer device includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, it implements the bacterial classification method based on Raman spectroscopy data in any one of the above embodiments. For example, when executing the method steps S110 to S170 described above Figure 1 in Figure 3 the method steps S310 to S330 in Figure 4 the method steps S410 to S420 in Figure 5 the method steps S510 to S520 in Figure 6 the method steps S610 to S620 in Figure 7 the method steps S710 to S720 in Figure 8 the method steps S810 to S830 in Figure 9 the method steps S910 to S940 in
[0112] The computer device 1000 according to the embodiments of the present application includes one or more processors 1010 and a memory 1020. Figure 10 Taking one processor 1010 and one memory 1020 as an example.
[0113] The processor 1010 and the memory 1020 can be connected through a bus or other means. Figure 10 Taking connection through a bus as an example.
[0114] The memory 1020, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. In addition, the memory 1020 may include high-speed random access memory and may also include non-transitory memory, such as at least one disk storage device, a flash memory device, or other non-transitory solid-state storage devices. In some embodiments, the memory 1020 may optionally include a memory 1020 remotely provided with respect to the processor 1010, and these remote memories can be connected to the computer device 1000 through a network. At the same time, examples of the above network include but are not limited to the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.
[0115] In some embodiments, when the processor executes a computer program, it executes the method for classifying bacteria based on Raman spectroscopy data according to any one of the above embodiments at a preset interval.
[0116] Those skilled in the art can understand that Figure 10 The device structure shown does not limit the computer device 1000, and it may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0117] In Figure 10 In the computer device 1000 shown, the processor 1010 can be used to call the method for classifying bacteria based on Raman spectroscopy data stored in the memory 1020, so as to implement the method for classifying bacteria based on Raman spectroscopy data.
[0118] Based on the above hardware structure of the computer device 1000, various embodiments of the apparatus for classifying bacteria based on Raman spectroscopy data of the present application are proposed. At the same time, the non-transitory software programs and instructions required to implement the method for classifying bacteria based on Raman spectroscopy data of the above embodiments are stored in the memory, and when executed by the processor, they execute the method for classifying bacteria based on Raman spectroscopy data of the above embodiments.
[0119] An embodiment of the present application further provides a computer-readable storage medium, which stores computer-executable instructions for executing the above-mentioned bacterial classification method based on Raman spectroscopy data, enabling the above-mentioned one or more processors to execute the bacterial classification method based on Raman spectroscopy data in any of the above embodiments. For example, execute the method steps S110 to S170 described above Figure 1 in the method steps S110 to S170 in Figure 3 in the method steps S310 to S330 in Figure 4 in the method steps S410 to S420 in Figure 5 in the method steps S510 to S520 in Figure 6 in the method steps S610 to S620 in Figure 7 in the method steps S710 to S720 in Figure 8 in the method steps S810 to S830 in Figure 9 in the method steps S910 to S940 in
[0120] An embodiment of the present application further provides a computer program product, which includes a computer program stored in a computer-readable storage medium. The processor of the computer device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, enabling the computer device to execute and implement the bacterial classification method based on Raman spectroscopy data in any of the above embodiments. For example, execute the method steps S110 to S170 described above Figure 1 in the method steps S110 to S170 in Figure 3 in the method steps S310 to S330 in Figure 4 in the method steps S410 to S420 in Figure 5 in the method steps S510 to S520 in Figure 6 in the method steps S610 to S620 in Figure 7 in the method steps S710 to S720 in Figure 8 in the method steps S810 to S830 in Figure 9 in the method steps S910 to S940. The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed to multiple network nodes. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0121] Those of ordinary skill in the art will appreciate that all or some of the steps and systems disclosed above in the methods can be implemented as software, firmware, hardware, and appropriate combinations thereof. Some or all of the physical components can be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or as hardware, or as an integrated circuit, such as an application specific integrated circuit. Such software can be distributed on a computer-readable medium, which can include a computer-readable storage medium (or non-transitory medium) and a communication medium (or transitory medium). As is well known to those of ordinary skill in the art, the term computer-readable storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information, such as computer-readable instructions, data structures, program modules, or other data. The computer-readable storage medium includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disks (DVDs) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and that can be accessed by a computer. In addition, it is well known to those of ordinary skill in the art that the communication medium typically contains computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transmission mechanism, and can include any information delivery medium. The above is a specific description of the preferred implementation of the present application, but the present application is not limited to the above embodiments. Those skilled in the art can also make various equivalent deformations or substitutions without departing from the spirit of the present application, and these equivalent deformations or substitutions are all included within the scope defined by the claims of the present application.
Claims
1. A method for classifying bacteria based on Raman spectroscopy data, characterized in that, Including: Obtain the original spectral data of different types of bacteria within a target wavenumber range and a target resolution; Obtain multiple bacterial category labels corresponding to different types of bacteria, and construct a multi-level tree-like classification structure characterizing the category membership relationships among the multiple bacterial category labels; Input the original spectral data and the multi-level tree-like classification structure into an initial classification model, where the initial classification model includes multiple cascaded feature extraction layers and a classification layer in sequence; Through the multiple cascaded feature extraction layers in sequence, perform extraction and fusion of spectral features and category features based on the original spectral data and the multi-level tree-like classification structure to generate multiple category-aware features; Calculate the similarity between the multiple category-aware features and preset prototype features through the classification layer, and predict the bacterial category prediction probability corresponding to the original spectral data based on the similarity; Optimize the model parameters of the initial classification model based on the bacterial category prediction probability to obtain an optimized target classification model; Input the target spectral data of the bacteria to be tested into the target classification model, and determine the target bacterial category of the bacteria to be tested based on the bacterial category prediction probability output by the target classification model.
2. The method for classifying bacteria based on Raman spectroscopy data according to claim 1, wherein The extraction and fusion of spectral features and category features based on the original spectral data and the multi-level tree-like classification structure to generate multiple category-aware features includes: According to the multi-level tree-like classification structure, encode each of the bacterial category labels through a hierarchical graph convolutional network to generate node features characterizing the category hierarchical relationship; Perform layer-by-layer abstraction on the original spectral data through a multi-layer one-dimensional convolutional network to extract a spectral feature matrix; Calculate the attention weights of multiple band features in the spectral feature matrix in the node features, and perform weighted summation on the multiple band features according to the weights to generate category-related perception features.
3. The method for classifying bacteria based on Raman spectroscopy data according to claim 2, characterized in that, The construction of a multi-level tree-like classification structure characterizing the category membership relationships among the multiple bacterial category labels includes: According to bacterial taxonomy standards, define hierarchical labels from coarse-grained to fine-grained, where the hierarchical labels include Gram staining results, genus classification, species classification, and strain classification; Generate a label hierarchical structure tree according to the hierarchical relationship among the hierarchical labels, and perform hierarchical processing on the multiple bacterial category labels according to the label hierarchical structure tree, so that the bacterial category labels belonging to the child nodes among the multiple bacterial category labels inherit the classification attributes of the bacterial category labels belonging to the parent nodes to construct a multi-level tree-like classification structure.
4. The method for classifying bacteria based on Raman spectroscopy data according to claim 3, wherein The encoding of each of the bacterial category labels through a hierarchical graph convolutional network according to the multi-level tree-like classification structure to generate node features characterizing the category hierarchical relationship includes: Perform feature aggregation on the bacterial category labels of each node in the tree-like classification structure through a hierarchical graph convolutional network to obtain the label features of each node; Among multiple nodes, fuse the label features of the parent node and the label features of its corresponding child node through a two-way propagation mechanism to generate node features characterizing the category hierarchical relationship.
5. The method for classifying bacteria based on Raman spectroscopy data according to claim 2, wherein The step of abstracting the original spectral data layer by layer through a multi-layer one-dimensional convolutional network to extract a spectral feature matrix includes: Inputting the original spectral data into the multi-layer one-dimensional convolutional network, so that each layer of the one-dimensional convolutional network extracts local features from the original spectral data through convolutional kernels of different sizes; Performing normalization layer integration processing on the band feature sequence output by the last layer in the multi-layer one-dimensional convolutional network to obtain a spectral feature matrix.
6. The method for classifying bacteria based on Raman spectroscopy data according to claim 2, wherein The step of calculating the attention weights of multiple band features in the spectral feature matrix in the node features and performing weighted summation on the multiple band features according to the attention weights to generate a category-related perception feature includes: For the node features of each category, calculating the correlation scores between each band feature in the spectral feature matrix and the node features respectively; Converting the correlation scores into attention weight values through normalization processing, and performing weighted summation on the multiple band features based on the attention weight values to generate a category-related perception feature.
7. The method for classifying bacteria based on Raman spectroscopy data according to claim 3, wherein The prototype features include positive sample prototype features and negative sample prototype features. The step of calculating the similarity between multiple category perception features and preset prototype features through the classification layer and predicting the bacterial category prediction probability corresponding to the original spectral data based on the similarity includes: Obtaining the positive sample prototype features and negative sample prototype features of a preset number of known bacterial species. The positive sample prototype features are generated by the mean value of the sample features of the samples belonging to the known bacterial species in the training samples, and the negative sample prototype features are generated by the mean value of the sample features of the samples not belonging to the known bacterial species in the training samples; Calculating the positive sample similarity between the category perception feature and the positive sample prototype feature, and the negative sample similarity between the category perception feature and the negative sample prototype feature through the classification layer; Taking the ratio of the positive sample similarity to the sum of the positive and negative sample similarities as the bacterial category prediction probability that the original spectral data belongs to the known bacterial species.
8. The method for classifying bacteria based on Raman spectroscopy data according to claim 1, characterized in that, The step of optimizing the model parameters of the initial classification model based on the bacterial category prediction probability to obtain an optimized target classification model includes: Randomly dividing the preset training samples into multiple batches of fixed size, and inputting each batch into the initial classification model in turn for forward inference and outputting the bacterial category prediction probability; Calculating the cross-entropy loss according to the difference between the bacterial category prediction probability and the true label corresponding to the training sample, and updating the model parameters of the initial classification model through the backpropagation algorithm; Repeating the iterative training process until the model loss of the initial classification model tends to be stable or reaches a preset maximum number of iterations to obtain an optimized target classification model.
9. The method for classifying bacteria based on Raman spectroscopy data according to claim 7, wherein The step of determining the target bacterial category of the to-be-detected bacteria based on the bacterial category prediction probability output by the target classification model includes: Setting a classification threshold for each known bacterial species, and performing hierarchical logical constraints on the bacterial category prediction probability according to the classification hierarchical structure: if the category prediction probability corresponding to the parent node is lower than the classification threshold, the categories corresponding to all its child nodes are automatically marked as invalid; The predicted probabilities of each of the known bacterial species are obtained based on the predicted probabilities of bacterial species output by the target classification model, and the predicted probabilities of each of the known bacterial species are compared with the classification threshold based on the hierarchical logical constraint; If the predicted probability of any one of the known bacterial species is higher than the classification threshold, it is determined that the bacteria to be tested belong to the known bacterial species; If the predicted probabilities of each of the known bacterial species are lower than the classification threshold, it is determined that the bacteria to be tested belong to unknown bacterial species.
10. A bacterial classification device based on Raman spectroscopy data, characterized in that, Comprising: A data acquisition module, configured to acquire original spectral data of different types of bacteria within a target wavenumber range and a target resolution; A hierarchical construction module, configured to acquire a plurality of bacterial species labels corresponding to different types of bacteria, and construct a multi-level tree-like classification structure characterizing the class membership relationship between the plurality of bacterial species labels; A data input module, configured to input the original spectral data and the multi-level tree-like classification structure into an initial classification model, where the initial classification model includes a plurality of cascaded feature extraction layers and a classification layer; A feature fusion module, configured to extract and fuse spectral features and class features based on the original spectral data and the multi-level tree-like classification structure through the plurality of cascaded feature extraction layers, and generate a plurality of class-aware features; A feature classification module, configured to calculate the similarity between the plurality of class-aware features and preset prototype features through the classification layer, and predict the predicted probability of the bacterial species corresponding to the original spectral data based on the similarity; A model training module, configured to optimize the model parameters of the initial classification model based on the predicted probability of the bacterial species to obtain an optimized target classification model; A model inference module, configured to input the target spectral data of the bacteria to be tested into the target classification model, and determine the target bacterial species of the bacteria to be tested based on the predicted probability of the bacterial species output by the target classification model.
11. An electronic device, characterized in that, Comprising: At least one processor; At least one memory, configured to store at least one program; When at least one of the at least one program is executed by at least one of the at least one processor, the method for classifying bacteria based on Raman spectral data according to any one of claims 1 to 9 is implemented.
12. A computer-readable storage medium, storing computer-executable instructions, where the computer-executable instructions are used to execute the method for classifying bacteria based on Raman spectral data according to any one of claims 1 to 9.
Citation Information
Cited By
Raman spectrum technology-based method for rapidly detecting types and contents of bacteria in gas
CN121499451A