Network model compression method, device and equipment and readable storage medium

By utilizing cosine similarity information in convolutional neural networks for model compression and generating candidate network models, the problems of large accuracy loss and high cost in existing technologies are solved, and efficient network model compression is achieved.

CN116090540BActive Publication Date: 2026-01-02CHINA MOBILE INFORMATION TECHNOLOGY CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211693995.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-28
Publication Date
2026-01-02
Estimated Expiration
2042-12-28

AI Technical Summary

Technical Problem

Existing technologies for compressing convolutional neural network models suffer from significant accuracy loss and require fine-tuning with the original training data, leading to increased time and operational costs.

Method used

By obtaining the convolutional layer weights of the network model to be compressed, using cosine similarity information to perform pre-defined model compression processing on multiple network models, generating candidate network models, and determining the target compressed network model based on cosine similarity information, fine-tuning of the original training data is avoided.

Benefits of technology

It achieves compression of visual algorithm models without increasing time and operational costs, with minimal loss of accuracy, while maintaining the model's efficient computational capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116090540B_ABST
    Figure CN116090540B_ABST
Patent Text Reader

Abstract

The application discloses a network model compression method and device, equipment and a readable storage medium. The method comprises the following steps: acquiring the weight of each convolution layer in a network model to be compressed; performing preset model compression processing on a target convolution layer of an nth network model in N network models respectively, to generate N first candidate network models; acquiring cosine similarity information between first identification data of the network model to preset image data and second identification data of each first candidate compression model to the preset image data; and determining a target compression network model according to the cosine similarity information. According to the embodiment of the application, the visual algorithm model composed of a large number of convolutional neural networks can be compressed without fine-tuning the original training data, and the precision loss is very small.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application belongs to the technical field of computer vision, and particularly relates to a network model compression method and device, equipment and a readable storage medium. BACKGROUND

[0002] Nowadays, convolutional neural networks have strong local information extraction capabilities and are widely used in advanced computer vision algorithm models. However, advanced vision algorithm models have high precision, but also involve a large number of convolutional neural networks, resulting in high model complexity and slow computing speed. Therefore, how to realize computing acceleration is very important for the deployment of vision algorithm models.

[0003] At present, computing acceleration is generally realized by compressing the size of the convolutional neural network, and the vision algorithm compression method mainly includes pruning and distillation. However, both of these two methods need to simplify the model structure to realize the compression of the model, and the simplification of the model structure will cause a significant loss of precision. If the original training data is used to train and fine-tune the simplified network to solve the problem of precision loss, the time cost and operation cost will be increased. SUMMARY

[0004] The embodiments of the present application provide a network model compression method, device, equipment and readable storage medium, which can compress the vision algorithm model composed of a large number of convolutional neural networks without fine-tuning the original training data, and the precision loss is very small.

[0005] In a first aspect, the embodiments of the present application provide a network model compression method, which comprises:

[0006] obtaining the weight of each convolutional layer in the network model to be compressed;

[0007] In the N network models, respectively, the nth layer target convolutional layer of the nth network model is subjected to a preset model compression processing, and N first candidate network models are generated;

[0008] obtaining the cosine similarity information between the first identification data of the network model to the preset image data and the second identification data of each first candidate compression model to the preset image data;

[0009] determining the target compression network model according to the cosine similarity information.

[0010] In some implementable manners of the first aspect, the target compression network model is determined according to the cosine similarity information, comprising:

[0011] determining the second candidate network model corresponding to each similarity data set according to the N cosine similarities in each similarity data set;

[0012] counting a number of times each of the first candidate network models is taken as a second candidate network model;

[0013] in a case where the cosine similarity of the second candidate network model corresponding to the maximum number is less than a preset threshold, taking the second candidate network model corresponding to the maximum number as a target compressed network model;

[0014] in a case where the cosine similarity of the second candidate network model corresponding to the maximum number is greater than or equal to the preset threshold, taking the second candidate network model corresponding to the maximum number as a network model to be compressed, and returning to perform the step of obtaining the weight of each convolutional layer in the network model to be compressed until the cosine similarity of the second candidate network model corresponding to the maximum number is less than the preset threshold, and taking the second candidate network model corresponding to the maximum number as the target compressed network model.

[0015] In some implementable manners of the first aspect, the obtaining of the cosine similarity information between the first recognition data of the network model on the preset image data and the second recognition data of each first candidate compressed model on the preset image data comprises:

[0016] generating the preset image data according to a preset data generation algorithm;

