Abnormal electrocardiosignal classification method and device based on interpretable technology

By introducing a multi-head attention mechanism and a self-attention layer into the abnormal ECG signal classification model, the problem of low credibility of ECG signal classification results in the existing technology is solved, and low-cost, convenient and reliable ECG signal classification is achieved. Remote real-time analysis and diagnostic assistance improve diagnostic accuracy and interpretability.

CN118526207APending Publication Date: 2024-08-23SOUTH CHINA UNIV OF TECH
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202410185068.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-02-19
Publication Date
2024-08-23

AI Technical Summary

Technical Problem

Existing methods for classifying abnormal ECG signals based on deep learning lack complete interpretability, resulting in low credibility of results and difficulty in being widely accepted in clinical practice. They also lack a convenient, low-cost remote real-time ECG signal analysis platform.

Method used

An abnormal ECG signal classification model based on the Transformer framework is used, an interpretable module is built through a multi-head attention mechanism, data preprocessing and model training are performed, and the self-attention layer and decoder module are combined to achieve model interpretability and deployed to The cloud platform performs real-time analysis and visual display.

Benefits of technology

It improves the diagnostic accuracy and interpretability of abnormal ECG signals, provides medical staff with a convenient auxiliary diagnostic tool, enhances the stability and credibility of the model, and realizes low-cost, convenient and reliable ECG signals. remote real-time analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118526207A
    Figure CN118526207A
Patent Text Reader

Abstract

The invention discloses an abnormal electrocardiosignal classification method and device based on an interpretable technology, and belongs to the technical field of signal analysis and artificial intelligence. The method comprises the following steps: acquiring electrocardiogram data fragments and disease labels, and constructing an abnormal electrocardiogram database; obtaining a training set according to the abnormal electrocardiogram database; constructing an abnormal electrocardiosignal classification model, and training the model by adopting the training set; outputting to-be-classified abnormal electrocardiosignals to the trained abnormal electrocardiosignal classification model, and outputting a classification result; wherein the abnormal electrocardiosignal classification model is constructed based on a Transform framework, and in the construction process, an interpretable module is constructed by a multi-head attention mechanism and used for processing the dependency relationship between different parts of an input sequence and completing calculation of the weight of each part of the sequence. A convenient abnormal electrocardiosignal classification auxiliary diagnosis tool is provided for doctors or other professionals, and the diagnosis accuracy and interpretability of the abnormal electrocardiosignals are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of signal analysis and artificial intelligence technology, and in particular to an abnormal electrocardiogram signal classification method and device based on interpretable technology. Background Art

[0002] As one of the important means to reflect heart disease, electrocardiogram examination has attracted much attention in clinical practice. Currently, early screening for many cardiovascular diseases requires patients to go to the hospital for professional medical imaging examinations or wear an electrocardiogram for long-term monitoring. Such examinations are expensive and time-consuming, so a low-cost, convenient, and highly reliable electrocardiogram signal analysis method is needed.

[0003] Compared with traditional ECG detection and analysis methods, devices such as ECG clothing can realize the remote real-time display of patients' ECGs by carrying small programs, APPs and other platforms, providing medical clinical staff with a more efficient way to obtain ECG signals. At the same time, it can also analyze and check patients' ECG data based on the machine learning / deep learning network models carried, providing medical staff with remote real-time auxiliary diagnosis assistance.

[0004] Currently, many abnormal ECG signal classification methods based on deep learning have been proposed, but their system functions are not perfect, lacking a complete and portable ECG acquisition platform and analysis and visualization platform. In addition, the black box characteristics of the neural network model are well known, and the credibility of the ECG signal analysis results obtained by it needs further discussion. Therefore, a low-cost, convenient, remotely viewable, and interpretable ECG signal analysis deep learning model and its series of solutions are needed. Summary of the invention

[0005] In order to solve at least one of the technical problems existing in the prior art to a certain extent, the object of the present invention is to provide a method and device for classifying abnormal electrocardiogram signals based on interpretable technology.

[0006] The technical solution adopted by the present invention is:

[0007] A method for classifying abnormal electrocardiogram signals based on interpretable technology comprises the following steps:

[0008] Obtain ECG data fragments and disease labels associated with the ECG data fragments, and build an abnormal ECG database;

[0009] Preprocess the data in the abnormal ECG database to obtain training sets, test sets, and validation sets;

[0010] Construct an abnormal ECG signal classification model and train the model using a training set;

[0011] Outputting the abnormal ECG signal to be classified to the trained abnormal ECG signal classification model and outputting the classification result;

[0012] Among them, the abnormal ECG signal classification model is built based on the Transformer framework. During the construction process, the multi-head attention mechanism MultiHeadAttention constructs an interpretable module to process the dependencies between different parts of the input sequence and complete the calculation of the weights of each part of the sequence; the interpretable module provides a more convincing model output result for the entire system, which is conducive to improving the stability and credibility of the model.

[0013] Furthermore, the acquisition of ECG data segments and disease labels associated with the ECG data segments and the construction of an abnormal ECG database includes:

[0014] Collect multiple three-lead normal or abnormal ECG signal segments, and obtain the clinical diagnosis type corresponding to each heartbeat in each ECG signal segment as the data input and label of the database to build an abnormal ECG database.

[0015] Furthermore, the data in the abnormal ECG database is preprocessed to obtain a training set, a test set and a validation set, including:

[0016] Perform data cleaning, data expansion and data division on the abnormal ECG segments to make the format of each abnormal ECG segment consistent;

[0017] The data cleaning process includes:

[0018] The n three-lead normal / abnormal ECG signal segments are processed to obtain N groups of three-dimensional tensors of preset length and preset frequency and N one-dimensional data labels corresponding to each group of three-dimensional tensors of ECG signals; the N groups of three-dimensional tensors are collectively referred to as data sets D value_ori , N one-dimensional data labels are collectively referred to as D label_ori , where N>n;

[0019] The data division process comprises:

[0020] The data set D value_ori , D label_ori Divide and obtain a new data set D generated by model fitting value_new , D label_new and the original dataset D value_ori , D label_ori The total data set D value , D label , the data set D value , D label Perform random sampling to obtain the training set D train, test set D test and validation set D val .

[0021] Furthermore, the abnormal ECG signal classification model also includes an encoder module, a decoder module and a classifier;

[0022] The encoder module includes multiple encoders connected in series, and the output of the previous encoder is used as the input of the next encoder; after the input matrix with position information enters the encoder, it is operated using the self-attention mechanism of the self-attention layer; when processing a specific element in the sequence, the information of other elements of the sequence is used to pay attention to the relationship between other elements and a specific element, providing the possibility of interpretability of the model;

[0023] The number of decoders in the decoder module corresponds to the number of encoders. After the ECG sequence data passes through the encoder, a set of attention vectors are output. These attention vectors will be used in the Encoder-Decoder Attention layer of each decoder to enable the decoder to focus on the appropriate position of the input sequence. One element is output at each time step in the decoding stage.

[0024] The classifier is used to convert the vector output by the decoder into a probability, and select the ECG signal category corresponding to the highest probability as the output of this time step.

[0025] Furthermore, the self-attention mechanism is implemented through a self-attention layer. After the ECG sequence is operated through the self-attention layer, it carries information features associated with other elements, so that the model has different attention weights for each time step in the sequence. Visualizing the attention weights can realize the interpretability of the model.

[0026] Furthermore, the specific implementation of the self-attention layer includes the following steps:

[0027] For each input vector of the encoder, three vectors are created: Query vector, Key vector and Value vector;

[0028] Calculate the attention score, and calculate a score for each element in the sequence based on a certain time step element X;

[0029] Divide each score by the dimension of the Key vector, perform Softmax operation on these scores, and normalize them to obtain Softmax scores;

[0030] Multiply each Softmax score by each Value vector to obtain a weighted Value vector;

[0031] Sum the weighted Value vectors to get the output of the self-attention layer.

[0032] Furthermore, the self-attention layer is further improved by:

[0033] In the multi-head self-attention mechanism, the Query vector, Key vector, and Value vector are mapped through h different linear transformations;

[0034] Different attentions are concatenated and a linear transformation is performed; each group of attention is used to map the input to a different sub-representation space so that the model pays attention to different positions in different sub-representation spaces.

[0035] Furthermore, when training the abnormal ECG signal classification model, the model is debugged and tested simultaneously:

[0036] After each round of model training, the model is verified using the validation set. val The ECG sequence data in the model is input to complete the forward propagation and obtain the predicted value of each ECG sequence signal; the accuracy is calculated and the model parameters are updated; after all rounds are completed, the test set D is used test The model is tested on the ECG sequence data in the dataset, and the test accuracy is used to determine whether the model structure needs to be readjusted or the model training needs to be re-done.

[0037] Furthermore, the abnormal electrocardiogram signal classification method further comprises the following steps:

[0038] An abnormal ECG signal cloud processing platform is constructed, and the abnormal ECG signal classification model is deployed to the cloud platform to realize real-time transmission of ECG signals on the hardware and software ends, real-time display of ECG signals, and real-time analysis of abnormal ECG signals, so as to perform real-time classification of abnormal ECG signals and visualization of waveforms, and display interpretable analysis results.

[0039] Another technical solution adopted by the present invention is:

[0040] An abnormal electrocardiogram signal classification device based on interpretable technology, comprising:

[0041] at least one processor;

[0042] at least one memory for storing at least one program;

[0043] When the at least one program is executed by the at least one processor, the at least one processor implements the above method.

[0044] Another technical solution adopted by the present invention is:

[0045] A computer-readable storage medium stores a program executable by a processor, wherein the program executable by the processor is used to execute the method described above when executed by the processor.

[0046] The beneficial effects of the present invention are as follows: the present invention provides a complete full-process solution from data preprocessing to model deployment and application, provides doctors or other professionals with a convenient abnormal ECG signal classification auxiliary diagnosis tool, and improves the diagnostic accuracy and interpretability of abnormal ECG signals. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the embodiments of the present invention or the drawings of related technical solutions in the prior art are introduced below. It should be understood that the drawings introduced below are only for the convenience of clearly describing some embodiments of the technical solutions of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0048] Figure 1 is an overall architecture diagram of an embodiment of the present invention;

[0049] Figure 2 is a flowchart of an abnormal electrocardiogram signal classification method according to an embodiment of the present invention;

[0050] Figure 3 This is a diagram of the SMOTE data amplification effect of an embodiment of the present invention;

[0051] Figure 4 is an interpretable visualization schematic diagram of an embodiment of the present invention;

[0052] Figure 5 is a model recognition effect diagram of an embodiment of the present invention;

[0053] Figure 6 This is a schematic diagram of a mobile phone terminal visualization interface of a system according to an embodiment of the present invention;

[0054] Figure 7 is a schematic diagram of a web page visualization interface according to an embodiment of the present invention;

[0055] Figure 8 It is a schematic diagram of the correlation between the attention distribution map and the heart beats. DETAILED DESCRIPTION

