A compression method and device of an image recognition network

By dynamically determining quantization bits and using cross-layer compensation techniques, the problem of critical channel information loss and accuracy degradation when image recognition networks are deployed on edge devices is solved, achieving efficient model compression and accuracy improvement.

CN121012925BActive Publication Date: 2026-01-23LANGCHAO ELECTRONIC INFORMATION IND CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511544932.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

Technical Problem

In existing technologies, when image recognition networks are deployed on resource-constrained edge devices, quantization bits need to be set manually, which leads to the loss of critical channel information and a decrease in accuracy. Furthermore, traditional methods fail to effectively consider the cumulative propagation of quantization errors between network layers.

Method used

By obtaining the original weights of the target convolutional layer of the image recognition network, performing pseudo-quantization, dynamically determining the target quantization bits using preset initial bits and mapping functions, and solving the scaling coefficient matrix by combining the statistical parameters of the batch normalization layer, cross-layer accurate compensation for quantization loss is achieved.

Benefits of technology

It reduces the loss of key features during quantization, improves model accuracy, avoids the accumulation of errors in the network, and significantly improves the accuracy of model compression.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121012925B_ABST
    Figure CN121012925B_ABST
Patent Text Reader

Abstract

The application discloses a compression method and device of an image recognition network, and relates to the technical field of artificial intelligence, which comprises the following steps: obtaining initial pseudo-quantized weights based on preset initial bits for pseudo-quantization, and then dynamically determining target quantization bits of an adaptive target convolution layer by combining original weights with a preset mapping function, so that the quantization precision can match the feature importance difference of different convolution layers, the problem that key channel information is lost or quantized insufficiently due to fixed quantization bits in traditional methods is solved, and the effects of reducing key feature loss in the quantization process and improving the precision of the model after quantization are achieved. Furthermore, a scaling coefficient matrix is solved by combining the target pseudo-quantized weights and batch normalization layer statistical parameters, so as to reflect the quantization loss degree of each channel, and then the weights of the next adjacent convolution layer are scaled in a targeted manner, the cross-layer accurate compensation of quantization loss is realized, and the problems that the traditional compensation methods ignore the interlayer correlation and have poor compensation effects are solved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of artificial intelligence, in particular to a compression method and device of an image recognition network. BACKGROUND

[0002] With the development of artificial intelligence technology, deep neural networks are widely used in image recognition. However, deep neural networks usually have a large number of parameters and a large amount of computation, so deploying image recognition networks in edge devices with limited computing resources and storage space in image recognition tasks faces great challenges.

[0003] Quantization is a common network lightening method to realize the deployment and inference acceleration of the network on the edge device with limited resources. Traditional quantization methods can be divided into quantization-aware training and post-training quantization. Although quantization-aware training can maintain high accuracy, it needs to retrain with original training data, which is time-consuming and cannot obtain data in some sensitive fields (such as medical images). Post-training quantization does not need to retrain, but it needs to manually set the quantization bits of each network layer, does not consider the feature importance difference of different network layers or channels, and is easy to cause key channel information loss. In addition, traditional methods usually only consider the local error within the network layer, and rarely consider the transmission and accumulation of quantization error between network layers, resulting in a significant decrease in overall accuracy.

[0004] In summary, how to determine the best quantization precision of each network layer and compensate for the accuracy loss caused by quantization is a problem to be solved at present. SUMMARY

[0005] The present application provides a compression method and device of an image recognition network to at least solve the problems that the quantization bits of each network layer still need to be manually set and how to compensate for the accuracy loss caused by quantization in related technologies.

[0006] The present application provides a compression method of an image recognition network, comprising:

[0007] obtaining original weights of a target convolutional layer in the image recognition network, and performing a pseudo-quantization operation on the original weights based on a preset initial bit to obtain initial pseudo-quantized weights;

[0008] determining a target quantization bit suitable for the target convolutional layer based on the original weights and the initial pseudo-quantized weights and using a preset mapping function;

[0009] performing a pseudo-quantization operation on the original weights based on the target quantization bit to obtain target pseudo-quantized weights, and determining a scaling coefficient matrix based on the target pseudo-quantized weights and the statistical parameters of the batch normalization layer corresponding to the target convolutional layer;