[0017] inputting each image data set into the network model and each first candidate compressed model respectively, and obtaining a similarity data set corresponding to each image data set through the first recognition data output by the network model and the second recognition data output by each first candidate compressed model.

[0018] calculating the cosine similarity between the first recognition data and each second recognition data in each similarity data set to obtain the cosine similarity information.

[0019] In some implementable manners of the first aspect, the obtaining of the weight of each convolutional layer in the network model to be compressed comprises:

[0020] obtaining model parameters corresponding to each convolutional layer in the network model;

[0021] calculating the model parameters of each convolutional layer according to a preset regular summation algorithm to obtain the weight of each convolutional layer.

[0022] In a second aspect, an embodiment of the present application provides a network model compression device, which comprises:

[0023] an obtaining module, configured to obtain the weight of each convolutional layer in the network model to be compressed and obtain the cosine similarity information between the first recognition data of the network model on the preset image data and the second recognition data of each first candidate compressed model on the preset image data;

[0024] The processing module is configured to perform preset model compression processing on the target convolutional layer of the nth network model in the N network models respectively, to generate N first candidate network models, and to determine the target compressed network model according to the cosine similarity information.

[0025] In some implementations of the second aspect, the processing module is further configured to determine a second candidate network model corresponding to each similarity data set according to the N cosine similarities in each similarity data set, to count a number of times that each first candidate network model in the N first candidate network models is used as a second candidate network model, and to use the second candidate network model corresponding to the maximum number of times as the target compressed network model if the cosine similarity of the second candidate network model corresponding to the maximum number of times is less than a preset threshold.

[0026] In some implementations of the second aspect, the processing module is further configured to use the second candidate network model corresponding to the maximum number of times as the network model to be compressed if the cosine similarity of the second candidate network model corresponding to the maximum number of times is greater than or equal to the preset threshold, and to return to performing the step of obtaining the weights of each convolutional layer in the network model to be compressed until the cosine similarity of the second candidate network model corresponding to the maximum number of times is less than the preset threshold, and to use the second candidate network model corresponding to the maximum number of times as the target compressed network model.

[0027] In a third aspect, the present application provides an electronic device, which comprises a processor and a memory storing computer program instructions; the processor implements the network model compression method in the first aspect or any implementation manner of the first aspect when executing the computer program instructions.

[0028] In a fourth aspect, the present application provides a computer readable storage medium, which stores computer program instructions; the computer program instructions are executed by a processor to implement the network model compression method in the first aspect or any implementation manner of the first aspect.

[0029] In a fifth aspect, the present application provides a computer program product, which comprises instructions; the instructions are executed by a processor of an electronic device to cause the electronic device to perform the network model compression method in the first aspect or any implementation manner of the first aspect.

[0030] The network model compression method, apparatus, device, and readable storage medium of this application embodiment can obtain the weights of each convolutional layer in the network model to be compressed, perform preset model compression processing on the nth target convolutional layer of the nth network model in N network models, generate N first candidate network models, and then obtain the cosine similarity information between the first recognition data of the network model on the preset image data and the second recognition data of each first candidate compressed model on the preset image data. Based on the cosine similarity information, the target compressed network model, i.e., the compressed network model, is determined. Since convolutional neural networks have extremely strong local information extraction capabilities, they are widely used in advanced computer vision algorithm models. Therefore, the network model compression method provided in this application embodiment, by leveraging the information extraction capabilities of convolutional neural networks and utilizing weight and similarity information, achieves compression of visual algorithm models. In this process, no fine-tuning of the original training data is required to compress visual algorithm models composed of a large number of convolutional neural networks, and the accuracy loss is very small. Attached Figure Description

[0031] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0032] Figure 1 This is a schematic flowchart of a network model compression method provided in an embodiment of this application;

[0033] Figure 2 This is a flowchart illustrating the specific implementation method of step S101;

[0034] Figure 3 This is a flowchart illustrating the specific implementation method of step S103;

[0035] Figure 4 This is a flowchart illustrating the specific implementation method of step S104;

[0036] Figure 5 This is a flowchart illustrating another network model compression method provided in an embodiment of this application;

[0037] Figure 6 This is a schematic diagram of the structure of a network model compression device provided in an embodiment of this application;

[0038] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0039] The features and exemplary embodiments of the various aspects of the present application will be described in detail below with reference to the drawings. For the purpose of clarity, the description is divided into the following sections: technical scheme, advantages, and specific embodiments. It should be understood that the specific embodiments described herein are intended to explain the principles of the present application, and are not intended to limit the present application. The present application can be implemented without some of the specific details described below. The following description of the embodiments is merely intended to provide a better understanding of the present application by showing examples of the present application.

