ECG data feature generation model based on contrast prediction coding

文档序号:1867469 发布日期:2021-11-23 浏览:29次 中文

阅读说明:本技术 基于对比预测编码的ecg数据特征生成模型 (ECG data feature generation model based on contrast prediction coding ) 是由 孙乐 任超旭 于 2021-08-25 设计创作,主要内容包括:本发明公开了一种基于对比预测编码的ECG数据特征生成模型,包括如下步骤:首先将划分ECG训练数据,横向看是正样本对与负样本对,正样本对是相同类别的数据,负样本对是不同类别的数据,纵向看是训练数据与待训练数据,然后通过编码器将训练数据与待训练数据都进行编码,接着把训练数据经过编码得到的结果放入自回归模型得到上下文信息Context,Context进入预测模型后得到未来多步的预测值,最后将预测值与待训练数据经过编码后的值一起计算点积得到损失值。本发明可以扩展样本数量不足的数据,提高下游任务的泛化能力。(The invention discloses an ECG data feature generation model based on contrast prediction coding, which comprises the following steps: the method comprises the steps of dividing ECG training data, wherein positive sample pairs and negative sample pairs are viewed transversely, the positive sample pairs are data of the same category, the negative sample pairs are data of different categories, training data and data to be trained are viewed longitudinally, then the training data and the data to be trained are encoded through an encoder, then results obtained by encoding the training data are put into an autoregressive model to obtain Context information Context, the Context enters a prediction model to obtain predicted values of future steps, and finally the predicted values and the values obtained by encoding the data to be trained are calculated together to obtain a loss value. The invention can expand the data with insufficient sample quantity and improve the generalization capability of downstream tasks.)

1. A model for generating features of ECG data based on contrast predictive coding, comprising the steps of:

s1, adopting the data set and preprocessing;

s2, dividing the ECG training data into positive sample pairs and negative sample pairs, wherein the positive sample pairs are data of the same category, and the negative sample pairs are data of different categories; the positive sample pair and the negative sample pair are respectively divided into training data and data to be trained;

s3, building a comparison prediction coding CPC model, and inputting training data and data to be trained;

coding the training data and the data to be trained through a coder, then putting the result obtained by coding the training data into an autoregressive model to obtain Context information Context, and obtaining the predicted values of future multiple steps after the Context enters a prediction model;

s4, calculating the dot product of the predicted value and the value of the data to be trained after encoding to obtain a loss value;

s5, training a Comparison Prediction Coding (CPC) model;

and S6, applying the trained CPC model to a downstream classification task.

2. The contrast-predictive coding-based ECG data feature generation model of claim 1, wherein the preprocessing of the data set in s1 includes:

s11, collecting heart beats by adopting the position of the R peak marked by the data set;

s12, resampling the heart beat;

s13, filtering using wavelet transform;

s14, re-labeling and disordering the data set, dividing the data set into a training set and a verification set, wherein the training set is divided into two parts, namely training data and data to be trained; positive and negative sample pairs are constructed simultaneously.

3. The contrast-predictive coding-based ECG data feature generation model of claim 1, wherein the autoregressive model construction process in s3 comprises:

the history information is fused using an autoregressive model GRU, with an output dimension of 256, returning only the output of the last unit.

4. The contrast-predictive coding-based ECG data feature generation model of claim 1, wherein building a predictive model process comprises:

fully connected layer output dimension 10, using a linear activation function; since the four fully-connected layers are placed in a list, the four fully-connected layers are transversely spliced together by using Lambda layers to form a network.

5. The contrast-predictive coding-based ECG data feature generation model of claim 1, wherein in s4, the dot-product derived loss value is brought to be in the [0,1] range using a sigmoid function as the output of the contrast-predictive coding CPC model.

6. The contrast-predictive coding-based ECG data feature generation model of claim 1, wherein the CPC model is trained by:

s51, initializing model parameters;

s52, inputting data into the model for training;

s53, saving the model, and drawing the accuracy of the training set and the verification set.

7. The contrast-predictive coding-based ECG data feature generation model of claim 1, wherein s6 includes the steps of:

s61, divide the training data, and divide the data set into 5 parts to keep the same with the trained CPC model.

s62, constructing a classification model, wherein the classification model uses three identical training data; each piece of training data passes through an encoder part of the CPC, a one-dimensional convolutional layer, a relu activation layer, a one-dimensional maximum pooling layer, a one-dimensional convolutional layer, a relu activation layer and a one-dimensional maximum pooling layer; splicing results obtained by the three data, then connecting a Flatten layer and two full-connection layers, and finally obtaining a classification result through the full-connection layer with an activation function of softmax;

