A compression method and device of an image recognition network
By constructing a target mask matrix and a reconstruction coefficient matrix in the image recognition network, the pruning channels are accurately filtered and compensated, solving the problems of information loss and accuracy degradation in traditional pruning methods, and achieving efficient network compression and accuracy improvement.
Patent Information
- Application Number
- CN202511544925.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-28
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2045-10-28
AI Technical Summary
Existing pruning techniques in image recognition networks cannot accurately select the channels involved in reconstruction, leading to information loss and decreased model accuracy. Traditional compensation methods cannot effectively make up for the losses caused by pruning.
By constructing a target mask matrix based on similarity calculations using channel weights, and combining this with the least squares method to determine the reconstruction coefficient matrix, closely related channels can be accurately located. Furthermore, by approximating the weight features of the pruned channels through linear combination, the weight parameters of the next adjacent convolutional layer can be adjusted to compensate for the pruning loss.
While reducing the number of channels, the original network feature representation ability is preserved to the greatest extent, significantly reducing the impact of pruning on network performance and improving the accuracy of the compressed model.
Smart Images

Figure CN121009941B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a compression method and device for image recognition networks. Background Technology
[0002] With the development of artificial intelligence technology, deep neural networks have been widely used in image recognition. However, the redundancy of parameters in deep neural networks is a major reason for their low computational efficiency. Model pruning is a commonly used method for lightweighting networks, which can effectively reduce the number of parameters and computational load.
[0003] Traditional pruning methods rely on predefined importance scoring criteria to select channels that need pruning. However, simply removing these channels results in information loss, leading to a decrease in model accuracy. To compensate for this loss, a common approach is to assume that the information loss of pruned channels can be approximated by a linear combination of retained channels, i.e., assuming a linear correlation between pruned channels and all retained channels. However, in real-world scenarios, not every pruned channel has a strong linear correlation with all retained channels. Including all retained channels in the reconstruction may introduce noise or ineffective compensation, or even amplify errors, limiting the improvement of the pruning rate and the final recovery of accuracy.
[0004] In summary, how to accurately select the channels to participate in the reconstruction and then construct the reconstruction coefficient matrix to compensate for the accuracy loss caused by pruning is a problem that needs to be solved. Summary of the Invention
[0005] This application provides a compression method and device for image recognition networks, which can accurately select the channels participating in reconstruction and then construct a reconstruction coefficient matrix to compensate for the accuracy loss caused by pruning.
[0006] This application provides a compression method for image recognition networks, including:
[0007] The output channels of the target convolutional layer in the image recognition network are pruned based on preset filtering rules to obtain a set of retained channels and a set of pruned channels.
[0008] The similarity between each retained channel in the retained channel set and the other output channels is calculated based on the channel weight, and a target mask matrix is constructed based on the similarity calculation results; the target mask matrix is used to mark the information of the retained channels in the retained channel set that participate in the reconstruction of each pruned channel;
[0009] For any pruned channel, the goal is to approximate the weight of any pruned channel with a linear combination of the weights of each retained channel in the retained channel information. The reconstruction coefficient matrix is determined based on the target mask matrix and the least squares method.
[0010] The weight parameters of the next adjacent convolutional layer of the target convolutional layer are adjusted using the target mask matrix and the reconstruction coefficient matrix to compensate for the pruning loss of the target convolutional layer.
[0011] This application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for executing the computer program to implement the compression method of any of the above-described image recognition networks.
[0012] This application also provides a computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of any of the above-described image recognition network compression methods.
[0013] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of any of the above-described image recognition network compression methods.
[0014] Beneficial Effects: This application considers that in real-world scenarios, a linear correlation between pruned channels and each retained channel cannot be guaranteed. Therefore, after pruning the output channels of the target convolutional layer to obtain a set of retained channels and a set of pruned channels, it is necessary to calculate the similarity between each retained channel and the remaining output channels based on the channel weights. This allows for the construction of a target mask matrix based on channel similarity, accurately locating retained channels closely associated with the pruned channels. Furthermore, this application uses the least squares method to obtain the reconstruction coefficient matrix, enabling the retained channels to accurately approximate the weight features of the pruned channels through linear combination, rather than simply removing the pruned channels. This solves the technical problem of key feature loss caused by ignoring channel correlation in traditional pruning, achieving the technical effect of maximizing the preservation of the original network feature expression capabilities while significantly reducing the number of channels. Finally, by combining the reconstruction coefficient matrix to quantify the contribution of each retained channel, the weight parameters of the next adjacent convolutional layer are adjusted in a targeted manner, so that the compensation operation accurately matches the feature distribution of the pruned channel. This solves the technical problem that traditional compensation methods are not targeted enough and cannot effectively compensate for pruning loss. It achieves the technical effect of significantly reducing the impact of pruning on network performance and reducing the decrease in accuracy, and further improves the accuracy of the compressed model. Attached Figure Description
[0015] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1A flowchart illustrating a compression method for an image recognition network provided in this application embodiment;
[0017] Figure 2 A schematic diagram illustrating a layer-by-layer reconstruction of the pruned output channel and scaling of the input channel of the next convolutional layer, provided as an embodiment of this application;
[0018] Figure 3 A flowchart illustrating a specific image recognition network compression method provided in this application embodiment;
[0019] Figure 4 A network structure diagram of a downsampling branch structure provided in an embodiment of this application;
[0020] Figure 5 A network structure diagram of an identity branch structure provided in an embodiment of this application;
[0021] Figure 6 A flowchart illustrating a quantization method for an image recognition model provided in this application embodiment;
[0022] Figure 7 A compression flowchart of joint quantization and pruning is provided for embodiments of this application;
[0023] Figure 8 A flowchart illustrating layer-by-layer pseudo-quantization and solving for scaling factors is provided in this application embodiment;
[0024] Figure 9 This is a schematic diagram of the compression device structure of an image recognition network provided in an embodiment of this application. Detailed Implementation
[0025] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.
[0026] It should be noted that, in the description of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or sequence.
[0027] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0028] See Figure 1 As shown in the figure, this application embodiment provides a compression method for image recognition networks, the method comprising:
[0029] Step S11: Prune the output channels of the target convolutional layer in the image recognition network based on preset filtering rules to obtain a set of retained channels and a set of pruned channels.
[0030] In this embodiment, it should first be noted that the image recognition network can specifically be a face recognition network, a vehicle recognition network, a medical image recognition network, etc., and this application embodiment does not limit the specific network structure of the image recognition network. For example, it can be a single-branch sequence network structure such as AlexNet and VGGNet, or a multi-branch network structure such as ResNet (residual network) and MobileNet. In addition, this application embodiment does not limit the convolution type of the convolution layer. For example, it can be standard convolution, depthwise separable convolution, grouped convolution, and dilated convolution, etc.
[0031] When compressing an image recognition network, the output channels of the convolutional layer can be pruned. Therefore, for the target convolutional layer in the image recognition network, this application can first prune the output channels of the target convolutional layer based on a preset filtering rule, thereby obtaining the set of retained channels and the set of pruned channels.
[0032] In a specific implementation, the above-mentioned pruning of the output channels of the target convolutional layer in the image recognition network based on preset filtering rules to obtain a set of retained channels and a set of pruned channels includes: obtaining the original weights of each output channel of the target convolutional layer in the image recognition network; and pruning each output channel of the target convolutional layer based on the original weights of each output channel and the L1 norm filtering rules to obtain a set of retained channels and a set of pruned channels. That is, in this embodiment, after obtaining the original weights of each output channel of the target convolutional layer, the L1 norm filtering rules are specifically used to prune each output channel to obtain a set of retained channels. and the set of pruned channels .
[0033] The process involves pruning the output channels of the target convolutional layer based on the original weights and L1 norm selection rules of each output channel to obtain a set of retained channels and a set of pruned channels. This includes: calculating the L1 norm of the original weights of each output channel; selecting a first target number of output channels in ascending order of L1 norm to construct the set of pruned channels; and constructing a set of retained channels based on the remaining output channels. The first target number is calculated based on a preset channel pruning rate. Specifically, this application first calculates the L1 norm of the original weights of each output channel, then sorts them in ascending order of L1 norm. The application calculates a first target number based on a preset channel pruning rate, then constructs the set of pruned channels from the first target number of output channels, while the remaining output channels form the set of retained channels. Specifically, the preset channel pruning rate is expressed as... If the total number of output channels of the target convolutional layer is N, then the previous... Each channel is stored in the set of pruned channels. Store the remaining channels into the reserved channel set. For example, suppose If the L1 norm of the original weights is 0.5 and N=64, then after sorting the original weights in ascending order, select the first 32 output channels and store them in the set of pruned channels. Store the remaining 32 output channels into the reserved channel set. .
[0034] Step S12: Calculate the similarity between each retained channel in the retained channel set and the other output channels based on the channel weights, and construct a target mask matrix based on the similarity calculation results; the target mask matrix is used to mark the information of the retained channels in the retained channel set that participate in the reconstruction of each pruned channel.
[0035] In this embodiment, after obtaining the set of retained channels and the set of pruned channels, it is necessary to calculate the similarity between each retained channel in the retained channel set and the other output channels based on the channel weights. This allows for the construction of a target mask matrix based on the inter-channel similarity, accurately locating the retained channels closely associated with the pruned channels. The purpose of calculating the target mask matrix is to mark the information of the retained channels in the retained channel set that participate in the reconstruction of each pruned channel.
[0036] In a specific implementation, the similarity between each retained channel in the retained channel set and the remaining output channels is calculated based on channel weights, and a target mask matrix is constructed based on the similarity calculation results. This includes: calculating the similarity between each retained channel in the retained channel set and the remaining retained channels and each pruned channel in the pruned channel set based on cosine similarity and channel weights; selecting a second target number of output channels in descending order of similarity calculation results to construct a target channel set; and constructing a target mask matrix based on the target channel set and the initial mask matrix; wherein, the second target number is calculated based on a preset channel pruning rate. That is, this application needs to calculate the similarity between each retained channel i ( ) respectively with all other output channels u ( , The cosine similarity between channels is calculated, and all other output channels include the remaining retained channels and each pruned channel in the set of pruned channels. It should be noted that when the target convolutional layer is any convolutional layer in a single-branch sequence network structure or a convolutional layer other than the last convolutional layer in a multi-branch network structure, the cosine similarity between channels is specifically calculated based on the channel weights. Furthermore, the similarity calculation results are sorted in descending order, and this application calculates a second target number based on a preset channel pruning rate. Then, the output channels corresponding to the first second target number of similarity calculation results are selected to construct a target channel set. Finally, a target mask matrix is constructed based on the target channel set and the initial mask matrix. Specifically, assuming the preset channel pruning rate is expressed as... If the total number of output channels of the target convolutional layer is N, then the previous... Each output channel constructs a target channel set.
[0037] The construction of the target mask matrix based on the target channel set and the initial mask matrix specifically includes: obtaining the initial mask matrix, wherein all elements in the initial mask matrix are zero values; performing an intersection operation on the target channel set and the pruned channel set to determine the target pruned channels, and updating the values of the target elements in the initial mask matrix using the target pruned channels to obtain the target mask matrix. That is, in this application, all elements in the initial mask matrix are zero values, and the target channel set and the pruned channel set are intersected to determine the target pruned channels. Which channels have been pruned? The channels that coexist in the two sets are used as target pruned channels, and the values of target elements in the initial mask matrix are updated using the target pruned channels to obtain the target mask matrix.
[0038] It should be noted that the number of rows in the initial mask matrix is the same as the number of channels in the set of retained channels, and the number of columns in the initial mask matrix is the same as the number of channels in the set of pruned channels. Correspondingly, the values of the target elements in the initial mask matrix are updated using the target pruned channels to obtain the target mask matrix. This includes: determining the row index based on the channel number of each retained channel in the set of retained channels, and determining the column index based on the channel number of the target pruned channel in the set of pruned channels; locating the target element in the initial mask matrix based on the row and column indices, and updating the value of the target element to the target value to obtain the target mask matrix. That is, the dimension of the target mask matrix M is... Specifically, this application determines the row index i based on the channel number of each retained channel in the retained channel set, and determines the column index j based on the channel number of the target pruned channel in the pruned channel set. Based on row index i and column index j, the position of the target element is located in the initial mask matrix, thereby updating the value of the target element to the target value 1, ultimately obtaining the target mask matrix. That is, each row of the target mask matrix is a binary vector indicating whether a certain retained channel participates in the reconstruction of the pruned channel.
[0039] As can be seen, this application calculates the cosine similarity between the i-th retained channel and the remaining retained channels as well as the pruned channels, sorts them in descending order based on the similarity values, and then determines the j-th ( The pruned channel and the i-th ( Whether the similarity values between channels are ranked first If the value is within the range, the i-th row and j-th column of the mask matrix is set to 1; otherwise, it remains 0.
[0040] For example, suppose =0.5, N=64, and assume that the last 32 channels with the lowest numbers are deleted, i.e., the set of channels to be pruned. The set of reserved channels is numbered 33-64. The channels are numbered 1-32, assuming they are reserved. Sort it in descending order of similarity with all channels. If the first 32 highly similar channels contain the pruned channel... If the first 32 highly similar channels of channel 1 contain pruned channels 33 and 35, then M(1,1)=1 (corresponding to channel 33) and M(1,3)=1 (corresponding to channel 35), and the remaining columns are all 0. Finally, a binary mask matrix M is generated to mark the channels that participated in the reconstruction.
[0041] Step S13: For any pruned channel, with the goal of approximating the weight of any pruned channel by a linear combination of the weights of each retained channel in the retained channel information, the reconstruction coefficient matrix is determined based on the target mask matrix and the least squares method.
[0042] In this embodiment, the reconstruction coefficient matrix is obtained based on the target mask matrix and the least squares method. This allows the retained channels to accurately approximate the weight features of the pruned channels through linear combination, rather than simply removing the pruned channels. This solves the technical problem of losing key features due to ignoring channel correlation in traditional pruning, and achieves the technical effect of maximizing the preservation of the original network feature expression ability while significantly reducing the number of channels.
[0043] In a specific implementation, the above-mentioned method of approximating the weight of any pruned channel by a linear combination of the weights of each retained channel in the retained channel information, and determining the reconstruction coefficient matrix based on the target mask matrix and the least squares method, includes: constructing a reconstruction error optimization function corresponding to any pruned channel; wherein, the objective of the reconstruction error optimization function is to minimize the difference between the linear combination of the weights of each retained channel in the retained channel information and the weight of any pruned channel, and the unknown quantity in the reconstruction error optimization function is the reconstruction coefficient vector; solving the reconstruction error optimization function based on the target mask matrix and the least squares method to obtain the reconstruction coefficient vector; and arranging the reconstruction coefficient vectors corresponding to each pruned channel in the set of pruned channels in channel order to obtain the reconstruction coefficient matrix.
[0044] Specifically, when the target convolutional layer is a convolutional layer other than the last convolutional layer in a multi-branch network structure, the embodiments of this application first construct a reconstruction error optimization function corresponding to any pruned channel:
[0045] ;
[0046] in, To preserve the channel set, It is the weight of the i-th reserved channel. The weights of the j-th pruned channel are used to reconstruct the coefficient vector. The dimension is , , It is an L1 norm. Let be the i-th mask value of the j-th mask vector in the target mask matrix M. The objective of this reconstruction error optimization function is to minimize the difference between the linear combination of the weights of the retained channels in the retained channel information and the weights of any pruned channel.
[0047] In other words, this application obtains the reconstruction coefficient vector by solving the reconstruction error optimization function based on the target mask matrix and the least squares method. Then, the reconstruction coefficient vectors corresponding to each pruned channel in the pruned channel set are arranged in channel order to obtain the reconstruction coefficient matrix. It should be noted that the reconstruction coefficient matrix S has a dimension of 1. The reconstructed coefficient matrix is composed of The reconstruction coefficient vector consists of several elements. Furthermore, through the reconstruction error optimization function, it can be obtained that each element in the reconstruction coefficient vector represents the reconstruction contribution of each retained channel to any pruned channel. Specifically, this application calculates a linear combination based on the weights of each retained channel, the target mask matrix, and the reconstruction coefficient vector in the retained channel information.
[0048] Furthermore, through the reconstruction error optimization function, it can be obtained that each element in the reconstruction coefficient vector is used to characterize the reconstruction contribution of each retained channel to any pruned channel. In this application, a linear combination is specifically calculated based on the weights of each retained channel, the target mask matrix, and the reconstruction coefficient vector in the retained channel information.
[0049] As can be seen, this application fully considers that in real-world scenarios, there is no guarantee that there is a linear correlation between the pruned channels and each retained channel. In the process of calculating the reconstructed coefficient matrix of the convolution kernel after pruning, a mask matrix based on cosine similarity is used to filter the retained channels, which further improves the accuracy of the compressed model.
[0050] Step S14: Adjust the weight parameters of the next adjacent convolutional layer of the target convolutional layer using the target mask matrix and reconstruction coefficient matrix to compensate for the pruning loss of the target convolutional layer.
[0051] In this embodiment, the contribution of each retained channel is quantified by combining the reconstruction coefficient matrix, and the weight parameters of the next adjacent convolutional layer are adjusted in a targeted manner. This makes the compensation operation accurately match the feature distribution of the pruned channels, thereby solving the technical problems of insufficient targeting and difficulty in effectively compensating for pruning loss in traditional compensation methods. This achieves the technical effect of significantly reducing the impact of pruning on network performance and reducing the decrease in accuracy, and further improving the accuracy of the compressed model.
[0052] In other words, the reconstruction coefficient matrix of the pruned channels can be used to scale the weights of the next convolutional layer, thereby reducing the accuracy loss of the image recognition network caused by pruning, such as... Figure 2 As shown, the reconstructed pruned output channels and the retained output channels form a new weight tensor for layer l. The output feature maps are input to the pruned input channels and the retained input channels of layer l+1, respectively. The feature map of each output channel in layer l+1 is the result of convolving and superimposing the input data of all input channels. Therefore, the reconstruction coefficient matrix of the pruned output channels in layer l can be used to adjust the weights of layer l+1 to reduce the information loss caused by channel pruning. Specifically, the feature map of the k-th output channel in layer l+1 is calculated by the following formula:
[0053] ;
[0054] in, It is the feature map of the k-th output channel of the (l+1)-th layer. It is the lth layer. Output channel feature map It is the reconstructed l-th layer. Output channel feature map , , This is the convolution symbol, and × is the matrix multiplication symbol. For the k-th output channel of layer l+1 The weights of the input channels, For the k-th output channel of layer l+1 The weights of the input channels, For the i-th reserved channel, For the j-th pruned channel, For the adjusted l+1 layer k-th output channel The weights of the input channels, It is the i-th mask value of the j-th mask vector in the target mask matrix. It is the i-th value of the j-th reconstruction coefficient vector in the reconstruction coefficient matrix.
[0055] In a specific implementation, the weight parameters of the next adjacent convolutional layer of the target convolutional layer are adjusted using the target mask matrix and the reconstruction coefficient matrix. This includes: obtaining the first weight parameter in the next adjacent convolutional layer of the target convolutional layer corresponding to the set of pruned channels, and determining a compensation term based on the product of the target mask matrix, the reconstruction coefficient matrix, and the first weight parameter; obtaining the second weight parameter in the next adjacent convolutional layer of the target convolutional layer corresponding to the set of retained channels, and obtaining the adjusted weight parameters of the next adjacent convolutional layer based on the sum of the compensation term and the second weight parameter.
[0056] Specifically, the weight parameters of the next adjacent convolutional layer can be adjusted according to the following formula:
[0057] ;
[0058] in, The first weight parameter in the next adjacent convolutional layer (i.e., the (l+1)th layer) of the target convolutional layer corresponds to the set of pruned channels. This is the second weight parameter corresponding to the set of channels to be retained in the next adjacent convolutional layer (i.e., the (l+1)th layer). It is the i-th mask value of the j-th mask vector in the target mask matrix. It is the i-th value of the j-th reconstruction coefficient vector in the reconstruction coefficient matrix; The compensation term is determined based on the product of the target mask matrix, the reconstruction coefficient matrix, and the first weight parameter.
[0059] As can be seen, this application takes into account that in real-world scenarios, a linear correlation between pruned channels and each retained channel cannot be guaranteed. Therefore, after pruning the output channels of the target convolutional layer to obtain a set of retained channels and a set of pruned channels, it is necessary to calculate the similarity between each retained channel and the remaining output channels based on the channel weights. This allows for the construction of a target mask matrix based on channel similarity, accurately locating retained channels closely associated with the pruned channels. Furthermore, this application uses the least squares method to obtain the reconstruction coefficient matrix, enabling the retained channels to accurately approximate the weight features of the pruned channels through linear combination, rather than simply removing the pruned channels. This solves the technical problem of key feature loss caused by ignoring channel correlation in traditional pruning, achieving the technical effect of maximizing the preservation of the original network feature expression capabilities while significantly reducing the number of channels. Finally, by combining the reconstruction coefficient matrix to quantify the contribution of each retained channel, the weight parameters of the next adjacent convolutional layer are adjusted in a targeted manner, so that the compensation operation accurately matches the feature distribution of the pruned channel. This solves the technical problem that traditional compensation methods are not targeted enough and cannot effectively compensate for pruning loss. It achieves the technical effect of significantly reducing the impact of pruning on network performance and reducing the decrease in accuracy, and further improves the accuracy of the compressed model.
[0060] See Figure 3 As shown, this application discloses a specific compression method for image recognition networks. Compared to the previous embodiment, this embodiment further explains and optimizes the technical solution. Specifically, it includes:
[0061] Step S21: Prune the output channels of the target convolutional layer in the image recognition network based on preset filtering rules to obtain a set of retained channels and a set of pruned channels; wherein, the target convolutional layer is located in the last layer of the main branch in the preset multi-branch structure.
[0062] This embodiment mainly describes in detail the specific pruning and compression process when the target convolutional layer is located in the last layer of the main branch in a preset multi-branch structure.
[0063] Step S22: Obtain the total output feature map of the preset multi-branch structure; the total output feature map is the sum of the feature maps output by each branch of the preset multi-branch structure after convolution operation with the corresponding channel weights.
[0064] In this embodiment, if the target convolutional layer is located at the last layer of the main branch in a preset multi-branch structure, the target mask matrix is not calculated directly using the weights of the target convolutional layer, but rather using the corresponding feature map. It is understandable that when compressing the last layer, the compensation is no longer for the error of a single layer, but for the final output error of the entire multi-branch network structure. The final output is the result of multiple branches merging, and this final output feature map is the only direct signal affecting subsequent parts of the network. Weights alone cannot fully reflect the difference in feature distribution before and after fusion. For example, if only the weights of the last layer of the main branch are reconstructed, it is equivalent to only compensating for the error of the main branch itself. Since the feature map contains the non-linear mapping result between the convolutional layer weights and the input features, it better represents the actual contribution of the layer to the final output than the weights. Especially in multi-branch fusion scenarios, the channel dimension and numerical distribution of the feature map directly determine the effectiveness of the fused features. Using feature map calculation ensures that the quantization loss compensation adapts to the actual needs of branch fusion, avoids compensation deviations caused by relying solely on weight calculations, and guarantees the integrity of the features after branch fusion.
[0065] Therefore, in order to construct the target mask matrix subsequently, this embodiment needs to first obtain the total output feature map of the preset multi-branch structure. , , To preserve the channel set, The set of pruned channels is the sum of the feature maps output by each branch of the preset multi-branch structure after convolution with corresponding channel weights.
[0066] The process of obtaining the total output feature map of the preset multi-branch structure includes: obtaining the first output feature map corresponding to each output channel of the main branch; obtaining the second output feature map corresponding to each output channel of the remaining branches in the preset multi-branch structure; and merging the first and second output feature maps to obtain the total output feature map. In other words, this application requires obtaining the first output feature map corresponding to each output channel of the main branch and the second output feature map corresponding to each output channel of the remaining branches in the preset multi-branch structure, and then merging the first and second output feature maps to obtain the total output feature map.
[0067] In specific implementations, the residual network contains two types of multi-branch network structures: a downsampling branch structure and an identity branch structure. Specifically, the preset multi-branch structure in this application is either a downsampling branch structure or an identity branch structure. The remaining branches in the downsampling branch structure are downsampling branches, and the remaining branches in the identity branch structure are identity branches. When the preset multi-branch structure is a downsampling branch structure, its network structure can be as follows: Figure 4As shown, a convolutional layer (CONV) plus a batch normalization layer (BN) is used as a convolutional unit. The downsampling branch structure consists of a main branch with two convolutional units and a downsampling branch with one convolutional unit. The downsampling branch is typically a 1x1 convolution with a stride of 2, responsible for adjusting the input size and number of channels to match the output of the main branch. When the preset multi-branch structure is an identity branch structure, its network structure can be specifically as follows: Figure 5 As shown, the identity branch structure consists of a main branch containing two convolutional units and an identity branch. It does not perform any calculations and directly passes the input unchanged. It is also called the Shortcut branch.
[0068] Accordingly, obtaining the second output feature map corresponding to each output channel of the remaining branches in the preset multi-branch structure includes: if the preset multi-branch structure is a downsampling branch structure, then pruning each output channel of the downsampling branch based on the retained channel set and the pruned channel set to obtain the second output feature map corresponding to each output channel of the downsampling branch; if the preset multi-branch structure is an identity branch structure, then using the input feature map of the identity branch as the second output feature map corresponding to each output channel.
[0069] That is, in one specific implementation, if the preset multi-branch structure is a downsampling branch structure, since the N output channels of the last convolutional layer (layer l) of the main branch are divided into two parts, namely the set of retained channels and the set of pruned channels, this means that the main branch ultimately only retains the set of retained channels and the set of pruned channels. There are N effective output channels, but the downsampling branch (layer l+1) still has N output channels. According to the rules of the residual structure, the output of the main branch and the output of the downsampling branch need to be added channel by channel. However, the number of channels of the two tensors do not match, so the addition operation cannot be performed. Therefore, in order to solve this problem of dimension mismatch, the downsampling branch layer l+1 must be pruned simultaneously. When pruning, the pruning decision of layer l (the last layer of the main branch) is directly copied. That is, the output channels of the downsampling branch are pruned directly based on the set of retained channels and the set of pruned channels to obtain the second output feature map corresponding to each output channel of the downsampling branch. At this time, the first output feature map includes both the output feature map corresponding to the set of retained channels and the output feature map corresponding to the set of pruned channels.
[0070] In another specific implementation, if the preset multi-branch structure is an identity branch structure, since the identity branch transmits the input feature map of the residual block, the number of channels of this input feature map is already fixed before entering the block. Therefore, the input feature map of the identity branch is directly used as the second output feature map corresponding to each output channel.
[0071] Step S23: Based on the total output feature map, calculate the feature map similarity between the output feature map corresponding to each retained channel in the retained channel set and the output feature maps corresponding to the other output channels.
[0072] In this embodiment, for the last convolutional layer, the similarity between the output feature map of each retained channel in the retained channel set and the output feature maps of the other output channels is calculated based on the total output feature map. The cosine similarity method is also used for calculation here.
[0073] Step S24: Construct a target mask matrix based on feature map similarity; the target mask matrix is used to mark the information of the preserved channels in the preserved channel set that participate in the reconstruction of each pruned channel.
[0074] In this embodiment, a target mask matrix is constructed based on the calculated feature map similarity.
[0075] Step S25: For any pruned channel, with the goal of approximating the output feature map of any pruned channel by a linear combination of the output feature maps of each preserved channel in the preserved channel information, the reconstruction coefficient matrix is determined based on the target mask matrix and the least squares method.
[0076] In this embodiment, similar to the aforementioned weight calculation process, this application needs to solve the reconstruction error optimization function of the output feature map of each channel in the pruned channel set one by one using the least squares method. To obtain the reconstruction coefficient vector , This leads to the determination of the reconstruction coefficient matrix S; where and These are the output feature maps of the i-th preserved channel and the j-th pruned channel, respectively. It is the mask value in the target mask matrix.
[0077] Step S26: Adjust the weight parameters of the next adjacent convolutional layer of the target convolutional layer using the target mask matrix and reconstruction coefficient matrix to compensate for the pruning loss of the target convolutional layer.
[0078] For more detailed processing procedures of steps S21, S23 and S27, please refer to the corresponding content disclosed in the foregoing embodiments, which will not be repeated here.
[0079] As can be seen, in order to improve the applicability to different multi-branch network structures, this application specifically designs different pruning processes for the characteristics of the downsampling branch structure and the identity branch structure in the residual network, to compensate for the compression loss of the downsampling branch and the identity branch, thereby improving the accuracy of the compressed model.
[0080] Furthermore, quantization is also a commonly used method for lightweighting networks, which can reduce the number of parameters, storage, floating-point computations during inference, and bit operations in image recognition networks, thereby enabling the deployment and inference acceleration of image recognition networks on resource-constrained edge devices. Considering the mutual influence between pruning and quantization, this application can also achieve joint optimization of pruning and quantization to achieve unified compression of image recognition networks. Specifically, the quantization process is executed first, followed by the pruning process. That is, before pruning the output channels of the target convolutional layer in the image recognition network based on preset filtering rules to obtain the set of retained channels and the set of pruned channels, the quantization process can also be executed, such as... Figure 6 and Figure 7 As shown, the specific steps include:
[0081] Step S31: Obtain the original weights of the target convolutional layer in the image recognition network, and perform pseudo-quantization on the original weights based on the preset initial bits to obtain the initial pseudo-quantized weights.
[0082] In this embodiment, the original weights of the target convolutional layer in the image recognition network are first obtained. It should be noted that the image recognition network can specifically be a face recognition network, a vehicle recognition network, a medical image recognition network, etc., and this embodiment does not limit the specific network structure of the image recognition network. For example, it can be a single-branch sequence network structure such as AlexNet or VGGNet, or a multi-branch network structure such as ResNet (residual network) or MobileNet. Furthermore, this embodiment does not limit the convolution type of the convolutional layer; for example, it can be standard convolution, depthwise separable convolution, grouped convolution, and dilated convolution, etc.
[0083] When compressing image recognition networks, quantization can be used. Specifically, this application discloses a quantization bit selection module. By inputting the original weights of the target convolutional layer into this module, the target quantization bits adapted to the target convolutional layer can be obtained, that is, the optimal quantization bits that minimize the quantization loss of the target convolutional layer. The quantization bit selection module first performs a pseudo-quantization operation on the original weights based on a preset initial bit to obtain the initial pseudo-quantized weights. It is understood that, considering the symmetrical quantization of the weights, there is a multiple relationship between the 2-bit pseudo-quantized weights and the higher-precision pseudo-quantized weights, for example, including... , The combined multiple relationships are shown in the following formula:
[0084] ;
[0085] Where b is the optimal quantization bit, The weights are 2-bit pseudo-quantized. It is the weight after b-bit pseudo-quantization.
[0086] Therefore, in a specific implementation, the preset initial bit can be set to 2 bits, that is, the weight is first pseudo-quantized by 2 bits, specifically including 2-bit quantization and 2-bit dequantization, so that the weight after pseudo-quantization by 2 bits is used as the initial pseudo-quantized weight.
[0087] Step S32: Based on the original weights and the initial pseudo-quantized weights, determine the target quantization bits that are compatible with the target convolutional layer using a preset mapping function.
[0088] In this embodiment, the quantization bit selection module is also equipped with a preset mapping function, which can determine the target quantization bits that are compatible with the target convolutional layer by using the preset mapping function based on the original weights, the weights after initial pseudo-quantization.
[0089] In a specific implementation, the target quantization bits adapted to the target convolutional layer are determined based on the original weights and the initial pseudo-quantized weights using a preset mapping function. This includes: calculating the ratio between the original weights and the initial pseudo-quantized weights; mapping the ratio to a pre-set target interval using the preset mapping function to obtain the corresponding mapping result; and determining the target quantization bits adapted to the target convolutional layer based on the mapping result. That is, this application first calculates the ratio between the original weights and the initial pseudo-quantized weights. Then, based on the ratio result and the preset mapping function, the target quantization bits that are compatible with the target convolutional layer are determined.
[0090] The expression for the preset mapping function is as follows:
[0091] ;
[0092] ;
[0093] in, The mapping result is represented by b, the target quantization bit, and relu represents an activation function, relu(x) = max(0, x), which is used to ensure that negative numbers do not occur during the calculation process. sign represents the sign function.
[0094] That is, this application first uses a preset mapping function to calculate the ratio result. Map to a pre-defined target range Within, to obtain the corresponding mapping result. Finally, based on the mapping results The target quantization bit b, which is suitable for the target convolutional layer, is determined. The quantization bit selection module of this application models the relationship between the multiples between the original weights and the weights after 2-bit pseudo-quantization and the optimal quantization bit using an inverse function. Then, it automatically selects the optimal quantization bit among 2 bits, 4 bits, 6 bits, and 8 bits using a nonlinear function, achieving mixed-precision quantization. In this way, by utilizing the multiple relationships between different quantization precipitates, the quantization precision can match the differences in feature importance of different convolutional layers, automatically selecting the optimal quantization bit for different convolutional layers, rather than relying on fixed selection based on human experience. Therefore, it can solve the technical problem of key channel information loss or insufficient quantization caused by fixed quantization bits in traditional methods, thereby achieving the technical effect of reducing the loss of key features during quantization and improving the accuracy of the quantized model.
[0095] Step S33: Perform pseudo-quantization on the original weights based on the target quantization bits to obtain the target pseudo-quantized weights, and determine the scaling coefficient matrix based on the target pseudo-quantized weights and the batch normalization layer statistical parameters corresponding to the target convolutional layer.
[0096] In this embodiment, as Figure 8 As shown, after obtaining the target quantized bits, the original weights are then pseudo-quantized using the target quantized bits b, i.e., b-bit quantization and dequantization are performed to obtain the target pseudo-quantized weights. Furthermore, the scaling factor matrix is solved by combining the target pseudo-quantized weights of the current layer and the statistical parameters of the batch normalized layer, in order to reflect the degree of quantization loss of each channel.
[0097] In a specific implementation, the scaling factor matrix is determined based on the target pseudo-quantized weights and the batch normalized layer statistical parameters corresponding to the target convolutional layer. This includes: obtaining the batch normalized layer statistical parameters corresponding to the target convolutional layer; adjusting the original weights based on the batch normalized layer statistical parameters to obtain a first weight adjustment result, and adjusting the target pseudo-quantized weights based on the batch normalized layer statistical parameters to obtain a second weight adjustment result; calculating the bias compensation term of the batch normalized layer based on the batch normalized layer statistical parameters; and determining the scaling factor matrix based on the first weight adjustment result, the second weight adjustment result, the bias compensation term, and a preset penalty factor. In other words, this embodiment first needs to obtain the batch normalized layer statistical parameters corresponding to the target convolutional layer, then calculate the first weight adjustment result obtained by adjusting the original weights after adjusting the batch normalized layer statistical parameters, and calculate the second weight adjustment result obtained by adjusting the target pseudo-quantized weights after adjusting the batch normalized layer statistical parameters, and calculate the bias compensation term of the batch normalized layer based on the batch normalized layer statistical parameters, thereby determining the scaling coefficient matrix based on the first weight adjustment result, the second weight adjustment result, the bias compensation term, and the preset penalty factor. It should be noted that this calculation process is mainly applicable to any convolutional layer in a single-branch sequence network structure and convolutional layers other than the last convolutional layer in a multi-branch network structure.
[0098] In a specific implementation, the scaling factor matrix is determined based on the first weight adjustment result, the second weight adjustment result, the bias compensation term, and the preset penalty factor. This includes: calculating the scaling factor for each output channel based on the first weight adjustment result, the second weight adjustment result, the bias compensation term, and the preset penalty factor; and combining the scaling factors according to the order of the output channels to obtain the scaling factor matrix. That is, this application calculates the scaling factor corresponding to each output channel for each output channel, combining the first weight adjustment result, the second weight adjustment result, the bias compensation term, and the preset penalty factor. Then, the scaling factors of all channels are arranged in channel order to form the scaling factor matrix R.
[0099] It should be noted that the batch normalization layer statistical parameters include the batch normalization layer's weight parameters, bias parameters, mean, and variance. Correspondingly, the bias compensation term of the batch normalization layer is calculated based on the batch normalization layer statistical parameters, including: determining the target ratio between the weight parameters and the variance, and determining the product result between the target ratio and the mean; the difference between the bias parameters and the product result is determined as the bias compensation term of the batch normalization layer.
[0100] In other words, the statistical parameters of the batch normalization layer specifically include the weight parameters of the batch normalization layer. Bias parameters mean and variance Where i represents the i-th output channel of the target convolutional layer, and each output channel corresponds to a set of independent batch normalized layer statistical parameters. In calculating the bias compensation term, this application first determines the target ratio between the weight parameters and the variance. Then calculate the product between the target ratio and the mean. Then the bias parameter product result The difference is determined as the bias compensation term for the batch normalization layer, i.e. .
[0101] Furthermore, the original weights are adjusted based on the batch normalization layer statistical parameters, including: adjusting the original weights based on the target ratio; correspondingly, the target pseudo-quantized weights are adjusted based on the batch normalization layer statistical parameters, including: adjusting the target pseudo-quantized weights based on the target ratio. That is, assuming the target convolutional layer is the l-th layer, the original weights of its i-th output channel are... The target weights after pseudo-quantization are Then the first weight adjustment result of the i-th output channel is: The second weight adjustment result is .
[0102] Based on the above, this application solves for the scaling factor values in the scaling factor matrix R. The expression is:
[0103] ;
[0104] in, Preset penalty factor.
[0105] Step S34: Scale the weights of the next adjacent convolutional layer of the target convolutional layer using the scaling factor matrix to compensate for the quantization loss of the target convolutional layer.
[0106] In this embodiment, a scaling factor matrix is used to specifically scale the weights of the next adjacent convolutional layer of the target convolutional layer, thereby achieving accurate cross-layer compensation for quantization loss. This avoids the accumulation of errors propagating in the network and solves the technical problems of traditional compensation methods that ignore inter-layer correlation and have poor compensation effects. The above scheme can significantly improve the accuracy of model compression.
[0107] In a specific implementation, it can be done according to The weights of the (l+1)th layer are scaled using a scaling factor matrix R to compensate for the quantization loss. These are the weights of the k-th output channel and the ith input channel of the (l+1)-th layer. It is the weight of the k-th output channel and the ith input channel of the (l+1)-th layer after scaling.
[0108] In other words, the quantization loss of layer l can also be compensated for by adjusting the weights of layer l+1. Specifically, the unquantized weights (i.e., the original weights) of layer l can be approximated by the product of the pseudo-quantized weights and the scaling factor matrix, which can be further used to scale the corresponding channels of the weights of layer l+1.
[0109] Furthermore, when the target convolutional layer is located at the last layer of the main branch in the preset multi-branch structure, the scaling factor matrix is determined based on the target pseudo-quantized weights and the statistical parameters of the batch normalized layer corresponding to the target convolutional layer. This includes: obtaining the first output feature map obtained after convolution operation of the target convolutional layer with the target pseudo-quantized weights, and obtaining the target feature maps corresponding to the remaining branches; and determining the scaling factor matrix based on the first output feature map, the target feature map, and the statistical parameters of the batch normalized layer corresponding to the target convolutional layer. That is, if the target convolutional layer is located at the last layer of the main branch in the preset multi-branch structure, the scaling factor matrix is not calculated directly using the weights of the target convolutional layer, but rather using the corresponding feature map.
[0110] In one specific implementation, the preset multi-branch structure is a downsampling branch structure, and the remaining branches are downsampling branches; accordingly, the target feature map corresponding to the remaining branches is obtained, including: determining the pseudo-quantized weight parameters corresponding to the downsampling branch; obtaining the second output feature map obtained after the downsampling branch is convolved with the pseudo-quantized weight parameters, and using the second output feature map as the target feature map.
[0111] In another specific implementation, the multi-branch structure is preset to be an identical branch structure, and the remaining branches are identical branches; accordingly, the target feature map corresponding to the remaining branches is obtained, including: obtaining the input feature map of the identical branch, and using the input feature map as the target feature map.
[0112] As can be seen, this application, by first performing pseudo-quantization based on a preset initial bit to obtain initial pseudo-quantized weights, and then combining the original weights with these initial pseudo-quantized weights, dynamically determines the target quantization bits adapted to the features of the target convolutional layer through a preset mapping function. This allows the quantization accuracy to match the differences in feature importance between different convolutional layers, rather than relying on fixed selection based on human experience. Therefore, it can solve the technical problem of key channel information loss or insufficient quantization caused by fixed quantization bits in traditional methods, thereby achieving the technical effect of reducing the loss of key features during quantization and improving the accuracy of the quantized model. Furthermore, after obtaining the target pseudo-quantized weights, this application solves the scaling coefficient matrix by combining the target pseudo-quantized weights of the current layer and the batch normalized layer statistical parameters to reflect the degree of quantization loss of each channel. This matrix is then used to specifically scale the weights of the next adjacent convolutional layer, achieving precise cross-layer compensation for quantization loss, avoiding the accumulation of errors in the network, and solving the technical problem of traditional compensation methods ignoring inter-layer correlation and having poor compensation effects. The above scheme can significantly improve the accuracy of model compression.
[0113] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method.
[0114] See Figure 9 As shown in the illustration, this application also provides a compression device for an image recognition network, the device comprising:
[0115] The pruning module 11 is used to prune the output channels of the target convolutional layer in the image recognition network based on preset filtering rules, so as to obtain the set of retained channels and the set of pruned channels.
[0116] The mask matrix construction module 12 is used to calculate the similarity between each retained channel in the retained channel set and the other output channels based on the channel weight, and to construct the target mask matrix based on the similarity calculation results; the target mask matrix is used to mark the information of the retained channels in the retained channel set that participate in the reconstruction of each pruned channel.
[0117] The reconstruction coefficient matrix determination module 13 is used to determine the reconstruction coefficient matrix based on the target mask matrix and the least squares method for any pruned channel, with the goal of approximating the weight of any pruned channel by a linear combination of the weights of each retained channel in the retained channel information.
[0118] The weight adjustment module 14 is used to adjust the weight parameters of the next adjacent convolutional layer of the target convolutional layer using the target mask matrix and the reconstruction coefficient matrix to compensate for the pruning loss of the target convolutional layer.
[0119] As can be seen, this application takes into account that in real-world scenarios, a linear correlation between pruned channels and each retained channel cannot be guaranteed. Therefore, after pruning the output channels of the target convolutional layer to obtain a set of retained channels and a set of pruned channels, it is necessary to calculate the similarity between each retained channel and the remaining output channels based on the channel weights. This allows for the construction of a target mask matrix based on channel similarity, accurately locating retained channels closely associated with the pruned channels. Furthermore, this application uses the least squares method to obtain the reconstruction coefficient matrix, enabling the retained channels to accurately approximate the weight features of the pruned channels through linear combination, rather than simply removing the pruned channels. This solves the technical problem of key feature loss caused by ignoring channel correlation in traditional pruning, achieving the technical effect of maximizing the preservation of the original network feature expression capabilities while significantly reducing the number of channels. Finally, by combining the reconstruction coefficient matrix to quantify the contribution of each retained channel, the weight parameters of the next adjacent convolutional layer are adjusted in a targeted manner, so that the compensation operation accurately matches the feature distribution of the pruned channel. This solves the technical problem that traditional compensation methods are not targeted enough and cannot effectively compensate for pruning loss. It achieves the technical effect of significantly reducing the impact of pruning on network performance and reducing the decrease in accuracy, and further improves the accuracy of the compressed model.
[0120] For a description of the features in the embodiment corresponding to the compression device of the image recognition network, please refer to the relevant description in the embodiment corresponding to the compression method of the image recognition network, which will not be repeated here.
[0121] Embodiments of this application also provide an electronic device, including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in any of the above-described compression method embodiments of an image recognition network.
[0122] Embodiments of this application also provide a computer-readable storage medium storing a computer program configured to execute the steps in any of the above-described compression method embodiments of an image recognition network at runtime.
[0123] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.
[0124] Embodiments of this application also provide a computer program product, which includes a computer program that, when executed by a processor, implements the steps in any of the above-described compression method embodiments of an image recognition network.
[0125] Embodiments of this application also provide another computer program product, including a non-volatile computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps in any of the above-described compression method embodiments of an image recognition network.
[0126] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0127] The compression method and apparatus for an image recognition network provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only for the purpose of helping to understand the method and its core ideas. It should be noted that those skilled in the art can make several improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of the claims of this application.
Claims
1. A compression method for an image recognition network, characterized in that, include: The output channels of the target convolutional layer in the image recognition network are pruned based on preset filtering rules to obtain a set of retained channels and a set of pruned channels. The similarity between each retained channel in the retained channel set and the other output channels is calculated based on the channel weight, and a target mask matrix is constructed based on the similarity calculation results; The target mask matrix is used to mark the information of the retained channels in the retained channel set that participate in the reconstruction of each pruned channel; For any pruned channel, the reconstruction coefficient matrix is determined based on the target mask matrix and the least squares method, with the goal of approximating the weight of any pruned channel by a linear combination of the weights of each retained channel in the retained channel information. The weight parameters of the next adjacent convolutional layer of the target convolutional layer are adjusted using the target mask matrix and the reconstruction coefficient matrix to compensate for the pruning loss of the target convolutional layer. The step of calculating the similarity between each retained channel in the retained channel set and the remaining output channels based on channel weights, and constructing a target mask matrix based on the similarity calculation results, includes: The similarity between each retained channel in the retained channel set and the other retained channels and each pruned channel in the pruned channel set is calculated based on cosine similarity and channel weight. The second target number of output channels are selected in descending order of similarity calculation results to construct a target channel set; the second target number is calculated based on a preset channel pruning rate. Obtain an initial mask matrix; wherein each element in the initial mask matrix is zero. The intersection operation is performed on the target channel set and the pruned channel set to determine the target pruned channel, and the target pruned channel is used to update the value of the target element in the initial mask matrix to obtain the target mask matrix; The step of adjusting the weight parameters of the next adjacent convolutional layer of the target convolutional layer using the target mask matrix and the reconstruction coefficient matrix includes: Obtain the first weight parameter corresponding to the set of pruned channels in the next adjacent convolutional layer of the target convolutional layer, and determine the compensation term based on the product of the target mask matrix, the reconstruction coefficient matrix and the first weight parameter; Obtain the second weight parameter corresponding to the set of reserved channels in the next adjacent convolutional layer of the target convolutional layer, and obtain the adjusted weight parameter of the next adjacent convolutional layer based on the sum of the compensation term and the second weight parameter.
2. The compression method for image recognition networks according to claim 1, characterized in that, The step of pruning the output channels of the target convolutional layer in the image recognition network based on preset filtering rules to obtain a set of retained channels and a set of pruned channels includes: Obtain the original weights of each output channel of the target convolutional layer in the image recognition network; Based on the original weights and L1 norm filtering rules of each output channel, the output channels of the target convolutional layer are pruned to obtain the set of retained channels and the set of pruned channels. Specifically, based on the original weights and L1 norm selection rules of each output channel, the output channels of the target convolutional layer are pruned to obtain a set of retained channels and a set of pruned channels, including: Calculate the L1 norm of the original weights of each output channel; The first target number of output channels are selected in ascending order of L1 norm to construct a set of pruned channels, and a set of retained channels is constructed based on the remaining output channels; wherein, the first target number is calculated based on a preset channel pruning rate.
3. The compression method for image recognition networks according to claim 1, characterized in that, The number of rows in the initial mask matrix is the same as the number of channels in the set of channels to be retained, and the number of columns in the initial mask matrix is the same as the number of channels in the set of channels to be pruned. Accordingly, updating the values of the target elements in the initial mask matrix using the pruned target channel to obtain the target mask matrix includes: The row index is determined based on the channel number of each retained channel in the set of retained channels, and the column index is determined based on the channel number of the target pruned channel in the set of pruned channels; Based on the row index and the column index, the target element is located in the initial mask matrix, and the value of the target element is updated to the target value to obtain the target mask matrix.
4. The compression method for image recognition networks according to claim 1, characterized in that, The step of approximating the weight of any pruned channel by a linear combination of the weights of each retained channel in the retained channel information, and determining the reconstruction coefficient matrix based on the target mask matrix and the least squares method, includes: Construct a reconstruction error optimization function corresponding to any of the pruned channels; wherein, the objective of the reconstruction error optimization function is to minimize the difference between the linear combination of the weights of each retained channel in the retained channel information and the weight of any pruned channel, and the unknown quantity in the reconstruction error optimization function is the reconstruction coefficient vector; each element in the reconstruction coefficient vector is used to characterize the reconstruction contribution of each retained channel to any pruned channel, and the linear combination is calculated based on the weights of each retained channel in the retained channel information, the target mask matrix, and the reconstruction coefficient vector; The reconstruction error optimization function is solved based on the target mask matrix and the least squares method to obtain the reconstruction coefficient vector; The reconstruction coefficient vectors corresponding to each pruned channel in the pruned channel set are arranged in channel order to obtain the reconstruction coefficient matrix.
5. The compression method for image recognition networks according to claim 1, characterized in that, When the target convolutional layer is located at the last layer of the main branch in a preset multi-branch structure, the step of calculating the similarity between each retained channel in the retained channel set and the remaining output channels based on channel weights, and constructing a target mask matrix based on the similarity calculation results, includes: Obtain the total output feature map of the preset multi-branch structure; the total output feature map is the sum of the feature maps output by the output channels of each branch in the preset multi-branch structure after performing convolution operations with the corresponding channel weights; Based on the total output feature map, calculate the feature map similarity between the output feature map corresponding to each retained channel in the retained channel set and the output feature maps corresponding to the other output channels. Construct a target mask matrix based on the feature map similarity; Accordingly, the step of approximating the weight of any pruned channel by a linear combination of the weights of each retained channel in the retained channel information, and determining the reconstruction coefficient matrix based on the target mask matrix and the least squares method, includes: The reconstruction coefficient matrix is determined based on the target mask matrix and the least squares method, with the goal of approximating the output feature map of any pruned channel by a linear combination of the output feature maps of each retained channel in the retained channel information.
6. The compression method for image recognition networks according to claim 5, characterized in that, The step of obtaining the total output feature map of the preset multi-branch structure includes: Obtain the first output feature map corresponding to each output channel of the main branch, and obtain the second output feature map corresponding to each output channel of the other branches in the preset multi-branch structure; The first output feature map and the second output feature map are merged to obtain the total output feature map; The preset multi-branch structure is either a downsampling branch structure or an identity branch structure, where the remaining branches in the downsampling branch structure are downsampling branches, and the remaining branches in the identity branch structure are identity branches. Accordingly, obtaining the second output feature map corresponding to each output channel of the remaining branches in the preset multi-branch structure includes: If the preset multi-branch structure is a downsampling branch structure, then each output channel of the downsampling branch is pruned based on the set of retained channels and the set of pruned channels to obtain the second output feature map corresponding to each output channel of the downsampling branch. If the preset multi-branch structure is an identical branch structure, then the input feature map of the identical branch is used as the second output feature map corresponding to each output channel.
7. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the compression method for an image recognition network as described in any one of claims 1 to 6 when executing the computer program.
Citation Information
Patent Citations
Model generation method and device, target detection method and device, equipment and storage medium
CN113408561A
Image recognition method, system and device and storage medium
CN116206188A