[0040] It should be noted that, in this document, the terms such as first and second are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "contain" or any other variants thereof are intended to cover non-exclusive inclusion, so that a 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 a process, method, article or device. Without more limitations, the elements defined by the statement "include" do not exclude the presence of other identical elements in the process, method, article or device that includes the elements.

[0041] At present, the visual algorithm compression method mainly includes pruning and distillation. Pruning is a classic method to reduce the complexity of the model, which evaluates the importance of each neuron, removes the unimportant ones, and fine-tunes the entire network. Distillation is to transfer the generalization ability "knowledge" of the trained complex model to a simpler network, or to learn the "knowledge" in the complex model through a simple network. Whether pruning or distillation is used, the model compression is achieved by simplifying the model structure, and simplifying the model structure inevitably causes significant loss of accuracy.

[0042] The existing method to solve the problem of accuracy loss is to use the original training data to fine-tune the simplified network, but fine-tuning means training the neural network, which increases the time cost and operation cost, and the original training data is private, which is usually not provided by the user.

[0043] To solve the problem of the prior art, the embodiments of the present application provide a network model compression method, device, equipment and readable storage medium. First, the network model compression method provided by the embodiments of the present application will be introduced.

[0044] Figure 1 A flowchart of a network model compression method provided by an embodiment of the present application is shown. As shown in FIG. 1, the network model compression method provided by the embodiment of the present application includes the following steps. Figure 1As shown, the method can include the following steps:

[0045] S101, obtaining the weight of each convolutional layer in the network model to be compressed;

[0046] S102, in N network models, respectively, the nth network model is the nth layer target convolutional layer, and the preset model compression processing is generated N first candidate network models;

[0047] S103, obtaining the cosine similarity information between the first identification data of the network model to the preset image data and the second identification data of each first candidate compression model to the preset image data;

[0048] S104, according to the cosine similarity information, determine the target compression network model.

[0049] Therefore, according to the network model compression method provided by the embodiment of the application, the weight of each convolutional layer in the network model to be compressed is obtained, and in N network models, the nth network model is the nth layer target convolutional layer, and the preset model compression processing is generated N first candidate network models, then according to the cosine similarity information between the first identification data of the network model to the preset image data and the second identification data of each first candidate compression model to the preset image data, the target compression network model is determined. In this process, with the help of the information extraction ability of convolutional neural network, the weight and similarity information are used, without the need to fine-tune the original training data, the visual algorithm model composed of a large number of convolutional neural networks can be compressed, and the precision loss is very small.

[0050] The specific implementation of each step is introduced below.

[0051] In some embodiments, in S101, the network model to be compressed contains different convolutional layers, and the influence weight of each convolutional layer on the network model needs to be evaluated, therefore, the weight of each convolutional layer in the network model to be compressed needs to be obtained first.

[0052] As an example, in order to obtain the weight of each convolutional layer in the network model to be compressed, as shown in Figure 2 As shown, the above S101 can include the following steps:

[0053] S1011, obtaining the model parameters corresponding to each convolutional layer in the network model;

[0054] S1012, according to the preset regular summation algorithm, the model parameters of each convolutional layer are calculated to obtain the weight of each convolutional layer.

[0055] In S1011, the convolution layer corresponding model parameters can include a coefficient of a learning rate, an output channel number of a convolution kernel, a size of the convolution kernel, a step of the convolution kernel, an expansion edge, a weight initialization method, whether to enable a bias term, an initialization of the bias term, grouping, and an input channel number.

[0056] In S1012, as an example, the preset regular sum algorithm is an L1 regularization sum algorithm, i.e., summing the absolute values of each element in the weight vector, performing L1 regularization on each convolution layer, and obtaining the weight of each convolution layer.

[0057] Thus, the L1 regularization sum algorithm can accurately evaluate the influence weight of each convolution layer in the network model to be compressed.

[0058] In some embodiments, in S102, the network model includes a plurality of convolution layers. Since the convolution layer is a high-order tensor, the convolution layer can be decomposed by low-rank approximation to compress the network model. Optionally, Tucker decomposition is used to decompose the convolution layer. Tucker decomposition is a high-order principal component analysis, which is represented as decomposing a tensor into a core tensor and a product of a corresponding matrix in each dimension. As an example, for a three-order tensor, Tucker decomposition can obtain three factor matrices and a core tensor. The factor matrix in each dimension is a basis matrix or a principal component of the tensor in each dimension.