s63, train classification model, loss function using categorical _ cross, optimizer using rmsprop, batch size set to 64, train 10 epochs.

Technical Field

The invention belongs to the technical field of computer software, and particularly relates to an ECG data feature generation model based on comparison prediction coding.

Background

Contrast predictive coding is one of the self-supervised learning, and the current main methods of self-supervised learning are divided into three categories, namely context-based, time sequence-based and contrast-based. Contrast-based self-supervised learning builds tokens by learning to encode the similarity or dissimilarity of two things, and the performance of this type of approach is very strong. The self-supervised learning algorithm no longer relies on labels, but rather generates labels from the data by revealing relationships between portions of the data. In the current deep learning application, data problems are ubiquitous, ECG is one kind of medical data, there are many problems such as unbalanced sample distribution and no label, and the manual labeling method is time-consuming and labor-consuming, so people need to learn rich feature representation through a self-supervision method without data labeling.

An Electrocardiogram (ECG) has a good effect on diagnosing and analyzing various arrhythmias and conduction blocks, is helpful for diagnosing and has great significance on diagnosing coronary heart diseases. The electrocardiogram mainly reflects the electrical activity of the excited heart, and the myocardial damage, insufficient blood supply, medicament and electrolyte disturbance can cause certain electrocardiogram change, and the reliable method for diagnosing myocardial infarction when the characteristic electrocardiogram changes. At present, various models for classifying ECG data face a problem, sample distribution in the ECG data is extremely unbalanced, the proportion of normal samples and irregular heart rate samples is seriously unbalanced, a supervision and learning network cannot obtain enough data for training, and the performance of the models cannot be guaranteed. High-dimensional features consistent with the original category of the ECG data can be generated by comparing the predictive codes, the number of samples is expanded equivalently, meanwhile, the score between the same samples is higher through a scoring function, the score between different samples is lower, the sample categories are further distinguished, the method can be used for downstream tasks such as classification tasks, model overfitting can be greatly prevented, the convergence rate of a downstream training model is improved, and the classification accuracy of the model is improved.

Disclosure of Invention

Aiming at the defects in the prior art, the invention provides an ECG data feature generation model based on comparison prediction coding, introduces the comparison prediction coding of a self-supervision learning model to predict the high-dimensional features of the same category as the original ECG data, reduces the manual labeling cost while increasing the sample set, and is matched with a downstream classification task for classification, thereby facilitating other classification models to reduce overfitting and improve the classification accuracy.

In order to achieve the purpose, the invention adopts the following technical scheme:

a model is generated based on contrast predictive coded ECG data features, comprising the steps of:

s1, adopting the data set and preprocessing;

s2, dividing the ECG training data into positive sample pairs and negative sample pairs, wherein the positive sample pairs are data of the same category, and the negative sample pairs are data of different categories; the positive sample pair and the negative sample pair are respectively divided into training data and data to be trained;

s3, building a comparison prediction coding CPC model, and inputting training data and data to be trained;

coding the training data and the data to be trained through a coder, then putting the result obtained by coding the training data into an autoregressive model to obtain Context information Context, and obtaining the predicted values of future multiple steps after the Context enters a prediction model;

s4, calculating the dot product of the predicted value and the value of the data to be trained after encoding to obtain a loss value;

s5, training a Comparison Prediction Coding (CPC) model;

and S6, applying the trained CPC model to a downstream classification task.

In order to optimize the technical scheme, the specific measures adopted further comprise:

further, the preprocessing of the data set in s1 includes:

s11, collecting heart beats by adopting the position of the R peak marked by the data set;

s12, resampling the heart beat;

s13, filtering using wavelet transform;

s14, re-labeling and disordering the data set, dividing the data set into a training set and a verification set, wherein the training set is divided into two parts, namely training data and data to be trained; positive and negative sample pairs are constructed simultaneously.

Further, the autoregressive model construction process in s3 includes:

the history information is fused using an autoregressive model GRU, with an output dimension of 256, returning only the output of the last unit.

Further, the process of building the prediction model comprises the following steps:

fully connected layer output dimension 10, using a linear activation function; since the four fully-connected layers are placed in a list, the four fully-connected layers are transversely spliced together by using Lambda layers to form a network.

Further, in s4, the dot product found loss value is made to be in the range of [0,1] using the sigmoid function as the output of the contrast prediction coding CPC model.

Further, training the CPC model comprises the following steps:

s51, initializing model parameters;

s52, inputting data into the model for training;

s53, saving the model, and drawing the accuracy of the training set and the verification set.

Further, s6 includes the steps of:

s61, divide the training data, and divide the data set into 5 parts to keep the same with the trained CPC model.

s62, constructing a classification model, wherein the classification model uses three identical training data; each piece of training data passes through an encoder part of the CPC, a one-dimensional convolutional layer, a relu activation layer, a one-dimensional maximum pooling layer, a one-dimensional convolutional layer, a relu activation layer and a one-dimensional maximum pooling layer; splicing results obtained by the three data, then connecting a Flatten layer and two full-connection layers, and finally obtaining a classification result through the full-connection layer with an activation function of softmax;

s63, train classification model, loss function using categorical _ cross, optimizer using rmsprop, batch size set to 64, train 10 epochs.

The invention has the beneficial effects that:

(1) the invention is suitable for ECG data under the condition of data imbalance;

the present invention is applicable to less common arrhythmia data where less ECG data is collected. Aiming at the condition of less collected data, the CPC can solve the problem caused by insufficient data quantity by maximizing mutual information of the CPC, so that the data with insufficient sample quantity can be expanded, and the generalization capability of downstream tasks is improved.

(2) The invention improves the accuracy of generating ECG data features of the same category;

the effective characteristics are extracted through the encoder, unnecessary noise is removed, the characteristics are more obvious, and subsequent processing is facilitated. Compared with the predictive coding, the predictive coding utilizes self mutual information, improves self prediction capability, strengthens the feature extraction capability of the coder, and has good feature extraction effect. The model achieves a fairly good result on the MIT-BIT arrhythmia database.

(3) The invention accelerates the training speed of the downstream ECG classification model;

the ECG data is coded by the coder through the contrast prediction coding, and then the data of different types are distinguished, so that the convergence rate of the model can be improved when the classification model is trained, and the model training is accelerated.

Drawings

FIG. 1 is a flowchart of the operation of the application of the contrast predictive coding of the present invention to ECG.

Fig. 2 is a schematic diagram of a model structure of an encoder according to the present invention.

FIG. 3 is a schematic diagram of a prediction model according to the present invention.

FIG. 4 is a diagram illustrating the relationship between training data and data to be trained, and between positive and negative sample pairs according to the present invention.

FIG. 5 is a graph of accuracy records for the training set and validation set of the present invention.

Fig. 6 is a schematic structural diagram of a classification model according to an embodiment of the present invention.

Fig. 7 is a schematic diagram of model accuracy in a classification model training process according to an embodiment of the present invention.

Detailed Description

The present invention will now be described in further detail with reference to the accompanying drawings.

It should be noted that the terms "upper", "lower", "left", "right", "front", "back", etc. used in the present invention are for clarity of description only, and are not intended to limit the scope of the present invention, and the relative relationship between the terms and the terms is not limited by the technical contents of the essential changes.

The invention provides an ECG data feature generation model based on comparison prediction coding, which introduces a self-supervision learning model to compare the prediction coding to predict features of the same category as the original ECG data, increases a sample set, reduces the manual labeling cost, and is convenient for other classification models to reduce overfitting and improve the classification accuracy. The present invention aims to solve the following problems:

1) the ECG data is not balanced in quantity. The data is used as a material for model training, and the size of the data often determines the performance of the model. There are various models for classifying ECG, however, due to the characteristics of ECG data, some heart rate types have very little data, and a computer has insufficient data to train, so that various problems occur in the classification model.

2) The labeling cost is high. A large amount of data sets of manual label labeling are needed in the process of full-supervised learning training, and a large amount of resources such as manpower and material resources are consumed for labeling data types. For ECG specific data, labeling requires a certain professional knowledge, which raises the threshold of manual labeling, and makes large-scale and more complex data set labeling increasingly difficult.

3) The prediction accuracy is not high. The ultimate goal of predicting features of ECG data using a deep learning model is to achieve prediction quickly and accurately. Most of the existing models are used for prediction based on the same probability distribution, the difference of characteristics among different types of data is not mined, and the prediction accuracy is not high.

4) And the training speed of the downstream task is improved. By comparing the predictive coding, the difference between the same samples after coding is smaller and smaller, and the difference between different samples is larger and larger, so that different types of data are distinguished before formal downstream task training, and the convergence rate of downstream tasks can be accelerated.

The invention mainly comprises the following steps:

as shown in fig. 1, fig. 1 shows a working step of applying a contrast prediction coding to ECG data, which includes dividing ECG training data into a positive sample pair and a negative sample pair in a horizontal view, the positive sample pair being data of the same category, the negative sample pair being data of different categories, and the training data and data to be trained in a vertical view, then coding both the training data and the data to be trained through a coder, then putting a result obtained by coding the training data into an autoregressive model to obtain Context information Context, entering the Context into a prediction model to obtain a predicted value of future multiple steps, and finally calculating a dot product of the predicted value and a value obtained by coding the data to be trained to obtain a loss value. Updating the gradient through back propagation gradually reduces the loss value. The specific implementation process is as follows:

step 1: data pre-processing

1.1 acquisition of Heart beat by Using the position of the R Peak labeled by the dataset itself

1.2 resampling cardiac beats

1.3 Filtering Using wavelet transforms

And 1.4, re-labeling and disordering the data set, dividing the data set into a training set and a verification set, wherein the training set is divided into two parts, namely training data and data to be trained. Positive and negative sample pairs are constructed simultaneously.

Step 2: building CPC model

2.1 constructing a coder model to extract data features

2.2, constructing an autoregressive network model, inputting the features extracted in the step 2.1 into the autoregressive network model, and fusing the historical information by using an autoregressive model GRU to obtain a feature fusion vector c of the historical information.

2.3, building a prediction model, and inputting the feature fusion vector obtained in the step 2.2 into the prediction model to generate a prediction result.

And 2.4, constructing model output, performing dot product operation on the prediction result obtained in the step 2.3 and the result obtained by the data to be trained through an encoder, wherein the two parts of data are approximately similar according to the characteristic of vector dot product operation, the larger the result is, and the smaller the result is, and the result obtained by calculation is enabled to be in the range of [0,1] by using a sigmoid function and is used as the output of the model.

And 2.5, constructing a CPC model, wherein input data of the CPC model comprises training data and data to be trained, and the output is the output calculated by 2.4.

And step 3: training CPC model

3.1 initializing model parameters

3.2 input of data into models for training

3.3 the model is saved and the accuracy of the training set and the validation set is plotted. The model can now generate features of the same category as the original ECG data, which can be used for training of downstream tasks such as classification tasks.

And 4, step 4: classification task

4.1 randomly disorganizing the training data, and dividing the training data into 5 folds by using the K-fold cross validation idea.

4.2 construct a classification model that is unique in that three identical training data sets are used, rather than only one.

4.3 training the model.

The following is a specific embodiment of the present invention.

Step 1: data pre-processing

1.1 intercept the heart beat by the R peak position. The experiment used the MIT-BIT arrhythmia database as the data set. MITAB contains 48 two-lead ECG recordings, the first lead of each recording being a II lead, with the exception of a few recordings, each recording being 30 minutes in length and 360Hz in sample rate, and each recording having 650000 points. Since the four records 102, 104, 107, 217 contain paced beats, the four records are deleted. With the R peak as a reference point, the first 0.4s and the last 0.5s are taken as one heartbeat, and the sampling rate is 360Hz, so the heartbeat length is 0.4 × 360+0.5 × 360 ═ 324, and the heartbeat is resampled to 251. According to The standards set forth by The Association for The Advancement of Medical Instrumentation, AAMI, all heartbeats can be divided into five major categories: normal heart beats (N), ventricular ectopic heart beats (SVEB), ventricular ectopic heart beats (VEB), fusion heart beats (F), and unknown classification heart beats (Q). When the heart beat is intercepted, the heart beat is classified at the same time, and the obtained numbers of the five heart beats of N, SVEB, VEB, F and Q are respectively: 90081. 2781, 7008, 802, 15. Since Q is an unclassified heartbeat, the final data set only contains four major classes, N, SVEB, VEB, and F, with label codes of 0,1, 2, and 3.

1.2, disordering and rearranging all the data and the corresponding labels according to the corresponding relationship. The first 90% of the data were taken as training set and the last 10% as validation set.

1.3 wavelet transform filtering is carried out on the signals. The wavelet basis uses db6, filtering replaces wavelet coefficients less than 5hz and greater than 90hz with 0, and only the coefficients between the 3 rd and 6 th detail subbands are retained for reconstruction.

1.4 generating positive and negative samples. The types of the positive sample pairs are the same, the types of the negative sample pairs are different, and the sample data are divided into training data and data to be trained. The training data and the data to be trained are both (32,4, 151).

Step 2: and (5) building a CPC model.

2.1 build the encoder model. The overall structure of the coding model is shown in fig. 2, the first half of the coding model is composed of four blocks composed of a fully-connected layer, a batch normalization layer and a LeakyReLu activation layer, the output dimension of the fully-connected layer is 64, the blocks are connected after passing through a Flatten layer, the output dimension of the fully-connected layer of the block is 256, the output dimension of the last fully-connected layer is 10, and all the fully-connected layers use linear activation functions. The role of the encoder is to extract features of the training data.

