Arrhythmia classification method based on self-attention mechanism
By employing wavelet transform and multi-head self-attention mechanism for arrhythmia classification, this method solves the problems of long classification time and difficulty in extracting low-amplitude features in existing technologies, and achieves efficient and accurate abnormal heart rhythm identification.
Patent Information
- Application Number
- CN202211133248.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-17
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2042-09-17
AI Technical Summary
Existing arrhythmia classification methods are time-consuming in feature extraction and selection, and deep learning-based methods are slow to process large datasets, cannot be parallelized, and are difficult to accurately acquire low-amplitude ECG signal features and automatically identify abnormal heart rhythms.
A self-attention mechanism-based arrhythmia classification method is adopted. The ECG signal is preprocessed by wavelet transform, and a multi-head self-attention mechanism arrhythmia classification network is constructed, including an ECG vector representation layer, a linear interval projection layer, a signal sequence encoding layer, a multi-head self-attention calculation layer, and an ECG signal output layer. The multi-head self-attention mechanism is used to capture global contextual information and extract semantic features between ECG segments.
It improves the quality of ECG signal data, enabling efficient and accurate automatic identification of abnormal heart rhythms. It fully utilizes the semantic information and local correlations in ECG signals, thereby enhancing the accuracy and efficiency of classification.
Smart Images

