A class weighted multi-output early-exit one-dimensional convolutional neural network heartbeat classification method, system and embedded edge device for resource-constrained microcontrollers
Patent Information
- Application Number
- CN202611122250.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-28
- Publication Date
- 2026-10-16
AI Technical Summary
样本数量占比高的心拍类别在训练过程中具有更高出现频次,浅层分类出口容易形成类别分布偏向,影响低样本量类别的分类稳定性
[0037] Compared with the prior art, the present invention has the following technical effects.
Smart Images

Figure CN122930474A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of electrocardiogram signal processing, embedded edge computing, and quantization deployment of neural network models, and particularly to a class-weighted multi-exit early termination one-dimensional convolutional neural network method, system, and embedded edge device for class-weighted multi-exit early termination of heartbeats for resource-constrained microcontrollers. Background Technology
[0002] ECG sampling signals contain continuous heartbeat waveforms, and each heartbeat category differs in waveform morphology, rhythm location, and local temporal characteristics. A one-dimensional convolutional neural network based on deep learning can directly process one-dimensional ECG sequences and output heartbeat category results.
[0003] Existing deep neural network models typically involve a large number of parameters and high computational cost. When running a complete inference path on a resource-constrained microcontroller, it results in high latency and significant storage consumption. Wearable ECG signal acquisition terminals and portable ECG signal processing terminals need to complete the heartbeat category output at the edge, which places high demands on model size, inference time, and running memory.
[0004] Early exit mechanisms can set classification exits at multiple feature extraction depths in a neural network, allowing samples with high classification confidence to output results at shallow or mid-level classification exits, thereby reducing the average inference depth and average computational cost.
[0005] In heartbeat classification tasks, the number of samples for each heartbeat category typically varies significantly. Heartbeat categories with a higher percentage of samples tend to appear more frequently during training, and shallow classification exits are prone to class distribution bias, affecting the classification stability of categories with lower sample sizes.
[0006] Category-weighted loss adjusts the loss contribution of each category based on the number of samples in each category; integer bit-width quantization adapts to the integer operation environment on the microcontroller; and early termination mechanism reduces the average inference depth. These techniques address the issues of training weights, model storage, and inference paths, respectively. For resource-constrained microcontroller-based heartbeat classification, it is also necessary to establish the correspondence between the distribution of the number of samples in each exit category during the training phase and the threshold early termination condition during the inference phase. Summary of the Invention
[0007] I. Technical problems to be solved
[0008] This invention provides a class-weighted multi-exit early termination one-dimensional convolutional neural network heartbeat classification method, system, and embedded edge device for resource-constrained microcontrollers, used to perform edge-side classification of one-dimensional heartbeat input sequences on resource-constrained microcontrollers.
[0009] The technical problem actually solved by this invention is: when performing heartbeat classification on a resource-constrained microcontroller, establishing a correspondence between the distribution of the number of exit category samples in each category during the training phase and the threshold early termination condition during the inference phase, so as to simultaneously improve the average inference depth, average inference delay and the stability of low sample size category classification on the end side.
[0010] This invention focuses on three technical aspects: the difference in the number of samples for different heart rate categories, multi-exit classification training, and microcontroller-side quantization deployment. It establishes a complete technical process for category weight generation, weighted joint training of each exit category, quantization model conversion, and threshold early termination inference.
[0011] II. Technical Solution
[0012] To achieve the above technical solution, the present invention employs the following steps.
[0013] S1. Obtain the one-dimensional heartbeat input sequence. The ECG sampling signal is filtered, R-wave localized, heartbeat segmented, and length normalized to form a one-dimensional heartbeat input sequence x with a preset sampling length L.
[0014] In one implementation, the original ECG sampling signal is first subjected to bandpass filtering, notch filtering, and smoothing filtering; then the R-wave peak value in the filtered ECG sampling signal is detected; then the heartbeat segmentation boundary is determined based on the position of adjacent R-wave peak values; then the segmented heartbeat samples are linearly interpolated and normalized to obtain a one-dimensional heartbeat input sequence with a preset sampling length L.
[0015] S2. Construct a one-dimensional convolutional neural network with multiple exits and early termination. The one-dimensional convolutional neural network with multiple exits and early termination includes M convolutional blocks connected sequentially according to the feature extraction depth, and a classification exit is set after two or more convolutional blocks, where M is an integer greater than one, and the number of classification exits is R.
[0016] In one implementation, the multi-exit early termination one-dimensional convolutional neural network includes a first convolutional block, a second convolutional block, a third convolutional block, and a fourth convolutional block. The number of convolutional channels in the first, second, third, and fourth convolutional blocks are 32, 64, 96, and 128 in order of increasing depth, respectively. A first classification exit, a second classification exit, a third classification exit, and a fourth classification exit are respectively provided after the first, second, third, and fourth convolutional blocks.
[0017] Each convolutional block consists of a one-dimensional convolutional layer, an activation layer, and a pooling layer. Each classification output consists of a global pooling layer, a fully connected layer, and a Softmax output layer. The Softmax output layer outputs the probability distribution of each heartbeat category in the target heartbeat category set.
[0018] S3. Set category weights. Set the target heartbeat category set, with K target heartbeat categories. This is based on the total number of training samples N and the number of heartbeat samples in the c-th category. Generate the category weights corresponding to the c-th type of heartbeat. Category weight It satisfies the following formula.
[0019]
[0020] The category weights mentioned above are generated from the number of target heartbeat categories, the total number of training samples, and the number of samples in each heartbeat category, and are updated as the number of samples in each heartbeat category changes in the training samples. This category weight generation method is suitable for heartbeat classification tasks with K target categories.
[0021] S4. Introduce category-weighted classification loss at each category exit. This is based on the category weight corresponding to the c-th category's center point. The cross-entropy loss of the c-th type of heartbeat sample is weighted to form the class-weighted classification loss of the i-th classification exit. , It satisfies the following formula.
[0022]
[0023] in, Encode the category label for the c-th type of heartbeat. Let be the output probability of the i-th category exit for the c-th category heartbeat.
[0024] S5. Train the multi-exit early termination one-dimensional convolutional neural network using a multi-exit joint supervision method. According to the export loss coefficients corresponding to each category of export... Category-weighted classification loss for each export category We perform a weighted summation to obtain the total loss L, which satisfies the following formula.
[0025] L = 0.20 + 0.25 + 0.25 + 0.30
[0026] In one implementation, the export loss coefficients for the first category of exports, the second category of exports, the third category of exports, and the fourth category of exports are 0.20, 0.25, 0.25, and 0.30, respectively, and the total loss L is 0.20. 0.25 0.25 and 0.30 sum.
[0027] S6. Perform integer bit-width quantization and model conversion on the trained multi-exit early-retreat one-dimensional convolutional neural network. Convert the network weight parameters and intermediate activation values from floating-point representation to integer representation to generate a quantized model file suitable for inference on resource-constrained microcontrollers.
[0028] In one implementation, integer-width quantization is performed using INT8 quantization, where the network weight parameters and intermediate activation values are converted from floating-point representations to 8-bit integer representations. The quantization model file can be a single multi-exit quantization model file or multiple quantization model files corresponding to different categories of exits.
[0029] S7. Load the quantization model file on the resource-constrained microcontroller, and perform inference calculations on the input one-dimensional heartbeat input sequence x in order of classification exit from shallow to deep.
[0030] S8. Calculate the maximum category probability at the i-th category exit. , It satisfies the following formula.
[0031]
[0032] Maximum class probability Compare with the preset exit threshold T. When When T ≥ T, use the current classification exit as the output exit and output the corresponding heartbeat classification result; when When < T, proceed to the next classification exit; when all intermediate classification exits have proceeded to the next classification exit, use the final classification exit as the output exit and output the corresponding heartbeat classification result.
[0033] In one implementation, the preset exit threshold T is determined by the category recall metric and the average exit depth metric on the validation sample set, with T set to a value of 0.90. The average exit depth D satisfies the following formula:
[0034]
[0035] in, Let be the number of samples output for the i-th category exit. To verify the total sample size.
[0036] III. Beneficial Effects
[0037] Compared with the prior art, the present invention has the following technical effects.
[0038] First, the present invention generates class weights based on the total number of training samples, the number of target heartbeat categories, and the number of samples in each category, so that the class weights have a parameter generation method that updates as the number of samples changes.
[0039] Second, this invention applies the category weights to the category-weighted classification loss of each classification exit, so that shallow, middle and terminal classification exits all participate in training according to the sample quantity distribution of the target heartbeat category set.
[0040] Third, this invention employs multi-exit joint supervised training, which sums the category-weighted classification losses of each category exit according to the exit loss coefficient to form a unified total loss and update the network parameters, so that the distribution of category sample quantity of each category exit during the training phase corresponds to the early exit output conditions of each category exit during the inference phase.
[0041] Fourth, the present invention uses a preset exit threshold to perform classification exit reasoning from shallow to deep, so that the resource-constrained microcontroller outputs the heartbeat classification result based on the maximum category probability of the current classification exit.
[0042] Fifth, this invention enables the multi-outlet early termination one-dimensional convolutional neural network to adapt to the storage space and integer operation environment of resource-constrained microcontrollers through integer bit-width quantization and model conversion.
[0043] Sixth, in the four-exit implementation, the present invention employs 32, 64, 96, and 128 convolutional channels, and non-uniform exit loss coefficients of 0.20, 0.25, 0.25, and 0.30, to enable shallow exits to participate in class-weighted training while retaining the classification ability of the terminal exits.
[0044] Seventh, the present invention establishes a cooperative relationship between category weight generation, weighted joint supervision of each exit category, preset threshold early termination inference, and INT8 quantization deployment on the resource-constrained microcontroller side, which can support end-side heartbeat classification. Attached Figure Description
[0045] Figure 1 is a schematic diagram of a one-dimensional convolutional neural network structure with multiple exits and early termination in an embodiment of the present invention.
[0046] Figure 2 is a graph of the model training process in an embodiment of the present invention, including the final exit accuracy, macro average recall, macro average F1 score and recall of each category.
[0047] Figure 3 is a flowchart of the early termination inference process on the microcontroller side in an embodiment of the present invention.
[0048] Figure 4 is a schematic diagram of the category-weighted multi-exit joint supervision training process in an embodiment of the present invention.
[0049] Figure 5 is a schematic diagram of the deployment structure of the INT8 quantization model on the Arduino Nano 33 BLE Sense Rev2 development board in an embodiment of the present invention. Detailed Implementation
[0050] The present invention will be further described below with reference to the embodiments. The following embodiments are used to illustrate the technical implementation of the present invention.
[0051] Example 1: Preprocessing of ECG sampling signals
[0052] This embodiment uses heartbeat tag data as the experimental data source. The original ECG sampling signal has a sampling rate of 360Hz, and the heartbeat tags adopt a five-class tag system, namely Class N, Class S, Class V, Class F, and Class Q.
[0053] When preprocessing the raw ECG sampling signals, a bandpass filter is first used to handle baseline drift and high-frequency noise, then a notch filter is used to handle power line interference, and finally a moving average filter is used to smooth the signal. Subsequently, the R-wave detection method is used to locate the R-wave peak, and the position between adjacent R-wave peaks is used to determine the heartbeat segmentation boundary. Each heartbeat sample is then linearly interpolated and normalized into a one-dimensional input sequence with a length of 260 sampling points.
[0054] In the training code implementation, the preprocessed and organized heartbeat sample file with 260 sampling points is read, and the input data is rearranged into a tensor composed of three dimensions: the number of samples, 260, and 1, which is used as the input to a one-dimensional convolutional neural network.
[0055] Example 2: One-dimensional convolutional neural network structure with multiple exits and early termination
[0056] This embodiment constructs a one-dimensional convolutional neural network with four classification exits. The input is a one-dimensional heartbeat sequence with a length of 260 and 1 channel.
[0057] The first convolutional block consists of two one-dimensional convolutional layers with 32 output channels, and a first classification exit is provided after the first convolutional block. The second convolutional block consists of two one-dimensional convolutional layers with 64 output channels, and a second classification exit is provided after the second convolutional block. The third convolutional block consists of two one-dimensional convolutional layers with 96 output channels, and a third classification exit is provided after the third convolutional block. The fourth convolutional block consists of two one-dimensional convolutional layers with 128 output channels, and a fourth classification exit is provided after the fourth convolutional block.
[0058] Each category output consists of a global average pooling layer, a Dropout layer, a fully connected layer, and a Softmax output layer. The Softmax output layer outputs the probability distribution of the five heartbeat categories.
[0059] Example 3: Category-Weighted Multi-Exit Joint Supervision Training
[0060] This embodiment generates class weights based on the number of samples for each heartbeat category in the training set. For the c-th heartbeat, the class weights are... satisfy × K × = N, where N is the total number of training samples and K is the number of target heartbeat categories. Let c be the number of heartbeat samples of type c.
[0061] In the training implementation, after reading the training labels, the number of samples for each heartbeat category is counted, a category weight array is generated, and a sample weight is generated according to the heartbeat category to which each training sample belongs. This sample weight is then input to the first, second, third, and fourth category exits, respectively.
[0062] The loss function for each category exit is the category-weighted cross-entropy. For the i-th category exit, the cross-entropy loss between the output probability distribution and the target heartbeat label is weighted according to the category. Weighted averages are used to determine the export losses by category. , .
[0063] The total loss was assessed through joint monitoring of multiple exports. The export loss coefficients for the first category of exports, the second category of exports, the third category of exports, and the fourth category of exports are 0.20, 0.25, 0.25, and 0.30, respectively. The total loss L is the sum of 0.20L1, 0.25L2, 0.25L3, and 0.30L4.
[0064] Example 4: Dynamic Early Exit Reasoning Mechanism and Exit Threshold Determination
[0065] This embodiment employs a multi-exit early termination one-dimensional convolutional neural network with four classification exits for heartbeat classification inference. The first, second, third, and fourth classification exits are set sequentially according to the network feature extraction depth from shallow to deep.
[0066] During inference, a preprocessed and normalized one-dimensional heartbeat input sequence of a preset sampling length is input into the first convolutional block. The one-dimensional heartbeat input sequence sequentially passes through the first classification exit, the second classification exit, the third classification exit, and the fourth classification exit.
[0067] For the i-th classification exit, the Softmax output layer of the classification exit outputs the probability corresponding to each heartbeat category in the target heartbeat category set, forming a probability vector:
[0068]
[0069] in, This represents the output probability that the i-th classification exit will predict the current one-dimensional heartbeat input sequence as a heartbeat of type c.
[0070] Calculate the maximum category probability of the i-th category export. :
[0071]
[0072] And determine the predicted heartbeat category corresponding to the maximum category probability qiq_iqi:
[0073]
[0074] Maximum class probability Compare with the preset exit threshold T.
[0075] When the i-th category exit satisfies:
[0076]
[0077] When the inference calculation for subsequent convolutional blocks and classification exits stops, the i-th classification exit is used as the output exit for the current one-dimensional heartbeat input sequence, and the predicted heartbeat category is output. And the corresponding export number i.
[0078] When the i-th category exit satisfies:
[0079]
[0080] When the final classification result is not output at the i-th classification exit, the inference calculation for the next convolutional block and the next classification exit continues.
[0081] If the maximum category probability at the first, second, and third category exits is less than the preset exit threshold T, the current one-dimensional heartbeat input sequence continues to enter the fourth category exit, and the fourth category exit outputs the final heartbeat classification result. As the final category exit, the fourth category exit outputs the corresponding predicted heartbeat category regardless of whether its maximum category probability reaches the preset exit threshold T.
[0082] To determine the preset exit threshold T, after the model training is completed, a set of validation samples that are independent of the training sample set are used to evaluate multiple candidate exit thresholds.
[0083] This embodiment pre-sets a set of candidate exit thresholds:
[0084]
[0085] For each candidate exit threshold in the candidate exit threshold set All tests used the same set of validation samples to perform a single complete multi-exit early termination inference. Except for the candidate exit threshold, the model parameters, validation samples, input preprocessing methods, and inference order remained unchanged.
[0086] Using candidate exit threshold During validation reasoning, the maximum class probability is calculated for the i-th classification exit:
[0087]
[0088] when ≥ When, the validation sample is output at the i-th classification exit; when < When the verification sample enters the next classification exit, the classification result is output by the final classification exit when none of the intermediate classification exits have reached the candidate exit threshold.
[0089] For each candidate exit threshold Count the number of true positives and false negatives for classes N, S, V, F, and Q respectively, and calculate the recall rate for each heartbeat class:
[0090]
[0091] in, To adopt candidate exit threshold The number of validation samples in which the c-th type of heartbeat is correctly classified as the c-th type. To adopt candidate exit threshold The number of validation samples of type c heartbeats that were misclassified as other categories.
[0092] Further calculate the candidate exit threshold Corresponding macro average recall:
[0093]
[0094] Where K=5.
[0095] Simultaneously, the candidate exit threshold is used in the statistics. The number of verification samples output from the first category exit, the second category exit, the third category exit, and the fourth category exit, respectively, are denoted as:
[0096]
[0097] Candidate Exit Threshold The corresponding average exit depth D(τ) is calculated according to the following formula:
[0098]
[0099] in, To verify the total sample size and satisfy:
[0100]
[0101] A smaller average exit depth means that more validation samples can be classified at shallower exits, and the model's average inference path is shorter; a larger average exit depth means that more validation samples need to enter deeper exits.
[0102] Before evaluating the candidate exit threshold, pre-set the minimum recall rates for each of the N, S, V, F, and Q classes:
[0103]
[0104] The minimum recall rate is determined before the candidate exit threshold is evaluated and remains unchanged during the evaluation of all candidate exit thresholds.
[0105] For each candidate exit threshold τ, determine whether it simultaneously satisfies:
[0106]
[0107]
[0108]
[0109]
[0110]
[0111] The feasible exit threshold set consists of candidate exit thresholds that simultaneously meet the minimum recall requirements of the above five categories:
[0112]
[0113] In the process, the average exit depths corresponding to each candidate exit threshold are compared, and the candidate exit threshold with the smallest average exit depth is selected as the preset exit threshold T.
[0114]
[0115] When two or more candidate exit thresholds correspond to the same average exit depth, their macro average recall rates are further compared, and the candidate exit threshold with the largest macro average recall rate is selected as the preset exit threshold T.
[0116] When the average exit depth and macro average recall corresponding to two or more candidate exit thresholds are the same, the candidate exit threshold with the larger value is selected as the preset exit threshold T to reduce the possibility of premature exit due to the maximum class probability being close to the threshold in shallow classification exit.
[0117] In this embodiment, candidate exit thresholds of 0.60, 0.70, 0.80, 0.85, 0.90, 0.95, and 0.99 were validated respectively. The validation results show that a candidate exit threshold of 0.90 can simultaneously meet the minimum recall requirements for classes N, S, V, F, and Q, and has the smallest average exit depth among candidate exit thresholds that meet the minimum recall requirements for all classes. Therefore, it is determined that:
[0118] T=0.90
[0119] During the inference process on the microcontroller side, when the maximum class probability of the first, second, or third classification exit reaches 0.90, the predicted heartbeat class is directly output from the current classification exit; when the maximum class probability of the current classification exit is less than 0.90, it proceeds to the next classification exit; when the maximum class probability of the current three classification exits is less than 0.90, the final heartbeat classification result is output from the fourth classification exit.
[0120] It is important to note that when submitting the formal application, it is best to include a "Comparison Table of Recall Rate and Average Exit Depth for Different Candidate Exit Thresholds for Each Category" in the specification, and fill in the relevant information. The actual value is needed; otherwise, the conclusion that "0.90 satisfies the minimum recall rate and the minimum average exit depth" still lacks direct experimental data support.
[0121] Example 5: INT8 Quantization and Microcontroller Deployment
[0122] After training, the model was quantized to INT8 using TensorFlow Lite Converter. During quantization, a representative dataset was used for calibration, converting the weight parameters and activation values from FP32 to INT8.
[0123] In one implementation, four INT8 model files are exported: ecg_exit1_int8.tflite, ecg_exit2_int8.tflite, ecg_exit3_int8.tflite, and ecg_exit4_int8.tflite.
[0124] The above model files are then converted into C / C++ header files: ecg_exit1_int8.h, ecg_exit2_int8.h, ecg_exit3_int8.h, and ecg_exit4_int8.h.
[0125] On the Arduino Nano 33 BLE Sense Rev2 development board, four model data blocks were loaded using the TensorFlow Lite Micro framework. The development board is equipped with an nRF52840 processor with a clock speed of 64 MHz, 1 MB Flash and 256 KB SRAM, which can be used for resource-constrained edge inference experiments.
[0126] In the microcontroller program, the input length is set to 260, the number of categories is 5, the number of outputs is 4, and the confidence threshold is 0.90.
[0127] During inference, the standardized 260-point input sequence is first converted into int8 data according to the corresponding model input tensor quantization parameters. Then, the inference operations are executed sequentially by calling each output model interpreter. After each inference, the int8 output tensor is read, and the probability of each class is obtained based on the output scale and zero point. The maximum class probability is calculated as the confidence score.
[0128] Example 6: Comparative Experiment and Verification of Technical Effects
[0129] To verify the technical effectiveness of this invention, three sets of comparative experiments were designed in this embodiment. The first set was a single-exit CNN model. The second set was a standard multi-exit early termination CNN model. The third set was the category-weighted multi-exit early termination CNN model proposed in this invention.
[0130] The three models were evaluated on the same heartbeat classification test set, and the recall rate, average exit depth, and average inference latency at the microcontroller end were statistically analyzed for N, S, V, F, and Q classes. The experimental results are shown in Table 1.
[0131] Table 1 Comparison of Recall Rate and Inference Delay for Five Categories
[0132] Single-exit CNN 99.09% 84.17% 95.44% 86.25% 98.63% Full path 403.0 ms CNN 99.66% 84.35% 96.54% 81.25% 99.38% 1.56 180.0 ms Invention Solution 99.50% 88.00% 97.00% 86.00% 99.50% 2.27 117.0 ms
[0133] As shown in Table 1, the average inference latency at the microcontroller end is 117.0 ms under the condition of an average exit depth of 2.27. Compared with a single-exit CNN model, the present invention reduces the average inference latency; compared with a common multi-exit early-exit CNN model, the present invention improves the recall rates of classes S and F.
[0134] The experimental results above show that there is a cooperative relationship between category weight generation, weighted joint supervision of each exit category, preset threshold early termination inference, and INT8 quantization deployment, which can support edge-based classification for resource-constrained microcontrollers.
[0135] Example 7: Resource Consumption
[0136] On the Arduino Nano 33 BLE Sense Rev2 development board, the single inference time and model size of each output model can be statistically analyzed separately.
[0137] In one implementation, the sizes of the exit models are as follows: ecg_exit1_int8.h is 29.8 KB, ecg_exit2_int8.h is 223 KB, ecg_exit3_int8.h is 560 KB, and ecg_exit4_int8.h is 1146 KB.
[0138] The complete program occupies 503 KB of Flash and 125 KB of SRAM. In dynamic inference mode with a threshold of 0.90, the average exit depth is 2.27 and the average inference time at the board is 117.0 ms.
[0139] Example 8: Heartbeat Classification System
[0140] This embodiment provides a heartbeat classification system for resource-constrained microcontrollers. The heartbeat classification system includes a heartbeat input module, a multi-output model construction module, a category-weighted joint training module, a model quantization deployment module, and an early termination inference module.
[0141] The heartbeat input module is used to acquire a one-dimensional heartbeat input sequence with a preset sampling length L. The multi-exit model construction module is used to construct a multi-exit early termination one-dimensional convolutional neural network. The category-weighted joint training module is used to calculate the total number of training samples N, the number of target heartbeat categories K, and the number of heartbeat samples in the c-th category. Generate category weights The multi-exit early termination one-dimensional convolutional neural network is trained using a multi-exit joint supervision method. The model quantization deployment module converts the trained multi-exit early termination one-dimensional convolutional neural network into a quantized model file. The early termination inference module performs inference calculations according to the classification exits from shallow to deep, and calculates the inference based on the maximum class probability. The heart rate classification results are compared with the preset exit threshold T.
[0142] Example 9: Embedded Edge Device
[0143] This embodiment provides an embedded edge device. The embedded edge device includes a processor, a memory, and a quantization model file or program instructions stored in the memory. When the processor executes the program instructions or calls the quantization model file, it realizes one-dimensional heartbeat input sequence acquisition, multi-exit early termination one-dimensional convolutional neural network inference, maximum class probability calculation, preset exit threshold comparison, and heartbeat classification result output.
[0144] In one implementation, the embedded edge device is an Arduino Nano 33 BLE Sense Rev2 development board equipped with an nRF52840 processor, model number ABX00070, and the quantization model file is deployed on the development board via the TensorFlow Lite Micro framework.
[0145] Industrial applicability
[0146] This invention can be applied to wearable ECG signal acquisition terminals, portable ECG signal processing terminals, edge ECG signal processing terminals, and low-power embedded signal processing devices. Through a category-weighted multi-outlet early termination structure and INT8 microcontroller deployment, this invention can perform heartbeat classification on the edge and reduce average computational overhead, thus possessing industrial application value.
Claims
1. A class-weighted multi-exit early termination one-dimensional convolutional neural network heartbeat classification method for resource-constrained microcontrollers, characterized in that, Includes the following steps: S1. Obtain a one-dimensional heartbeat input sequence, and perform filtering, R-wave localization, heartbeat segmentation, and length normalization on the ECG sampling signal to form a one-dimensional heartbeat input sequence x with a preset sampling length L; S2. Construct a one-dimensional convolutional neural network with multiple exits and early termination. The one-dimensional convolutional neural network with multiple exits and early termination includes M convolutional blocks connected sequentially according to the feature extraction depth, and sets a classification exit after two or more convolutional blocks. M is an integer greater than one, and the number of classification exits is R. S3. Set the target heartbeat category set, with K target heartbeat categories, based on the total number of training samples N and the number of heartbeat samples in the c-th category. Generate the category weights corresponding to the c-th type of heartbeat. ,in: ; In the formula, N is the total number of samples in the training set, and K is the total number of heartbeat categories. Let c be the number of heartbeat samples. The category weight corresponding to the c-th type of heartbeat; S4. Introduce category-weighted classification loss at each category exit, according to the category weight corresponding to the c-th category center. The cross-entropy loss of the c-th type of heartbeat sample is weighted to form the category-weighted classification loss of the i-th classification exit. , ; in Encode the category label for the c-th type of heartbeat. Let be the output probability of the i-th category exit for the c-th category heartbeat; S5. Train the multi-exit early termination one-dimensional convolutional neural network using a multi-exit joint supervision method, according to the export loss coefficients corresponding to each category of exits. Category-weighted classification loss for each export category Perform a weighted summation to arrive at the total loss. The network parameters of the multi-exit early termination one-dimensional convolutional neural network are updated according to the total loss L. S6. Perform integer bit-width quantization and model conversion on the trained multi-exit early-retreat one-dimensional convolutional neural network, converting the network weight parameters and intermediate activation values from floating-point representation to integer representation, and generating a quantized model file suitable for inference on resource-constrained microcontrollers. S7. Load the quantization model file on the resource-constrained microcontroller, and perform inference calculations on the input one-dimensional heartbeat input sequence x in order of classification exit from shallow to deep. S8. Calculate the maximum category probability at the i-th category exit. , The maximum class probability Compared with the preset exit threshold T, when When T ≥ T, use the current classification exit as the output exit and output the corresponding heartbeat classification result; when When < T, proceed to the next classification exit; when all intermediate classification exits have proceeded to the next classification exit, use the final classification exit as the output exit and output the corresponding heartbeat classification result.
2. The method according to claim 1, characterized in that, In step S1, the one-dimensional heartbeat input sequence is obtained as follows: bandpass filtering, notch filtering, and smoothing filtering are applied to the original ECG sampling signal; the R-wave peak value in the filtered ECG sampling signal is detected; the heartbeat segmentation boundary is determined based on the position of adjacent R-wave peak values; and the segmented heartbeat samples are linearly interpolated and normalized to obtain a one-dimensional heartbeat input sequence with a preset sampling length L.
3. The method according to claim 1, characterized in that, In step S2, the convolutional block includes a one-dimensional convolutional layer, an activation layer, and a pooling layer; the classification output includes a global pooling layer, a fully connected layer, and a Softmax output layer; the Softmax output layer outputs the probability distribution of each heartbeat category in the target heartbeat category set.
4. The method according to claim 1, characterized in that, The target heartbeat category set adopts a five-category heartbeat labeling system, which includes N, S, V, F, and Q categories; the category weights... The total number of training samples N, the number of target heartbeat categories K, and the number of heartbeat samples in the c-th category are all determined by these factors. The class weights are generated and updated as the number of heartbeat category samples in the training samples changes; The category-weighted classification loss is applied to each category exit, so that each category exit participates in parameter updates according to the sample size distribution of the target heartbeat category set.
5. The method according to claim 1, characterized in that, In step S5, the export loss coefficient The sum of the exit loss coefficients for each category exit is one, and the multi-exit early termination one-dimensional convolutional neural network includes a first convolutional block, a second convolutional block, a third convolutional block, and a fourth convolutional block. The number of convolutional channels in the first, second, third, and fourth convolutional blocks are 32, 64, 96, and 128 in order from shallowest to deepest, respectively. A first category exit, a second category exit, a third category exit, and a fourth category exit are set after the first, second, third, and fourth convolutional blocks, respectively. The exit loss coefficient αi is determined based on the classification performance index and early termination efficiency index on the validation sample set, specifically including: pre-setting multiple candidate exit loss coefficient combinations, each candidate exit loss coefficient combination satisfying... A multi-exit early termination one-dimensional convolutional neural network was trained using each candidate exit loss coefficient combination, and the macro-average recall, macro-average F1 score, and average exit depth were calculated on the validation sample set. Based on the macro-average recall, macro-average F1 score, and average exit depth, the target exit loss coefficient combination was selected from the multiple candidate exit loss coefficient combinations. In the four-category export implementation method, the target export loss coefficient combination includes... , The values are 0.20, 0.25, 0.25, and 0.30, respectively.
6. The method according to claim 5, characterized in that, The total loss L is generated by weighting the export losses according to the categories of exports in the first category, the second category, the third category, and the fourth category, where the export loss coefficients for exports in the first category, the second category, the third category, and the fourth category are 0.20, 0.25, 0.25, and 0.30, respectively.
7. The method according to claim 1, characterized in that, In step S6, the integer bit width quantization is INT8 quantization, and the network weight parameters and intermediate activation values are converted from floating-point representation to 8-bit integer representation; the quantization model file includes a multi-exit quantization model file with multiple classification exits, or multiple quantization model files corresponding to each classification exit respectively; ; in, Let J be the J-th candidate exit threshold, and J be the number of candidate exit thresholds; each candidate exit threshold is used separately. Perform multi-exit premature termination inference from shallow to deep on the same validation sample set, and calculate the recall rate of the c-th type of heartbeats corresponding to each candidate exit threshold. Macro average recall and average exit depth ,in: ; ; ; In the formula, To adopt candidate exit threshold The number of validation samples in which the cth type of heartbeat was correctly classified. To adopt candidate exit threshold Let K be the number of validation samples where the c-th type of heartbeat is misclassified as other categories, and R be the number of classification exits. To adopt candidate exit threshold The number of validation samples for the classification result output at the i-th classification exit. To verify the total sample size; Pre-set the minimum recall rate for each heartbeat category, denoted as . From the set of candidate exit thresholds, select candidate exit thresholds that satisfy the following formula: ; The set of feasible exit thresholds consists of candidate exit thresholds that simultaneously meet the minimum recall requirements for all heartbeat categories. ; From the set of feasible exit thresholds In the middle, select the average exit depth The smallest candidate exit threshold is taken as the preset exit threshold T, that is: ; When two or more candidate exit thresholds correspond to the same average exit depth, macro average recall is selected. The largest candidate exit threshold is used as the preset exit threshold T; when the average exit depth and macro average recall corresponding to two or more candidate exit thresholds are the same, the candidate exit threshold with the larger value is selected as the preset exit threshold T.
8. A heartbeat classification system for resource-constrained microcontrollers, characterized in that, include: The heartbeat input module is used to acquire a one-dimensional heartbeat input sequence with a preset sampling length L; A multi-exit model construction module is used to construct the multi-exit early termination one-dimensional convolutional neural network as described in claim 1; a category-weighted joint training module is used to calculate the training samples based on the total number of training samples N, the number of target heartbeat categories K, and the number of heartbeat samples of the c-th category. Generate category weights The multi-exit early termination one-dimensional convolutional neural network is trained using a multi-exit joint supervision method. The model quantization deployment module converts the trained multi-exit early termination one-dimensional convolutional neural network into a quantized model file; the early termination inference module performs inference calculations according to the classification exits from shallow to deep, and calculates the model based on the maximum class probability. The heart rate classification results are output along with the preset exit threshold T.
9. An embedded edge device, characterized in that, The method includes a processor, a memory, and a quantization model file or program instructions stored in the memory. When the processor executes the program instructions or calls the quantization model file, it implements the method according to any one of claims 1 to 7.
10. The embedded edge device according to claim 9, characterized in that, The embedded edge device is an Arduino Nano 33 BLE Sense Rev2 development board equipped with an nRF52840 processor. The development board model is ABX00070. The quantization model file is deployed on the development board through the TensorFlow Lite Micro framework.