[0056] The embodiments of the present invention are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and are not to be construed as limitations of the present invention. For the step numbers in the following embodiments, they are only provided for the convenience of explanation, and the order between the steps is not limited in any way, and the execution order of each step in the embodiment can be adaptively adjusted according to the understanding of those skilled in the art.

[0057] In the description of the present invention, it should be understood that descriptions involving orientations, such as up, down, front, back, left, right, etc., and orientations or positional relationships indicated are based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the present invention.

[0058] In the description of the present invention, "several" means one or more, "more" means more than two, "greater than", "less than", "exceed" etc. are understood as not including the number itself, and "above", "below", "within" etc. are understood as including the number itself. If there is a description of "first" or "second", it is only used for the purpose of distinguishing the technical features, and cannot be understood as indicating or implying the relative importance or implicitly indicating the number of the indicated technical features or implicitly indicating the order of the indicated technical features.

[0059] In the description of the present invention, unless otherwise clearly defined, terms such as setting, installing, connecting, etc. should be understood in a broad sense, and technicians in the relevant technical field can reasonably determine the specific meanings of the above terms in the present invention based on the specific content of the technical solution.

[0060] Terminology explanation:

[0061] Interpretable technology is a technology that allows machine learning / deep learning models to explain their output results. Since deep learning models usually have a large number of parameters and complex structures, they are often considered black box models and it is difficult to understand their decision-making process. Therefore, in order to improve the credibility and usability of deep learning models, researchers have been working hard to develop various interpretable technologies.

[0062] Take the ECG classification task of this application as an example. If there is no explainable technology, after doctors and patients see the classification results of the deep learning model, they do not know how the model judges the input ECG sequence. The model cannot provide specific reasons for distinguishing the disease, which will cause users to feel uncertain and reduce their trust in the model. Furthermore, in some medical application scenarios, there may be ethical requirements for transparent explanations of medical decisions, whether they are wrong or right. If only fuzzy classification results are provided, it may cause responsibility and trust issues. If explainable technology is used to make the model explainable, for example, in a section of ECG sequence, let the model mark the intervals it considers important, or output the weight distribution (attention distribution) at each time step, then the user can see which area of ​​the entire sequence the model focuses on. A certain type of abnormal ECG always has similar features. If the model focuses on this feature (the weight distribution of the time step near the feature is large) and outputs the corresponding discrimination result, then the user will think that the model has a higher reliability. Therefore, explainable technology is more important in sensitive fields such as medicine. For example: Figure 8 As shown in the figure, the attention distribution diagram output by the model (red represents high attention in the figure) shows that when an abnormal signal occurs, the model pays higher attention to the time steps nearby. Similarly, when other heartbeats occur, there is also a certain degree of attention.

[0063] Based on the above, the present invention provides a method for classifying abnormal ECG signals based on deep learning and interpretable technology. First, ECG data fragments of patients with different cardiovascular diseases and their associated disease labels are collected into an abnormal ECG database through data collection. Then, in the data preprocessing stage, the abnormal ECG fragments are cleaned, expanded, and divided to ensure that each abnormal ECG fragment has a consistent format and can be recognized by the training model. Then, the training and learning of abnormal ECG signals are carried out through each layer of the training model network, and the characteristic information of abnormal ECG signals is extracted. At the same time, the weight information of ECG signal fragments is stored using interpretable technology. Finally, the model can be deployed to a cloud server, and abnormal ECG signals can be sent to the server. Abnormal ECG signal classification and waveform visualization can be performed in real time, and interpretable analysis results can be displayed.

[0064] This embodiment provides a method for classifying abnormal ECG signals based on interpretable technology, including the following steps:

[0065] S1. Data collection and source. Collect n three-lead normal / abnormal ECG signal segments and the clinical diagnosis type corresponding to each heartbeat in each ECG signal segment as data input and labels for the database.

[0066] As an optional implementation, abnormal or normal three-lead ECG data of patients with more than seven cardiovascular diseases are collected. The patients range in age from 6 to 80 years old, and have different ages, occupations, genders and medical histories. The cardiovascular diseases included include atrial premature beats (APB), fusion waveforms (F), left bundle branch block (LBBB), right bundle branch block (RBBB), supraventricular premature beats (SPB), ventricular premature beats (VPB), sinus rhythm (N), etc. The collected three-lead ECG signal segments are all labeled with the abnormal name corresponding to each heartbeat signal.

[0067] S2. Data cleaning. Data preprocessing is performed based on the n three-lead normal / abnormal ECG signal segments to obtain N groups of three-dimensional tensors with a length of 1600 and a sampling frequency of 160 Hz and N one-dimensional data labels corresponding to each group of three-dimensional tensors of ECG signals. The N groups of three-dimensional tensors are collectively referred to as data sets D. value_ori , N one-dimensional data labels are collectively referred to as D label_ori , where N>n.

[0068] As an optional implementation, the data cleaning includes processes such as data clipping, label normalization, filtering and noise reduction, and unified sampling rate, and removes ECG signal sequences with little reference significance such as excessive noise and missing leads, and organizes three-lead ECG data with a total length of several hours into more than 70,000 three-lead ECG data with a time length of 10 seconds, and each ECG data corresponds to an ECG signal feature.

[0069] S3, data division. The data set D value_ori , D label_ori After necessary data expansion and other means, a new data set D generated by model fitting is obtained. value_new , D label_new and the original dataset D value_ori , D label_ori The total data set D value , D label , which aims to reduce the impact of the imbalanced category in the original data set on the model training results. The total data set D value , D label The number of normal / abnormal ECG signal segments corresponding to each category label in the three-lead is similar. The total data set is randomly sampled to obtain the training set D train , test set D test and validation set D val .