Figure CN115530788B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of medical signal processing, and in particular to a method for detecting arrhythmia from electrocardiogram signals. BACKGROUND
[0002] Cardiovascular disease is the leading cause of human death. One important manifestation of patients with cardiovascular disease is the abnormality of electrical impulses. The abnormality of electrical impulses can lead to arrhythmia, thereby causing cardiovascular disease to occur. Cardiovascular disease is not easy to detect in the early stage, and timely and accurate diagnosis of the type of arrhythmia is the key to the early prevention and diagnosis of cardiovascular disease. Electrocardiogram can record the physiological state of the heart and is the data basis for diagnosing the type of arrhythmia. Generally, electrocardiogram signals are periodic and consist of multiple heartbeats, and each heartbeat consists of several consecutive waves. Different types of arrhythmia are associated with a certain specific waveform pattern, which makes it possible to classify arrhythmia.
[0003] Currently, the methods for classifying arrhythmia mainly include machine learning methods and deep learning methods. Machine learning methods usually require a large amount of time overhead in feature extraction and feature selection. The classification process of machine learning methods uses a large number of mathematical formulas, which has an advantage in interpretability, but has weak adaptability to different electrocardiogram signals. In other words, even for the same patient, the classification results will be different due to the small differences in waveform performance in different environments. Deep learning-based methods have shown superiority in data preprocessing, feature extraction, and local correlation of signals, but there are still some problems in deep learning-based methods. First, most deep learning-based methods require many complex convolution and recursive structures. CNN uses convolution kernels to extract abstract high-level features, and in theory, its receptive field should cover the whole graph, but many studies have shown that its actual receptive field is much smaller than the theoretical receptive field, which is not conducive to our full use of context information for feature extraction and association. The current hidden state of the RNN model depends on the previous one, resulting in a low degree of parallelization of the model. In the electrocardiogram monitoring classification task, the high QRS wave often causes the model to ignore the low-amplitude electrocardiogram signal, resulting in information loss.
[0004] In summary, deep learning-based methods usually require many complex convolution and recursive structures, only consider morphological features, and are slow in processing when the data volume is large, and cannot be parallelized. The accuracy of obtaining low-amplitude electrocardiogram signal features and automatically identifying abnormal arrhythmia is low. SUMMARY
[0005] The present application aims to overcome the above-mentioned shortcomings and proposes a deep learning-based arrhythmia classification method based on self-attention mechanism, which can fully utilize the rich semantic information in electrocardiogram signals and the local correlation of signals, obtain low-amplitude electrocardiogram signal features, and automatically identify abnormal arrhythmia efficiently and accurately.
[0006] The application discloses an arrhythmia classification method based on a self-attention mechanism.
[0007] Step one, collecting electrocardio signals and preprocessing data: wavelet transform preprocessing is performed on electrocardio signal data to remove baseline drift and noise of the electrocardio signals.
[0008] Step two, generating an electrocardio signal training data set, and randomly dividing the electrocardio signal training data set into a training set and a test set.
[0009] Step three, constructing a multi-head self-attention mechanism arrhythmia classification network, the structure of which comprises an electrocardio vector representation layer, a linear interval projection layer, a signal sequence encoding layer, a multi-head self-attention calculation layer, a normalization layer and an electrocardio signal output layer; and designing an arrhythmia classification algorithm based on the multi-head self-attention mechanism.
[0010] Step four, training the multi-head self-attention mechanism arrhythmia classification network: inputting the electrocardio signal training set into the multi-head self-attention mechanism arrhythmia classification network, using a cross-entropy loss function, setting a network learning rate, training the network by using a gradient descent method, updating the weight values and the learning rate of the training set and the validation set until the network loss function converges, and obtaining the trained multi-head self-attention mechanism arrhythmia classification network.
[0011] Step five, classifying electrocardio signals: inputting the electrocardio signal test set into the trained multi-head self-attention mechanism arrhythmia classification network, obtaining the electrocardio classification result, and comparing the result with correct labels to calculate the accuracy of the multi-head self-attention mechanism arrhythmia classification network model in classifying arrhythmia.
[0012] The above-mentioned arrhythmia classification method based on the self-attention mechanism, wherein the wavelet transform preprocessing of the electrocardio signal data in the step one comprises the following steps.
[0013] Step 1.1, setting an initial wavelet transform level;
[0014] Step 1.2, performing wavelet decomposition on the electrocardio signals by using a wavelet Db6;
[0015] Step 1.3, performing low-pass filtering and down-sampling on the signal s i to obtain a signal cA i ; and performing high-pass filtering and down-sampling on the signal s i to obtain a signal cD i .
[0016] Step 1.4, performing decomposition on the signals cA i and cD iWavelet reconstruction is performed to obtain the processed electrocardio signal set;
[0017] Step 1.5, the processed electrocardio signal is cut into electrocardio segments, and the labels are recorded, and the signal segments are resampled into electrocardio signal segments with a length of 300.
[0018] The above-mentioned arrhythmia classification method based on the self-attention mechanism, wherein: the initial wavelet transform level level = 9 in step 1.1 is set.
[0019] The above-mentioned arrhythmia classification method based on the self-attention mechanism, wherein: in step 1.5, the processed electrocardio signal is cut into electrocardio segments, and 100 points before the R peak and 140 points after the R peak are taken as a signal segment and the label is recorded.
[0020] The above-mentioned arrhythmia classification method based on the self-attention mechanism, wherein: the arrhythmia classification algorithm based on the multi-head self-attention mechanism in step three includes the following steps:
[0021] Step 3.1, the electrocardio vector representation layer converts the preprocessed electrocardio data segment into a training vector of the model;
[0022] Step 3.2, the linear interval projection layer projects the electrocardio signal into multiple heart beat wave segments by linear projection to improve the semantic feature expression of the electrocardio signal;
[0023] Step 3.3, in the signal sequence encoding layer, the position encoder of the position encoding PE jz The calculation formula is:
[0024]
[0025] Wherein, z = 1, 2, …, W, W is the number of electrocardio signal points, pos j,m is the position coordinate of the electrocardio signal of the mth sequence of the jth heart beat wave segment, is the x coordinate value of the electrocardio signal, is the average amplitude of the electrocardio signal of the jth heart beat wave segment, V max is the maximum amplitude of the electrocardio signal;
[0026] Step 3.4, multi-head self-attention calculation layer: multi-head self-attention uses multiple scaled dot attention modules to perform parallel calculation between electrocardio signal segments, and the multi-head self-attention mechanism can learn more semantic information from different spaces;
[0027] Step 3.5, normalization layer: the normalized electrocardio signal is processed to reduce the training time;
[0028] Step 3.6, full connection electrocardio signal output layer: the calculated electrocardio signal is classified and the number of neurons in the full connection layer is equal to the total number of classified electrocardio signal categories.
[0029] The above arrhythmia classification method based on self-attention mechanism, wherein the electrocardio vector representation layer in step 3.1 converts the preprocessed electrocardio data segment into a model training vector with a length of 300.
[0030] The above arrhythmia classification method based on self-attention mechanism, wherein the multi-head self-attention in step 3.4 uses multiple scaled dot attention modules to perform parallel calculation between electrocardio signal segments, wherein the input self-attention module is composed of Q n , three matrices, where R is a real number, the scaled dot attention module has n layers, and the attention calculation is as follows:
[0031]
[0032]
[0033] where Q n , is the input matrix, d k ,d v is the dimension of the corresponding input data, because the self-attention mechanism is used in the multi-head attention, the dimensions of the input Q, K, and V matrices are the same; in the multi-head attention model, when one of the scaled dot attention modules is operating, as shown in equation (1), the Q, K, and V vectors are first linearly transformed; then the self-attention calculation is performed on the i-th input electrocardio signal segment q i , the dot product of q i and each key-value weight matrix is calculated to obtain the weight, which is then scaled by dividing by to avoid the softmax function falling in a place with very small gradient, the weight is normalized using the softmax function, and finally the weight and the corresponding key-value are weighted and summed to obtain the attention value of one block, after n times of attention calculation, the attention value of one head is obtained; the total formula of the scaled dot attention is as shown in equation (2), after multiple scaled attention calculations, n heads are obtained, each head is spliced, and the final result with the same dimension as the input is obtained through linear transformation, and the calculation formula is as shown in equation.
[0034] head i = attention(QW i Q ,KW iK ,VW i V ) (3)
[0035] MultiHead(Q,K,V)=Concat(head1,…,head N )W o (4)
[0036] wherein is the parameter matrix of linear mapping, d model is the data input dimension set by the model, is the weight of linear transformation, Concat is the vector splicing operation; MultiHead(Q,K,V) is the final calculation result; through multiple Attention calculation, the multi-head self-attention mechanism can learn more semantic information from different spaces.
[0037] The arrhythmia classification method based on the self-attention mechanism, wherein: in the step two, the electrocardio signal training data set is randomly divided into a training set and a test set according to a proportion of 7:3.
[0038] The arrhythmia classification method based on the self-attention mechanism, wherein: in the step four, the network learning rate is set to 0.0001.
[0039] Compared with the prior art, the present application has obvious beneficial effects, as can be seen from the above scheme, in order to improve the quality of electrocardio signal data, a wavelet transform electrocardio signal data preprocessing algorithm is used, and db6 wavelet transform is used for noise reduction processing of the electrocardio signal. Secondly, a multi-head self-attention mechanism arrhythmia classification network is constructed, and the structure thereof is respectively an electrocardio vector representation layer, a linear interval projection layer, a signal sequence coding layer, a multi-head self-attention calculation layer, and an electrocardio signal output layer. A multi-head self-attention mechanism arrhythmia classification algorithm is designed. Among them, by establishing the matching relationship of the segmented electrocardio signal and the electrocardio label, a linear projection layer capable of obtaining the semantic features of the electrocardio signal is designed. Then, a position coding based electrocardio signal sequence space-time feature representation method is designed, and the time sequence information is integrated into matrix operation. Finally, a multi-head self-attention mechanism capable of capturing global context information is constructed to extract the relationship and semantic features between electrocardio segments, realize semantic association and information splicing of long-distance electrocardio signals. In summary, in order to fully utilize the rich semantic information in the electrocardio signal and the local correlation of the signal, obtain the low-amplitude electrocardio signal features, and automatically identify abnormal arrhythmia accurately and efficiently, the multi-head self-attention mechanism arrhythmia classification algorithm is proposed.
[0040] The beneficial effects of the present application will be further described through the specific embodiments. BRIEF DESCRIPTION OF DRAWINGS
[0041] Figure 1 for the method flowchart of the present application;
[0042] Figure 2 for the heart beat structure schematic diagram in the specific embodiment of the present application;
[0043] Figure 3 for the part electrocardiogram signal before and after pre-processing comparison chart in the specific embodiment of the present application. DETAILED DESCRIPTION
[0044] The specific embodiments, features and effects of a heart arrhythmia classification method based on a self-attention mechanism according to the present application are described in detail as follows in combination with the preferred embodiments and the accompanying drawings.
[0045] Referring to Figure 1 , the heart arrhythmia classification method based on a self-attention mechanism according to the present application, wherein the method comprises the following steps:
[0046] Step one, collecting electrocardio signals and pre-processing data: wavelet transform pre-processing is performed on electrocardio signal data to remove baseline drift and noise of the electrocardio signals;
[0047] The wavelet transform pre-processing of the electrocardio signal data comprises the following specific steps:
[0048] Step 1.1, setting an initial wavelet transform level level=9;
[0049] Step 1.2, wavelet decomposition of the electrocardio signals by using wavelet Db6;
[0050] Step 1.3, low-pass filtering and down-sampling the signal s i to obtain a signal cA i ; high-pass filtering and down-sampling the signal s i to obtain a signal cD i ;
[0051] Step 1.4, wavelet reconstruction of the decomposed signals cA i , cD i to obtain a processed electrocardio signal set;
[0052] Step 1.5, electrocardio segment division of the processed electrocardio signals, taking 100 points before R peak and 140 points after R peak as a signal segment and recording the label, and then resampling the signal segment into an electrocardio signal segment with a length of 300.
[0053] Step two, generating an electrocardio signal training data set: randomly dividing the electrocardio signal training data set into a training set and a test set in a ratio of 7:3 according to equal proportions;
[0054] Step three, build a multi-head self-attention mechanism arrhythmia classification network, its structure is respectively electrocardiogram vector representation layer, linear interval projection layer, signal sequence encoding layer, multi-head self-attention calculation layer, normalization layer, electrocardiogram signal output layer; Design arrhythmia classification algorithm based on multi-head self-attention mechanism;
[0055] The arrhythmia classification algorithm based on multi-head self-attention mechanism has the following specific steps:
[0056] Step 3.1, the electrocardiogram vector representation layer converts the preprocessed electrocardiogram data segment into a model training vector with a length of 300;
[0057] Step 3.2, the linear interval projection layer projects the electrocardiogram signal into p heart beat wave segments through linear projection to improve the semantic feature expression of the electrocardiogram signal;
[0058] Step 3.3, in the signal sequence encoding layer, the position encoding PE of the position encoder is jz The calculation formula is:
[0059]
[0060] Where, z=1,2,…,W, W is the number of electrocardiogram signal points, pos j,m is the position coordinate of the electrocardiogram signal value of the mth sequence of the jth heart beat wave segment, is the x coordinate value of the electrocardiogram signal, is the average amplitude of the electrocardiogram signal of the jth heart beat wave segment, V max is the maximum amplitude of the electrocardiogram signal;
[0061] Step 3.4, multi-head self-attention calculation layer:
[0062] Multi-head self-attention uses multiple scaled dot attention modules to perform parallel calculation between electrocardiogram signal segments, wherein the input self-attention module is composed of Q∈R n , Three matrices, where R is a real number, the scaled dot attention module has n layers, and the attention calculation is as shown in the following formula:
[0063]
[0064]
[0065] Where Q∈R n , is the input matrix, d k , d vThe dimensions of the input data are the same because multi-head attention uses a self-attention mechanism. In the multi-head attention model, when one of the scaling dot product attention modules is operating, as shown in equation (1), the Q, K, and V vectors are first linearly transformed; then the dimensions of the input q are... i Perform self-attention calculation q i For the input ECG signal segment, q i and each Calculate similarity by performing a dot product and obtaining the weights, then divide by... Scaling is performed to avoid the Softmax function falling in a place where the gradient is very small. The Softmax function is used to normalize the weights. Finally, the weights and the corresponding key values are weighted and summed to obtain the attention value of a block. After n attention calculations, the attention value of a head is obtained. The general formula for scaling dot product attention is shown in (2). After multiple scaling attention calculations, n heads are obtained. Each head is concatenated and linearly transformed to obtain the final result with the same dimension as the input. The calculation formula is shown in the formula.
[0066] head i =attention(QW i Q ,KW i K VW i V (3)
[0067] MultiHead(Q,K,V)=Concat(head1,…,head N W o (4)
[0068] in Let d be the parameter matrix of the linear mapping. model The data input dimensions set for the model. The weights are for the linear transformation; Concat is the vector concatenation operation; MultiHead(Q,K,V) is the final calculated result; through multiple Attention calculations, the multi-head self-attention mechanism can learn more semantic information from different spaces.
[0069] Step 3.5, Normalization layer: Normalize the calculated ECG signal to reduce training time.
[0070] Step 3.6, Fully Connected ECG Signal Output Layer: Calculate the class probability of the calculated ECG signal. The number of neurons in the fully connected layer is equal to the total number of ECG signal classes.
[0071] Step four, training the arrhythmia classification network based on the multi-head self-attention mechanism: input the electrocardiogram signal training set into the arrhythmia classification network based on the multi-head self-attention mechanism, use the cross-entropy loss function, set the network learning rate learning_rate to 0.0001, train the network by using the gradient descent method, update the weight values and learning rates of the training set and the validation set until the network loss function converges, and obtain the trained arrhythmia classification network based on the multi-head self-attention mechanism.
[0072] Step five, classifying the electrocardiogram signal: input the electrocardiogram signal test set into the trained arrhythmia classification network based on the multi-head self-attention mechanism, obtain the electrocardiogram classification result, and calculate the accuracy of the arrhythmia classification network model based on the multi-head self-attention mechanism for arrhythmia classification by comparing with the correct label.
[0073] Wherein:
[0074] 1. An electrocardiogram signal data preprocessing algorithm based on wavelet transform
[0075] The electrocardiogram signal is composed of P wave, T wave and QRS complex (see Figure 2 ), which is an important basis for diagnosing arrhythmia types.
[0076] In the process of information collection, the electrocardiogram signal is usually affected by noise signals such as baseline drift, motion artifact and electromyogram noise. Direct use of the original signal cannot guarantee the accuracy of the classification result, and removing the noise of the electrocardiogram signal plays a crucial role in diagnosing arrhythmia types. The original electrocardiogram signal data contains key information and frequency components of the original signal, wherein the baseline drift always exists in the frequency component below 5Hz, the high-frequency noise exists in the range above 90Hz, the frequency range of the third-level detail coefficient is 45-90Hz, and the frequency range of the sixth-level approximation coefficient is 0-5.625Hz. Considering that wavelet transform can perform localized analysis on time-space frequency and can realize multi-scale refinement through scaling and translation operations. If the wavelet details below 5Hz and above 90Hz can be eliminated, the baseline drift noise signal in the ECG can be removed. Therefore, in order to reduce the influence of noise in the original electrocardiogram signal data on the diagnosis of arrhythmia types, the present application proposes an electrocardiogram signal data preprocessing algorithm based on wavelet transform, and the detailed process of the algorithm is shown in Algorithm 1.
[0077]
[0078] Figure 3 is a comparison chart of part of the electrocardiogram signal before and after preprocessing. From Figure 3 it can be seen that after using Algorithm 1, the noise points of the data are obviously improved, and the symmetry of the distribution on the baseline is more obvious.
[0079] 2 Arrhythmia classification algorithm based on multi-head self-attention mechanism
[0080] 2.1 Algorithm of the present application
[0081] Currently, arrhythmia is classified directly based on ECG pictures, which loses key information such as spatiotemporal features and low-amplitude electrocardio signal features, and increases unnecessary image noise, which is not conducive to fully utilizing context information for feature extraction and association.
[0082] In order to directly utilize the preprocessed ECG digital signal, the present application proposes an arrhythmia classification algorithm based on multi-head self-attention mechanism (algorithm flow is shown in Algorithm 2). As shown in the structure diagram of the arrhythmia classification network based on multi-head self-attention mechanism in the present application, Figure 1 from bottom to top, which are: electrocardio vector representation layer, linear interval projection layer, signal sequence encoding layer, segmented attention calculation layer, and electrocardio signal category determination Softmax layer. The linear interval projection layer is used to obtain the mutual semantic relationship between different segments; the signal sequence encoding layer mainly represents the sequence spatiotemporal features of the electrocardio signal; and the segmented attention calculation layer is used to extract the semantic features between segments and calculate the similarity between segments.
[0083] In Algorithm 2, steps 1 and 2 correspond to the electrocardio vector representation layer, and the digital data preprocessed by Algorithm 1 is converted into a training vector, and the processed data is sent to the electrocardio interval linear projection layer. In step 2, n is the total number of heart beat splits, and L is the heart beat category. According to the R-peak position category label provided by the original data set, the number of heart beat categories is determined; 100 points before the R-peak and 140 points after the R-peak are taken as a signal segment and the label is recorded, and the electrocardio signal is divided into n heart beats. The resample function is used to realize resampling of the signal segment.
[0084] In step 3, the parameters set include the input sample size Batch size, the heart beat segment dimension d model , the Q, K, and V matrix dimensions of the self-attention module, the number of layers Num_layers, and the number of subspaces Num_heads.
[0085] In step 6, p is the projection number, and the linear projection of the electrocardio signal is used to improve the semantic feature expression of the electrocardio signal;
[0086] In step 7, the signal is embedded with classification information.
[0087] In step 8, the signal sequence encoding layer embeds the position encoding of the electrocardio signal segment to express the time sequence features of the electrocardio signal, and integrates the sequence information into matrix operation, so that the model has parallelism.
[0088] Steps 10-13 are sub-attention calculation layers, which use multi-head self-attention to capture global context information of signals and establish semantic association between signals at a long distance. The sub-attention calculation layers extract different information from the input electrocardio signals in parallel and splice them together, map the query matrix, key matrix and value matrix to multiple different subspaces, obtain attention in each subspace respectively, and finally splice the outputs of each subspace together to realize global receptive field and obtain better global consistency to extract stronger semantic information.
[0089] In steps 14-17, the data after multi-head attention calculation is added to the original data to extract features without losing features, and then normalized. Then the data is processed by a multi-layer perception, which is consistent with the dimension of the input data. After adding the result to the data of the previous layer and normalizing, a new round of training is started.
[0090] Step 18 is the electrocardio signal category determination Softmax layer, which calculates the signal data to output the heart rhythm category.
[0091]
[0092] 2.2 Linear projection layer design for obtaining electrocardio signal semantic features
[0093] The multi-head self-attention mechanism model takes the word vector model to convert single words into 1-dimensional word vectors, and the words have fixed dimensions. A complete electrocardio signal can be regarded as a sentence sequence vector containing rich semantic information. Therefore, it is necessary to convert the electrocardio signal into a vector that can be calculated and into a 1-dimensional time sequence electrocardio signal that can be processed by the multi-head self-attention mechanism model. If the preprocessed signal is directly used for classification calculation, it means that all electrocardio signal segments are set with the same weight, which is not conducive to the expression of global feature attention. Therefore, our strategy is to cut and resample the electrocardio signal into equal length electrocardio signals, and obtain the electrocardio signal semantic features through linear projection.
[0094] For the electrocardio signal set S = {s1, s2, …, s i, …,s n}(s i is a continuous electrocardio data from the same person, and n is the total number of electrocardio signals). For any s i According to the time coordinates of the R points of the electrocardio signal, it is cut into equal length and Fourier transformed and resampled to form a heart beat set where k is s iThe total number of heartbeats is segmented, and L is the set of heartbeat category labels, L = {N, S, V, F} (non-ectopic (N), supraventricular ectopic (S), ventricular ectopic (V), fused heartbeat (F)).
[0095] Assume the j-th heartbeat is input. The length is W(z=1,2,…,W,v jz Given the ECG signal value and the expected projection length P, then one heartbeat... The total number of projected bands g = W / P, and the heartbeat band sequence obtained by isometric projection. In this invention, the heartbeat length W = 300 and P = 60 are set, therefore g = 5.
[0096] To avoid bias towards a specific heartbeat segment in the signal sequence, a learnable class vector x is embedded before the signal segment. class This assigns a definite vector identifier to the signal segment for subsequent classification. The new heartbeat band sequence after embedding the category vector.
[0097] 2.3 Spatiotemporal Feature Representation Method of ECG Signal Sequence Based on Position Encoding
[0098] Heartbeat signals are time-series data. After linear projection into heartbeat segments, the original sequence order is lost. If attention calculation is performed directly at this point, the original spatiotemporal features will be lost. Considering that ECG signal data represents not only one-dimensional spatial length but also a specific value representing two-dimensional voltage amplitude, an absolute positional encoding is injected into the heartbeat segments to utilize the original spatiotemporal information. This encoding extends from the 1-encoded value to the total length of the heartbeat segment. A positional encoding-based spatiotemporal feature representation method for ECG signal sequences is designed, and this method, along with self-learning positional encoding, serves as the model's positional encoding. The specific implementation steps are as follows:
[0099] 1) For each ECG signal point Perform the following operations:
[0100] Determined using the original signal sequence order and voltage amplitude Cartesian coordinates
[0101] yes exist The sequence number of the sequence, where z∈{1,2,…,W}.
[0102] 2) Calculate the positional order coordinates of the heartbeat segments. For each Its position code posj,m The value is m.
[0103] 3) Calculate the average amplitude of the electrocardiogram signal for each beat band.
[0104] 4) Calculate the entire heartbeat. Maximum amplitude V of ECG signal max .
[0105] 5) Calculate the ECG signal value for one heartbeat. Location code PE jz The calculation formula is:
[0106]
[0107] 3. Comparison and Analysis of the Invention with Other Methods
[0108] To examine the superiority of this invention, we selected deep convolutional neural networks (reference
[31] ), parallel combination models of LSTM and CNN (reference
[32] ), dual-heartbeat coupled convolutional neural networks (reference
[33] ), convolutional neural network hybrid models (reference
[34] ), ensemble classifiers based on resampling technology and AdaBoost (reference
[35] ), and improved convolutional neural networks (reference
[13] ) as comparison algorithms.
[0109] The algorithm was run based on the dataset and experimental parameters given above. The statistical results of accuracy, specificity, and sensitivity are shown in Table 1.
[0110] As can be seen from Table 1:
[0111] 1) This invention uses positional encoding to express the temporal characteristics of electrocardiograms, associates the contextual semantic information of electrocardiogram signals through a multi-head self-attention mechanism, automatically extracts features, and effectively distinguishes between S-class and F-class heartbeats in the case of imbalanced datasets.
[0112] 2) In terms of specificity, the algorithm of this invention achieves 99.41%, which is significantly better than references
[34] and
[35] that use balanced datasets, and is basically on par with reference
[32] . As can be seen from the confusion matrix of reference
[32] , its high specificity is due to the fact that its algorithm achieves a high accuracy in classifying the fifth category, thereby improving the overall specificity. From the perspective of classification performance of the first four categories, the specificity of the algorithm of this invention is still higher than that of reference
[32] .
[0113] 3) The sensitivity of the algorithm of the present application is 97.36%, as can be seen from Table 1, the algorithm of the present application maintains high sensitivity under unbalanced data set, which is higher than that of the comparative classification algorithm using unbalanced data set. Sensitivity represents the recognition ability of abnormal electrocardio classification. In the unbalanced data set of electrocardio classification, the normal class occupies the majority, and the small sample of abnormal electrocardio class classification will greatly affect the overall sensitivity. The literatures
[34] and
[35] both use balanced data set, and the number of classification tends to be consistent, which can effectively improve the classification sensitivity. Therefore, the algorithm of the present application is slightly lower than the classification algorithm using balanced data set.
[0114] Table 1 Accuracy, specificity and sensitivity statistics of different algorithms
[0115] Document Publication date Acc Spe Sen Number of classifications The invention -- 99.39 99.41 97.36 4 documents
[31] ]] 2017 94.03 91.54 96.71 5 documents
[32] ]] 2019 99.11 99.44 97.27 5 documents
[33] ]] 2018 99.10 - 96.4 5 documents
[34] ]]> 2021 99.16 98.89 99.85 4 documents
[35] ]] 2018 99.10 99.40 97.9 5 documents
[13] ]] 2020 99.06 - - 4
[0116] In summary, timely and accurate diagnosis of arrhythmia type is the key to early prevention and diagnosis of cardiovascular diseases. Machine learning methods usually use fixed features and classical signal processing techniques to determine the morphological features of electrocardiogram waveforms. However, in reality, electrocardio signals will exhibit different waveforms in different environments, making it difficult to accurately distinguish different types of diseases using fixed features. In order to reduce the influence of noise in the original electrocardio signal data on the diagnosis of arrhythmia type, an electrocardio signal data preprocessing algorithm based on wavelet transform is proposed; Considering that the features between heart beat bands play an important role in electrocardio signal recognition, we designed a linear projection layer to obtain the semantic features of electrocardio signals; In order to utilize the spatial and temporal information of ECG information, a position encoding based electrocardio signal sequence spatial and temporal feature representation method is designed. Finally, the multi-head self-attention mechanism is used to capture global context information, thereby forming an arrhythmia classification algorithm based on multi-head self-attention mechanism. With the continuous advancement of internet medical treatment, disease risk assessment and online disease consultation will become more and more common, and how to use the present application to build an electrocardio signal automatic monitoring system in a home environment is a direction worthy of further research.
[0117] The above is only a preferred embodiment of the present application, and does not limit the present application in any form. Any simple modification, equivalent change and modification of the above embodiment without departing from the technical solution of the present application, according to the technical essence of the present application, are still within the scope of the technical solution of the present application.
Claims
1. A method for classifying cardiac arrhythmias based on a self-attention mechanism, characterized in that: The method includes the following steps: Step 1: Acquire ECG signals and preprocess the data: Perform wavelet transform preprocessing on the ECG signal data to remove baseline drift and noise; Step 2: Generate an ECG signal training dataset, and randomly divide the ECG signal training dataset into a training set and a test set; Step 3: Construct a multi-head self-attention mechanism-based arrhythmia classification network, whose structure includes an ECG vector representation layer, a linear interval projection layer, a signal sequence encoding layer, a multi-head self-attention computation layer, a normalization layer, and an ECG signal output layer; design an arrhythmia classification algorithm based on the multi-head self-attention mechanism. The arrhythmia classification algorithm based on multi-head self-attention mechanism includes the following steps: Step 3.1: The ECG vector representation layer converts the preprocessed ECG data segments into training vectors for the model; Step 3.2: The linear interval projection layer projects the ECG signal into multiple heartbeat bands to improve the semantic feature expression of the ECG signal. Step 3.3: In the signal sequence coding layer, the Cartesian coordinates of each ECG signal point are determined using the original ECG signal sequence order and voltage amplitude. ; Calculate the positional order coordinates of the heartbeat band ; Calculate the average amplitude of the electrocardiogram signal for each beat band. ; Calculate the maximum amplitude of the electrocardiogram signal throughout the entire heartbeat band. ; Calculate the location encoding of the electrocardiogram signal value in the heartbeat band The calculation formula is as follows: ; Where z = 1, 2, ..., W, The number of ECG signal points. Let be the position coordinates of the electrocardiogram signal in the m-th sequence of the j-th heartbeat band. The x-coordinate value of the electrocardiogram signal. Let be the average amplitude of the electrocardiogram signal in the j-th heartbeat band. This represents the maximum amplitude of the electrocardiogram signal. Step 3.4, Multi-head self-attention computation layer: Multi-head self-attention uses multiple scaled dot product attention modules to perform parallel computation between ECG signal segments. The multi-head self-attention mechanism can learn more semantic information from different spaces. The multi-head self-attention uses multiple scaled dot product attention modules to perform parallel computation between ECG signal segments, wherein the input self-attention module consists of... , , It consists of three matrices, where R is a real number. The scaled dot product attention module has n layers, and its attention calculation is shown in the following formula: (1); (2); in , , For the input matrix, , The dimension of the input data is determined by the self-attention mechanism used in multi-head attention. The three matrices have the same dimension; in the multi-head attention model, when one of the scaling dot product attention modules is being computed, as shown in equation (1), it first... Perform a linear transformation on the vector; then perform a linear transformation on the input vector. Each ECG signal segment Perform self-attention calculations, and and each key-value weight matrix Calculate similarity by performing a dot product and obtaining the weights, then divide by... Scaling is performed to avoid the Softmax function falling on areas with very small gradients. The Softmax function is then used to normalize the weights. Finally, the weights and their corresponding key values are weighted and summed to obtain the attention value for a block. After n attention calculations, a single attention value is obtained. The attention value; the general formula for scaled dot product attention is shown in (2). After multiple scaled attention calculations, n values are obtained. Each time The data is concatenated and then subjected to a linear transformation to obtain the final result with the same dimensions as the input. The calculation formula is as follows: (3); (4); in , , Let be the parameter matrix of the linear mapping. The data input dimensions set for the model. The weights for the linear transformation, This is a vector concatenation operation; This is the final calculation result; through multiple Attention calculations, the multi-head self-attention mechanism can learn more semantic information from different spaces; Step 3.5, Normalization layer: Normalize the calculated ECG signal to reduce training time; Step 3.6, Fully Connected ECG Signal Output Layer: Calculate the category probability of the calculated ECG signal. The number of neurons in the fully connected layer is equal to the total number of ECG signal categories. Step 4: Training the arrhythmia classification network based on multi-head self-attention mechanism: Input the ECG signal training set into the arrhythmia classification network based on multi-head self-attention mechanism, use the cross-entropy loss function, set the network learning rate, train the network using gradient descent, update the weights and learning rate of the training set and validation set until the network loss function converges, and obtain the trained arrhythmia classification network based on multi-head self-attention mechanism. Step 5: Classify ECG signals: Input the ECG signal test set into the trained multi-head self-attention mechanism arrhythmia classification network to obtain the ECG classification results. By comparing with the correct labels, calculate the accuracy of the multi-head self-attention mechanism arrhythmia classification network model in classifying arrhythmias.
2. The arrhythmia classification method based on self-attention mechanism as described in claim 1, characterized in that: The wavelet transform preprocessing of the electrocardiogram signal data in step one includes the following steps: Step 1.1: Set the initial wavelet transform level; Step 1.2: Perform wavelet decomposition on the ECG signal using wavelet Db6; Step 1.3, for the signal The signal is obtained by low-pass filtering and downsampling. ; For signals The signal is obtained by high-pass filtering and downsampling. ; Step 1.4: Decompose the signal Wavelet reconstruction is performed to obtain the processed electrocardiogram signal set; Step 1.5: Divide the processed ECG signal into ECG segments, record and mark them, and then resample the signal segments to form ECG signal segments with a length of 300.
3. The arrhythmia classification method based on self-attention mechanism as described in claim 2, characterized in that: Setting the initial wavelet transform level in step 1.1 .
4. The arrhythmia classification method based on self-attention mechanism as described in claim 2, characterized in that: In step 1.5, the processed ECG signal is segmented into ECG segments, and the 100 points before the R peak and the 140 points after the R peak are taken as a signal segment and recorded and marked.
5. The arrhythmia classification method based on self-attention mechanism as described in claim 1, characterized in that: In step 3.1, the ECG vector representation layer converts the preprocessed ECG data segments into training vectors for the model with a length of 300.
6. The arrhythmia classification method based on self-attention mechanism as described in any one of claims 1 to 5, characterized in that: In step two, the ECG signal training dataset is randomly divided into a training set and a test set in a 7:3 ratio.
7. The arrhythmia classification method based on self-attention mechanism as described in any one of claims 1 to 5, characterized in that: In step four, the network learning rate is set to 0.0001.