Neural network pruning method, device, equipment and storage medium
By pruning the convolutional layers of the feature extraction module of the neural network model, the problem of longer inference time when the performance of the neural network model is improved is solved, and the inference speed is improved while the accuracy is maintained.
Patent Information
- Application Number
- CN202110937759.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-16
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2041-08-16
AI Technical Summary
While improving the performance of neural network models, existing technologies increase the structural complexity of the neural network models, resulting in longer inference time and affecting the real-time detection of electrocardiogram signals.
The pruned network model is obtained by copying the original network model. The convolution kernel parameters of the fourth convolutional layer are used to process the channels of the first feature map. The channel performance is determined by combining the output of the second convolutional layer. Pruning is performed based on the channel performance. Only the convolutional layers in the feature extraction module are pruned to simplify the connections and neurons.
It reduces the inference time of the neural network model and improves the inference speed, while maintaining the basic structure and accuracy of the model and avoiding serious structural changes.
Smart Images

Figure CN115936096B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of neural network technology, and in particular to a neural network pruning method, apparatus, device, and storage medium. Background Art
[0002] ECG signals are electrical signals that represent human cardiac activity and can assist in the detection and diagnosis of cardiovascular diseases. ECG analysis is a crucial component of ECG signal detection. ECG analysis involves analyzing the collected ECG signals to screen for various abnormalities and provide timely warnings. Extracting the ECG characteristics of the ECG signal and accurately detecting the heartbeat reference points in the ECG signal based on these characteristics are crucial steps. (For heartbeats, commonly used reference points include the P wave start, P wave end, QRS wave start, QRS wave end, and T wave end.)
[0003] Relying on artificial neural network technology, using neural network models to extract ECG features is a common technique. To extract and represent more advanced ECG features, some techniques use multiple convolutional layers within the neural network model to increase its depth and performance. However, this increases the structural complexity of the neural network model, which in turn increases its inference time and hinders real-time ECG detection.
[0004] In summary, how to reduce the inference time of neural network models while improving their performance has become a technical problem that needs to be solved urgently. Summary of the Invention
[0005] An embodiment of the present application provides a neural network pruning method, apparatus, device and storage medium to solve the technical problem in related technologies of increasing the structural complexity of a neural network model when improving its performance, which causes prolonged inference time.
[0006] In a first aspect, an embodiment of the present application provides a neural network pruning method, comprising:
[0007] Inputting the same ECG signal into an original network model and a pruned network model, the original network model is used to extract ECG features of the ECG signal, and the pruned network model is obtained by copying the original network model, the original network model includes at least one first feature extraction module, the first feature extraction module includes a first convolutional layer and a second convolutional layer, the pruned network model includes at least one second feature extraction module, the second feature extraction module includes a third convolutional layer and a fourth convolutional layer, and the first feature extraction module and the second feature extraction module correspond one to one;
[0008] Processing a corresponding channel in the first feature map using a convolution kernel parameter within a channel in the fourth convolutional layer to obtain a third feature map output by the fourth convolutional layer, where the first feature map is output to the fourth convolutional layer by the third convolutional layer of the same second feature extraction module;
[0009] Determining channel performance of a corresponding channel in the second convolutional layer using the third feature map and the second feature map output by the second convolutional layer, wherein the fourth convolutional layer is obtained by copying the second convolutional layer;
[0010] Determining a channel to be pruned in the second convolutional layer according to channel performance of multiple channels in the second convolutional layer;
[0011] The first convolutional layer and the second convolutional layer are pruned according to the to-be-pruned channel, where the second convolutional layer and the first convolutional layer are located in the same first feature extraction module.
[0012] In a second aspect, an embodiment of the present application further provides a neural network pruning device, comprising:
[0013] A signal input module, configured to input the same ECG signal into an original network model and a pruned network model, wherein the original network model is configured to extract ECG features of the ECG signal, and the pruned network model is obtained by copying the original network model, wherein the original network model includes at least one first feature extraction module, the first feature extraction module includes a first convolutional layer and a second convolutional layer, and the pruned network model includes at least one second feature extraction module, the second feature extraction module includes a third convolutional layer and a fourth convolutional layer, and the first feature extraction module and the second feature extraction module have a one-to-one correspondence;
[0014] a feature output module, configured to process a corresponding channel in the first feature map using a convolution kernel parameter within a channel in the fourth convolutional layer to obtain a third feature map output by the fourth convolutional layer, where the first feature map is output to the fourth convolutional layer by the third convolutional layer of the same second feature extraction module;
[0015] a performance determination module, configured to determine the channel performance of the corresponding channel in the second convolutional layer using the third feature map and the second feature map output by the second convolutional layer, wherein the fourth convolutional layer is obtained by copying the second convolutional layer;
[0016] a channel selection module, configured to determine channels to be pruned in the second convolutional layer according to channel performance of the channels in the second convolutional layer;
[0017] A channel pruning module is used to prune the first convolutional layer and the second convolutional layer according to the to-be-pruned channel, where the second convolutional layer and the first convolutional layer are located in the same first feature extraction module.
[0018] In a third aspect, an embodiment of the present application further provides a neural network pruning device, comprising:
[0019] one or more processors;
[0020] a memory for storing one or more programs;
[0021] When the one or more programs are executed by the one or more processors, the one or more processors implement the neural network pruning method as described in the first aspect.
[0022] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the neural network pruning method as described in the first aspect.
[0023] The above-mentioned neural network pruning method, device, equipment and storage medium obtain a pruned network model by copying the original network model. Then, when the original network model and the pruned network model process the same electrocardiogram signal, the convolution kernel parameters of a channel in the fourth convolution layer of the second feature extraction module in the pruned network model are used to process the corresponding channel in the first feature map output by the third convolution layer of the second feature extraction module to obtain the corresponding third feature map. Then, the second feature map and the third feature map output by the second convolution layer of the first feature extraction module in the original network model are used to determine the channel performance of the corresponding channel in the second convolution layer, wherein the second feature extraction module corresponds to the first feature extraction module and the second convolution layer corresponds to the fourth convolution layer. Then, based on the channel performance of multiple channels in the second convolution layer, the channels to be pruned in the second convolution layer are determined, and the first and second convolution layers in the first feature extraction module are pruned based on the channels to be pruned. This technical means solves the technical problem of increasing the structural complexity of the neural network model when improving the performance of the neural network model, which causes the inference time to increase. By pruning the neural network model, the connections and neurons of the neural network model are simplified, the inference speed is improved, and the inference time is reduced. Moreover, during pruning, only the convolutional layers in the feature extraction module need to be pruned, that is, the internal structure of the feature extraction module is optimized, which can maintain the basic structure of the neural network model and avoid serious structural changes in the neural network model after pruning. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 A schematic diagram of the structure of a neural network model provided in one embodiment of the present application;
[0025] Figure 2 for Figure 1 Schematic diagram of the structure of the C0 submodule;
[0026] Figure 3 for Figure 1 Schematic diagram of the structure of the C1 submodule;
[0027] Figure 4 A flowchart of a neural network pruning method provided in one embodiment of the present application;
[0028] Figure 5 A flowchart of another neural network pruning method provided in one embodiment of the present application;
[0029] Figure 6 A schematic diagram of loss performance provided in one embodiment of the present application;
[0030] Figure 7 A schematic diagram of inference speed provided for one embodiment of the present application;
[0031] Figure 8 A schematic diagram of the structure of a neural network pruning device provided in one embodiment of the present application;
[0032] Figure 9 A schematic diagram of the structure of a neural network pruning device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0033] The present application will be further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are intended to explain the present application, not to limit the present application. It should also be noted that, for ease of description, the accompanying drawings only illustrate portions relevant to the present application, not all structures.
[0034] In order to reduce the inference time of the neural network model, the pruning method can be used to process the neural network model. Pruning can delete some connections and / or neurons in the neural network model to improve the inference speed of the neural network model and reduce the inference time of the neural network model. When using the pruning method, a neural network pruning method based on a weight threshold can be used, wherein the weight is the weight used by the convolution kernel in the convolution layer, which is a type of convolution kernel parameter. The neural network pruning method based on the weight threshold maintains the structure of the original neural network model and removes some unimportant weights and their connections in the convolution layer according to the weight threshold. Although this method can improve the inference speed of the neural network model (i.e., reduce the inference time of the neural network model), it requires the use of a sparse weight matrix and requires specific hardware when using a sparse weight matrix, i.e., there are hardware limitations, and therefore, it is not conducive to wide application; when using the pruning method, the importance of the filter (i.e., the convolution kernel) of the neural network model can also be measured based on the L1 norm of the filter weight, and then some filters with lower importance are pruned. Moreover, after each pruning, the accuracy of the neural network model is calculated, and a convolution layer with less impact on the accuracy is removed to simplify the structural complexity of the neural network model, thereby reducing the inference time. However, this method considers relatively single features during pruning, ignoring the neural network model in Using the distribution characteristics of the data set, and it is difficult to obtain the optimal pruning depth using the preset pruning rate during pruning; when using the pruning method, it is also possible to guide the pruning of the filter of the i-th convolution layer according to the feature map of the i+1-th convolution layer in the neural network model to improve the reasoning speed of the neural network model, but this method will reduce the accuracy of the neural network model, and it is difficult to obtain the optimal pruning depth using the preset pruning rate during pruning; when using the pruning method, it is also possible to prune and compress the neural network model based on the pruning rate and the attenuation parameter (obtained after attenuating the parameters of the convolution layer) to reduce the model parameters of the neural network model, thereby improving the reasoning speed of the neural network model, but for a neural network model containing multiple convolution layers, the preset pruning rate limits the pruning depth of each convolution layer, thereby making it impossible to balance the reasoning speed and accuracy of the neural network model; when using the pruning method, it is also possible to prune in combination with the variance of the features extracted by the neural network model, but this method only considers the depth of pruning, but does not consider the accuracy of the neural network model after pruning.
[0035] In summary, an embodiment of the present application provides a neural network pruning method to reduce the inference time of the neural network model while improving the performance of the neural network model, and at the same time, balance the accuracy and inference speed of the pruned neural network model.
[0036] The neural network pruning method provided in one embodiment of the present application can be performed by a neural network pruning device. The neural network pruning device can be implemented via software and / or hardware. The neural network pruning device can be composed of two or more physical entities, or a single physical entity, without limitation. In one embodiment, the neural network pruning device can be an electronic device with data processing and analysis capabilities, such as a desktop computer, a laptop computer, an interactive smart tablet, a server, or an electrocardiograph.
[0037] In one embodiment, a neural network model is deployed in a neural network pruning device, which can extract ECG features of ECG signals. ECG signals can be collected through leads. In the professional terminology of electrocardiography, the placement of electrodes on the human body surface and the connection method between the electrodes and the amplifier when recording an ECG are referred to as ECG leads. In the scenario of heartbeat reference point detection, ECG features refer to ECG features related to heartbeat reference points and characteristic waveforms, wherein heartbeat reference points refer to the P wave starting point, P wave end point, QRS complex starting point, QRS complex end point, and T wave end point in a heartbeat. Characteristic waveforms refer to the waveforms of the QRS wave, P wave, and T wave. The neural network model deployed in the neural network pruning device is a neural network model that has completed training and verification and is ready for application.
[0038] The neural network model deployed in the neural network pruning device contains multiple sets of convolutional layers to extract more advanced ECG features. The structure of the neural network model is not limited here. For example, the neural network model deployed in the neural network pruning device is as follows: Figure 1 As shown, Figure 1 A schematic diagram of the structure of a neural network model provided in one embodiment of the present application. Figure 1 , after the neural network model inputs a length of ECG signal, it can output three ECG feature maps that describe ECG features. Exemplarily, after the neural network model receives the ECG signal, it first passes through the C0 submodule to obtain a feature map, then passes through the C1 submodule to extract features to obtain a new feature map, then downsamples the output of the C1 submodule and passes through the C2 submodule to extract features to obtain a new feature map, then downsamples the output of the C2 submodule and passes through the C3 submodule to extract features to obtain a new feature map, that is, the C1 submodule, C2 submodule and C3 submodule can all output new feature maps based on the input feature map. Among them, Figure 2 for Figure 1 The structural diagram of the C0 submodule is shown in the figure. Figure 2 ,The C0 submodule consists of a convolutional layer, a normalization layer, and an activation layer (including activation functions). Figure 3 for Figure 1 The structural diagram of the C1 submodule in Figure 3The C1 submodule consists of a convolutional layer (c1), a normalization layer (bn1), an activation layer (r1), a convolutional layer (c2), a normalization layer (bn2), and an activation layer (r2). The output of the second normalization layer (bn2) is added to the input of the C1 submodule before passing through the second activation layer (r2). The C2 and C3 submodules have the same structure as the C1 submodule and can both be used to extract ECG features. This will not be described in detail here. The output of the C3 submodule then passes through a convolutional layer to obtain the output of the C3 submodule, which can be recorded as the ECG feature map C3. The output of the C3 submodule is upsampled to obtain the upsampled result. The output of the C2 submodule then passes through a convolutional layer and is added to the upsampled result of the C3 submodule to obtain the output of the C2 submodule. This output is then passed through a convolutional layer to obtain the ECG feature map C2. The output of the C2 submodule is upsampled to obtain the upsampled result. Afterwards, the output of the C1 submodule passes through the convolution layer and is added to the upsampling result of the C2 submodule to obtain the output result corresponding to the C1 submodule. After that, the output result passes through a convolution layer to obtain the ECG feature map C1. Among them, c (number of channels), k (convolution kernel length), p (padding size) and s (step size) of each convolution layer in the neural network model can be set according to actual conditions. The activation function used in the activation layer mentioned above can be selected according to actual conditions. For example, the ReLu activation function is used. The three ECG feature maps output by the above neural network model have different lengths.
[0039] In one embodiment, the specific implementation process of the neural network pruning method is described using the above-mentioned neural network model as an example. The C1, C2, and C3 submodules can all be considered as convolutional layer groups configured to extract high-level ECG features. In one embodiment, the C1, C2, and C3 submodules are all used as feature extraction modules, and the number of input channels of the second convolutional layer (c2) in each feature extraction module is affected by the number of convolution kernels in the first convolutional layer (c1). When the above neural network model is deployed on a PC platform (CPU Inter Core i7-6850K 3.6GHz*6, RAM 128G) and an embedded platform with a low-frequency CPU (QualcommMSM89091.1GHz*4, RAM 1G) to extract ECG features and perform heartbeat reference point detection based on the ECG features, the inference time of the neural network model can reach 20.9ms and 871ms respectively, and most of the inference time of the neural network model is used for the convolution operation of the feature extraction module. Therefore, when pruning the neural network model, the convolution layer in the feature extraction module is mainly pruned. For example, the basic concept of pruning is to make the output of some input channels of a convolution layer as close as possible to the output of the convolution layer, so as to determine the channel performance of the channel in the convolution layer, and then prune the channels with low channel performance. At this time, the basic concept of pruning can be expressed by the following formula:
[0040]
[0041] in, Represents the part of the convolution kernel selected in the convolution layer (c1), which can also be understood as the part of the input channel selected in the convolution layer (c2). Indicates The feature map output by the convolutional layer (c2) for the corresponding channel set, y′ represents the original feature map output by the convolutional layer (c2), DIST(·) represents the function used to calculate similarity, and argmin represents finding the minimum value. Using the above formula, we can find the channel set corresponding to the minimum similarity and then perform pruning based on this channel set.
[0042] For example, Figure 4 A flowchart of a neural network pruning method provided in one embodiment of the present application is provided. Figure 4 , the neural network pruning method includes:
[0043] Step 110: Input the same ECG signal to the original network model and the pruned network model. The original network model is used to extract ECG features of the ECG signal. The pruned network model is obtained by copying the original network model. The original network model includes at least one first feature extraction module, which includes a first convolutional layer and a second convolutional layer. The pruned network model includes at least one second feature extraction module, which includes a third convolutional layer and a fourth convolutional layer. The first feature extraction module and the second feature extraction module correspond one to one.
[0044] For example, the original network model is a neural network model used in ECG signal detection, which can extract ECG features and output ECG feature maps. In one embodiment, the structure of the original network model is as follows: Figure 1 As shown. The feature extraction module in the original network model is recorded as the first feature extraction module, that is, Figure 1 When the original network model is used, the C1 submodule, the C2 submodule, and the C3 submodule are all first feature extraction modules. It is understood that the original network model can also adopt other structures. Under other structures, the original network model can include other numbers of first feature extraction modules, which are not limited here. In one embodiment, the structure of the first feature extraction module is as follows Figure 3 As shown, at this time, the convolution layer (c1) in the first feature extraction module is recorded as the first convolution layer, and the convolution layer (c2) is recorded as the second convolution layer. The number of convolution kernels of the first convolution layer is equal to the number of input channels of the second convolution layer. For each convolution layer, the number of channels it outputs (i.e., the number of output channels) is equal to the number of convolution kernels set for itself, and the number of input channels is related to the number of output channels of the previous convolution layer. In one embodiment, the channel of each convolution layer can also be understood as the input channel of the convolution layer, that is, the channels of each convolution layer mentioned below refer to the input channels of each convolution layer. At this time, each convolution layer includes two types of channels: channels and output channels. The first feature extraction module can also adopt other structures, which are not limited here.
[0045] The pruned network model is a neural network model obtained by copying the original network model. The current pruned network model has the same structure and parameters as the original network model, that is, the model structure of the pruned network model is also the same. Figure 1 As shown. The pruned network model plays a guiding role in the pruning process, that is, the channel performance of the convolution layer of each first feature extraction module in the original network model is determined by the pruned network model, and then the convolution layer is pruned. In one embodiment, the feature extraction module in the pruned network model is recorded as the second feature extraction module, that is Figure 1In the case of a pruned network model, the C1 submodule, the C2 submodule, and the C3 submodule are all second feature extraction modules. It can be understood that the second feature extraction modules in the pruned network model correspond one-to-one to the first feature extraction modules in the original network model, that is, each second feature extraction module is copied from the corresponding first feature extraction module. In one embodiment, the structure of the second feature extraction module is as follows: Figure 3 As shown in the figure, at this time, the convolution layer (c1) in the second feature extraction module is recorded as the third convolution layer, and the convolution layer (c2) is recorded as the fourth convolution layer. The number of convolution kernels in the third convolution layer is equal to the number of channels in the fourth convolution layer (equivalent to the number of input channels in the fourth convolution layer).
[0046] When pruning the original neural network, a length of ECG signal is first collected and input into the original network model and the pruned network model respectively. The ECG signal collection method and signal length can be set according to actual conditions.
[0047] Step 120: Use the convolution kernel parameters in a channel in the fourth convolutional layer to process the corresponding channel in the first feature map to obtain a third feature map output by the fourth convolutional layer. The first feature map is output to the fourth convolutional layer by the third convolutional layer of the same second feature extraction module.
[0048] The pruned network model processes the input ECG signal to extract ECG features. During the processing of the pruned network model, each second feature extraction module receives the feature map output by the upper layer and outputs a new feature map after processing. The neural network pruning device processes each second feature extraction module in the same way. Therefore, we currently use a second feature extraction module as an example to describe how to determine channel performance.
[0049] In one embodiment, during the processing of the pruning network model, the feature map output from the third convolution layer of the second feature extraction module to the fourth convolution layer is obtained, and reference is made to Figure 3, the feature map output by the third convolutional layer passes through the normalization layer and the activation layer and is input to the fourth convolutional layer. Therefore, the feature map output by the third convolutional layer to the fourth convolutional layer can also be considered as the feature map output after the normalization layer and the activation layer. It can be understood that it is currently necessary to determine the channel performance of the second convolutional layer channel in the first feature extraction module, and to prune the first convolutional layer and the second convolutional layer based on the channel performance, and the second feature extraction module is used to guide the pruning of the first feature extraction module. Therefore, the output of the third convolutional layer after copying the first convolutional layer (i.e., the first convolutional layer) in the first feature extraction module is currently obtained to determine the channel performance based on the output. In one embodiment, the feature map output by the third convolutional layer to the fourth convolutional layer is recorded as the first feature map, wherein the number of channels of the first feature map is equal to the number of convolution kernels of the third convolutional layer, and is also equal to the number of channels of the fourth convolutional layer. Exemplarily, each channel of the fourth convolutional layer corresponds to each channel of the first feature map. For example, the number of channels of the first feature map is 32, that is, the first feature map has 32 channels, the fourth convolutional layer has 32 channels, and each channel corresponds to a channel of the input first feature map. Optionally, each channel has a corresponding channel number, and the channel number is used to indicate which channel the current channel is. For example, the first feature map has 32 channels, then the first channel of the first feature map corresponds to the channel number 1, the second channel of the first feature map corresponds to the channel number 2, and so on. At this time, the first channel of the fourth convolutional layer corresponds to the first channel of the first feature map, and so on.
[0050] In one embodiment, Figure 3 For example, when traversing the channels of the first feature map output by the third convolutional layer (which can also be understood as the feature map output by the first activation layer (r1)), a channel of the first feature map is first selected. For the second feature extraction module, the feature map ( Figure 3 The number of channels in the feature map (denoted as Fin in FIG) is related to the number of convolution kernels (also understood as the number of output channels) set in the first convolution layer (c1). In one embodiment, for ease of description, the i-th channel in the first feature map is used as an example for description.
[0051] In one embodiment, when the i-th channel of the first feature map is selected, the convolution kernel parameters used in the i-th channel (i.e., the i-th input channel) of each convolution kernel in the fourth convolution layer can also be obtained. It can be understood that each convolution kernel in the fourth convolution layer has n channels, n is the number of input channels of the fourth convolution layer, 1≤i≤n, and the convolution kernel parameters of all convolution kernels in the fourth convolution layer in the i-th channel are obtained according to the i-th channel of the first feature map. Among them, the currently used fourth convolution layer and the third convolution layer used above belong to the same second feature extraction module. In one embodiment, the convolution kernel parameters include weights and biases, that is, the convolution kernel parameters can represent the weights and biases of the corresponding convolution kernels in the corresponding channels, and the convolution of the feature map can be achieved after processing the feature map by the convolution kernel parameters.
[0052] Subsequently, the i-th channel of the first feature map is processed using the convolution kernel parameters for the i-th channel. That is, a convolution operation is performed on the data within the i-th channel of the first feature map to output a new feature map. In one embodiment, the new feature map is recorded as the third feature map. It should be noted that the third feature map currently obtained can be considered to be the third feature map corresponding to the i-th channel in the fourth convolutional layer. In this case, the other channels of the first feature map are not processed by the fourth convolutional layer.
[0053] Step 130: Determine the channel performance of the corresponding channel in the second convolutional layer using the third feature map and the second feature map output by the second convolutional layer, and the fourth convolutional layer is obtained by copying the second convolutional layer.
[0054] The original network model processes the input ECG signal to extract ECG features. During the processing of the original network model, each first feature extraction module receives the feature map output by the upper layer and outputs a new feature map after processing. In one embodiment, the feature map output in the second convolutional layer of the first feature extraction module is recorded as the second feature map. At this time, the number of channels of the second feature map is equal to the number of convolution kernels of the second convolutional layer (that is, the number of output channels of the second convolutional layer). The second feature map can be considered as a feature map obtained by the conventional processing method of the first feature extraction module. It can be understood that the above-mentioned first feature extraction module can be copied to obtain the above-mentioned second feature extraction module. At this time, the above-mentioned fourth convolutional layer is copied from the above-mentioned second convolutional layer, that is, the structures and parameters of the two convolutional layers are the same.
[0055] The main difference between the third feature map and the second feature map is that the third feature map is a feature map obtained after the i-th input channel in the second convolutional layer of the feature extraction module processes the i-th channel in the feature map input to the second convolutional layer, while the second feature map is a feature map obtained according to the conventional processing method of the feature extraction module. The second feature map and the third feature map are of the same size. The more similar the third feature map and the second feature map are, the closer the output after processing the i-th channel in the fourth convolutional layer is as close as possible to the original output of the second convolutional layer. Therefore, in one embodiment, the similarity between the second feature map and the third feature map is calculated, and the channel performance of the corresponding channel in the second convolutional layer is obtained by the similarity, that is, the channel performance of the i-th channel (equivalent to the i-th input channel) in the second convolutional layer is obtained by the similarity. Among them, the higher the similarity, the better the corresponding channel performance. It can be understood that this channel performance also reflects the channel performance of the corresponding channel in the fourth convolutional layer.
[0056] Illustratively, after obtaining the channel performance of one channel, the above operations may be repeated to obtain the channel performance of multiple channels. Optionally, each time the channel performance of a channel is determined, the number of currently determined channel performances may be determined. Thereafter, the number of channel performances may be compared with a set target number. If the number of channel performances reaches the target number, subsequent steps may be performed. If the number of channel performances does not reach the target number, the above operations may be repeated until the number of channel performances reaches the target number.
[0057] Step 140: Determine the channels to be pruned in the second convolutional layer according to the channel performance of multiple channels in the second convolutional layer.
[0058] Exemplarily, after determining the channel performance of multiple channels in the second convolutional layer, the multiple channel performances are compared to determine the channels that can be pruned in the second convolutional layer. In one embodiment, the channels that can be pruned are recorded as channels to be pruned, where the number of channels to be pruned can be set according to actual conditions.
[0059] In one embodiment, the lower the channel performance, the smaller the impact on the accuracy of the neural network model after the corresponding channel is pruned. Therefore, based on the performance of each channel, one or more low channel performances are selected, and then the channels corresponding to the selected channel performances in the second convolutional layer are used as channels to be pruned. In one embodiment, the channel performances are sorted from low to high and selected after sorting.
[0060] In one embodiment, when the original neural network is repeatedly pruned, in order to avoid over-pruning, before selecting the channels to be pruned, it is first determined whether the number of unselected channels in the first feature map (i.e., unselected input channels in the fourth convolutional layer) is less than a set number. The number can be determined by the length of the convolution kernel arrangement in the third convolutional layer and the set minimum pruning rate (used to avoid over-pruning). If it is less than the set number, it means that more channels have been selected, that is, more channels of the original network model have been pruned. Therefore, pruning the original network model is stopped to avoid over-pruning. Otherwise, step 140 is continued.
[0061] Step 150: Prune the first convolutional layer and the second convolutional layer according to the to-be-pruned channel, where the second convolutional layer and the first convolutional layer are located in the same first feature extraction module.
[0062] Exemplarily, the first convolution layer and the second convolution layer of the original network model are pruned according to the channel to be pruned. In one embodiment, when the first convolution layer is pruned, the corresponding convolution kernel in the first convolution layer is determined according to the channel to be pruned, and the convolution kernel parameters of the convolution kernel in each channel of the first convolution layer (i.e., the input channel) are removed. At this time, the neurons of the first convolution layer are reduced. For example, when the j-th channel in the second convolution layer is the channel to be pruned, the convolution kernel parameters corresponding to the j-th convolution kernel in the first convolution layer are removed. In one embodiment, when the second convolution layer is pruned, the channel to be pruned is mainly removed. At this time, the connection of the second convolution layer is reduced. For example, when the j-th channel in the second convolution layer is the channel to be pruned, the j-th channel in the second convolution layer is removed. At this time, each convolution kernel in the second convolution layer is no longer connected to the j-th channel.
[0063] Optionally, when pruning the original network model, the pruned network model can be pruned simultaneously so that when the original network model needs to be pruned again, the pruned network model can continue to guide it. In one embodiment, the fourth convolutional layer uses the same pruning method as the second convolutional layer, and the third convolutional layer is pruned by removing the convolution kernel. For example, when the jth channel in the second convolutional layer is the channel to be pruned, the jth convolution kernel in the third convolutional layer is removed.
[0064] After pruning each of the first feature extraction module and the second feature extraction module in the above manner, a pruned original network model and a pruned network model are obtained. In one embodiment, in order to ensure the performance of the pruned model, the pruned original network model is iteratively trained, that is, the pruned original network model is trained using a training data set to stabilize the performance of the original network model. The training data set is composed of a large number of ECG signals, and the training data set can be the training data set used for training the original network model when it was constructed. Optionally, after the iterative training is completed, the pruned original network model can also be verified to verify the accuracy of the model, wherein a verification data set can be used for verification, and the verification data set also consists of a large number of ECG signals, and the verification data set and the training data set can contain different ECG signals.
[0065] It can be understood that iterative training refers to using the training data set to train the pruned original network model multiple times. After each training, the parameters of the original network model will be adjusted, and the model with adjusted parameters will be used in the next training. During each training, the loss value corresponding to this training can be obtained based on the input and output of the model and the loss parameter of the model, and then the parameters of the model are adjusted according to the loss value. The models mentioned above all refer to the original network model after pruning. In one embodiment, after iterative training, the average of the loss value of each training is calculated, and then the average of the loss value is used to determine whether to continue pruning. If pruning is to continue, the process returns to step 120 to recalculate the channel performance of the channel in the second convolutional layer and continue to prune the original network model based on the channel performance. If pruning is not to continue, the pruning is terminated. Afterwards, the pruned original network model can be used to extract the ECG features of the ECG signal, and then ECG detection can be performed based on the ECG features. In one embodiment, when determining whether to continue pruning based on the average loss value, a queue can be constructed to record the average loss value obtained from each iterative training. The length of the queue can reflect the number of iterative trainings. Since iterative training is performed after each pruning, the number of iterative trainings is also equal to the number of prunings. If the queue length exceeds a set queue length, the original network model has been pruned a certain number of times, and a subsequent judgment can be made. Otherwise, pruning is continued. During the subsequent judgment, whether to continue pruning is determined by the difference between the average of the last loss value in the queue and the average of the smallest loss value in the queue. If the difference is greater than a pre-set value, it indicates that the current pruning has a significant impact on the model. Therefore, pruning is paused and rolled back to the last pruning operation, that is, the pruning operation on the model is withdrawn. Afterwards, the original network model after the last pruning operation is used as the final result, and pruning is stopped. Otherwise, pruning is continued.
[0066] In the above, by copying the original network model to obtain a pruned network model, when the original network model and the pruned network model process the same electrocardiogram signal, the convolution kernel parameters of a channel in the fourth convolution layer of the second feature extraction module in the pruned network model are used to process the corresponding channel in the first feature map output by the third convolution layer of the second feature extraction module to obtain the corresponding third feature map. Then, the second feature map and the third feature map output by the second convolution layer of the first feature extraction module in the original network model are used to determine the channel performance of the corresponding channel in the second convolution layer, wherein the second feature extraction module corresponds to the first feature extraction module, and the second convolution layer corresponds to the fourth convolution layer. Then, based on the channel performance of multiple channels in the second convolution layer, the channels to be pruned in the second convolution layer are determined, and the first and second convolution layers in the first feature extraction module are pruned based on the channels to be pruned. This technical approach solves the technical problem of increasing the structural complexity of the neural network model when improving the performance of the neural network model, which causes the inference time to increase. By pruning the neural network model, the connections and neurons of the neural network model are simplified, the inference speed is improved, and the inference time is reduced. Moreover, during pruning, only the convolutional layers in the feature extraction module need to be pruned, that is, the internal structure of the feature extraction module is optimized, which can maintain the basic structure of the neural network model and avoid serious structural changes in the neural network model after pruning.
[0067] Figure 5 This is a flowchart of another neural network pruning method provided in one embodiment of the present application. This neural network pruning method is a specific implementation of the above neural network pruning method. Figure 5 , the neural network pruning method includes:
[0068] Step 210: Input the same ECG signal to the original network model and the pruned network model. The original network model is used to extract ECG features of the ECG signal. The pruned network model is obtained by copying the original network model. The original network model includes at least one first feature extraction module, which includes a first convolutional layer and a second convolutional layer. The pruned network model includes at least one second feature extraction module, which includes a third convolutional layer and a fourth convolutional layer. The first feature extraction module and the second feature extraction module correspond one to one.
[0069] Step 220: traverse each channel of the first feature map and select a channel currently traversed. The number of channels of the first feature map is determined by the convolution kernel arrangement length of the third convolutional layer. The i-th channel in the first feature map is the channel currently traversed.
[0070] The structure of the second feature extraction module is as follows Figure 3As shown, each channel of the fourth convolutional layer in the second feature extraction module is used to input the feature map output by the first activation layer, that is, to input the first feature map. The number of channels of the fourth convolutional layer can also be understood as the number of input channels of the fourth convolutional layer, which is equal to the number of channels of the first feature map. The number of channels of the first feature map can be determined by the length of the convolution kernel arrangement of the third convolutional layer. In one embodiment, the convolution kernel of the third convolutional layer is first obtained, and then the convolution kernel is arranged. The arranged convolution kernel queue can be recorded as D c1 , D c1 ={1, 2, 3, ..., d c1}, where 1 represents the first convolution kernel, 2 represents the second convolution kernel, and so on. c1 Represents the last convolution kernel, the length of the queue can be recorded as |D c1 |, which determines the length of the first feature map ( Figure 3 It should be noted that the length of the convolution kernel queue is at least 4. In practical applications, the length of the convolution kernel queue can be at least 2.
[0071] Exemplarily, each channel of the first feature map is traversed, that is, each input channel of the fourth convolutional layer is traversed. During the traversal process, the channel of the first feature map currently traversed is recorded as the i-th channel. In this case, the channel number corresponding to the channel is i, where i ≥ 1. The order in which the channels are selected during traversal can be set according to actual conditions. For example, during traversal, the first channel of the first feature map is first selected for subsequent processing, followed by the second channel of the first feature map, and so on.
[0072] Step 230: Obtain the convolution kernel parameters used by the i-th channel in the fourth convolutional layer.
[0073] Exemplarily, according to the i-th channel of the first feature map, the i-th channel of each convolution kernel of the fourth convolution layer is selected, and the convolution kernel parameters of the i-th channel are obtained, that is, the convolution kernel parameters of each convolution kernel used by the i-th input channel in the fourth convolution layer are obtained. In one embodiment, the convolution kernel parameters include the weight and bias of the convolution kernel. The weight of the i-th channel currently obtained is 1×D c2 ×K×K matrix, where D c2 Indicates the number of convolution kernels in the fourth convolution layer, K indicates the length and width of the currently acquired weights, that is, each convolution kernel in the fourth convolution layer has a corresponding weight in the i-th channel, and the weights of each convolution kernel form a matrix. The bias corresponding to the i-th channel in the currently acquired fourth convolution layer is 1×D c2 For example, the currently acquired weight is recorded as weight', the currently acquired bias is recorded as bias', and the weight of the i-th channel in the fourth convolutional layer (equivalent to the weight matrix) is recorded as weightc4,i, , where c4 represents the fourth convolutional layer, i represents the i-th channel, and the bias of the i-th channel is recorded as bias c4, At this time, weight'=weight c4,i, , bias'=bias c4, It can be understood that each channel of the fourth convolutional layer can share the same bias.
[0074] It is understandable that the convolution kernel parameters and the first feature map can be obtained simultaneously or successively, and there is no current limitation.
[0075] Step 240: Process the i-th channel of the first feature map according to the convolution kernel parameters to obtain a third feature map output by the fourth convolution layer.
[0076] In one embodiment, the convolution kernel parameters include the weight and bias of the convolution kernel. This step may specifically include: performing a convolution operation on the i-th channel of the first feature map according to the weight and the convolution kernel of the fourth convolution layer, and adding a bias after the convolution operation to obtain the third feature map output by the fourth convolution layer.
[0077] Exemplarily, when the convolution kernel performs a convolution operation on the data in the i-th channel of the first feature map, the weight of the convolution kernel in the i-th channel (i.e., the weight in the currently acquired convolution kernel parameters) is used, and a bias is added after the convolution operation to obtain a third feature map. In one embodiment, the currently calculated third feature map can be expressed as:
[0078] Fout′=G(weight′)*Fin′+bias′
[0079] Among them, Fout′ represents the third feature map, and the size of Fout′ is D×H Fout′ ×W Fout′ , D represents the number of channels of the third feature map (which is also equal to the number of convolution kernels in the fourth convolutional layer), H Fout′ and W Fout′ Represent the height and width of Fout' respectively. Fout' is the same size as the second feature map output by the second convolutional layer. G(weight')*Fin' represents the convolution operation of the convolution kernel with weiqht' as the weight matrix on Fin', where weight' represents the weight of the convolution kernel of the fourth convolutional layer in the i-th channel, Fin' represents the i-th channel of the first feature map, and Fin'=Fin i , Fin i is the i-th channel of the first feature map Fin, and bias′ represents the bias of the convolution kernel in the i-th channel in the fourth convolutional layer.
[0080] Step 250: Calculate the similarity between the second feature map and the third feature map. The similarity and the i-th channel form a data pair, and the data pair represents the channel performance of the i-th channel in the second convolutional layer.
[0081] The algorithm used to calculate the similarity between the second feature map and the third feature map can be selected according to the actual situation. In one embodiment, the L2 norm is used as the basis for similarity. In this case, the similarity calculation formula is:
[0082]
[0083] Where Fout′ represents the third feature map. Fout represents the second feature map, x′ j represents the jth element of Fout′, x j represents the j-th element of Fout, DIST(Fout, Fout′) represents the similarity between Fout and Fout′, and ||*||2 represents the L2 norm.
[0084] It can be understood that after each channel of the first feature map is selected in step 220, a similarity can be calculated. For the convenience of description, the similarity corresponding to the i-th channel is recorded as DIST i Calculate DIST i After that, the traversed channels (equivalent to the input channels in the fourth convolutional layer) and the similarities are combined into pairs. In one embodiment, the paired data are recorded as data pairs. For the i-th channel, the data pair is (i, DIST i ), (i, DIST i ) represents the channel performance of the i-th channel (i.e., the i-th input channel) in the second convolutional layer, where the fourth convolutional layer is copied from the second convolutional layer. It can be understood that the higher the similarity, the better the channel performance.
[0085] Step 260: Determine whether the number of channel performances determined in the second convolutional layer reaches a first target number. If not, return to step 220. If so, proceed to step 270.
[0086] The first target number is the maximum number of channels traversed when traversing each channel of the first feature map, and it can be set according to actual conditions. Each time a channel performance is obtained, the number of determined channel performances is obtained and compared with the first target number. If the first target number is reached, it means that a sufficient number of channels have been traversed, that is, the channel performance of a sufficient number of channels in the second convolutional layer has been determined. Therefore, the channels to be pruned can be determined in each channel with determined channel performance, that is, step 270 is executed. If the first target number is not reached, it means that a sufficient number of channels have not been traversed. Therefore, it is necessary to continue traversing the remaining channels in the first feature map. At this time, the i+1th channel can be selected (that is, the unselected channels are traversed) to continue calculating the channel performance until the number of determined channel performances reaches the first target number.
[0087] In one embodiment, step 260 may include steps 261 and 262:
[0088] Step 261: Store the currently determined channel performance into a candidate channel queue, which is used to record the determined channel performance.
[0089] The candidate channel queue is a pre-built queue used to record the channel performance currently determined during this traversal process. That is, each time a channel performance (i, DIST i ), then (i, DIST i ) is stored as a data pair in the candidate channel queue. After storage, the queue length of the candidate channel queue increases by 1.
[0090] Step 262: Determine whether the length of the candidate channel queue meets the first queue length. If the first queue length is not met, determine that the number of channel performances determined in the second convolutional layer has not reached the first target number, and return to step 220. If the first queue length is met, determine that the number of channel performances determined in the second convolutional layer has reached the first target number, and execute step 270.
[0091] For example, the first queue length can be set according to actual conditions. In one embodiment, the first queue length is equal to the current number of channels in the third convolutional layer. After the length of the candidate channel queue is updated, the queue length L of the candidate channel queue is added to the first queue length |CH c1 | for comparison, where |CH c1 | represents the number of channels in the third convolutional layer. If L = |CH c1|, it indicates that the length of the candidate channel queue has reached the first queue length, that is, it is determined that the number of determined channel performances has reached the first target number, and the subsequent steps can be performed, that is, step 270. Otherwise, it indicates that the length of the candidate channel queue has not reached the first queue length, that is, it is determined that the determined channel performances have not reached the first target number, and further channel performance calculation is required, so the process returns to step 220.
[0092] Step 270: Arrange the channel performances of the multiple channels in descending order of channel performance.
[0093] Because channel performance is related to similarity, channel performance can be ranked in ascending order of similarity. In one embodiment, when recording the performance of each channel in a candidate channel queue, the candidate channel queue is reordered so that the head of the candidate channel queue corresponds to the channel with the lowest channel performance. It is understood that the channels stored in the channel performance are the channels of the pruned network model. Therefore, when ranking channel performance, it can be considered to be ranking the channels of the pruned network model.
[0094] Step 280: Take out the second target number of channel performances from the head of the queue of the arranged channel performances, where the second target number is determined by pruning step.
[0095] In one embodiment, a set number of channel performances are extracted from the head of the queue of sorted channel performances, where the set number is recorded as the second target number. The second target number can be understood as the number of channels pruned at each time in a convolutional layer. When recording channel performances via a candidate channel queue, the second target number of channel performances can be directly extracted from the head of the candidate channel queue after sorting the candidate channel queue. It is understood that the channel performance at the head is the lowest.
[0096] The second target number can be determined by a pruning step, and the pruning step value can be set according to actual conditions. Optionally, the pruning step includes two modes: an arithmetic decreasing mode, in which the second target number obtained each time gradually decreases, and the difference between the second target number determined previously and the second target number determined currently is the pruning step value; and a geometric decreasing mode, in which the second target number obtained each time gradually decreases, and the ratio between the second target number determined previously and the second target number determined currently is the pruning step value. In one embodiment, the current second target number can be determined based on the pruning step mode, the corresponding value, and the previous second target number. In one embodiment, the number of pruning step channels is determined by a pruning step rate, which is a pre-set fixed value that directly responds to the pruning step mode and specific value. In one embodiment, when the pruning step rate of the pruning step is greater than or equal to the target threshold, the pruning step adopts an arithmetic decreasing mode; when the pruning step rate of the pruning step is less than the target threshold, the pruning step adopts a geometric decreasing mode. Exemplarily, the target threshold is a pre-set value, which is the critical value for whether to adopt a geometric decrease mode or an arithmetic decrease mode. In one embodiment, the target threshold can be 1. When the pruning step rate is greater than or equal to the target threshold, the arithmetic decrease mode is adopted, and the value of the pruning step is equal to the pruning step rate, that is, the difference between each determined second target number is equal to the pruning step rate. Generally speaking, when the pruning step rate is greater than or equal to 1, it is an integer value. When the pruning step rate is less than the target threshold, the geometric decrease mode is adopted. At this time, the value of the pruning step is calculated as follows: determine the number of input channels that have not been traversed in the fourth convolutional layer (that is, the number of channels that have not been traversed in the first feature map), and then use the difference between this number and 1 minus the pruning step rate for multiplication calculation. The value obtained after the multiplication calculation is the pruning step used in this pruning. It can be understood that as pruning proceeds, the number of untraversed input channels in the fourth convolutional layer will gradually decrease with each pruning. At this time, the value of the pruning step determined each time will also change.
[0097] The original network model and the pruned network model can be pruned multiple times. To avoid excessive pruning, in one embodiment, before step 280, the following step is further performed: determining whether the untraversed channels in the first feature graph meet a first pruning stop condition; if the first pruning stop condition is not met, performing an operation of extracting a second target number of channel performances from the head of the queue of the arranged channel performances, i.e., executing step 280. If the first pruning stop condition is met, pruning of the original network model is stopped.
[0098] Among them, the first pruning stop condition is a limiting condition to avoid excessive pruning. The first pruning stop condition can be set according to actual conditions. In one embodiment, the first pruning stop condition is that the queue length of the untraversed channels in the first feature map (i.e., the untraversed input channels in the fourth convolutional layer) is less than the second queue length. The second queue length is determined by the arrangement length of the convolution kernels in the third convolutional layer and the preset minimum pruning rate. Exemplarily, the minimum pruning rate is pre-set, and the specific value of the minimum pruning rate can be set according to actual conditions. In one embodiment, the product of the arrangement length of the convolution kernels in the third convolutional layer and the minimum pruning rate is used as the second queue length. The second queue length can be understood as the minimum queue length that triggers pruning. When traversing each channel of the first feature map, the channels that are not currently traversed can be formed into a queue, and the queue length of the queue is equal to the total number of channels that have not been traversed. Afterwards, the queue length is compared with the second length queue. If the queue length is less than the second queue length, it indicates that the total number of channels that have not been traversed is small, that is, a sufficient number of channels have been pruned. Therefore, it is determined that the first pruning stop condition is met and the pruning of the original network model is stopped. If the queue length is greater than or equal to the second queue length, it indicates that the total number of channels that have not been traversed is relatively large, that is, the number of channels that can still be pruned is relatively large. Therefore, the first pruning stop condition is not met, and the subsequent steps are continued to prune, that is, step 280 is executed. At this time, when using the first pruning stop condition for judgment, the specific implementation can refer to the following formula:
[0099]
[0100] Among them, |L stb | represents the queue length of the untraversed channels (i.e., the remaining channels) in the first feature graph, |D c1 | represents the kernel length of the third convolutional layer, compress_rate_min represents the preset minimum pruning rate, break indicates stopping pruning the original network model, and continue indicates executing step 290.
[0101] Step 290: The channel in the second convolutional layer corresponding to the extracted channel performance is used as the channel to be pruned.
[0102] In one embodiment, after extracting the channel performance, the channels recorded in each channel performance are determined. These channels can form a channel set, which can be recorded as a pruned channel set. Subsequently, in the second convolutional layer, the channels corresponding to the channels recorded in the pruned channel set are determined. For example, if the channels recorded in the pruned channel set are the third channel and the fifth channel, then the third and fifth channels in the second convolutional layer are both channels to be pruned.
[0103] Step 2100: Remove the convolution kernel parameters of the corresponding convolution kernel in the first convolution layer according to the channel to be pruned.
[0104] In one embodiment, based on the channel to be pruned, the convolution kernel corresponding to the first convolution layer and the convolution kernel parameters for each channel of the first convolution layer are obtained, and the convolution kernel parameters for each channel are removed. For example, if the jth channel in the second convolution layer is the channel to be pruned, the convolution kernel parameters for the jth convolution kernel in each channel of the first convolution layer are obtained in the first convolution layer, and the convolution kernel parameters are removed.
[0105] In one embodiment, when executing this step, it also includes: removing the corresponding convolution kernel in the third convolution layer according to the channel to be pruned. In order to facilitate the subsequent pruned network model to continue to guide the original network model for pruning, it is also necessary to remove the convolution kernel corresponding to the third convolution layer in the pruned network model, wherein the third convolution layer is obtained by copying the first convolution layer, and the convolution kernel obtained in the third convolution layer is the same as that obtained in the first convolution layer. For example, the j-th channel in the second convolution layer is the channel to be pruned, so the j-th convolution kernel is obtained in the third convolution layer. At this time, the number of convolution kernels in the third convolution layer, that is, the length of the convolution kernel arrangement, changes.
[0106] Step 2110: Remove the channels to be pruned in the second convolutional layer.
[0107] In one embodiment, after determining the channels to be pruned in the second convolutional layer, the channels to be pruned in the second convolutional layer are removed. Removing the channels to be pruned may include deleting connections of the channels to be pruned to reduce the number of connections in the second convolutional layer.
[0108] In one embodiment, when executing this step, the following step is further included: removing the channels to be pruned in the fourth convolutional layer. In order to facilitate the subsequent pruned network model to continue to guide the original network model for pruning, it is also necessary to remove the channels to be pruned in the fourth convolutional layer of the pruned network model, wherein the fourth convolutional layer is obtained by copying the second convolutional layer, and the channels to be pruned in the fourth convolutional layer have the same channel number as the channels to be pruned in the second convolutional layer. The implementation process of removing the channels to be pruned in the fourth convolutional layer is the same as that of removing the channels to be pruned in the second convolutional layer, and will not be repeated here.
[0109] Step 2120: Load the pruned original network model.
[0110] After pruning the first convolutional layer and the second convolutional layer, the pruned original network model is loaded, that is, the model structure and parameters of the pruned original network model are loaded. At this time, the pruned original network model can be considered as a new original network model.
[0111] Step 2130: Iteratively train the pruned original neural network model and obtain the average loss parameter after the iterative training.
[0112] Exemplarily, the pruned original neural network model is iteratively trained to fine-tune the parameters of the pruned original neural network model. In one embodiment, the training dataset used in iterative training is the same as the training dataset used when constructing the original network model. The source of the ECG signals in the training dataset is not currently specified. It is understood that during iterative training, one or more ECG signals from the training dataset are first selected and input into the pruned original network model. A loss parameter is then calculated based on the output of the original network model. The loss parameter can be obtained by using the loss function of the original network model. The specific type of the loss function of the original network model is not currently specified. It is understood that the relevant data can be substituted into the loss function based on the input and output of the original network model to calculate the loss parameter. The parameters of the pruned original network model are then updated based on the loss parameter. Then, one or more ECG signals from the training dataset are selected again, and the above process is repeated until the loss parameter stabilizes or the number of iterations reaches a preset number. An average loss parameter is then obtained based on the loss parameters obtained from the iterative training. The average loss parameter can be considered to be the average of the loss parameters obtained during each training iteration. The average loss parameter can reflect the average prediction (i.e., ECG feature extraction) error of the original network model after pruning. After each pruning, the corresponding average loss parameter can be obtained.
[0113] Step 2140: Add the average loss parameter to the average loss parameter queue.
[0114] In one embodiment, an average loss parameter queue is constructed to record the average loss parameters calculated during the pruning process. After each pruning, an average loss parameter is calculated and added to the average loss parameter queue. At this time, the length of the average loss parameter queue is increased by 1.
[0115] In step 2150, when the length of the average loss parameter queue is greater than the preset third queue length, determine whether the average loss parameter queue satisfies the second pruning stop condition. If the average loss parameter queue does not satisfy the second pruning stop condition, return to step 220. If the average loss parameter queue satisfies the second pruning stop condition, execute step 2160.
[0116] Exemplarily, the third queue length can be set according to actual conditions. In one embodiment, the third queue length can be set to 1. The number of pruning times for the original network model needs to reach the value of the third queue length. At this time, after adding the average loss parameter to the average loss parameter queue, it is determined whether the length of the average loss parameter queue is greater than the third queue length. If the length of the average loss parameter queue is less than or equal to the third queue length, it means that the number of pruning times for the original network model has not yet met the number requirement. Therefore, it is determined that the average loss parameter queue does not meet the third queue length, and the original network model needs to continue to be pruned, that is, return to execute step 220 until the length of the average loss parameter queue is greater than the third queue length, that is, the number of pruning times for the original network model meets the number requirement. At this time, the subsequent steps are performed, that is, whether the average loss parameter queue meets the second pruning stop condition.
[0117] After returning to step 220 , pruning the original network model means pruning the original network model obtained after the previous pruning again based on the previous pruning.
[0118] Exemplarily, the second pruning stop condition is a limiting condition for stopping pruning the original network model. The second pruning stop condition can be set according to actual conditions. In one embodiment, the second pruning stop condition is that the difference between the last average loss parameter in the average loss parameter queue and the smallest average loss parameter in the average loss parameter queue is greater than or equal to a preset loss variation tolerance. Exemplarily, the loss variation tolerance is a pre-set value, which serves to balance the pruning and original network model fitting effects. Its value can be set according to actual conditions. In one embodiment, the loss variation tolerance can be set to 0.01. When the length of the average loss parameter queue is greater than the preset third queue length, the last average loss parameter in the average loss parameter queue is obtained. Generally speaking, the last average loss parameter is the average loss parameter obtained in this iteration. Obtain the average loss parameter with the smallest value in the average loss parameter queue. Then, subtract the last average loss parameter from the smallest average loss parameter. If the obtained difference is less than the preset loss variation tolerance, it means that this pruning is effective and has the least impact on the performance of the original network model. There is room for further optimization. Therefore, continue pruning, that is, return to step 220. If the obtained difference is greater than or equal to the preset loss variation tolerance, it means that this pruning has a great impact on the original network model. If pruning is continued, the performance of the original network model will be affected. Therefore, pruning is suspended and step 2160 is executed. The specific implementation can refer to the following formula:
[0119]
[0120] Wherein, L[-1] represents the last average loss parameter in the average loss parameter queue, min(L) represents the minimum average loss parameter in the average loss parameter queue, loss_toler represents the preset loss variation tolerance, break represents pausing pruning, and then executing step 2160. continuesetp 1 represents returning to executing step 220.
[0121] Step 2160: Roll back to the previous pruning result of pruning the first convolutional layer and the second convolutional layer, and stop pruning the original network model.
[0122] Exemplarily, the pruning result of the previous pruning of the first convolutional layer and the second convolutional layer is rolled back, that is, the operation on the first convolutional layer and the second convolutional layer is undone, and the original network model is restored to the original network model obtained after the previous pruning. In addition, some data obtained in this pruning process can also be deleted. Afterwards, the original network model obtained after the previous pruning is used as the final original network model, and pruning of the original network model is stopped. After stopping pruning the original network model, the pruned original network model can be used to extract ECG features, and then heartbeat detection can be performed based on the ECG features.
[0123] The following is an exemplary description of the above neural network pruning method. In this example, the structures of the original network model and the pruned network model are both Figure 1As shown, the neural network pruning method is applied to all three feature extraction modules in each neural network model. The implementation of one feature extraction module is described as an example. The same ECG signal is input into the original network model and the pruned network model. Then, the channels of the first feature map from the third convolutional layer in the second feature extraction module to the fourth convolutional layer in the pruned network model are traversed. The number of channels in the first feature map is related to the length of the convolution kernels in the third convolutional layer. When traversing the channels of the first feature map, the first channel is selected. Based on the selected channel, the first channel corresponding to each convolution kernel in the fourth convolutional layer of the second feature extraction module (equivalent to the first input channel) is selected, and the weights and biases of each convolution kernel in the first channel are obtained. The weights and biases are then used to process the first channel of the first feature map to obtain the third feature map. The second feature map output by the second convolutional layer of the first feature extraction module in the original network model is then obtained. The first feature extraction module is copied to obtain the aforementioned second feature extraction module. It can be understood that the third feature map and the second feature map are of the same size. After that, the similarity between the third feature map and the second feature map is calculated using the L2 norm, and the first channel and the similarity are combined into a data pair and stored in the candidate channel queue. After that, it is determined whether the length of the candidate channel queue is equal to the length of the first queue. If it is not equal to the length of the first queue, the channels of the first feature map are traversed continuously, and the next channel is selected to continue calculating the corresponding similarity until the length of the candidate channel queue is equal to the length of the first queue. After that, the data pairs in the candidate channel queue are sorted in order of similarity from small to large. After that, it is determined whether the number of channels that have not been traversed in the first feature map is less than the product of the convolution kernel arrangement length and the minimum pruning rate in the third convolutional layer. If it is less than, it means that after continuing to prune, there will be over-pruning. Therefore, the pruning of the original neural network model is stopped. Otherwise, according to the preset pruning step, the data pairs with the second target number are taken out from the candidate channel queue, and the channels in the taken data pairs are formed into a pruned channel set. Afterwards, two branches are executed according to the pruned channel set. One branch prunes the convolution kernel parameters of the corresponding convolution kernels in the first convolution layer and the corresponding convolution kernels in the third convolution layer, and the other branch prunes the corresponding channels in the second and fourth convolution layers.Afterwards, the model structure and parameters of the pruned original network model are reloaded to obtain a new original network model (i.e., the pruned original network model). Afterwards, the new original network model is iteratively trained according to the training data set used to train the original network model to adjust the parameters of the new original network model and calculate the average loss parameter during the iterative training process. Afterwards, the average loss parameter is added to the average loss parameter queue. When the length of the average loss parameter queue is greater than the preset third queue length, it is determined whether the average loss parameter queue meets the second pruning stop condition. When the second pruning stop condition is not met, the channels of the first feature map continue to be traversed and the channel performance is calculated to continue pruning. When the second pruning stop condition is met, roll back to the previous pruning result and stop pruning the original network model.
[0124] It can be understood that after each iterative training is completed, the new original network model can also be verified. Figure 6 A schematic diagram of loss performance is provided for an embodiment of the present application. Figure 1 The performance of the loss parameters of the original network model when iterative training and validation are performed after each pruning of the original network model. Figure 6 In the figure, each dot on the curve represents a pruning operation on the original network model. After each pruning, the loss parameter during iterative training is recorded as training_loss, and the loss parameter during each validation is recorded as validate_loss. The loss parameter curves can be shown as Figure 6 Reference Figure 6 During iterative training, the four pruning operations with loss parameters significantly higher than 0.003 are all the first pruning operations of each first feature extraction module. When reasonable pruning stop conditions (first pruning stop condition and second pruning stop condition) are adopted, both training_loss and validate_loss decrease with the increase of the number of pruning operations. Figure 6 In the example, the first value of training_loss and validate_loss is the loss parameter obtained during the last iteration of training and validation before pruning the original network model. The last value of training_loss and validate_loss is the loss parameter obtained during the last iteration of training and validation after all pruning is completed. Figure 6 It can be seen that the loss parameter of the original network model obtained after pruning is smaller than the loss parameter of the original network model before pruning, and the performance of the original network model after pruning is improved, that is, the accuracy of the original network model after pruning is guaranteed, and the complexity of the model structure is reduced, and the overfitting phenomenon is reduced.
[0125] Figure 7 A schematic diagram of inference speed provided for one embodiment of the present application. Figure 7 , the original network model is deployed on a PC platform with the hardware parameters of CPU Inter Core i7-6850K 3.6GHz*6 and RAM 128G. After each pruning operation, the inference speed of the original network model on the PC platform is as follows Figure 7 As shown. Figure 7 The reason for the oscillation phenomenon is that the computer on the PC platform is affected by the current environment and the inference time measurement error occurs. Figure 7 As can be seen, the inference time (inference_time) of the original network model gradually decreases with each pruning iteration (i.e., the number of pruning branches increases). It is understandable that the performance of the original network model varies under different optimization parameters (pruning step rate and loss tolerance) on the PC platform. Table 1 shows the performance of the original network model under different optimization parameters on the PC platform.
[0126]
[0127] Table 1
[0128] The optimization parameters include pruning step and loss variation tolerance. Table 1 shows the performance of the original network model under different pruning step and loss variation tolerance, where the columns in the table are represented by serial number, remaining channel (channel), instrument (Device), pruning step rate (CP_step_rate), loss variation tolerance (loss_toler), inference time of the original network model (ORIGINAL time), inference time of the original network model after pruning (Compressed time), the index (Validate metric) obtained during the final verification (i.e., the last verification) (the index includes sensitivity se, precision pre and F1 value f1), test set sensitivity (Testing SE), test set precision (Testingpre), test set F1 value (Testing f1), where the test set refers to the data set used when testing the original network model. It can be understood that the pruning step rate (CP_step_rate) can directly affect the pruning step mode, where the pruning step can be determined by the following formula:
[0129]
[0130] Among them, CP_step_rate represents the pruning step rate, CP_step represents the pruning step, |L stb| represents the number of untraversed input channels in the fourth convolutional layer. The target threshold is 1. When CP_step_rate is less than 1, CP_step is in geometric decreasing mode. When CP_step_rate is greater than or equal to 1, CP_step is in arithmetic decreasing mode.
[0131] As shown in Table 1, the greater the loss tolerance, the better the pruning effect, that is, the greater the reduction in inference time and the higher the validation set metrics, but the lower the test set accuracy. In the arithmetic decreasing mode, the pruning step can reach the maximum pruning depth, resulting in a smaller number of channels. Therefore, different optimization parameters can be set based on actual needs.
[0132] It is understandable that the processing speed of the original neural network will change when it is deployed on different embedded platforms. Table 2 shows the inference time of the original network model before pruning and after pruning on different embedded platforms:
[0133] CPU ORIGNAL time(ms) Compressed time(ms) Kirin 980 87 69 MSM8909 871 394
[0134] Table 2
[0135] Refer to Table 2, which specifically shows the pre-pruning and post-pruning inference times for the original network model numbered 3 in Table 1, deployed on the Kirin 980 (Hisilicon Kirin 980 2.6GHz*2+1.92GHz*2+1.8GHz*4, 8GB RAM) and the MSM8909 (Qualcomm MSM8909 1.1GHz*4, 1GB RAM). As can be seen from Table 2, the inference time of the original network model after pruning is shortened to varying degrees across different embedded platforms, meaning the inference speed of the original network model is increased to varying degrees. In particular, on the lower-clocked embedded platform (i.e., the MSM8909), the inference speed is increased by over 50%.
[0136] In the above, the pruned network model is obtained by copying the original network model. Then, when the original network model and the pruned network model process the same ECG signal, the third convolution layer of the second feature extraction module in the pruned network model is traversed to input each channel of the first feature map of the fourth convolution layer, and the currently traversed channel is selected. Then, according to the currently selected channel, the convolution kernel parameters of the corresponding channel in the fourth convolution layer are selected. Then, the currently selected channel in the first feature map is processed according to the convolution kernel parameters to obtain the corresponding third feature map. Then, the second feature map output by the second convolution layer of the first feature extraction module in the original network model is selected, and the channel performance of the corresponding channel in the second convolution layer is determined according to the similarity between the second feature map and the third feature map, wherein The second feature extraction module corresponds to the first feature extraction module. After that, it is determined whether the number of determined channel performances reaches the first target number. If the first target number is not reached, the channels of the first feature map are traversed until the first target number is reached. After that, the channel performances are arranged in order from low to high, and the second target number of channel performances with low performance are selected according to the pruning step, and the channels to be pruned of the second convolutional layer are determined according to the selected channel performance. The technical means of pruning the first convolutional layer, the third convolutional layer, the second convolutional layer and the fourth convolutional layer according to the channels to be pruned solves the technical problem of increasing the structural complexity of the neural network model when improving the performance of the neural network model. By pruning the neural network model, the connections and neurons of the neural network model are simplified, the reasoning speed is improved, and the reasoning time is reduced. Moreover, when pruning, only the convolutional layer in the feature extraction module needs to be pruned, that is, the internal structure of the feature extraction module is optimized, which can maintain the basic structure of the neural network model and avoid serious structural changes in the neural network model after pruning. Furthermore, during pruning, a minimum pruning rate and loss tolerance are introduced as criteria for terminating pruning. The first pruning stopping condition is determined by the minimum pruning rate, and the second pruning stopping condition is determined by the loss tolerance. This balances the inference speed and accuracy of the pruned model, achieving better optimization results and avoiding the severe accuracy degradation caused by excessive pruning and the lack of significant inference speed improvement caused by insufficient pruning. Furthermore, during pruning, a minimum pruning rate, pruning step, and loss tolerance are introduced, and an adaptive pruning strategy is adopted, eliminating the need for manual intervention in the pruning process and automatically achieving the optimal optimization results.
[0137] Figure 8 A schematic diagram of the structure of a neural network pruning device provided in one embodiment of the present application. Figure 8 The neural network pruning device includes: a signal input module 301, a feature output module 302, a performance determination module 303, a channel selection module 304 and a channel pruning module 305.
[0138] Among them, the signal input module 301 is used to input the same ECG signal to the original network model and the pruned network model, the original network model is used to extract the ECG features of the ECG signal, the pruned network model is obtained by copying the original network model, the original network model includes at least one first feature extraction module, the first feature extraction module includes a first convolution layer and a second convolution layer, the pruned network model includes at least one second feature extraction module, the second feature extraction module includes a third convolution layer and a fourth convolution layer, and the first feature extraction module and the second feature extraction module correspond one to one; the feature output module 302 is used to use the convolution kernel parameters in a channel in the fourth convolution layer to process the corresponding channel in the first feature map to obtain the fourth convolution layer. The third feature map output by the convolution layer, the first feature map is output by the third convolution layer of the same second feature extraction module to the fourth convolution layer; the performance determination module 303 is used to determine the channel performance of the corresponding channel in the second convolution layer using the third feature map and the second feature map output by the second convolution layer, the fourth convolution layer is obtained by copying the second convolution layer, and the third convolution layer and the fourth convolution layer are located in the same second feature extraction module; the channel selection module 304 is used to determine the channel to be pruned in the second convolution layer according to the channel performance of multiple channels in the second convolution layer; the channel pruning module 305 is used to prune the first convolution layer and the second convolution layer according to the channel to be pruned, and the second convolution layer and the first convolution layer are located in the same first feature extraction module.
[0139] In one embodiment, the performance determination module 303 includes: an input channel selection unit for traversing each channel of the first feature map and selecting a currently traversed channel, wherein the number of channels of the first feature map is determined by the length of the convolution kernel arrangement of the third convolutional layer, the i-th channel in the first feature map is the currently traversed channel, and the first feature map is output to the fourth convolutional layer by the third convolutional layer of the same second feature extraction module; a first acquisition unit for acquiring the convolution kernel parameters used for the i-th channel in the fourth convolutional layer; and an image processing unit for processing the i-th channel of the first feature map according to the convolution kernel parameters to obtain a third feature map output by the fourth convolutional layer. Accordingly, the apparatus further includes: a quantity determination module for determining the channel performance of the corresponding channel in the second convolutional layer using the third feature map and the second feature map output by the second convolutional layer, and then determining whether the number of channel performances determined in the second convolutional layer reaches a first target number; and a first return module for continuing to traverse the remaining channels in the first feature map if the first target number has not been reached until the number of channel performances determined reaches the first target number.
[0140] In one embodiment, the convolution kernel parameters include the weight and bias of the convolution kernel, and the image processing unit is specifically used to: perform a convolution operation on the i-th channel of the first feature map according to the weight and the convolution kernel of the fourth convolution layer, and add the bias after the convolution operation to obtain a third feature map output by the fourth convolution layer.
[0141] In one embodiment, the quantity determination module includes: a performance recording unit, used to store the currently determined channel performance into a candidate channel queue, and the candidate channel queue is used to record the determined channel performance; a length determination unit, used to determine whether the length of the candidate channel queue meets the first queue length; a first quantity determination unit, used to determine that the number of determined channel performances in the second convolutional layer does not reach the first target number if the first queue length is not met; and a second quantity determination unit, used to determine that the number of determined channel performances in the second convolutional layer reaches the first target number if the first queue length is met.
[0142] In one embodiment, the performance determination module 303 is specifically used to: calculate the similarity between the second feature map and the third feature map, the similarity and the i-th channel constitute a data pair, the data pair represents the channel performance of the i-th channel in the second convolutional layer, the second feature map output by the second convolutional layer, and the fourth convolutional layer is obtained by copying the second convolutional layer.
[0143] In one embodiment, the channel selection module 304 includes: a performance sorting unit, configured to arrange the channel performance of multiple channels in ascending order; a performance extraction unit, configured to extract a second target number of channel performances from the head of the queue of the arranged channel performances, where the second target number is determined by pruning steps; and a to-be-pruned channel determination unit, configured to select channels in the second convolutional layer corresponding to the extracted channel performances as to-be-pruned channels.
[0144] In one embodiment, when the pruning step rate of the pruning step is greater than or equal to the target threshold, the pruning step adopts an arithmetic decreasing mode; when the pruning step rate of the pruning step is less than the target threshold, the pruning step adopts a geometric decreasing mode.
[0145] In one embodiment, the method further includes: a first stop judgment module, which is used to judge whether the untraversed channels in the first feature graph meet the first pruning stop condition before taking out the second target number of channel performances from the head of the queue of the arranged channel performances; and a continue execution module, which is used to execute the operation of taking out the second target number of channel performances from the head of the queue of the arranged channel performances if the first pruning stop condition is not met.
[0146] In one embodiment, the first pruning stopping condition is that the queue length of the untraversed channels in the first feature map is less than the second queue length, and the second queue length is determined by the convolution kernel arrangement length in the third convolutional layer and a preset minimum pruning rate.
[0147] In one embodiment, the channel pruning module 305 includes: a first removal unit, configured to remove convolution kernel parameters of corresponding convolution kernels in the first convolution layer according to the channels to be pruned; and a second removal unit, configured to remove the channels to be pruned in the second convolution layer.
[0148] In one embodiment, the channel pruning module 305 further includes: a third removal unit, configured to remove the corresponding convolution kernel in the third convolutional layer according to the channel to be pruned; and a fourth removal unit, configured to remove the channel to be pruned in the fourth convolutional layer.
[0149] In one embodiment, it also includes: a model loading module, which is used to load the pruned original network model after pruning the first convolutional layer and the second convolutional layer according to the channel to be pruned; an iterative training module, which is used to iteratively train the pruned original neural network model and obtain the average loss parameter after the iterative training; a parameter adding module, which is used to add the average loss parameter to the average loss parameter queue; a stop judgment module, which is used to judge whether the average loss parameter queue meets the second pruning stop condition when the length of the average loss parameter queue is greater than the preset third queue length; a second return module, which is used to continue calculating the channel performance and continue to prune the original network model until the second pruning stop condition is met when the average loss parameter queue does not meet the second pruning stop condition; a rollback module, which is used to roll back to the previous pruning result of pruning the first convolutional layer and the second convolutional layer when the average loss parameter queue meets the second pruning stop condition, and stop pruning the original network model.
[0150] In one embodiment, the second pruning stop condition is that the difference between the last average loss parameter in the average loss parameter queue and the smallest average loss parameter in the average loss parameter queue is greater than or equal to a preset loss variation tolerance.
[0151] The neural network pruning device provided above can be used to execute the neural network pruning method provided in any of the above embodiments, and has corresponding functions and beneficial effects.
[0152] It is worth noting that in the embodiment of the above-mentioned neural network pruning device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application.
[0153] Figure 9 This is a schematic diagram of the structure of a neural network pruning device provided in one embodiment of the present application. Figure 9As shown, the neural network pruning device includes a processor 40, a memory 41, an input device 42, and an output device 43; the number of processors 40 in the neural network pruning device can be one or more. Figure 9 In the figure, a processor 40 is taken as an example. The processor 40, memory 41, input device 42, and output device 43 in the neural network pruning device can be connected via a bus or other means. Figure 9 The bus connection is taken as an example.
[0154] Memory 41, as a computer-readable storage medium, can be used to store software programs, computer-executable programs, and modules, such as program instructions / modules corresponding to the neural network pruning method in one embodiment of the present application (e.g., the signal input module, feature output module, performance determination module, channel selection module, and channel pruning module in the neural network pruning device). Processor 40 executes the software programs, instructions, and modules stored in memory 41 to execute various functional applications and data processing of the neural network pruning device, thereby implementing the aforementioned neural network pruning method.
[0155] The memory 41 may primarily include a program storage area and a data storage area. The program storage area may store an operating system and at least one application required for a function; the data storage area may store data created based on the use of the neural network pruning device, etc. Furthermore, the memory 41 may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some instances, the memory 41 may further include a memory remotely located relative to the processor 40, and these remote memories may be connected to the neural network pruning device via a network. Examples of the aforementioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0156] The input device 42 can be used to receive input digital or character information and generate key signal input related to user settings and function control of the neural network pruning device. It can also include devices required for each lead when collecting ECG signals. The output device 43 can include a display device such as a display screen.
[0157] The above-mentioned neural network pruning equipment includes a neural network pruning device, which can be used to execute any neural network pruning method and has corresponding functions and beneficial effects.
[0158] In addition, an embodiment of the present application also provides a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform relevant operations in the neural network pruning method provided in any embodiment of the present application, and have corresponding functions and beneficial effects.
[0159] Those skilled in the art should understand that the embodiments of the present application may be provided as methods, systems, or computer program products.
[0160] Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing device to work in a specific way, so that the instructions stored in the computer-readable memory produce a product including the instruction device, which implements the function specified in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0161] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory. Memory may include non-permanent storage in a computer-readable medium, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0162] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0163] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0164] Note that the above are only preferred embodiments of the present application and the technical principles employed. Those skilled in the art will understand that the present application is not limited to the specific embodiments described herein, and that various obvious changes, readjustments, and substitutions can be made by those skilled in the art without departing from the scope of protection of the present application. Therefore, although the present application has been described in more detail through the above embodiments, the present application is not limited to the above embodiments and may include many other equivalent embodiments without departing from the scope of the present application. The scope of the present application is determined by the scope of the appended claims.
Claims
1. A neural network pruning method, characterized in that: include: Inputting the same ECG signal into an original network model and a pruned network model, the original network model is used to extract ECG features of the ECG signal, and the pruned network model is obtained by copying the original network model, the original network model includes at least one first feature extraction module, the first feature extraction module includes a first convolutional layer and a second convolutional layer, the pruned network model includes at least one second feature extraction module, the second feature extraction module includes a third convolutional layer and a fourth convolutional layer, and the first feature extraction module and the second feature extraction module correspond one to one; Processing a corresponding channel in the first feature map using a convolution kernel parameter within a channel in the fourth convolutional layer to obtain a third feature map output by the fourth convolutional layer, where the first feature map is output to the fourth convolutional layer by the third convolutional layer of the same second feature extraction module; Determining channel performance of a corresponding channel in the second convolutional layer using the third feature map and the second feature map output by the second convolutional layer, wherein the fourth convolutional layer is obtained by copying the second convolutional layer; Determining a channel to be pruned in the second convolutional layer according to channel performance of multiple channels in the second convolutional layer; The first convolutional layer and the second convolutional layer are pruned according to the to-be-pruned channel, where the second convolutional layer and the first convolutional layer are located in the same first feature extraction module.
2. The neural network pruning method according to claim 1, characterized in that: The using the convolution kernel parameters in a channel of the fourth convolutional layer to process the corresponding channel in the first feature map to obtain the third feature map output by the fourth convolutional layer includes: Traversing each channel of the first feature map and selecting a channel currently traversed, where the number of channels of the first feature map is determined by the convolution kernel arrangement length of the third convolutional layer, and the i-th channel in the first feature map is the currently traversed channel; Obtain the convolution kernel parameters used by the i-th channel in the fourth convolutional layer; Processing the i-th channel of the first feature map according to the convolution kernel parameters to obtain a third feature map output by the fourth convolution layer; After determining the channel performance of the corresponding channel in the second convolutional layer by using the third feature map and the second feature map output by the second convolutional layer, the method further includes: Determining whether the number of channel performances determined in the second convolutional layer reaches a first target number; If the first target number is not reached, the remaining channels in the first feature map are traversed until the number of determined channel performances reaches the first target number.
3. The neural network pruning method according to claim 2, characterized in that: The convolution kernel parameters include the weight and bias of the convolution kernel. The processing of the i-th channel of the first feature map according to the convolution kernel parameters to obtain a third feature map output by the fourth convolution layer includes: Performing a convolution operation on the i-th channel of the first feature map according to the weight and the convolution kernel of the fourth convolution layer, and adding the bias after the convolution operation to obtain a third feature map output by the fourth convolution layer.
4. The neural network pruning method according to claim 2, wherein: The determining whether the number of channel performances determined in the second convolutional layer reaches a first target number includes: Storing the currently determined channel performance in a candidate channel queue, wherein the candidate channel queue is used to record the determined channel performance; Determining whether the length of the candidate channel queue meets a first queue length; If the first queue length is not satisfied, determining that the number of channel performances determined in the second convolutional layer does not reach a first target number; If the first queue length is satisfied, it is determined that the number of determined channel performances in the second convolutional layer reaches the first target number.
5. The neural network pruning method according to claim 2, characterized in that: Determining the channel performance of the corresponding channel in the second convolutional layer by using the third feature map and the second feature map output by the second convolutional layer includes: The similarity between the second feature map and the third feature map is calculated, where the similarity and the i-th channel form a data pair, and the data pair represents the channel performance of the i-th channel in the second convolutional layer.
6. The neural network pruning method according to claim 1, characterized in that: The determining, according to the channel performances of the plurality of channels in the second convolutional layer, the channels to be pruned in the second convolutional layer comprises: Arrange the channel performance of multiple channels in order from low to high; Taking out a second target number of channel performances from the head of the queue of the arranged channel performances, where the second target number is determined by pruning step; The channel in the second convolutional layer corresponding to the extracted channel performance is used as the channel to be pruned.
7. The neural network pruning method according to claim 6, characterized in that: When the pruning step rate of the pruning step is greater than or equal to the target threshold, the pruning step adopts an arithmetic decreasing mode; when the pruning step rate of the pruning step is less than the target threshold, the pruning step adopts a geometric decreasing mode.
8. The neural network pruning method according to claim 6, characterized in that: Before taking out the second target number of channel performances from the queue head of the arranged channel performances, the method further includes: Determining whether an untraversed channel in the first feature graph satisfies a first pruning stop condition; If the first pruning stop condition is not satisfied, an operation of taking out a second target number of channel performances from the heads of the queues of the arranged channel performances is performed.
9. The neural network pruning method according to claim 8, characterized in that: The first pruning stopping condition is that the queue length of the untraversed channels in the first feature map is less than the second queue length, and the second queue length is determined by the convolution kernel arrangement length in the third convolutional layer and the preset minimum pruning rate.
10. The neural network pruning method according to claim 1, characterized in that: The pruning of the first convolutional layer and the second convolutional layer according to the to-be-pruned channel includes: According to the to-be-pruned channel, remove the convolution kernel parameters of the corresponding convolution kernel in the first convolution layer; Remove the to-be-pruned channel in the second convolutional layer.
11. The neural network pruning method according to claim 1 or 10, characterized in that: When pruning the first convolutional layer and the second convolutional layer according to the to-be-pruned channel, the method further includes: According to the channel to be pruned, remove the corresponding convolution kernel in the third convolutional layer; Remove the to-be-pruned channel in the fourth convolutional layer.
12. The neural network pruning method according to claim 1, wherein: After pruning the first convolutional layer and the second convolutional layer according to the to-be-pruned channel, the method further includes: Load the pruned original network model; Iteratively train the pruned original neural network model and obtain the average loss parameter after iterative training; Adding the average loss parameter to an average loss parameter queue; When the length of the average loss parameter queue is greater than a preset third queue length, determining whether the average loss parameter queue meets a second pruning stop condition; When the average loss parameter queue does not meet the second pruning stop condition, continue to calculate the channel performance and continue to prune the original network model until the second pruning stop condition is met; When the average loss parameter queue meets the second pruning stop condition, roll back to the pruning result of the previous pruning of the first convolutional layer and the second convolutional layer, and stop pruning the original network model.
13. The neural network pruning method according to claim 12, characterized in that: The second pruning stop condition is that the difference between the last average loss parameter in the average loss parameter queue and the smallest average loss parameter in the average loss parameter queue is greater than or equal to a preset loss variation tolerance.
14. A neural network pruning device, characterized in that: include: A signal input module, configured to input the same ECG signal into an original network model and a pruned network model, wherein the original network model is configured to extract ECG features of the ECG signal, and the pruned network model is obtained by copying the original network model, wherein the original network model includes at least one first feature extraction module, the first feature extraction module includes a first convolutional layer and a second convolutional layer, and the pruned network model includes at least one second feature extraction module, the second feature extraction module includes a third convolutional layer and a fourth convolutional layer, and the first feature extraction module and the second feature extraction module have a one-to-one correspondence; a feature output module, configured to process a corresponding channel in the first feature map using a convolution kernel parameter within a channel in the fourth convolutional layer to obtain a third feature map output by the fourth convolutional layer, where the first feature map is output to the fourth convolutional layer by the third convolutional layer of the same second feature extraction module; a performance determination module, configured to determine the channel performance of the corresponding channel in the second convolutional layer using the third feature map and the second feature map output by the second convolutional layer, wherein the fourth convolutional layer is obtained by copying the second convolutional layer; a channel selection module, configured to determine a channel to be pruned in the second convolutional layer according to channel performance of multiple channels in the second convolutional layer; A channel pruning module is used to prune the first convolutional layer and the second convolutional layer according to the to-be-pruned channel, where the second convolutional layer and the first convolutional layer are located in the same first feature extraction module.
15. A neural network pruning device, characterized in that: include: one or more processors; a memory for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the neural network pruning method as described in any one of claims 1 to 13.
16. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the neural network pruning method as described in any one of claims 1 to 13 is implemented.
Citation Information
Patent Citations
Electrocardiosignal feature extraction method and device, computer device and storage medium
CN110309758A
Convolutional neural network channel pruning method based on characteristic variance ratio
CN111144551A