An ECG classification method based on contrastive learning and CHNet model
Through the electrocardiogram classification method based on comparative learning and CHNet model, the problem of relying on a large amount of labeled data for electrocardiogram classification in the prior art is solved, and good classification results are achieved on a small number of labeled samples, and the robustness and generalization ability of the model are improved.
Patent Information
- Application Number
- CN202410417179.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-09
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2044-04-09
AI Technical Summary
Existing electrocardiogram classification methods rely on a large amount of labeled data, and common encoders are not sufficient in the utilization of timing information and inter-lead information, and are susceptible to noise, resulting in insufficient feature extraction and poor classification across data sets.
The ECG classification method based on contrast learning and CHNet model is adopted, and the timing and spatial information of the ECG signal is extracted through data augmentation and the design of the CHNet encoder network, and the timing and spatial information of the ECG signal are extracted by the HM module, the convolution module and the LSTM layer, and the comparison loss function InfoNCE is trained to improve the robustness and generalization ability of the model.
A good ECG signal classification effect is achieved on a small number of labeled samples, which improves the performance and robustness of the model, and can effectively use unlabeled data to learn characteristic representations with high characterization capabilities.
Smart Images

Figure CN118133188B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of electrocardiogram (ECG) signal classification, and in particular to an ECG classification method based on contrastive learning and a CHNet model. Background Art
[0002] Most of the current methods for ECG signal classification rely on a large amount of labeled data. The label scarcity problem still limits ECG classification. The method in this paper can achieve better classification results by using unlabeled data and a small amount of labeled data. In contrastive learning methods, the design of encoders is crucial. Currently, common encoders do not fully utilize the timing information and inter-lead information of ECG signals in their designs, and are easily affected by various types of noise, which makes insufficient use of ECG signal feature extraction. In addition, when common encoders extract data features, they are prone to poor classification results on other data sets due to differences in data sets, making it difficult to effectively play the advantages of contrastive learning. Summary of the invention
[0003] In order to overcome the deficiencies of the above technologies, the present invention provides an ECG classification method for improving the performance and robustness of ECG signal classification tasks.
[0004] The technical solution adopted by the present invention to overcome the technical problems is:
[0005] An electrocardiogram classification method based on contrastive learning and CHNet model includes the following steps:
[0006] a) Obtaining the original ECG signal X;
[0007] b) Perform data enhancement on the original ECG signal X to obtain the enhanced ECG signal X T1 And the enhanced ECG signal X T2 ;
[0008] c) Construct a CHNet encoder network, which consists of an HM module, a convolution module, an LSTM layer, a first one-dimensional convolution layer, a first BN layer, a first ReLU function, a second one-dimensional convolution layer, a second BN layer, a second ReLU function, and a fully connected layer;
[0009] d) The enhanced ECG signal X T1 Input into the HM module of the CHNet encoder network, and output the feature X T1 ′, the enhanced ECG signal X T2 Input into the HM module of the CHNet encoder network, and output the feature X T2 ′;
[0010] e) Change feature X T1′ is input into the convolution module of the CHNet encoder network, and the output is feature X F3 , the feature X T2 ′ is input into the convolution module of the CHNet encoder network, and the output is feature X N3 ;
[0011] f) The feature X F3 Input into the LSTM layer of the CHNet encoder network, and output the feature X F3 ′, the feature X F3 With feature X F3 ′ performs addition operation to obtain feature X F4 , the feature X F4 It is sequentially input into the first one-dimensional convolutional layer, the first BN layer, and the first ReLU function of the CHNet encoder network, and the output is feature X. F5 , the feature X F3 ′ and feature X F5 After adding, we get feature X F6 , the feature X F6 Input into the second one-dimensional convolutional layer of the CHNet encoder network, and output the feature X F7 , the feature X F7 It is input into the second BN layer, the second ReLU function, and the fully connected layer of the CHNet encoder network in sequence, and the output is feature X g1 ;
[0012] g) The feature X N3 Input into the LSTM layer of the CHNet encoder network, and output the feature X N3 ′, the feature X N3 With feature X N3 ′ performs addition operation to obtain feature X N4 , the feature X N4 It is sequentially input into the first one-dimensional convolutional layer, the first BN layer, and the first ReLU function of the CHNet encoder network, and the output is feature X. N5 , the feature X N3 ′ and feature X N5 After adding, we get feature X N6 , the feature X N6 Input into the second one-dimensional convolutional layer of the CHNet encoder network, and output the feature X N7 , the feature X N7 It is input into the second BN layer, the second ReLU function, and the fully connected layer of the CHNet encoder network in sequence, and the output is feature X g2 ;
[0013] h) Using feature X g1 With feature Xg2 Calculate the contrast loss function InfoNCE, use the Adam optimizer to train the CHNet encoder network using the contrast loss function InfoNCE, and obtain the optimized CHNet encoder network; i) Input the ECG signal Y to be predicted into the optimized CHNet encoder network, and output the feature X g ;
[0014] j) Change feature X g Input into the Softmax activation function, the number of Softmax activation function output units is 2, and the ECG signal category between [0,1] is obtained. When the ECG signal category is 0, it means that the original ECG signal X is a normal signal. When the ECG signal category is 1, it means that the original ECG signal X is an abnormal signal.
[0015] Furthermore, in step a), an original ECG signal X with a length of 10 seconds and a sampling frequency of 500 Hz is obtained from the Chapman data set.
[0016] Further, step b) comprises the following steps:
[0017] b-1) Use the numpy.random.normal function of the numpy library to generate Gaussian noise of the same shape as the original ECG signal X, and add the Gaussian noise to the original ECG signal X to form the noisy ECG signal X′; b-2) Use the MinMaxScaler of the Scikit-learn library to regularize the noisy ECG signal X′ to obtain the enhanced ECG signal X T1 ;
[0018] b-3) Use the signal.butter method of the scipy.singnal module of the SciPy library to filter the original ECG signal X to obtain the enhanced ECG signal X T2 .
[0019] Preferably, in step b-1), the mean value of the Gaussian noise is 0 and the standard deviation is 1; in step b-3), the order of the filter during the filtering process is 4 and the cutoff frequency is 500.
[0020] Further, step d) comprises the following steps:
[0021] d-1) The HM module of the CHNet encoder network consists of the first branch, the second branch, and the third branch;
[0022] d-2) The first branch of the HM module consists of the first one-dimensional convolutional layer, the first BN layer, the second one-dimensional convolutional layer, the second BN layer, the average pooling layer, the third one-dimensional convolutional layer, the third BN layer, and the ReLU function. The enhanced ECG signal X T1It is sequentially input into the first one-dimensional convolution layer, the first BN layer, the second one-dimensional convolution layer, the second BN layer, and the average pooling layer of the first branch, and the output is feature X. b1 , the feature X b1 It is sequentially input into the third one-dimensional convolutional layer, the third BN layer, and the ReLU function of the first branch, and the output is feature X. b1 ′, the enhanced ECG signal X T2 It is sequentially input into the first one-dimensional convolution layer, the first BN layer, the second one-dimensional convolution layer, the second BN layer, and the average pooling layer of the first branch, and the output is feature X. m1 , the feature X m1 It is sequentially input into the third one-dimensional convolutional layer, the third BN layer, and the ReLU function of the first branch, and the output is feature X. m1 ′;
[0023] d-3) The second branch of the HM module consists of the first one-dimensional convolutional layer, the first BN layer, the second one-dimensional convolutional layer, the second BN layer, the average pooling layer, the third one-dimensional convolutional layer, the third BN layer, and the ReLU function. The enhanced ECG signal X T1 It is sequentially input into the first one-dimensional convolution layer, the first BN layer, the second one-dimensional convolution layer, the second BN layer, and the average pooling layer of the second branch, and the output is feature X. b2 , the feature X b2 It is input into the third one-dimensional convolution layer, the third BN layer, and the ReLU function of the second branch in sequence, and the output is feature X b2 ′, the enhanced ECG signal X T2 It is sequentially input into the first one-dimensional convolution layer, the first BN layer, the second one-dimensional convolution layer, the second BN layer, and the average pooling layer of the second branch, and the output is feature X. m2 , the feature X m2 It is input into the third one-dimensional convolution layer, the third BN layer, and the ReLU function of the second branch in sequence, and the output is feature X m2 ′;
[0024] d-4) The third branch of the HM module consists of the first one-dimensional convolutional layer, the second one-dimensional convolutional layer, the first BN layer, the ReLU function, the third one-dimensional convolutional layer, the second BN layer, the average pooling layer, the fully connected layer, the fourth one-dimensional convolutional layer, the fifth one-dimensional convolutional layer, and the fully connected layer. The enhanced ECG signal X T1 Input into the first one-dimensional convolutional layer of the third branch, and output the feature X b3 , the feature X b3 It is sequentially input into the second one-dimensional convolution layer, the first BN layer, the ReLU function, the third one-dimensional convolution layer, the second BN layer, and the average pooling layer of the third branch, and the output is feature X. b3 ′, the feature X b3′ is input into the fully connected layer of the third branch, and the output is feature X b3 ″, feature X b3 ″ and feature X b2 'Add the result to get feature X c , the feature X c Input to the fourth one-dimensional convolution layer of the third branch, and output the feature X c ′, the feature X c ′ and feature X b1 ′ performs addition operation to obtain feature X d , the feature X d Input to the fifth one-dimensional convolutional layer of the third branch, and output the feature X d ′, the feature X d ′ is input into the fully connected layer of the third branch, and the output is feature X T1 ′, the enhanced ECG signal X T2 Input into the first one-dimensional convolutional layer of the third branch, and output the feature X m3 , the feature X m3 It is sequentially input into the second one-dimensional convolution layer, the first BN layer, the ReLU function, the third one-dimensional convolution layer, the second BN layer, and the average pooling layer of the third branch, and the output is feature X. m3 ′, the feature X m3 ′ is input into the fully connected layer of the third branch, and the output is feature X m3 ″, feature X m3 ″ and feature X m2 'Add the result to get feature X h , the feature X h Input to the fourth one-dimensional convolution layer of the third branch, and output the feature X h ′, the feature X h ′ and feature X m1 'Add the result to get feature X k , the feature X k Input to the fifth one-dimensional convolutional layer of the third branch, and output the feature X k ′, the feature X k ′ is input into the fully connected layer of the third branch, and the output is feature X T2’. The convolution kernel size of the first one-dimensional convolution layer of the first branch of the HM module is 7, the convolution kernel size of the second one-dimensional convolution layer of the first branch is 5, and the convolution kernel size of the third one-dimensional convolution layer of the first branch is 5; the convolution kernel size of the first one-dimensional convolution layer of the second branch of the HM module is 9, the convolution kernel size of the second one-dimensional convolution layer of the second branch is 9, and the convolution kernel size of the third one-dimensional convolution layer of the second branch is 7; the convolution kernel size of the first one-dimensional convolution layer of the third branch of the HM module is 11, the convolution kernel size of the second one-dimensional convolution layer of the third branch is 5, the convolution kernel size of the third one-dimensional convolution layer of the third branch is 9, the convolution kernel size of the fourth one-dimensional convolution layer of the third branch is 5, and the convolution kernel size of the fifth one-dimensional convolution layer of the third branch is 3.
[0025] Further, step e) comprises the following steps:
[0026] e-1) The convolution module of the CHNet encoder network consists of the first one-dimensional convolution layer, the second one-dimensional convolution layer, the third one-dimensional convolution layer, the fourth one-dimensional convolution layer, and the fully connected layer;
[0027] e-2) Feature X T1 ′ and the enhanced ECG signal X T1 Perform the addition operation to obtain feature X F1 , the feature X F1 Input into the first one-dimensional convolutional layer of the convolution module, and output the feature X F2 , the feature X F2 It is sequentially input into the second one-dimensional convolutional layer, the third one-dimensional convolutional layer, the fourth one-dimensional convolutional layer, and the fully connected layer of the convolutional module, and the output is feature X. F2 ′, the feature X F2 With feature X F2 'Add the result to get feature X F3 ;
[0028] e-3) Feature X T2 ′ and the enhanced ECG signal X T2 Perform the addition operation to obtain feature X N1 , the feature X N1 Input into the first one-dimensional convolutional layer of the convolution module, and output the feature X N2 , the feature X N2 It is sequentially input into the second one-dimensional convolutional layer, the third one-dimensional convolutional layer, the fourth one-dimensional convolutional layer, and the fully connected layer of the convolutional module, and the output is feature X. N2 ′, the feature X N2 With feature X N2 'Add the result to get feature X N3 .
[0029] Preferably, the convolution kernel size of the first one-dimensional convolution layer of the convolution module is 5, the convolution kernel size of the second one-dimensional convolution layer of the convolution module is 7, the convolution kernel size of the third one-dimensional convolution layer of the convolution module is 5, and the convolution kernel size of the fourth one-dimensional convolution layer of the convolution module is 3.
[0030] Preferably, the convolution kernel size of the first one-dimensional convolution layer of the CHNet encoder network is 3, and the convolution kernel size of the second one-dimensional convolution layer of the CHNet encoder network is 5.
[0031] Furthermore, in step i), an electrocardiogram signal Y to be predicted with a length of 10 seconds and a sampling frequency of 500 Hz is obtained from the CPSC data set.
[0032] The beneficial effect of the present invention is that it enables the prediction of ECG signals to obtain relatively good prediction results on a small number of labeled samples through the model. Compared with the traditional contrastive learning method, this method learns feature representations with higher representation capabilities from unlabeled ECG signals by utilizing contrastive learning. During the training process, we use the CHNet model to perform contrastive learning on two ECG signals from the same patient to enhance the similarity of the same type of signals while suppressing the similarity between different types of signals. The CHNet model extracts the timing information and spatial information between different leads of the ECG signal layer by layer through a special model structure, and converts it into weights so that the model can learn more information. In this way, we can make full use of a small number of labeled samples for training while maintaining the generalization performance of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 The figure is a flow chart of the method of the present invention. DETAILED DESCRIPTION
[0034] The following is combined with Figure 1 The present invention is further described.
[0035] An electrocardiogram classification method based on contrastive learning and CHNet model includes the following steps:
[0036] a) Obtain the original ECG signal X.
[0037] b) Perform data enhancement on the original ECG signal X to obtain the enhanced ECG signal X T1 And the enhanced ECG signal X T2 .
[0038] c) Construct the CHNet encoder network, which consists of an HM module, a convolution module, an LSTM layer, a first one-dimensional convolution layer, a first BN layer, a first ReLU function, a second one-dimensional convolution layer, a second BN layer, a second ReLU function, and a fully connected layer.
[0039] d) The enhanced ECG signal X T1 Input into the HM module of the CHNet encoder network, and output the feature X T1 ′, the enhanced ECG signal X T2 Input into the HM module of the CHNet encoder network, and output the feature X T2 ′.
[0040] e) Change feature X T1 ′ is input into the convolution module of the CHNet encoder network, and the output is feature X F3 , the feature X T2 ′ is input into the convolution module of the CHNet encoder network, and the output is feature X N3 .
[0041] f) The feature X F3 Input into the LSTM layer of the CHNet encoder network, and output the feature X F3 ′, the feature X F3 With feature X F3 'Add the result to get feature X F4 , the feature X F4 It is sequentially input into the first one-dimensional convolutional layer, the first BN layer, and the first ReLU function of the CHNet encoder network, and the output is feature X. F5 , the feature X F3 ′ and feature X F5 After adding, we get feature X F6 , the feature X F6 Input into the second one-dimensional convolutional layer of the CHNet encoder network, and output the feature X F7 , the feature X F7 It is input into the second BN layer, the second ReLU function, and the fully connected layer of the CHNet encoder network in sequence, and the output is feature X g1 .
[0042] g) The feature X N3 Input into the LSTM layer of the CHNet encoder network, and output the feature X N3 ′, the feature X N3 With feature X N3 'Add the result to get feature X N4 , the feature X N4 It is sequentially input into the first one-dimensional convolutional layer, the first BN layer, and the first ReLU function of the CHNet encoder network, and the output is feature X. N5 , the feature X N3 ′ and feature X N5 After adding, we get feature XN6 , the feature X N6 Input into the second one-dimensional convolutional layer of the CHNet encoder network, and output the feature X N7 , the feature X N7 It is input into the second BN layer, the second ReLU function, and the fully connected layer of the CHNet encoder network in sequence, and the output is feature X g2 .
[0043] h) Using feature X g1 With feature X g2 Calculate the contrast loss function InfoNCE, use the Adam optimizer to train the CHNet encoder network using the contrast loss function InfoNCE, and obtain the optimized CHNet encoder network.
[0044] i) Input the ECG signal Y to be predicted into the optimized CHNet encoder network and output the feature X g ;
[0045] j) Change feature X g Input into the Softmax activation function, the number of Softmax activation function output units is 2, and the ECG signal category between [0,1] is obtained. When the ECG signal category is 0, it means that the original ECG signal X is a normal signal. When the ECG signal category is 1, it means that the original ECG signal X is an abnormal signal.
[0046] Through the unsupervised learning method of contrastive learning, the model can use a large amount of unlabeled ECG signal data for feature representation learning, thereby improving the performance and robustness of ECG classification tasks.
[0047] In the comparative experiment, the effects of several different encoder architectures on ECG signal classification in the same comparative learning method were compared. The results show that although all models can learn useful representations from unlabeled ECG data to some extent, the overall evaluation indicators are inferior to the experimental results of the method in this paper. As shown in Table 1, the CHNet model of this patent performs well in AUROC and F1 scores, which can evaluate whether the model has better discrimination and generalization capabilities. AUROC is an indicator to measure the performance of a classification model. The closer the value is to 1, the better the performance of the model. The AUROC of the CHNet model used here is 0.783, which is higher than the previous best method using the Densenet model of 0.772. After comparing the accuracy of the classification effect of the method in this paper, it can be found that compared with the method using the xresnet101 model, the accuracy of the CHNet model used in this example is 0.779, which is higher than the comparative learning result of the xresnet101 model of 0.762. Higher AUROC, accuracy, and F1 scores mean that the representation learned by the model is better for predicting the task and has better discrimination and generalization capabilities.
[0048] Table 1 Comparison of experimental results
[0049]
[0050] In this embodiment, preferably, in step a), an original ECG signal X with a length of 10 seconds and a sampling frequency of 500 Hz is obtained from the Chapman data set.
[0051] In one embodiment of the present invention, step b) comprises the following steps:
[0052] b-1) Use the numpy.random.normal function of the numpy library to generate Gaussian noise of the same shape as the original ECG signal X, and add the Gaussian noise to the original ECG signal X to form a noisy ECG signal X′.
[0053] b-2) Use the MinMaxScaler of the Scikit-learn library to regularize the noisy ECG signal X′ to obtain the enhanced ECG signal X T1 .
[0054] b-3) Use the signal.butter method of the scipy.singnal module of the SciPy library to filter the original ECG signal X to obtain the enhanced ECG signal X T2 .
[0055] In this embodiment, the mean value of the Gaussian noise in step b-1) is 0 and the standard deviation is 1; the order of the filter during the filtering process in step b-3) is 4 and the cutoff frequency is 500.
[0056] In one embodiment of the present invention, step d) comprises the following steps:
[0057] d-1) The HM module of the CHNet encoder network consists of the first branch, the second branch, and the third branch. d-2) The first branch of the HM module consists of the first one-dimensional convolutional layer, the first BN layer, the second one-dimensional convolutional layer, the second BN layer, the average pooling layer, the third one-dimensional convolutional layer, the third BN layer, and the ReLU function, which transforms the enhanced ECG signal X T1 It is sequentially input into the first one-dimensional convolution layer, the first BN layer, the second one-dimensional convolution layer, the second BN layer, and the average pooling layer of the first branch, and the output is feature X. b1 , the feature X b1 It is sequentially input into the third one-dimensional convolutional layer, the third BN layer, and the ReLU function of the first branch, and the output is feature X. b1 ′, the enhanced ECG signal X T2 It is sequentially input into the first one-dimensional convolution layer, the first BN layer, the second one-dimensional convolution layer, the second BN layer, and the average pooling layer of the first branch, and the output is feature X. m1 , the feature X m1 It is sequentially input into the third one-dimensional convolutional layer, the third BN layer, and the ReLU function of the first branch, and the output is feature X. m1 ′.
[0058] d-3) The second branch of the HM module consists of the first one-dimensional convolutional layer, the first BN layer, the second one-dimensional convolutional layer, the second BN layer, the average pooling layer, the third one-dimensional convolutional layer, the third BN layer, and the ReLU function. The enhanced ECG signal X T1 It is sequentially input into the first one-dimensional convolution layer, the first BN layer, the second one-dimensional convolution layer, the second BN layer, and the average pooling layer of the second branch, and the output is feature X. b2 , the feature X b2 It is input into the third one-dimensional convolution layer, the third BN layer, and the ReLU function of the second branch in sequence, and the output is feature X b2 ′, the enhanced ECG signal X T2 It is sequentially input into the first one-dimensional convolution layer, the first BN layer, the second one-dimensional convolution layer, the second BN layer, and the average pooling layer of the second branch, and the output is feature X. m2 , the feature X m2 It is input into the third one-dimensional convolution layer, the third BN layer, and the ReLU function of the second branch in sequence, and the output is feature X m2 ′.
[0059] d-4) The third branch of the HM module consists of the first one-dimensional convolutional layer, the second one-dimensional convolutional layer, the first BN layer, the ReLU function, the third one-dimensional convolutional layer, the second BN layer, the average pooling layer, the fully connected layer, the fourth one-dimensional convolutional layer, the fifth one-dimensional convolutional layer, and the fully connected layer. The enhanced ECG signal X T1 Input into the first one-dimensional convolutional layer of the third branch, and output the feature X b3 , the feature X b3 It is sequentially input into the second one-dimensional convolution layer, the first BN layer, the ReLU function, the third one-dimensional convolution layer, the second BN layer, and the average pooling layer of the third branch, and the output is feature X. b3 ′, the feature X b3 ′ is input into the fully connected layer of the third branch, and the output is feature X b3 ″, feature X b3 ″ and feature X b2 'Add the result to get feature X c , the feature X c Input to the fourth one-dimensional convolution layer of the third branch, and output the feature X c ′, the feature X c ′ and feature X b1 'Add the result to get feature X d , the feature X d Input to the fifth one-dimensional convolutional layer of the third branch, and output the feature X d ′, the feature X d ′ is input into the fully connected layer of the third branch, and the output is feature X T1 ′, the enhanced ECG signal X T2 Input into the first one-dimensional convolutional layer of the third branch, and output the feature X m3 , the feature X m3 It is sequentially input into the second one-dimensional convolution layer, the first BN layer, the ReLU function, the third one-dimensional convolution layer, the second BN layer, and the average pooling layer of the third branch, and the output is feature X. m3 ′, the feature X m3 ′ is input into the fully connected layer of the third branch, and the output is feature X m3 ″, feature X m3 ″ and feature X m2 'Add the result to get feature X h , the feature X h Input to the fourth one-dimensional convolution layer of the third branch, and output the feature X h ′, the feature X h ′ and feature X m1 'Add the result to get feature X k , the feature X kInput to the fifth one-dimensional convolutional layer of the third branch, and output the feature X k ′, the feature X k ′ is input into the fully connected layer of the third branch, and the output is feature X T2 ’. The convolution kernel size of the first one-dimensional convolution layer of the first branch of the HM module is 7, the convolution kernel size of the second one-dimensional convolution layer of the first branch is 5, and the convolution kernel size of the third one-dimensional convolution layer of the first branch is 5; the convolution kernel size of the first one-dimensional convolution layer of the second branch of the HM module is 9, the convolution kernel size of the second one-dimensional convolution layer of the second branch is 9, and the convolution kernel size of the third one-dimensional convolution layer of the second branch is 7; the convolution kernel size of the first one-dimensional convolution layer of the third branch of the HM module is 11, the convolution kernel size of the second one-dimensional convolution layer of the third branch is 5, the convolution kernel size of the third one-dimensional convolution layer of the third branch is 9, the convolution kernel size of the fourth one-dimensional convolution layer of the third branch is 5, and the convolution kernel size of the fifth one-dimensional convolution layer of the third branch is 3.
[0060] In one embodiment of the present invention, step e) comprises the following steps:
[0061] e-1) The convolution module of the CHNet encoder network consists of the first one-dimensional convolution layer, the second one-dimensional convolution layer, the third one-dimensional convolution layer, the fourth one-dimensional convolution layer, and a fully connected layer.
[0062] e-2) Feature X T1 ′ and the enhanced ECG signal X T1 Perform the addition operation to obtain feature X F1 , the feature X F1 Input into the first one-dimensional convolutional layer of the convolution module, and output the feature X F2 , the feature X F2 It is sequentially input into the second one-dimensional convolutional layer, the third one-dimensional convolutional layer, the fourth one-dimensional convolutional layer, and the fully connected layer of the convolutional module, and the output is feature X. F2 ′, the feature X F2 With feature X F2 'Add the result to get feature X F3 .
[0063] e-3) Feature X T2 ′ and the enhanced ECG signal X T2 Perform the addition operation to obtain feature X N1 , the feature X N1 Input into the first one-dimensional convolutional layer of the convolution module, and output the feature X N2 , the feature X N2 It is sequentially input into the second one-dimensional convolutional layer, the third one-dimensional convolutional layer, the fourth one-dimensional convolutional layer, and the fully connected layer of the convolutional module, and the output is feature X. N2 ′, the feature XN2 With feature X N2 'Add the result to get feature X N3 .
[0064] In this embodiment, the convolution kernel size of the first one-dimensional convolution layer of the convolution module is 5, the convolution kernel size of the second one-dimensional convolution layer of the convolution module is 7, the convolution kernel size of the third one-dimensional convolution layer of the convolution module is 5, and the convolution kernel size of the fourth one-dimensional convolution layer of the convolution module is 3.
[0065] In this embodiment, the convolution kernel size of the first one-dimensional convolution layer of the CHNet encoder network is 3, and the convolution kernel size of the second one-dimensional convolution layer of the CHNet encoder network is 5.
[0066] In one embodiment of the present invention, in step i), an electrocardiogram signal Y to be predicted with a length of 10 seconds and a sampling frequency of 500 Hz is obtained from the CPSC data set.
[0067] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. An electrocardiogram classification method based on contrastive learning and CHNet model, characterized in that: The steps include: a) Obtaining the original ECG signal X; b) Perform data enhancement on the original ECG signal X to obtain the enhanced ECG signal X T1 And the enhanced ECG signal X T2 ; c) Construct a CHNet encoder network, which consists of an HM module, a convolution module, an LSTM layer, a first one-dimensional convolution layer, a first BN layer, a first ReLU function, a second one-dimensional convolution layer, a second BN layer, a second ReLU function, and a fully connected layer; d) The enhanced ECG signal X T1 Input into the HM module of the CHNet encoder network, and output the feature X T1 ′, the enhanced ECG signal X T2 Input into the HM module of the CHNet encoder network, and output the feature X T2 ′; e) Change feature X T1 ′ is input into the convolution module of the CHNet encoder network, and the output is feature X F3 , the feature X T2 ′ is input into the convolution module of the CHNet encoder network, and the output is feature X N3 ; f) The feature X F3 Input into the LSTM layer of the CHNet encoder network, and output the feature X F3 ′, the feature X F3 With feature X F3 ′ performs addition operation to obtain feature X F4 , the feature X F4 It is sequentially input into the first one-dimensional convolutional layer, the first BN layer, and the first ReLU function of the CHNet encoder network, and the output is feature X. F5 , the feature X F3 ′ and feature X F5 After adding, we get feature X F6 , the feature X F6 Input into the second one-dimensional convolutional layer of the CHNet encoder network, and output the feature X F7 , the feature X F7 It is input into the second BN layer, the second ReLU function, and the fully connected layer of the CHNet encoder network in sequence, and the output is feature X g1 ; g) The feature X N3 Input into the LSTM layer of the CHNet encoder network, and output the feature X N3 ′, the feature X N3 With feature X N3 ′ performs addition operation to obtain feature X N4 , the feature X N4 It is sequentially input into the first one-dimensional convolutional layer, the first BN layer, and the first ReLU function of the CHNet encoder network, and the output is feature X. N5 , the feature X N3 ′ and feature X N5 After adding, we get feature X N6 , the feature X N6 Input into the second one-dimensional convolutional layer of the CHNet encoder network, and output the feature X N7 , the feature X N7 It is input into the second BN layer, the second ReLU function, and the fully connected layer of the CHNet encoder network in sequence, and the output is feature X g2 ; h) Using feature X g1 With feature X g2 Calculate the contrast loss function InfoNCE, use the Adam optimizer to train the CHNet encoder network using the contrast loss function InfoNCE, and obtain the optimized CHNet encoder network; i) Input the ECG signal Y to be predicted into the optimized CHNet encoder network, and output the feature X g ; j) Change feature X g Input into the Softmax activation function, the number of Softmax activation function output units is 2, and the ECG signal category between [0,1] is obtained. When the ECG signal category is 0, it means that the original ECG signal X is a normal signal, and when the ECG signal category is 1, it means that the original ECG signal X is an abnormal signal; Step d) comprises the following steps: d-1) The HM module of the CHNet encoder network consists of the first branch, the second branch, and the third branch; d-2) The first branch of the HM module consists of the first one-dimensional convolutional layer, the first BN layer, the second one-dimensional convolutional layer, the second BN layer, the average pooling layer, the third one-dimensional convolutional layer, the third BN layer, and the ReLU function. The enhanced ECG signal X T1 It is sequentially input into the first one-dimensional convolution layer, the first BN layer, the second one-dimensional convolution layer, the second BN layer, and the average pooling layer of the first branch, and the output is feature X. b1 , the feature X b1 It is sequentially input into the third one-dimensional convolutional layer, the third BN layer, and the ReLU function of the first branch, and the output is feature X. b1 ′, the enhanced ECG signal X T2 It is sequentially input into the first one-dimensional convolution layer, the first BN layer, the second one-dimensional convolution layer, the second BN layer, and the average pooling layer of the first branch, and the output is feature X. m1 , the feature X m1 It is sequentially input into the third one-dimensional convolutional layer, the third BN layer, and the ReLU function of the first branch, and the output is feature X. m1 ′; d-3) The second branch of the HM module consists of the first one-dimensional convolutional layer, the first BN layer, the second one-dimensional convolutional layer, the second BN layer, the average pooling layer, the third one-dimensional convolutional layer, the third BN layer, and the ReLU function. The enhanced ECG signal X T1 It is sequentially input into the first one-dimensional convolution layer, the first BN layer, the second one-dimensional convolution layer, the second BN layer, and the average pooling layer of the second branch, and the output is feature X. b2 , the feature X b2 It is input into the third one-dimensional convolution layer, the third BN layer, and the ReLU function of the second branch in sequence, and the output is feature X b2 ′, the enhanced ECG signal X T2 It is sequentially input into the first one-dimensional convolution layer, the first BN layer, the second one-dimensional convolution layer, the second BN layer, and the average pooling layer of the second branch, and the output is feature X. m2 , the feature X m2 It is input into the third one-dimensional convolution layer, the third BN layer, and the ReLU function of the second branch in sequence, and the output is feature X m2 ′; d-4) The third branch of the HM module consists of the first one-dimensional convolutional layer, the second one-dimensional convolutional layer, the first BN layer, the ReLU function, the third one-dimensional convolutional layer, the second BN layer, the average pooling layer, the fully connected layer, the fourth one-dimensional convolutional layer, the fifth one-dimensional convolutional layer, and the fully connected layer. The enhanced ECG signal X T1 Input into the first one-dimensional convolutional layer of the third branch, and output the feature X b3 , the feature X b3 It is sequentially input into the second one-dimensional convolution layer, the first BN layer, the ReLU function, the third one-dimensional convolution layer, the second BN layer, and the average pooling layer of the third branch, and the output is feature X. b3 ′, the feature X b3 ′ is input into the fully connected layer of the third branch, and the output is feature X b3 ″, the feature X b3 ″ and feature X b2 ′ performs addition operation to obtain feature X c , the feature X c Input to the fourth one-dimensional convolution layer of the third branch, and output the feature X c ′, the feature X c ′ and feature X b1 ′ performs addition operation to obtain feature X d , the feature X d Input to the fifth one-dimensional convolutional layer of the third branch, and output the feature X d ′, the feature X d ′ is input into the fully connected layer of the third branch, and the output is feature X T1 ′, the enhanced ECG signal X T2 Input into the first one-dimensional convolutional layer of the third branch, and output the feature X m3 , the feature X m3 It is sequentially input into the second one-dimensional convolution layer, the first BN layer, the ReLU function, the third one-dimensional convolution layer, the second BN layer, and the average pooling layer of the third branch, and the output is feature X. m3 ′, the feature X m3 ′ is input into the fully connected layer of the third branch, and the output is feature X m3 ″, the feature X m3 ″ and feature X m2 ′ performs addition operation to obtain feature X h , the feature X h Input to the fourth one-dimensional convolution layer of the third branch, and output the feature X h ′, the feature X h ′ and feature X m1 ′ performs addition operation to obtain feature X k , the feature X k Input to the fifth one-dimensional convolutional layer of the third branch, and output the feature X k ′, the feature X k ′ is input into the fully connected layer of the third branch, and the output is feature X T2 ′.
2. The ECG classification method based on contrastive learning and CHNet model according to claim 1, characterized in that: In step a), an original ECG signal X with a length of 10 seconds and a sampling frequency of 500 Hz is obtained from the Chapman data set.
3. The ECG classification method based on contrastive learning and CHNet model according to claim 1, characterized in that: Step b) comprises the following steps: b-1) Use the numpy.random.normal function of the numpy library to generate Gaussian noise of the same shape as the original ECG signal X, and add the Gaussian noise to the original ECG signal X to form the noisy ECG signal X′; b-2) Use the MinMaxScaler of the Scikit-learn library to regularize the noisy ECG signal X′ to obtain the enhanced ECG signal X T1 ; b-3) Use the signal.butter method of the scipy.singnal module of the SciPy library to filter the original ECG signal X to obtain the enhanced ECG signal X T2 .
4. The ECG classification method based on contrastive learning and CHNet model according to claim 3, characterized in that: In step b-1), the mean value of the Gaussian noise is 0 and the standard deviation is 1; in step b-3), the order of the filter during the filtering process is 4 and the cutoff frequency is 500.
5. The ECG classification method based on contrastive learning and CHNet model according to claim 1, characterized in that: The convolution kernel size of the first one-dimensional convolution layer of the first branch of the HM module is 7, the convolution kernel size of the second one-dimensional convolution layer of the first branch is 5, and the convolution kernel size of the third one-dimensional convolution layer of the first branch is 5; the convolution kernel size of the first one-dimensional convolution layer of the second branch of the HM module is 9, the convolution kernel size of the second one-dimensional convolution layer of the second branch is 9, and the convolution kernel size of the third one-dimensional convolution layer of the second branch is 7; the convolution kernel size of the first one-dimensional convolution layer of the third branch of the HM module is 11, the convolution kernel size of the second one-dimensional convolution layer of the third branch is 5, the convolution kernel size of the third one-dimensional convolution layer of the third branch is 9, the convolution kernel size of the fourth one-dimensional convolution layer of the third branch is 5, and the convolution kernel size of the fifth one-dimensional convolution layer of the third branch is 3.
6. The ECG classification method based on contrastive learning and CHNet model according to claim 1, characterized in that: Step e) comprises the following steps: e-1) The convolution module of the CHNet encoder network consists of the first one-dimensional convolution layer, the second one-dimensional convolution layer, the third one-dimensional convolution layer, the fourth one-dimensional convolution layer, and a fully connected layer; e-2) Feature X T1 ′ and the enhanced ECG signal X T1 Perform the addition operation to obtain feature X F1 , the feature X F1 Input into the first one-dimensional convolutional layer of the convolution module, and output the feature X F2 , the feature X F2 It is sequentially input into the second one-dimensional convolutional layer, the third one-dimensional convolutional layer, the fourth one-dimensional convolutional layer, and the fully connected layer of the convolutional module, and the output is feature X. F2 ′, the feature X F2 With feature X F2 ′ performs addition operation to obtain feature X F3 ; e-3) Feature X T2 ′ and the enhanced ECG signal X T2 Perform the addition operation to obtain feature X N1 , the feature X N1 Input into the first one-dimensional convolutional layer of the convolution module, and output the feature X N2 , the feature X N2 It is sequentially input into the second one-dimensional convolutional layer, the third one-dimensional convolutional layer, the fourth one-dimensional convolutional layer, and the fully connected layer of the convolutional module, and the output is feature X. N2 ′, the feature X N2 With feature X N2 ′ performs addition operation to obtain feature X N3 .
7. The ECG classification method based on contrastive learning and CHNet model according to claim 6, characterized in that: The convolution kernel size of the first one-dimensional convolution layer of the convolution module is 5, the convolution kernel size of the second one-dimensional convolution layer of the convolution module is 7, the convolution kernel size of the third one-dimensional convolution layer of the convolution module is 5, and the convolution kernel size of the fourth one-dimensional convolution layer of the convolution module is 3.
8. The ECG classification method based on contrastive learning and CHNet model according to claim 1, characterized in that: The convolution kernel size of the first 1D convolution layer of the CHNet encoder network is 3, and the convolution kernel size of the second 1D convolution layer of the CHNet encoder network is 5.
9. The ECG classification method based on contrastive learning and CHNet model according to claim 1, characterized in that: In step i), an electrocardiogram signal Y to be predicted with a length of 10 seconds and a sampling frequency of 500 Hz is obtained from the CPSC data set.
Citation Information
Patent Citations
Electrocardiosignal detecting and positioning method based on weak supervised learning
CN116584951A
KR20230133230A