[0010] The scaling coefficient matrix is used to scale the weight of the next adjacent convolution layer of the target convolution layer to compensate for the quantization loss of the target convolution layer.

[0011] The application further provides an electronic device, comprising a memory for storing a computer program, and a processor for executing the computer program to implement the steps of the compression method of the image recognition network.

[0012] The application further provides a computer-readable storage medium, which stores a computer program, wherein the computer program is executed by a processor to implement the steps of the compression method of the image recognition network.

[0013] The application further provides a computer program product, which comprises a computer program, wherein the computer program is executed by a processor to implement the steps of the compression method of the image recognition network.

[0014] Beneficial effects: According to the application, the initial pseudo-quantized weight is obtained based on the preset initial bit, and then the target quantization bit that adapts to the characteristics of the target convolution layer is dynamically determined by a preset mapping function in combination with the original weight and the initial pseudo-quantized weight, so that the quantization precision can match the feature importance difference of different convolution layers, instead of relying on artificial experience to fixedly select, thereby solving the technical problem of key channel information loss or insufficient quantization caused by fixed quantization bits in the traditional method, and achieving the technical effects of reducing the loss of key features in the quantization process and improving the precision of the model after quantization. Moreover, after obtaining the target pseudo-quantized weight, the scaling coefficient matrix is solved by combining the target pseudo-quantized weight of the current layer and the batch normalization layer statistical parameters, so as to reflect the quantization loss degree of each channel, and then the weight of the next adjacent convolution layer is scaled by using the matrix, so as to realize the accurate compensation of the quantization loss across layers, avoid the error accumulation in the network, and solve the technical problem of poor compensation effect caused by ignoring the correlation between layers in the traditional compensation method. The above scheme can significantly improve the accuracy of model compression. BRIEF DESCRIPTION OF DRAWINGS

[0015] In order to more clearly illustrate the embodiments of the application, the drawings needed in the embodiments will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the application, and other drawings can be obtained by those skilled in the art without creative labor.

[0016] Figure 1 A flowchart of the compression method of the image recognition network provided by the embodiments of the application is provided.

[0017] Figure 2 A flowchart of the layer-by-layer pseudo-quantization and scaling coefficient solving provided by the embodiments of the application is provided.

[0018] Figure 3 A specific image recognition network compression method flowchart provided for the embodiments of the present application;

[0019] Figure 4 A network structure diagram of a down-sampling branch structure provided for the embodiments of the present application;

[0020] Figure 5 A network structure diagram of an identity branch structure provided for the embodiments of the present application;

[0021] Figure 6 A pruning method flowchart of an image recognition model provided for the embodiments of the present application;

[0022] Figure 7 A joint quantization and pruning compression flowchart provided for the embodiments of the present application;

[0023] Figure 8 A schematic diagram of layer-by-layer reconstruction of pruned output channels and scaling of input channels of a next convolutional layer provided for the embodiments of the present application;

[0024] Figure 9 A compression device structure schematic diagram of an image recognition network provided for the embodiments of the present application. DETAILED DESCRIPTION

[0025] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the protection scope of the present application.

[0026] It should be noted that, in the description of the present application, the terms “include”, “contain” or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. The terms “first”, “second” and the like in the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence.

[0027] In order to make those skilled in the art better understand the present application, the present application will be further described in detail below with reference to the drawings and specific embodiments.

[0028] Referring to Figure 1 The embodiments of the present application provide an image recognition network compression method, which comprises:

[0029] Step S11: Obtain the original weight of the target convolution layer in the image recognition network, and perform a pseudo quantization operation on the original weight based on a preset initial bit to obtain an initial pseudo quantized weight.

[0030] In this embodiment, the original weight of the target convolution layer in the image recognition network is first obtained. It should be noted that the image recognition network can be a face recognition network, a vehicle recognition network, a medical image recognition network, etc., and the specific network structure of the image recognition network is not limited in the embodiments of the present application, for example, it can be a single-branch sequence network structure such as AlexNet, VGGNet, etc., or a multi-branch network structure such as ResNet (Residual Network), MobileNet, etc. In addition, the convolution type of the convolution layer is not limited in the embodiments of the present application, for example, it can be a standard convolution, a depth separable convolution, a group convolution, an expansion convolution, etc.