[0070] As an optional implementation, the data partitioning is to divide the data set D value_ori , D label_ori Divide into training set Dtrain , test set D test and validation set D val The process needs to ensure that all types of ECG data in each data set account for a roughly equal proportion to ensure the effectiveness of model training. The data division adopts the SMOTE oversampling method to synthesize minority class samples. The principle is to use a minority sample and its k nearest samples, calculate the difference between the samples and fit a new synthetic sample. The generated training set D train , test set D test and validation set D val Both include seven types of normal / abnormal three-lead ECG data, including atrial premature beats (APB), fusion waveform (F), left bundle branch block (LBBB), right bundle branch block (RBBB), supraventricular premature beats (SPB), ventricular premature beats (VPB), and sinus rhythm (N), and the number of each category is comparable.

[0071] S4. Construct an abnormal ECG signal classification model. The model framework is constructed based on the Transformer framework, including an input layer, an encoder module, a decoder module and a classifier. In the process of constructing the abnormal ECG signal classification model, an interpretable module is constructed based on the multi-head attention mechanism MultiHeadAttention in the Transformer framework system, which is used to process the dependencies between different parts of the input sequence and complete the calculation of the weights of each part of the sequence. The interpretable module provides a more convincing model output result for the entire system, which is conducive to improving the stability and credibility of the model.

[0072] S5, training model. train As input, and set the initial model parameters, the test set D test and validation set D val Input the model framework, train the output model to predict the ECG signal classification results and the trained Transformer network model and network model node weight parameters.

[0073] As an optional implementation, the training of the abnormal ECG signal classification model includes the following contents:

[0074] Position encoding, the ECG sequence tensor flows into the encoder. In order to use the order information of the sequence, the encoder injects absolute or relative position information by adding position encoding to the input representation. In order to make the Transformer model understand the order relationship of elements in the sequence, the position encoding technology can input the ECG sequence tensor into the model in an ordered form. The dimension of the position encoding matrix P is the same as the dimension of the input matrix X.

[0075] Encoder: The Transformer has more than one encoder, but a group of N encoders connected in series, and the output of the previous encoder is used as the input of the next encoder. After the input matrix with position information enters the encoder, the self-attention mechanism of the Self-Attention layer is used for calculation. When processing a specific element in the sequence, the information of other elements of the sequence is used. Therefore, the model can pay attention to the relationship between other elements and a specific element, and provide the possibility of model interpretability.

[0076] Decoder: The number of decoders in the Transformer corresponds to that of encoders. After the ECG sequence data passes through the encoder, a set of attention vectors is output. These vectors will be used in the Encoder-Decoder Attention layer of each decoder, which helps the decoder focus on the appropriate position of the input sequence. One element is output at each time step in the decoding stage.

[0077] Softmax layer classifier, the float vector output by the decoder passes through the linear layer and the Softmax layer classifier. The linear layer is a simple fully connected neural network that maps the output vector of the decoder stack to a longer vector space, and then the Softmax layer will convert these score vectors into probabilities, and finally select the ECG signal category corresponding to the highest probability as the output of this time step.

[0078] The self-attention mechanism is implemented through the Self-Attention layer and is crucial to the interpretability of the model. After the ECG sequence is operated by the Self-Attention layer, it will carry information features associated with other elements, so that the model has different attention weights for each time step in the sequence. Visualizing it can achieve the interpretability of the model. The specific implementation of the Self-Attention layer includes the following steps:

[0079] S51. For each input vector of the encoder, three vectors are created: a Query vector, a Key vector, and a Value vector. They are obtained by multiplying the input vector with three matrices respectively, and the three matrices are obtained through training.

[0080] S52, calculating the attention score, according to a certain time step element X, a score is calculated for each element in the sequence, these scores determine how much attention needs to be placed on each element at other positions in the sequence when encoding the X element. The score is obtained by calculating the dot product of the query vector of the time step element X and the key vector of the element to be scored.

[0081] S53. Divide each fraction by (the dimension of the Key vector), and perform Softmax operations on these scores and normalize them so that they are all positive numbers and sum to 1. These Softmax scores determine how much attention is paid to the elements at all positions when encoding the element at the current position.

[0082] S54. Multiply each Softmax score by each Value vector respectively. The purpose is: for positions with high scores, the larger the multiplied value is, the model pays more attention to them; for positions with low scores, the smaller the multiplied value is, the elements at these positions are not highly correlated, and the model can ignore the elements at these positions.

[0083] S55, sum the weighted Value vector (i.e. the vector obtained in the previous step). This will give the output of the self-attention layer at this position.

[0084] The above steps complete the calculation of self-attention, and the generated vector is input into the feedforward network. In actual implementation, this calculation is performed in matrix form to achieve faster processing speed.

[0085] As an optional implementation, the self-attention mechanism needs to be further improved. In the multi-head self-attention mechanism, first, the Query vector, Key vector, and Value vector are mapped through h different linear transformations; then, different Attentions are concatenated and a linear transformation is performed. Each group of attention is used to map the input to a different sub-representation space, which allows the model to focus on different positions in different sub-representation spaces. The entire calculation process can be expressed as:

[0086] MultiHead(Q,K,V)=Concat(head1,…,head h )W O

[0087] head i =Attention(QW i o ,KW i O ,VW i O )

[0088] S6. Debug the model. val The model is input for verification and debugging, and the model effect is evaluated. If it is found that the model evaluation result is inconsistent with the expected effect, the model parameters will be adjusted, and the model pre-training and fine-tuning will be repeated until the model evaluation result meets the expected requirements.