2.2 construct an autoregressive network model. The autoregressive network model uses GRU (gated Recurrent Unit), the output dimension is 256, and only the output of the last unit is returned. This part results in a feature fusion vector c into which the history information is fused.

2.3 building a prediction model. The prediction model is shown in fig. 3, where a fully connected layer outputs dimension 10, using a linear activation function. Since the four fully-connected layers are placed in a list, the four fully-connected layers are transversely spliced together by using Lambda layers to form a network. And outputting a prediction result after the feature fusion vector output by the autoregressive model is input into the prediction model.

2.4 building an output model. And the output model calculates the dot product between the result of the data to be trained, which is obtained by encoding through the encoder, and the result to be predicted, which is generated by the prediction model, and the value of the result is mapped into the range of [0,1] through a sigmoid function after the average value is calculated.

2.5, constructing an integral CPC model, inputting training data and data to be trained, obtaining a result 1 after the training data passes through an encoder, an autoregressive model and a prediction model, obtaining a result 2 after the data to be trained passes through the encoder, calculating a dot product value of the result 1 and the result 2, and outputting the result after the dot product value passes through sigmoid.

And 3, initializing model parameters, and inputting ECG data into the model for training.

3.1 initialize the model parameters. The model learning rate is set to 0.001, the sample batch size is set to 32, and the iteration number is 10. Adam was used to optimize the learning rate and the loss function used binary _ cross. Where the learning rate is specially treated to allow the model to converge faster, the learning rate will be reduced to 1/3 when 2 epochs are elapsed without the model performance being improved.

3.2 generating training data and data to be trained. The relationship between the training data and the data to be trained, and the relationship between the positive sample pair and the negative sample pair are shown in fig. 4. The number of the positive sample pairs is the same as that of the negative sample pairs, and the probabilities of generating N, SVEB, VEB and F classes are respectively 0.1,0.3,0.2 and 0.4 according to the different numbers of the classes of the training set, so that the classes with fewer samples can be fully trained. And the data generated after the training data passes through the encoder, the autoregressive model and the prediction model is prediction data, and the data generated after the data to be trained passes through the encoder becomes the data to be predicted. And inputting the training data and the data to be trained into the model for training.

3.3 save the model. The trained model is stored, and meanwhile, the accuracy of the training set and the accuracy of the verification set in the training process are drawn, as shown in fig. 5, the model achieves a very good effect.

Step four: applying the trained CPC model to a downstream classification task

4.1 divide training data. To maintain consistency with the trained CPC model, the training set data was again partitioned into 5 using the MIT-BIT arrhythmia database.

4.2 constructing a classification model. The classification model uses three identical training data. Each piece of training data passes through an encoder part of the CPC, a one-dimensional convolutional layer, a relu activation layer, a one-dimensional max pooling layer, a one-dimensional convolutional layer, a relu activation layer and a one-dimensional max pooling layer. And splicing results obtained by the three data, then connecting a Flatten layer and two full-connection layers, and finally obtaining a classification result through the full-connection layer with the activation function of softmax. The concrete model structure is shown in fig. 6.

4.3 training the classification model. The loss function uses categorical _ cross control, the optimizer uses rmsprop, the batch size is set to 64, and 10 epochs are trained. The model accuracy of the training process is shown in fig. 7.

The invention is applicable to ECG data under data imbalance conditions.

The present invention is applicable to less common arrhythmia data where less ECG data is collected. Aiming at the condition of less collected data, the CPC can solve the problem caused by insufficient data quantity by maximizing mutual information of the CPC, so that the data with insufficient sample quantity can be expanded, and the generalization capability of downstream tasks is improved.

The present invention improves the accuracy of generating features of ECG data of the same category.

The effective characteristics are extracted through the encoder, unnecessary noise is removed, the characteristics are more obvious, and subsequent processing is facilitated. Compared with the predictive coding, the predictive coding utilizes self mutual information, improves self prediction capability, strengthens the feature extraction capability of the coder, and has good feature extraction effect. The model achieves a fairly good result on the MIT-BIT arrhythmia database.

The invention accelerates the training speed of the downstream ECG classification model.

The ECG data is coded by the coder through the contrast prediction coding, and then the data of different types are distinguished, so that the convergence rate of the model can be improved when the classification model is trained, and the model training is accelerated.

The above is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above-mentioned embodiments, and all technical solutions belonging to the idea of the present invention belong to the protection scope of the present invention. It should be noted that modifications and embellishments within the scope of the invention may be made by those skilled in the art without departing from the principle of the invention.

14页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:基于相关性的运动想象的导联选择方法及装置

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!