[0031] The present application discloses a quantization bit selection module, which can obtain the target quantization bit adapted to the target convolution layer by inputting the original weight of the target convolution layer into the module, i.e. the optimal quantization bit that minimizes the quantization loss of the target convolution layer. The quantization bit selection module first performs a pseudo quantization operation on the original weight based on a preset initial bit to obtain an initial pseudo quantized weight. It can be understood that, in the case of considering symmetric quantization of the weight, there is a multiple relationship between the 2-bit pseudo quantized weight and the higher-precision pseudo quantized weight, for example, including , The comprehensive multiple relationship is shown in the following formula:

[0032] ;

[0033] wherein b is the optimal quantization bit, is the 2-bit pseudo quantized weight, is the b-bit pseudo quantized weight.

[0034] Therefore, in the specific embodiment, the preset initial bit can be set to 2 bits, i.e. the weight is first pseudo quantized by 2 bits, which specifically includes 2-bit quantization and 2-bit dequantization, so as to take the 2-bit pseudo quantized weight as the initial pseudo quantized weight.

[0035] Step S12: Determine the target quantization bit adapted to the target convolution layer based on the original weight and the initial pseudo quantized weight, and using a preset mapping function.

[0036] In this embodiment, the preset mapping function is also provided in the quantization bit selection module, and the target quantization bit adapted to the target convolution layer can be determined based on the original weight, the initial pseudo quantized weight, and the preset mapping function.

[0037] 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.

[0038] The expression for the preset mapping function is as follows:

[0039] ;

[0040] ;

[0041] 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.

[0042] 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.

[0043] Step S13: 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.

[0044] In this embodiment, as Figure 2 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.

[0045] 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.

[0046] 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.

[0047] 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.

[0048] 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. .

[0049] 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 .

[0050] Based on the above, this application solves for the scaling factor values ​​in the scaling factor matrix R. The expression is:

[0051] ;

[0052] in, Preset penalty factor.

[0053] Step S14: 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.

[0054] 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.

[0055] 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.

[0056] 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.

[0057] In traditional approaches, the scaling factor matrix of the l-th layer can be obtained by solving the objective function. Obtain, among which This represents the weight of the i-th output channel of the l-th layer after pseudo-quantization. Represents the original weights of the i-th output channel in the l-th layer. Let be the i-th scaling factor value in the scaling factor matrix R. The feature map output by the pseudo-quantized weights of layer l is input to the corresponding input channel of layer l+1, thus affecting the output feature map of layer l+1 due to the quantization loss of layer l. The calculation process of the k-th output feature map of layer l+1 is as follows:

[0058] ;

[0059] In the formula, It is the output feature map of the k-th output channel of the (l+1)-th layer affected by quantization. It is the output feature map of the i-th output channel of the l-th layer after pseudo-quantization. It is the weight of the i-th input channel of the k-th output channel in the (l+1)-th layer. Let i be the i-th scaling factor value in the scaling factor matrix R. N is the number of output channels in the l-th layer. The scaling of the weights in the (l+1)-th layer is performed channel-by-channel according to the following expression:

[0060] ;

[0061] in, It is the scaled weight of the (l+1)th layer.

[0062] In this application, to reduce the impact of pseudo-quantization of the weights in layer l on the output feature map of layer l+1, the scaling coefficient matrix can be solved by optimizing the output feature map loss of layer l+1 to obtain a global optimum across layers rather than a local optimum within a layer. The output feature map loss of layer l+1... It can be represented in the following form:

[0063] ;