[0089] S7. In the model testing phase, the relevant data test set D is used test The fine-tuned abnormal ECG signal classification model is tested and the model effect is evaluated. If the evaluation result does not meet the expected requirements, the model parameters are adjusted, and the model is pre-trained and fine-tuned again until the model evaluation result meets the preset standard.

[0090] Model debugging and testing are carried out simultaneously during the model training process. After each round of model training, the model will be verified using the validation set. val The ECG sequence data in is input into the model, the forward propagation is completed and the predicted value of each ECG sequence signal is obtained; the accuracy is calculated and the model parameters, such as the learning rate, are updated. After all rounds are completed, the test set D is used test The model is tested on the ECG sequence data in the dataset, and the test accuracy is used to determine whether the model structure needs to be readjusted or the model training needs to be re-done.

[0091] S8. At the application level, an abnormal ECG signal cloud processing platform is constructed, and the abnormal ECG signal classification model is deployed to the cloud platform to realize real-time transmission of ECG signals on the hardware and software ends, real-time display of ECG signals, and real-time analysis of abnormal ECG signals, providing users with a good operating environment and intuitive data analysis results.

[0092] As an optional implementation, the abnormal ECG signal cloud processing platform is designed to realize functions such as remote real-time data viewing, remote auxiliary diagnosis and data cloud storage. Its design and construction include the construction of a cloud database. The steps of building the cloud database are as follows: first, install the MySQL database service and the tomcat container service in the cloud server; secondly, use the JavaScript language to write a JavaWeb project and deploy it to the cloud server, and request data from the cloud database in the form of external instructions sent by the user. The abnormal ECG signal cloud processing platform also includes a real-time data viewing function. After the user selects data synchronization on the client, the manager can remotely log in to the Web page to view the user's ECG sequence data in real time. Its design is realized by WebSocket technology, which is a technology that can perform arbitrary two-way data transmission between the client and the server. The difference between ordinary Http requests and Http requests is that the client initiates the request, the server connection is opened, and the connection is closed after the request is responded, while the WebSocket is the client that first performs a handshake procedure. After the handshake is successful, the WebSocket connection will always exist, and a two-way channel of the WebSocket will be established during the period. The corresponding code needs to be written on the server side. After the server receives the data sent by the client, it will automatically perform logical processing and return the corresponding data to the client. WebSocket technology is suitable for frequent two-way communication with small data volume, which can avoid opening connections multiple times and save resources. At the same time, WebSocket will establish different channels with the server for each client, which can realize the data synchronization function of multiple people at the same time.

[0093] The remote auxiliary diagnosis is based on the abnormal ECG signal classification model deployed in the cloud. The flask application service is deployed in the cloud server, and the abnormal ECG signal classification model is packaged and deployed in the flask application. In the client code, WebSocket technology is used to communicate with the cloud server flask application, and the real-time collected ECG sequence data is sent to the flask application. Then, the forward propagation of the ECG sequence is completed in the cloud server, and the corresponding analysis results are obtained through model classification, and then synchronously sent back to the client for the user to view. In this way, real-time remote auxiliary diagnosis of ECG sequence signals is realized, and the data analysis results are visualized.

[0094] ECG analysis visualization includes the following steps: First, the client receives the ECG sequence signal prediction result returned by the cloud server, which contains the attention vector and analysis result of the real-time ECG sequence in the form of an array; second, the receiving information callback method in the client code is triggered, and the returned data is simply post-processed and fed back to the UI interface. This completes the visualization of ECG sequence signal analysis, which shows the model's attention to each time step of the sequence and the ECG analysis results, and has a certain degree of interpretability.

[0095] The above method is explained in detail below with reference to the accompanying drawings and specific embodiments.

[0096] See also Figure 1 , Figure 2 , an abnormal electrocardiogram signal classification method based on deep learning and interpretable technology in this embodiment includes the following steps:

[0097] Step 1: Data collection and source. Collect n three-lead normal / abnormal ECG signal segments and the clinical diagnosis type corresponding to each heartbeat in each ECG signal segment as data input and labels for the database.

[0098] Among them, n three-lead normal / abnormal ECG signal fragments are collected through a three-lead ECG clothing device. The collection subjects are selected from groups with different ages, genders, occupations, and medical histories. Each person has ECG data collected for a few minutes to several hours, and professional medical staff label the data with heart beats.

[0099] Step 2: Data cleaning. This includes the following steps:

[0100] A1. Resample the ECG data using the resample method in the scipy.signal library in Python, and set the resampling frequency to 160Hz.

[0101] A2. Use a bandpass filter to filter, and set the filter bandwidth to 0.5Hz to 50Hz, that is, filter out low-frequency noise below 0.5Hz to reduce the impact of baseline drift, and filter out high-frequency noise interference above 50Hz;

[0102] A3. Use LOESS smoothing filter and call the lowess method in the sm.nonparametric library in Python to further filter the ECG waveform to further eliminate the influence of noise. The parameter frac is set to 0.0025.

[0103] A4, perform NLM filtering, i.e. non-local mean filtering noise reduction, the goal is to consider the non-local similarity information in the signal, perform noise reduction on each point, and maintain the overall characteristics of the signal by normalizing the noise reduction results. The key parameter Nvar represents the degree of non-local similarity, which affects the weight calculation, P represents the difference range considered when calculating non-local similarity, PatchHW represents the half width of the block in the signal used to calculate similarity. In this embodiment, Nvar takes the variance of a section of the signal, P takes 7, and PatchHW takes 10;

[0104] A5. Round the signal value to three decimal places to reduce the required computing power;

[0105] A6. Cut the signal into 10s segments, i.e. one segment of ECG sequence contains 1600 data points;