[0059] As an example, since the matrix HOSVD is based on the idea of finding a matrix that can well capture the changes in the dimension and is not affected by other dimensions, the matrix HOSVD is used to initialize the high-order tensor of the target convolution layer. Although HOSVD cannot guarantee the optimal fitting of Tucker decomposition, the result can be a good iteration starting point for the iterative alternating least squares ALS. The iterative algorithm HOOI is an ALS algorithm that decomposes the tensor as an optimization process and iteratively obtains the decomposition result.

[0060] After decomposing and compressing the convolution layer, the structure of the original network model changes, and the L1 regularization sum algorithm in S101 cannot be used to evaluate the influence weight of the convolution layer. Therefore, a method for automatically constructing training data to evaluate the influence weight of the convolution layer is needed.

[0061] In some embodiments, in S103, the first identification data refers to the output tensor of the original model, the second identification data refers to the output tensor of the candidate compressed model, the image data set refers to each data, and the preset image data refers to a batch of input data randomly initialized. As an example, in order to obtain the cosine similarity information between the first identification data of the network model to the preset image data and the second identification data of each first candidate compressed model to the preset image data, as shown in Figure 3 S103 can include the following steps:

[0062] S1031, generating the preset image data according to the preset data generation algorithm;

[0063] S1032, inputting each image data set into the network model and each first candidate compressed model respectively, and obtaining the similarity data set corresponding to each image data set through the first identification data output by the network model and the second identification data output by each first candidate compressed model;

[0064] S1033, calculating the cosine similarity of the first identification data and each second identification data in each similarity data set to obtain the cosine similarity information.

[0065] As an example, in S1031, since the user's training data cannot be obtained, the training data is automatically constructed to evaluate the influence weight of the convolution layer. Optionally, a batch of input data is randomly initialized as the preset image data.

[0066] As an example, in S1032, the similarity data set includes a plurality of cosine similarities corresponding to the data. Each input data is input into the original network model and the candidate compressed model respectively, and the output tensor of the original network model and the output tensor of the candidate compressed model can be obtained.

[0067] As an example, in S1033, the cosine similarity information includes all the cosine similarities. Based on the output tensor of the original network model and the output tensor of the candidate compressed model obtained in S1032, the cosine similarity of the candidate compressed model and the output tensor of the original model is calculated.

[0068] Since the user's training data cannot be obtained, a batch of input data is randomly initialized. Based on the performance on the constructed input image data, it is selected which layer of convolution layer to perform low-rank decomposition on the high-order tensor. Thus, the cosine similarity information between the first identification data of the network model to the preset image data and the second identification data of each first candidate compressed model to the preset image data can be accurately obtained.

[0069] In order to ensure the uniqueness of the compression model and reduce the variance of the output result, a batch data voting method can be used to construct batch_size data. If the highest similarity compression model is found for each data, the vote number is increased by one. Finally, the vote number of each model is counted for all batch_size data, and the model with the highest vote number is output as the final output compression model. batch_size is a model hyperparameter, which represents the number of data samples passed to the program for training at a time. Setting batch_size can reduce memory usage and improve training speed. The larger the batch_size, the smaller the variance of the output result, and the more reliable the output result.

[0070] In some embodiments, in S104, the cosine similarity information includes a preset number of similarity data sets, and each similarity data set includes N cosine similarities. As an example, in order to determine the target compression network model, as shown in Figure 4 S104 can include the following steps:

[0071] S1041, determining a second candidate network model corresponding to each similarity data set according to the N cosine similarities in each similarity data set;

[0072] S1042, counting the number of times that each first candidate network model is used as a second candidate network model in the N first candidate network models;

[0073] S1043, in the case that the cosine similarity of the second candidate network model corresponding to the maximum number of times is less than a preset threshold, the second candidate network model corresponding to the maximum number of times is used as the target compression network model.

[0074] In S1041, based on the calculated multiple cosine similarities in each similarity data set, the network compression model with the highest similarity is selected as the second candidate network model.

[0075] In S1042, the number of times refers to the number of votes for each model. In order to determine the final target compression network model, the number of votes for each first candidate network model as a second candidate network model in the multiple first candidate network models needs to be counted.

[0076] In S1043, if the cosine similarity of the second candidate network model corresponding to the maximum number of times is less than the preset threshold, it indicates that the accuracy loss of the current network compression model has exceeded the predetermined range, and the process of compressing the network model is stopped. The current network compression model is output, and the current network compression model is determined as the target compression network model, that is, the compression of the network model is completed.

[0077] Therefore, based on the method of automatically constructing training data to evaluate the convolution layer influence weight, the problem that the original regular summation algorithm cannot be used to evaluate the convolution layer influence weight due to the change of the network model structure after the convolution layer is decomposed and compressed is effectively solved.