[0064] In the formula, , , . The processing of the representative batch normalization layer, , , , These are the weight parameters, bias parameters, mean, and variance of the batch normalization layer. This is the original output feature map of the k-th output channel of the (l+1)-th layer. It is the output feature map of the k-th output channel of the (l+1)-th layer affected by quantization. It is the output feature map of the i-th output channel of the l-th layer after pseudo-quantization. This is the original output feature map of the i-th output channel of the l-th layer. Considering that the input data and weights of the (l+1)-th layer are unaffected by the pseudo-quantization operation, the constraint term to reduce the pseudo-quantization loss is designed as follows:

[0065] ;

[0066] in, As the penalty factor, the scaling factor is obtained by finding the minimum point of the constraint term using the following formula. The cross-layer global optimal solution:

[0067] ;

[0068] .

[0069] 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.

[0070] 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:

[0071] Step S21: 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; wherein, the target convolutional layer is located in the last layer of the main branch in the preset multi-branch structure.

[0072] This embodiment mainly describes in detail the specific quantization and compression process when the target convolutional layer is located in the last layer of the main branch in a preset multi-branch structure.

[0073] Step S22: 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.

[0074] Step S23: Perform pseudo-quantization on the original weights based on the target quantization bits to obtain the target pseudo-quantized weights, and obtain the first output feature map of the target convolutional layer after performing convolution operation on the target pseudo-quantized weights, as well as obtain the target feature maps corresponding to the other branches.

[0075] 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 scaling coefficient 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.

[0076] Specifically, this application requires obtaining the first output feature map obtained after the target convolutional layer's weights have undergone target pseudo-quantization and then convolution, as well as obtaining the target feature maps corresponding to the remaining branches. That is, the output feature map is the direct result of convolution operations between the input feature map and the channel weights.

[0077] It should be noted that there are two types of multi-branch network structures in residual networks, namely the downsampling branch structure and the identity branch structure.

[0078] In one specific implementation, the preset multi-branch structure is a downsampling branch structure, and the remaining branches are downsampling branches. Correspondingly, obtaining the target feature maps corresponding to the remaining branches includes: determining the pseudo-quantized weight parameters corresponding to the downsampling branches; obtaining the second output feature map obtained after convolution of the downsampling branches with the pseudo-quantized weight parameters, and using the second output feature map as the target feature map. It can be understood that when the preset multi-branch structure is a downsampling branch structure, its network structure can specifically be as follows: Figure 4As shown, a convolutional layer (CONV) plus a batch normalization layer (BN) is considered as a convolutional unit. The downsampling branch structure consists of a main branch containing two convolutional units and a downsampling branch containing 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. In this embodiment, the target feature map corresponding to the downsampling branch is specifically the second output feature map obtained after the downsampling branch performs a convolution operation on the corresponding pseudo-quantized weight parameters.

[0079] The process of determining the pseudo-quantized weight parameters corresponding to the downsampling branch includes: performing pseudo-quantization on the original weights of the downsampling branch based on a preset initial bit to obtain an initial pseudo-quantization result; determining the quantization bit that matches the downsampling branch based on the original weights and the initial pseudo-quantization result, using a preset mapping function; and performing pseudo-quantization on the original weights of the downsampling branch based on the quantization bit that matches the downsampling branch to obtain the corresponding pseudo-quantized weight parameters. That is, this embodiment also requires inputting the original weights of the downsampling branch into the quantization bit selection module to determine the quantization bit that matches the downsampling branch, and then further performing pseudo-quantization on the original weights of the downsampling branch to obtain the corresponding pseudo-quantized weight parameters. This process is the same as the aforementioned process of solving for the target quantization bit that matches the target convolutional layer, and will not be repeated here.

[0080] In another specific implementation, the preset multi-branch structure is an identical branch structure, and the remaining branches are identical branches; correspondingly, obtaining the target feature maps corresponding to the remaining branches includes: obtaining the input feature maps of the identical branches, and using the input feature maps as the target feature maps. It can be understood that when the preset multi-branch structure is an identical branch structure, its network structure can specifically be 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. Therefore, the target feature map corresponding to the identity branch is actually the input feature map.

[0081] Step S24: Determine the scaling coefficient matrix based on the first output feature map, the target feature map, and the batch normalization layer statistical parameters corresponding to the target convolutional layer.