[0106] A7. Select the most abnormal labels that appear in the 10s window as the sequence label of this segment, so that each ECG data corresponds to an ECG signal feature.

[0107] Step 3: Data partitioning. Figure 3 , it is necessary to transform the dataset D value_ori , D label_ori Divide into training set D train , test set D test and validation set D val The process. It is necessary to ensure that the proportion of all types of ECG data in each data set is basically equal to ensure the effectiveness of model training. The data division adopts the SMOTE oversampling method to synthesize minority category samples. The principle is to use a minority sample and its k nearest samples, calculate the difference between samples and fit a new synthetic sample. In this embodiment, SMOTE oversampling includes the following steps:

[0108] B1. Dimensionality reduction by principal component analysis: Use PCA to reduce the multidimensional ECG sequence data to a two-dimensional plane and check the data distribution.

[0109] B2. Use the SMOTE method to amplify various types of data. To ensure the repeatability of the results, random_state is set to 42. To ensure that the number of normal / abnormal three-lead ECG data of atrial premature beats (APB), fusion waveform (F), left bundle branch block (LBBB), right bundle branch block (RBBB), supraventricular premature beats (SPB), ventricular premature beats (VPB), and sinus rhythm (N) is equivalent, the sampling_strategy parameters used for SMOTE amplification of various types of data are 1:25000, 1:10000, 1:12500, 1:20000, 1:20000, 1:8000, and None, respectively.

[0110] Step 4: Build the network model.

[0111] The key parameters of the model are seq_len, n_features, d_model, num_heads, num_classes, num_layers, and dropout. seq_len represents the length of the input sequence, n_features represents the feature dimension of the input data, and d_model represents the hidden layer dimension of the Transformer model, which is also the output dimension of the input embedding layer. In this model, the input data is embedded through a linear layer (self.input_layer) to map the feature dimension to the hidden layer dimension. num_heads represents the number of heads in the multi-head attention mechanism, num_classes represents the number of categories in the classification task, and the number of categories that the model finally outputs. num_layers represents the number of stacked layers in the Transformer model. Each layer contains a TransformerBlock, which contains a multi-head self-attention layer and a feedforward neural network layer. Dropout represents the probability of the dropout layer used inside the TransformerBlock.

[0112] In this embodiment, seq_len is set to 1600, indicating that the length of each sequence is 1600, n_features is set to 3, indicating that each time step has three leads, i.e., three feature dimensions of information, d_model is set to 128, num_heads is set to 8, num_classes is set to 7, indicating that the model performs seven classification tasks, num_layers is set to 4, and dropout is set to 0.1.

[0113] Step 5: Training module. This includes the following steps:

[0114] C1. Use Python to create a DataLoader object and store the encapsulated dataset in the DataLoader object for subsequent calls. The hyperparameter batch_size is set to 18 and shuffle is set to True.

[0115] C2. Create a model using the above model building method, create a loss function and an optimizer. In this embodiment, the loss function is calculated using CrossEntropyLoss cross entropy, and the optimizer uses an SGD optimizer.

[0116] C3. Set hyperparameters. In this embodiment, the initial learning rate learning_rate is set to 0.0005, and the number of training rounds epoch is set to 2000.

[0117] C4. Reshape the ECG sequence data and labels to convert them into tensor form for model training. The ECG sequence tensor after the Reshape operation is [18,1600,1], where 18 represents batch_size, 1600 represents seq_len, and 1 represents the expanded dimension;

[0118] C5, model training, its specific steps include forward propagation, residual calculation, back propagation, parameter optimization, etc., among which the parameter optimization step uses the gradient descent method to find the optimal parameters;

[0119] C6, model verification, use the verification set data to perform periodic verification on the training results, calculate the accuracy (Accuracy), precision (Precision), recall (Recall) and other information, which helps to understand the performance of the model and further adjust the model's training hyperparameters. Among them, the accuracy calculation formula is The accuracy calculation formula is: The recall calculation formula is: Among them, TP represents true positive examples, TN represents true negative examples, FP represents false positive examples, and FN represents false negative examples.

[0120] In this embodiment, the learning rate is adjusted dynamically, and the learning rate gradually decreases as the training progresses. This example uses a fixed decay strategy, using a learning rate of 0.0005 for the first 100 Epochs, a learning rate of 0.0002 for 100 to 200 Epochs, and a learning rate of 0.0001 for 200 Epochs and beyond. Dynamically adjusting the learning rate can help the model converge faster, especially in the early stages of training. As the model approaches the optimal solution, gradually reducing the learning rate can improve the stability of convergence.

[0121] Step 6: Evaluate model interpretability.

[0122] In this example, the interpretability of the model is evaluated by the following steps:

[0123] D1. Load the model and use torch.load and load_state_dict to load the trained Transformer model from the saved weights.

[0124] D2, forward propagation and obtaining attention weights: Make transformer(ECG_data) perform forward propagation to obtain the output and attention weights of the model;

[0125] D3, visualization of attention weights, here, by looping through each head, plt.imshow is used to visualize the attention weights as images, which shows how much the model pays attention to the input sequence during inference. Figure 4The figure shows the visualization of the attention weight distribution of the first dimension of multi-head attention for a certain ECG sequence signal, which is helpful for explaining the model's decision-making process for the input. Figure 5 The figure shows the clustering visualization and confusion matrix effect of the Transformer model, which can characterize the effect of model training.

[0126] In the acquisition of attention weights in step D2 above, the following steps are taken:

[0127] D21, linear transformation, maps the original input to multiple subspaces through the linear transformation of the weight matrix. For each position of the input sequence, three different representations are obtained through linear transformation, namely, the Query vector, the Key vector, and the Value vector. Specifically, for the i-th head, the linear transformation is calculated as follows:

[0128]

[0129] Where X is the input sequence, and is the weight matrix.

[0130] D22, Attention weight calculation, for each head, calculate the attention weight. The attention weight is obtained by calculating the similarity between the query vector and the key vector, then scaled, and finally processed by the softmax function to ensure the normalization of the attention weight;

[0131] D23, weighted summation, using the obtained attention weights for weighted summation to obtain the output of each head:

[0132] head i =Attention(QW i O ,KW i O ,VW i O )

[0133] D24, splicing and linear transformation, splicing the outputs of all heads together:

[0134] MultiHead(Q,K,V)=Concat(head1,…,head h )W O

[0135] Step 7: Build an abnormal ECG signal cloud processing platform.

[0136] Written WEB applications and Android APP applications. The core of the WEB application is the WebSocket communication protocol, which is designed to process the ECG signal data of multiple users. Its remote auxiliary diagnosis is based on the abnormal ECG signal classification model deployed in the cloud. The flask application service is deployed in the cloud server, and then the abnormal ECG signal classification model is packaged and deployed in the flask application. In the client code, WebSocket technology is used to communicate with the cloud server flask application, and the real-time collected ECG sequence data is sent to the flask application. Then the forward propagation of the ECG sequence is completed in the cloud server, and the corresponding analysis results are obtained through model classification, and then sent back to the client synchronously for users to view. See Figure Figure 6 , thereby realizing real-time remote assisted diagnosis of ECG sequence signals and visualizing the data analysis results.

[0137] See also Figure 7 In this embodiment, the software platform can manage the smart wearable three-lead ECG clothing device, and has the functions of real-time viewing of device sensor data, intelligent data analysis, cloud server database storage, and remote real-time management. The platform has compiled user and administrator data systems to enhance the customer's user experience and is a feature-rich group health data management platform. Among them, users of the smart three-lead ECG clothing device can download the APP to view and manage their own health data. Medical staff or other health managers can serve as administrators of the smart three-lead ECG clothing device software service platform and use the system's Web management terminal to manage and monitor the health data of multiple users. Administrators can also formulate health intervention plans based on data analysis results to provide users with more professional health advice.

[0138] This embodiment also provides an abnormal electrocardiogram signal classification device based on interpretable technology, including:

[0139] at least one processor;

[0140] at least one memory for storing at least one program;

[0141] When the at least one program is executed by the at least one processor, the at least one processor implements Figure 2 The method shown.

[0142] An abnormal ECG signal classification device based on interpretable technology in this embodiment can execute an abnormal ECG signal classification method based on interpretable technology provided by the method embodiment of the present invention, can execute any combination of implementation steps of the method embodiment, and has the corresponding functions and beneficial effects of the method.

[0143] The present application also discloses a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device can read the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes Figure 2 The method shown.

[0144] This embodiment also provides a storage medium storing instructions or programs that can execute an abnormal ECG signal classification method based on interpretable technology provided by the method embodiment of the present invention. When the instructions or programs are run, any combination of implementation steps of the method embodiment can be executed, and the corresponding functions and beneficial effects of the method can be obtained.

[0145] In some selectable embodiments, the function / operation mentioned in the block diagram may not occur in the order mentioned in the operation diagram. For example, depending on the function / operation involved, the two boxes shown in succession can actually be executed substantially simultaneously or the boxes can sometimes be executed in reverse order. In addition, the embodiment presented and described in the flow chart of the present invention is provided by way of example, for the purpose of providing a more comprehensive understanding of technology. The disclosed method is not limited to the operation and logic flow presented herein. Selectable embodiments are expected, wherein the order of various operations is changed and the sub-operation of a part for which is described as a larger operation is performed independently.

[0146] In addition, although the present invention is described in the context of functional modules, it should be understood that, unless otherwise specified, one or more of the functions and / or features described may be integrated into a single physical device and / or software module, or one or more functions and / or features may be implemented in separate physical devices or software modules. It is also understood that a detailed discussion of the actual implementation of each module is unnecessary for understanding the present invention. More specifically, in view of the properties, functions, and internal relationships of the various functional modules in the device disclosed herein, the actual implementation of the module will be understood within the conventional skills of the engineer. Therefore, those skilled in the art can implement the present invention set forth in the claims without excessive experimentation using ordinary techniques. It is also understood that the specific concepts disclosed are merely illustrative and are not intended to limit the scope of the present invention, which is determined by the full scope of the appended claims and their equivalents.

[0147] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program codes.

[0148] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in conjunction with such instruction execution systems, devices or apparatuses. For the purposes of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in conjunction with such instruction execution systems, devices or apparatuses.

[0149] More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk case (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be a paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, deciphering or, if necessary, processing in another suitable manner, and then stored in a computer memory.

[0150] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0151] In the above description of this specification, the description with reference to the terms "one embodiment / example", "another embodiment / example" or "certain embodiments / examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.

[0152] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the claims and their equivalents.

[0153] The above is a specific description of the preferred implementation of the present invention, but the present invention is not limited to the above embodiments. Those skilled in the art may make various equivalent modifications or substitutions without violating the spirit of the present invention. These equivalent modifications or substitutions are all included in the scope defined by the claims of this application.

Claims

1. A method for classifying abnormal electrocardiogram signals based on interpretable technology, characterized in that: The following steps are involved: Obtain ECG data fragments and disease labels associated with the ECG data fragments, and build an abnormal ECG database; Preprocess the data in the abnormal ECG database to obtain training sets, test sets, and validation sets; Construct an abnormal ECG signal classification model and train the model using a training set; Outputting the abnormal ECG signal to be classified to the trained abnormal ECG signal classification model and outputting the classification result; Among them, the abnormal ECG signal classification model is built based on the Transformer framework. During the construction process, the multi-head attention mechanism constructs an interpretable module to process the dependencies between different parts of the input sequence and complete the calculation of the weights of each part of the sequence.