[0078] It should be noted that the compressed convolution layer of the candidate model with high similarity can still clearly capture the information in the original image after compression, while the compressed convolution layer of the candidate model with low similarity cannot do so. Therefore, Figure 5 A flowchart of another network model compression method provided by an embodiment of the application is shown.

[0079] In a case where the cosine similarity of the second candidate network model corresponding to the maximum number is greater than or equal to the preset threshold, it is indicated that the accuracy loss of the current network model is small, and therefore the method can return to perform S101 to continue the loop of the network model compression method. As shown in Figure 5 After S1042, the method can further include the following steps:

[0080] S1044, determining whether the cosine similarity of the second candidate network model corresponding to the maximum number is less than the preset threshold;

[0081] S1045, in a case where the cosine similarity of the second candidate network model corresponding to the maximum number is less than the preset threshold, taking the second candidate network model corresponding to the maximum number as a target compressed network model;

[0082] S1046, in a case where the cosine similarity of the second candidate network model corresponding to the maximum number is greater than or equal to the preset threshold, taking the second candidate network model corresponding to the maximum number as a network model to be compressed, and returning to perform S101 until the cosine similarity of the second candidate network model corresponding to the maximum number is less than the preset threshold, and taking the second candidate network model corresponding to the maximum number as the target compressed network model.

[0083] In some embodiments, in S1044, it is necessary to determine the size relationship between the cosine similarity of the second candidate network model corresponding to the maximum number and the preset threshold, so as to determine whether to take the current second candidate network model as a target compressed network model, stop the loop compression process, or continue the loop compression process.

[0084] In some embodiments, in S1045, when the cosine similarity of the second candidate network model corresponding to the maximum number is less than the preset threshold, it is indicated that the accuracy loss of the current compressed model has exceeded the predetermined range, and therefore it is necessary to stop the loop of the network model compression method and output the second candidate network model corresponding to the maximum number as the target compressed network model.

[0085] In some embodiments, in S1046, when the cosine similarity of the second candidate network model corresponding to the maximum number of times is greater than or equal to the preset threshold, it indicates that the accuracy loss of the current compressed model is small, and has not exceeded the predetermined range, and the current network model can continue to be compressed, so return to step S101, continue the loop compression process, until the cosine similarity of the second candidate network model corresponding to the maximum number of times is less than the preset threshold, end the network model compression process, and output the current network model as the target compressed network model.

[0086] Thus, by judging the size relationship between the cosine similarity of the second candidate network model corresponding to the maximum number of times and the preset threshold, it is determined whether to continue to compress the current network model or to stop the loop compression process of the network model, thereby completing the compression of the network model.

[0087] It should be noted that the application scenarios described in the above embodiments of the application are for more clearly explaining the technical solutions of the embodiments of the application, and do not constitute a limitation on the technical solutions provided by the embodiments of the application. It is known to those skilled in the art that with the emergence of new application scenarios, the technical solutions provided by the embodiments of the application are also applicable to similar technical problems.

[0088] Based on the same inventive concept, the application also provides a network model compression device 600 corresponding to the above network model compression method. The specific combination Figure 6 will be described in detail.

[0089] Figure 6 is a structural schematic diagram of a network model compression device provided by an embodiment of the application, as Figure 6 shown, the network model compression device 600 can include:

[0090] The acquisition module 610 is configured to acquire the weights of each convolutional layer in the network model to be compressed, and acquire the cosine similarity information between the first recognition data of the network model to the preset image data and the second recognition data of each first candidate compressed model to the preset image data.

[0091] The processing module 620 is configured to perform preset model compression processing on the nth target convolutional layer of the nth network model in the N network models, respectively, to generate N first candidate network models, and determine a target compressed network model according to the cosine similarity information.

[0092] Thus, by the network model compression device provided in the embodiments of the present application, the weights of each convolutional layer in the network model to be compressed are obtained, and the preset model compression processing is respectively performed on the nth layer target convolutional layer of the nth network model in the N network models, to generate N first candidate network models, and then the cosine similarity information between the first identification data of the preset image data obtained by the network model and the second identification data of the preset image data obtained by each first candidate compression model is determined to determine the target compression network model. Without the need of fine-tuning on the original training data, by means of the information extraction capability of the convolutional neural network, the visual algorithm model composed of a large number of convolutional neural networks can be compressed according to the weight similarity information, and the precision loss is very small.

[0093] The network model compression device 600 is described in detail as follows.

[0094] In some embodiments, in order to obtain the weights of each convolutional layer in the network model to be compressed, the obtaining module 610 can include the following units:

[0095] The obtaining unit is configured to obtain the model parameters corresponding to each convolutional layer in the network model.

[0096] The first calculating unit is configured to calculate the model parameters of each convolutional layer according to a preset regular summation algorithm, to obtain the weights of each convolutional layer.

[0097] In some embodiments, in order to obtain the cosine similarity information between the first identification data of the preset image data obtained by the network model and the second identification data of the preset image data obtained by each first candidate compression model, the obtaining module 610 can further include the following units:

[0098] The generating unit is configured to generate the preset image data according to a preset data generation algorithm.

[0099] The input unit is configured to input each image data set into the network model and each first candidate compression model respectively, and obtain the similarity data set corresponding to each image data set through the first identification data output by the network model and the second identification data output by each first candidate compression model.

[0100] The second calculating unit is configured to calculate the cosine similarity between the first identification data and the second identification data in each similarity data set, to obtain the cosine similarity information.

[0101] In some embodiments, in order to determine the target compression network model according to the cosine similarity information, the processing module 620 can include the following units:

[0102] The determining unit is configured to determine a second candidate network model corresponding to each similarity data set according to N cosine similarities in each similarity data set.

[0103] The statistical unit is configured to count a number of times that each first candidate network model in the N first candidate network models is used as a second candidate network model.

[0104] The first processing unit is configured to use the second candidate network model corresponding to the maximum number of times as the target compressed network model in a case where the cosine similarity of the second candidate network model corresponding to the maximum number of times is less than the preset threshold.

[0105] The second processing unit is configured to use the second candidate network model corresponding to the maximum number of times as the network model to be compressed in a case where the cosine similarity of the second candidate network model corresponding to the maximum number of times is greater than or equal to the preset threshold, and return to execute the step of obtaining the weight of each convolution layer in the network model to be compressed until the cosine similarity of the second candidate network model corresponding to the maximum number of times is less than the preset threshold, and use the second candidate network model corresponding to the maximum number of times as the target compressed network model.

[0106] It can be understood that the network model compression apparatus 600 of the embodiments of the present application can correspond to the execution subject of the network model compression method provided by the embodiments of the present application. The specific details of the operations and / or functions of each module / unit of the network model compression apparatus 600 can be referred to the description of the corresponding part in the network model compression method provided by the embodiments of the present application. For the sake of brevity, it will not be repeated here.

[0107] Figure 7 A hardware structure schematic diagram of an electronic device provided by the embodiments of the present application is shown. As shown in the figure, the electronic device 700 can include a processor 701 and a memory 702 storing computer program instructions. Figure 7

[0108] Specifically, the processor 701 described above can include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or can be configured to implement one or more integrated circuits of the embodiments of the present application.

[0109] ​The memory 702 can include mass storage for information or instructions. By way of example, and not limitation, the memory 702 can include a hard disk drive (HDD), a floppy disk drive, flash memory, an optical disc, a magneto-optical disc, magnetic tape, or a Universal Serial Bus (USB) drive or a combination of two or more of these. In one example, the memory 702 can include removable or non-removable (or fixed) media, where the memory 702 is nonvolatile solid-state memory. The memory 702 can be internal or external to the electronic device 700.

[0110] The memory 702 can include read-only memory (ROM), random-access memory (RAM), magnetic disk storage mediums, optical storage mediums, flash memory devices, electrical, optical, or other physical / tangible memory storage devices. Accordingly, generally, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., a memory device) encoded with software that, when executed (by one or more processors), is operable to perform operations described with reference to the network model compression method according to the first aspect of the present application.

[0111] The processor 701 implements the network model compression method described in the embodiments of the present application by reading and executing computer program instructions stored in the memory 702, and achieves the corresponding technical effects achieved by the embodiments of the present application in executing the method. For brevity, the description is not repeated here.

[0112] In one example, the electronic device 700 can also include a communication interface 703 and a bus 704. As shown, the processor 701, the memory 702, and the communication interface 703 are connected through the bus 704 and complete communication among each other. Figure 7

[0113] The communication interface 703 is mainly used to realize the communication between the modules, devices, units and / or equipment in the embodiments of the present application.