[0082] In this embodiment, the first output feature map is obtained by pseudo-quantization of the last target convolutional layer of the main branch, and the scaling coefficient matrix is ​​determined by the target feature maps of the other branches and the statistical parameters of the batch normalization layer corresponding to the target convolutional layer.

[0083] Specifically, the scaling factor matrix is ​​determined based on the first output feature map, the target feature map, and the batch normalization layer statistical parameters corresponding to the target convolutional layer. This includes: summing the first output feature map and the target feature map to obtain a first summation result, and using this first summation result as the first total feature map output by the preset multi-branch structure after pseudo-quantization; obtaining the second total feature map of the original output of the preset multi-branch structure; and determining the scaling factor matrix based on the first total feature map, the second total feature map, and the batch normalization layer statistical parameters corresponding to the target convolutional layer. In other words, this embodiment obtains the first total feature map output by the preset multi-branch structure after pseudo-quantization by summing the first output feature map and the target feature map, and obtains the second total feature map of the original output of the preset multi-branch structure (i.e., without pseudo-quantization). Then, the scaling factor matrix is ​​determined using the first total feature map, the second total feature map, and the batch normalization layer statistical parameters.

[0084] For example, when quantizing the last convolutional layer of the main branch in a downsampling branch structure, this application needs to obtain the total output feature map of the original downsampling branch structure. The total output feature map of the downsampling branch structure after pseudo-quantization , , It is a collection of pruned channels. It retains the set of channels. The total output feature map is the sum of the output feature maps of the main branch and the downsampling branch. Then, the scaling factor matrix is ​​solved using the statistical parameters of the last batch normalization layer of the main branch. In other words, the parameters required for quantization of the last convolutional layer in the main branch are: the statistical parameters of the last batch normalization layer in the main branch, the sum of the output feature maps of the last convolutional layer in the main branch and the downsampling branch, and the sum of the pseudo-quantized output feature map of the last convolutional layer in the main branch and the pseudo-quantized output feature map of the downsampling branch.

[0085] The scaling factor matrix is ​​determined based on the first total feature map, the second total feature map, and the batch normalization layer statistical parameters corresponding to the target convolutional layer. This includes: adjusting the first total feature map based on the batch normalization layer statistical parameters to obtain the adjusted first feature map result, and adjusting the second total feature map based on the batch normalization layer statistical parameters to obtain the adjusted second feature map result; calculating the bias compensation term of the batch normalization layer based on the batch normalization layer statistical parameters; and determining the scaling factor matrix based on the adjusted first feature map result, the adjusted second feature map result, the bias compensation term, and the preset penalty factor. In other words, referring to the aforementioned process for solving the scaling factor matrix corresponding to the non-last convolutional layer, it is only necessary to replace the weights in the formula with the total output feature map. Specifically, the first total feature map is used to replace the target pseudo-quantized weights, the second total feature map is used to replace the original weights, and then the corresponding scaling factor matrix is ​​calculated according to the aforementioned method.

[0086] Step S25: 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.

[0087] For more detailed processing of steps S22 and S25, please refer to the relevant content disclosed in the foregoing embodiments, which will not be repeated here.

[0088] As can be seen, in order to improve the applicability to different multi-branch network structures, this application specifically designs different quantization 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.

[0089] Furthermore, model pruning is a commonly used method for lightweighting networks, effectively reducing the number of parameters and computational cost. 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, after scaling the weights of the next adjacent convolutional layer of the target convolutional layer using the scaling factor matrix, the pruning process can still be performed, such as... Figure 6 and Figure 7 As shown, the specific steps include:

[0090] Step S31: 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.

[0091] In this embodiment, 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 specifically 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 .

[0092] 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. .

[0093] Step S32: 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.

[0094] 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.

[0095] 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.

[0096] 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.

[0097] 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.

[0098] 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.

[0099] 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.

[0100] Step S33: 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.

[0101] 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.

[0102] 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.

[0103] 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:

[0104] ;

[0105] 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.

[0106] 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.

[0107] 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.

[0108] Step S34: 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.

[0109] 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.

[0110] 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 8 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:

[0111] ;

[0112] 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.

[0113] 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.