2. The abnormal electrocardiogram signal classification method based on interpretable technology according to claim 1 is characterized in that: The step of acquiring ECG data segments and disease labels associated with the ECG data segments and constructing an abnormal ECG database includes: Collect multiple three-lead normal or abnormal ECG signal segments, and obtain the clinical diagnosis type corresponding to each ECG signal segment as the data input and label of the database to build an abnormal ECG database.

3. The abnormal electrocardiogram signal classification method based on interpretable technology according to claim 1 is characterized in that: The data in the abnormal ECG database is preprocessed to obtain a training set, a test set and a validation set, including: Perform data cleaning, data expansion and data division on the abnormal ECG segments to make the format of each abnormal ECG segment consistent; The data cleaning process includes: The n three-lead normal / abnormal ECG signal segments are processed to obtain N groups of three-dimensional tensors of preset length and preset frequency and N one-dimensional data labels corresponding to each group of three-dimensional tensors of ECG signals; the N groups of three-dimensional tensors are collectively referred to as data sets D value_ori , N one-dimensional data labels are collectively referred to as D label_ori , where N>n; The data division process comprises: The data set D value_ori , D label_ori Divide and obtain the total data set D value , D label , the data set D value , D label Perform random sampling to obtain the training set D train , test set D test and validation set D val .

4. The abnormal electrocardiogram signal classification method based on interpretable technology according to claim 1 is characterized in that: The abnormal ECG signal classification model also includes an encoder module, a decoder module and a classifier; The encoder module includes multiple encoders connected in series, and the output of the previous encoder is used as the input of the next encoder; after the input matrix with position information enters the encoder, it is operated using the self-attention mechanism of the self-attention layer; when processing a specific element in the sequence, the information of other elements of the sequence is used to pay attention to the relationship between other elements and a specific element, providing the possibility of interpretability of the model; The number of decoders in the decoder module corresponds to the number of encoders. After the ECG sequence data passes through the encoder, a set of attention vectors is output. These attention vectors will be used in the Encoder-Decoder Attention layer of each decoder so that the decoder can focus on the appropriate position of the input sequence. One element is output at each time step in the decoding stage. The classifier is used to convert the vector output by the decoder into a probability and select the ECG signal category corresponding to the highest probability as the output of this time step.

5. The abnormal electrocardiogram signal classification method based on interpretable technology according to claim 4 is characterized in that: The self-attention mechanism is implemented through the self-attention layer. After the ECG sequence is operated by the self-attention layer, it carries information features associated with other elements, so that the model has different attention weights for each time step in the sequence. Visualizing it can realize the interpretability of the model.

6. The abnormal electrocardiogram signal classification method based on interpretable technology according to claim 4 or 5, characterized in that: The specific implementation of the self-attention layer includes the following steps: For each input vector of the encoder, three vectors are created: Query vector, Key vector and Value vector; Calculate the attention score, and calculate a score for each element in the sequence based on a certain time step element; Divide each score by the dimension of the Key vector, perform Softmax operation on these scores, and normalize them to obtain Softmax scores; Multiply each Softmax score by each Value vector to obtain a weighted Value vector; Sum the weighted Value vectors to get the output of the self-attention layer.

7. The abnormal electrocardiogram signal classification method based on interpretable technology according to claim 6 is characterized in that: The self-attention layer is further improved by: In the multi-head self-attention mechanism, the Query vector, Key vector, and Value vector are mapped through multiple different linear transformations; Different attentions are concatenated and a linear transformation is performed; each group of attention is used to map the input to a different sub-representation space so that the model pays attention to different positions in different sub-representation spaces.

8. According to the abnormal ECG signal classification method based on interpretable technology described in claim 1, when the abnormal ECG signal classification model is trained, the model is debugged and tested simultaneously: After each round of model training, the model is verified using the validation set. val The ECG sequence data in the model is input to complete the forward propagation and obtain the predicted value of each ECG sequence signal; the accuracy is calculated and the model parameters are updated; after all rounds are completed, the test set D is used test The model is tested on the ECG sequence data in the dataset, and the test accuracy is used to determine whether the model structure needs to be readjusted or the model training needs to be re-done.

9. The abnormal electrocardiogram signal classification method based on interpretable technology according to claim 1, characterized in that: The abnormal electrocardiogram signal classification method further comprises the following steps: An abnormal ECG signal cloud processing platform is constructed, and the abnormal ECG signal classification model is deployed to the cloud platform to realize real-time transmission of ECG signals on the hardware and software ends, real-time display of ECG signals, and real-time analysis of abnormal ECG signals, so as to perform real-time classification of abnormal ECG signals and visualization of waveforms, and display interpretable analysis results.

10. An abnormal electrocardiogram signal classification device based on interpretable technology, characterized in that: include: at least one processor; at least one memory for storing at least one program; When the at least one program is executed by the at least one processor, the at least one processor implements the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Electrocardiosignal identification and classification method based on multi-cascade deep neural network

    CN113901893A

  • Medical health dynamic prediction method, system and equipment

    CN114420292A

  • Model interpretation method and device, electronic equipment and storage medium

    CN115457365A

  • Electrocardiosignal detecting and positioning method based on weak supervised learning

    CN116584951A

  • Multi-source heterogeneous data fusion and analysis method in engineering field

    CN116861269A