[0114] ​Bus 704 includes hardware, software, or both, to couple components of electronic device 700 to each other and to couple electronic device 700 to other systems or devices. While Fig. 7 shows bus 704 as a single component, bus 704 can be composed of multiple buses or separate communication lines, which are viewed conventionally as a bus. Also, while Fig. 7 shows bus 704 as a single component, bus 704 could be implemented using multiple different buses or separate communication lines, which are viewed conventionally as a bus. In some embodiments, bus 704 can include one or more busses, such as an Accelerated Graphics Port (AGP) or other graphics bus, an Extended Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an InfiniBand interconnect, a Low Pin Count (LPC) bus, a memory bus, a Micro Channel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association local (VLB) bus, or another suitable bus or a combination of two or more of these. Where appropriate, bus 704 can be used to implement communication between components over the network.

[0115] Electronic device 700 can perform the network model compression method in the embodiments of the present application, thereby achieving the corresponding technical effects of the network model compression method described in the embodiments of the present application.

[0116] In addition, in combination with the network model compression method in the above embodiments, the embodiments of the present application can provide a readable storage medium to implement. The readable storage medium has computer program instructions stored thereon; the computer program instructions are executed by a processor to implement any one of the network model compression methods in the above embodiments. Examples of the readable storage medium can be non-transitory machine-readable media, such as electronic circuits, semiconductor memory devices, Read-Only Memory (ROM), floppy disks, Compact Disc Read-Only Memory (CD-ROM), optical disks, hard disks, etc.

[0117] It needs to be clear that the present application is not limited to the specific configurations and processes described above and shown in the drawings. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method processes of the present application are not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between steps, after understanding the spirit of the present application.

[0118] The functions indicated in the structural block diagrams described above can be implemented as hardware, software, firmware, or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, and the like. When implemented in software, the elements of the present application are program or code segments that are used to perform the required tasks. The program or code segments can be stored in a machine-readable medium or transmitted through a data signal carried in a carrier wave over a transmission medium or communication link. The "machine-readable medium" can include any medium that can store or transfer information. Examples of the machine-readable medium include an electronic circuit, a semiconductor memory device, a read-only memory (ROM), a flash memory, an erasable read-only memory (EROM), a floppy diskette, a compact disk read-only memory (CD-ROM), an optical disk, a hard disk, a fiber optic medium, a radio frequency (RF) link, and the like. The code segments can be downloaded via computer networks such as the Internet, an intranet, and the like.

[0119] It is also noted that the examples mentioned in the present application describe some methods or systems based on a series of steps or devices. However, the present application is not limited to the order of the steps mentioned in the examples, that is, the steps can be performed in the order mentioned in the examples, or in an order different from the examples, or several steps can be performed simultaneously.

[0120] The above-described aspects and implementations of the present application can be embodied in a specific way. For example, the above-described aspects and implementations of the present application can be implemented in hardware, software, firmware or a combination thereof. The functions indicated in the structural block diagrams described above can be implemented as hardware, software, firmware, or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, and the like. When implemented in software, the elements of the present application are program or code segments that are used to perform the required tasks. The program or code segments can be stored in a machine-readable medium or transmitted through a data signal carried in a carrier wave over a transmission medium or communication link. The "machine-readable medium" can include any medium that can store or transfer information. Examples of the machine-readable medium include an electronic circuit, a semiconductor memory device, a read-only memory (ROM), a flash memory, an erasable read-only memory (EROM), a floppy diskette, a compact disk read-only memory (CD-ROM), an optical disk, a hard disk, a fiber optic medium, a radio frequency (RF) link, and the like. The code segments can be downloaded via computer networks such as the Internet, an intranet, and the like.

[0121] The above merely describes a specific implementation of the present application. Those skilled in the art can clearly understand the specific working processes of the system, modules and units described above for the convenience and brevity of description, and can refer to the corresponding processes in the foregoing method embodiments, which will not be described herein again. It should be understood that the protection scope of the present application is not limited to this, and any person skilled in the art can easily think of various equivalent modifications or replacements within the technical range disclosed by the present application, and these modifications or replacements should be covered within the protection scope of the present application.

Claims

1. A network model compression method, characterized in that, The method includes: Obtain the weights of each convolutional layer in the network model to be compressed, wherein the network model includes M convolutional layers, and M is an integer greater than 1; In the N network models, the nth target convolutional layer of the nth network model is subjected to preset model compression processing to generate N first candidate network models, where 1≤n≤N≤M, N is a positive integer, and the target convolutional layer is the convolutional layer corresponding to the largest N weights among the M convolutional layers. Obtain the cosine similarity information between the first recognition data of the network model for the preset image data and the second recognition data of each first candidate network model for the preset image data. The preset image data is generated according to a preset data generation algorithm. The first recognition data refers to the output tensor of the original model and the second recognition data refers to the output tensor of the candidate network model. Based on the cosine similarity information, the target compression network model is determined.