[0114] Specifically, the weight parameters of the next adjacent convolutional layer can be adjusted according to the following formula:

[0115] ;

[0116] 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.

[0117] Furthermore, when the target convolutional layer is located at the last layer of the main branch in the preset multi-branch structure, the similarity between each retained channel in the retained channel set and the remaining output channels is calculated based on the channel weights, and a target mask matrix is ​​constructed based on the similarity calculation results. This includes: obtaining 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 convolution with their corresponding channel weights; based on the total output feature map, calculating 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 remaining output channels; and constructing the target mask matrix based on the feature map similarity. Correspondingly, 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. This includes: 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, the reconstruction coefficient matrix is ​​determined based on the target mask matrix and the least squares method.

[0118] Similarly, when the target convolutional layer is the last layer of the main branch in the 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. This embodiment requires first obtaining 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.

[0119] Furthermore, similar to the aforementioned weight calculation process, this application requires solving 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.

[0120] 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 identifying the retained channels that are closely related to 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 traditional pruning losing key features due to ignoring channel correlation, achieving the technical effect of significantly reducing the number of channels while maximizing the preservation of the original network feature expression capabilities. 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.

[0121] 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.

[0122] See Figure 9 As shown, embodiments of this application also provide a compression device for an image recognition network, the device comprising:

[0123] The first quantization module 11 is used to obtain the original weights of the target convolutional layer in the image recognition network, and to perform pseudo-quantization on the original weights based on the preset initial bits to obtain the initial pseudo-quantized weights.

[0124] The quantization bit determination module 12 is used to determine the target quantization bits that are compatible with the target convolutional layer based on the original weights and the initial pseudo-quantized weights and using a preset mapping function.

[0125] The second quantization module 13 is used to perform pseudo-quantization on the original weights based on the target quantization bits to obtain the target pseudo-quantized weights, and to 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.

[0126] The weight scaling module 14 is used to scale the weights of the next adjacent convolutional layer of the target convolutional layer using a scaling factor matrix to compensate for the quantization loss of the target convolutional layer.

[0127] 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.

[0128] 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.

[0129] 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.

[0130] 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.

[0131] 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.

[0132] 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.

[0133] 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.

[0134] 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.

[0135] 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: Obtain the original weights of the target convolutional layer in the image recognition network, and perform pseudo-quantization on the original weights based on a preset initial bit to obtain the initial pseudo-quantized weights; Based on the original weights and the initial pseudo-quantized weights, the target quantized bits that are compatible with the target convolutional layer are determined using a preset mapping function; Based on the target quantization bits, a pseudo-quantization operation is performed on the original weights to obtain the target pseudo-quantized weights, and the scaling coefficient matrix is ​​determined based on the target pseudo-quantized weights and the batch normalization layer statistical parameters corresponding to the target convolutional layer. The scaling factor matrix is ​​used to scale the weight parameters of the next adjacent convolutional layer of the target convolutional layer to compensate for the quantization loss of the target convolutional layer.

2. The compression method for image recognition networks according to claim 1, characterized in that, The step of determining the target quantization bits adapted to the target convolutional layer based on the original weights and the initial pseudo-quantized weights, and using a preset mapping function, includes: Calculate the ratio between the original weights and the initial pseudo-quantized weights; The ratio result is mapped to a pre-set target interval using a preset mapping function to obtain the corresponding mapping result; Based on the mapping result, the target quantization bits that are compatible with the target convolutional layer are determined.

3. The compression method for image recognition networks according to claim 1, characterized in that, 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, including: Obtain the batch normalized layer statistical parameters corresponding to the target convolutional layer; The original weights are adjusted based on the batch normalization layer statistical parameters to obtain a first weight adjustment result, and the target pseudo-quantized weights are adjusted based on the batch normalization layer statistical parameters to obtain a second weight adjustment result. The bias compensation term of the batch normalization layer is calculated based on the statistical parameters of the batch normalization layer. The scaling coefficient matrix is ​​determined based on the first weight adjustment result, the second weight adjustment result, the bias compensation term, and the preset penalty factor; The step of 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 includes: The scaling factor for each output channel is calculated based on the first weight adjustment result, the second weight adjustment result, the bias compensation term, and the preset penalty factor. The scaling factors are combined in the order of the output channels to obtain a scaling factor matrix.

4. The compression method for image recognition networks according to claim 3, characterized in that, The statistical parameters of the batch normalization layer include the weight parameters, bias parameters, mean, and variance of the batch normalization layer; Accordingly, the calculation of the bias compensation term for the batch normalization layer based on the statistical parameters of the batch normalization layer includes: Determine the target ratio between the weight parameter and the variance, and determine the product between the target ratio and the mean; The difference between the bias parameter and the product result is determined as the bias compensation term of the batch normalization layer; Accordingly, adjusting the original weights based on the batch normalization layer statistical parameters includes: The original weights are adjusted based on the target ratio; Accordingly, adjusting the target pseudo-quantized weights based on the batch normalization layer statistical parameters includes: The pseudo-quantized weights of the target are adjusted based on the target ratio.

5. The compression method for an image recognition network according to any one of claims 1 to 4, 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 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, including: Obtain the first output feature map obtained after the target convolutional layer is convolved with the weights after the target pseudo-quantization, and obtain the target feature maps corresponding to the remaining branches; The scaling factor matrix is ​​determined based on the first output feature map, the target feature map, and the batch normalization layer statistical parameters corresponding to the target convolutional layer.

6. The compression method for image recognition networks according to claim 5, characterized in that, The preset multi-branch structure is a downsampling branch structure, and the remaining branches are downsampling branches; Alternatively, the preset multi-branch structure is an identical branch structure, and the remaining branches are identical branches; Accordingly, obtaining the target feature maps corresponding to the remaining branches includes: Determine the pseudo-quantized weight parameters corresponding to the downsampling branch, obtain the second output feature map obtained after the downsampling branch is convolved by the pseudo-quantized weight parameters, and use the second output feature map as the target feature map; Alternatively, obtain the input feature map of the identity branch and use the input feature map as the target feature map.

7. The compression method for image recognition networks according to claim 6, characterized in that, The determination of the pseudo-quantized weight parameters corresponding to the downsampling branch includes: The original weights of the downsampling branch are pseudo-quantized based on the preset initial bits to obtain the initial pseudo-quantization result. Based on the original weights of the downsampling branch and the initial pseudo-quantization result, the quantization bits adapted to the downsampling branch are determined using the preset mapping function. The original weights of the downsampling branch are pseudo-quantized based on the quantization bits adapted to the downsampling branch, resulting in the corresponding pseudo-quantized weight parameters.

8. The compression method for image recognition networks according to claim 5, characterized in that, The process of determining the scaling factor matrix based on the first output feature map, the target feature map, and the batch normalization layer statistical parameters corresponding to the target convolutional layer includes: The first output feature map and the target feature map are summed to obtain a first summation result, and the first summation result is used as the first total feature map output by the preset multi-branch structure after pseudo-quantization; Obtain the second overall feature map of the original output of the preset multi-branch structure; The scaling factor matrix is ​​determined based on the first total feature map, the second total feature map, and the batch normalized layer statistical parameters corresponding to the target convolutional layer.

9. The compression method for image recognition networks according to claim 8, characterized in that, The scaling factor matrix is ​​determined based on the first total feature map, the second total feature map, and the batch normalized layer statistical parameters corresponding to the target convolutional layer, including: The first total feature map is adjusted based on the batch normalization layer statistical parameters to obtain the first feature map adjustment result, and the second total feature map is adjusted based on the batch normalization layer statistical parameters to obtain the second feature map adjustment result. The bias compensation term of the batch normalization layer is calculated based on the statistical parameters of the batch normalization layer. The scaling coefficient matrix is ​​determined based on the adjustment results of the first feature map, the adjustment results of the second feature map, the bias compensation term, and the preset penalty factor.

10. 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 9 when executing the computer program.

Citation Information

Patent Citations

  • Model compression method, image recognition method, product, equipment and medium

    CN119721168A

  • Compression method and apparatus for deep neural network model, and storage medium

    WO2021143070A1