2. The method according to claim 1, characterized in that, The cosine similarity information includes a preset number of similarity datasets, each of which includes N cosine similarities. The step of determining the target compression network model based on the cosine similarity information includes: Based on N cosine similarities in each similarity dataset, a second candidate network model is determined for each similarity dataset, wherein the second candidate network model is the network model corresponding to the largest cosine similarity in the similarity dataset; Count the number of times each of the N first candidate network models is used as a second candidate network model; If the cosine similarity of the second candidate network model corresponding to the highest number of occurrences is less than a preset threshold, the second candidate network model corresponding to the highest number of occurrences is selected as the target compressed network model.

3. The method according to claim 2, characterized in that, The method further includes: If the cosine similarity of the second candidate network model corresponding to the highest number of occurrences is greater than or equal to the preset threshold, the second candidate network model corresponding to the highest number of occurrences is used as the network model to be compressed, and the step of obtaining the weights of each convolutional layer in the network model to be compressed is returned to be executed until the cosine similarity of the second candidate network model corresponding to the highest number of occurrences is less than the preset threshold, and the second candidate network model corresponding to the highest number of occurrences is used as the target compressed network model.

4. The method according to claim 2, characterized in that, The step of obtaining the cosine similarity information between the first recognition data of the network model for the preset image data and the second recognition data of each of the first candidate network models for the preset image data includes: According to a preset data generation algorithm, preset image data is generated, wherein the preset image data includes the preset number of image datasets; Each image dataset is input into the network model and each of the first candidate network models respectively, and the similarity dataset corresponding to each image dataset is obtained by using the first recognition data output by the network model and the second recognition data output by each of the first candidate network models. Calculate the cosine similarity between the first identification data and each second identification data in each similarity dataset to obtain the cosine similarity information.

5. The method according to claim 4, characterized in that, The process of obtaining the weights of each convolutional layer in the network model to be compressed includes: Obtain the model parameters corresponding to each convolutional layer in the network model; The model parameters of each convolutional layer are calculated according to a preset regular summation algorithm to obtain the weights of each convolutional layer.

6. A network model compression device, characterized in that, The device includes: The acquisition module is used to acquire the weights of each convolutional layer in the network model to be compressed, wherein the network model includes M convolutional layers, and M is an integer greater than 1; The processing module is used to perform preset model compression processing on the nth target convolutional layer of the nth network model in N network models to generate N first candidate network models, where 1≤n≤N≤M, N is a positive integer, and the target convolutional layer is the convolutional layer corresponding to the largest N weights among the M convolutional layers; The acquisition module is further configured to acquire cosine similarity information between the first recognition data of the network model for the preset image data and the second recognition data of each first candidate network model for the preset image data. The preset image data is generated according to a preset data generation algorithm. The first recognition data refers to the output tensor of the original model, and the second recognition data refers to the output tensor of the candidate network model. The processing module is further configured to determine the target compressed network model based on the cosine similarity information.

7. The apparatus according to claim 6, characterized in that, The cosine similarity information includes a preset number of similarity datasets, and each similarity dataset includes N cosine similarities; The processing module is further configured to determine a second candidate network model corresponding to each similarity dataset based on N cosine similarities in each similarity dataset, wherein the second candidate network model is the network model corresponding to the largest cosine similarity in the similarity dataset; The processing module is also used to count the number of times each of the N first candidate network models is used as a second candidate network model; The processing module is further configured to use the second candidate network model corresponding to the largest number of times as the target compressed network model if the cosine similarity of the second candidate network model corresponding to the largest number of times is less than a preset threshold.

8. The apparatus according to claim 7, characterized in that, The device further includes: The processing module is further configured to, if the cosine similarity of the second candidate network model corresponding to the largest number of times is greater than or equal to the preset threshold, use the second candidate network model corresponding to the largest number of times as the network model to be compressed, and return to execute the step of obtaining the weights of each convolutional layer in the network model to be compressed, until the cosine similarity of the second candidate network model corresponding to the largest number of times is less than the preset threshold, and use the second candidate network model corresponding to the largest number of times as the target compressed network model.

9. An electronic device, characterized in that, The device includes: a processor, and a memory storing computer program instructions; The processor reads and executes the computer program instructions to implement the network model compression method as described in any one of claims 1-5.

10. A readable storage medium, characterized in that, The readable storage medium stores computer program instructions, which, when executed by a processor, implement the network model compression method as described in any one of claims 1-5.

Citation Information

Patent Citations

  • Convolutional neural network compression method based on Tacker decomposition and principal component analysis

    CN110032951A

  • Compressed representation learning method based on tensor decomposition

    CN111340186A