A method, apparatus and storage medium for compressing network models

By optimizing the compression method of the network model layer by layer, and combining accuracy and compression ratio, the problem of low compression effect in the existing technology is solved, and more efficient resource utilization and model accuracy are achieved.

CN116258169BActive Publication Date: 2026-04-03HANGZHOU HIKVISION DIGITAL TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-08
Publication Date
2026-04-03

AI Technical Summary

Technical Problem

In existing technologies, compression methods for deep learning network models fail to fully consider the differences between network layers, resulting in low compression efficiency and high resource consumption.

Method used

By following a preset compression order, the current network layer to be compressed is determined from the network model, and compression is performed for each preset compression method. Combining the accuracy and/or compression ratio of the compressed network model, the optimal compression method is determined, and the compression process is optimized layer by layer.

Benefits of technology

It improves the compression effect of the network model, fully considers the differences between each network layer, reduces resource consumption, and ensures the accuracy and efficiency of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116258169B_ABST
    Figure CN116258169B_ABST
Patent Text Reader

Abstract

This application provides a network model compression method, apparatus, and storage medium, relating to the field of deep learning technology. The method involves determining the current network layer to be compressed from the network model according to a preset compression order; for each preset compression method, compressing the current network layer according to that method to obtain the compressed network model corresponding to that preset compression method; wherein, in the compressed network model, other network layers are obtained by compressing them according to their respective determined optimal compression methods; based on the accuracy and / or compression ratio of the corresponding compressed network model, determining the optimal compression method for the current network layer to be compressed from each preset compression method, and returning to execute the step of determining the current network layer to be compressed from each network layer according to the preset compression order, until the optimal compression method for each network layer is determined. Based on this, the compression effect can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of deep learning technology, and in particular to a method, apparatus and storage medium for compressing network models. Background Technology

[0002] With the rapid development of deep learning technology, functions such as object detection and object classification can be achieved based on deep learning network models.

[0003] For edge devices, the limited storage space is the biggest bottleneck for the application of deep learning network models. Therefore, in order to enable edge devices to effectively run deep learning network models for data processing, the deep learning network models can be compressed.

[0004] In related technologies, the entire deep learning network model is compressed uniformly according to a preset compression method. However, due to the high complexity of deep learning network models, this compression method is not very effective, and the compressed data still occupies a significant amount of resources. Summary of the Invention

[0005] The purpose of this application is to provide a network model compression method, apparatus, and storage medium to improve compression performance. The specific technical solution is as follows:

[0006] Firstly, in order to achieve the above objectives, embodiments of this application disclose a network model compression method, the method comprising:

[0007] According to the preset compression order, determine the network layer to be compressed from the network model;

[0008] For each preset compression method, the network layer to be compressed is compressed according to the preset compression method to obtain the compressed network model corresponding to the preset compression method; wherein, in the compressed network model, other network layers are obtained by compressing them according to their respective determined optimal compression methods;

[0009] Based on the accuracy and / or compression ratio of the corresponding compressed network model, determine the optimal compression method for the current network layer to be compressed from each preset compression method, and return to execute the step of determining the current network layer to be compressed from each network layer according to the preset compression order, until the optimal compression method for each network layer is determined.

[0010] Optionally, the preset compression methods include lossless compression.

[0011] The step of determining the optimal compression method for the current network layer to be compressed from among various preset compression methods based on the accuracy and / or compression ratio of the corresponding compressed network model includes:

[0012] Based on the compression ratio of the corresponding compressed network model, the compression method with the highest compression ratio is determined from each preset compression method and used as the candidate compression method;

[0013] If the alternative compression method is a lossless compression method, then the alternative compression method is determined as the optimal compression method for the current network layer to be compressed.

[0014] Optionally, each preset compression method also includes a lossy compression method; the method further includes:

[0015] If the candidate compression method is a lossy compression method, determine whether the accuracy of the compressed network model corresponding to the candidate compression method is greater than a preset accuracy threshold.

[0016] If the accuracy of the compressed network model corresponding to the candidate compression method is greater than the preset accuracy threshold, then the candidate compression method is determined as the optimal compression method for the current network layer to be compressed.

[0017] Optionally, the method further includes:

[0018] If the accuracy of the compressed network model corresponding to the candidate compression method is not greater than the preset accuracy threshold, then the lossless compression method with the highest compression ratio of the corresponding compressed network model is determined as the optimal compression method for the current network layer to be compressed.

[0019] Optionally, the lossless compression method includes Huffman coding compression and / or sparse matrix compression; the lossy compression method includes quantization compression and / or shift compression.

[0020] Optionally, the method further includes:

[0021] The network layer is compressed according to the optimal compression method to obtain the compressed network model, and the optimal compression method of each network layer is marked in the compressed network model.

[0022] Secondly, in order to achieve the above objectives, embodiments of this application disclose a network model compression device, the device comprising:

[0023] The network layer determination module is used to determine the current network layer to be compressed from each network layer according to a preset compression order.

[0024] The compression module is used to compress the network layer to be compressed according to each preset compression method to obtain the compressed network model corresponding to the preset compression method; wherein, in the compressed network model, other network layers are obtained by compressing them according to their respective determined optimal compression methods;

[0025] The first optimal compression method determination module is used to determine the optimal compression method of the current network layer to be compressed from each preset compression method according to the accuracy and / or compression ratio of the corresponding compressed network model, and trigger the network layer determination module until the optimal compression method of each network layer is determined.

[0026] Optionally, the preset compression methods include lossless compression.

[0027] The first optimal compression method determination module includes:

[0028] The alternative compression method determination submodule is used to determine the compression method with the highest compression ratio from each preset compression method according to the compression ratio of the corresponding compressed network model, and use it as the alternative compression method.

[0029] The optimal compression method determination submodule is used to determine the candidate compression method as the optimal compression method for the current network layer to be compressed if the candidate compression method is a lossless compression method.

[0030] Optionally, each preset compression method also includes a lossy compression method; the device further includes:

[0031] The judgment module is used to determine whether the accuracy of the compressed network model corresponding to the candidate compression method is greater than a preset accuracy threshold if the candidate compression method is a lossy compression method.

[0032] The second optimal compression method determination module is used to determine the candidate compression method as the optimal compression method for the current network layer to be compressed if the accuracy of the compressed network model corresponding to the candidate compression method is greater than the preset accuracy threshold.

[0033] Optionally, the device further includes:

[0034] The third optimal compression method determination module is used to determine the lossless compression method with the highest compression ratio of the corresponding compressed network model as the optimal compression method for the current network layer to be compressed if the accuracy of the compressed network model corresponding to the candidate compression method is not greater than the preset accuracy threshold.

[0035] Optionally, the lossless compression method includes Huffman coding compression and / or sparse matrix compression; the lossy compression method includes quantization compression and / or shift compression.

[0036] Optionally, the device further includes:

[0037] The network model generation module is used to compress each network layer according to the optimal compression method to obtain the compressed network model, and to mark the optimal compression method of each network layer in the compressed network model.

[0038] In another aspect of this application, in order to achieve the above objectives, an embodiment of this application also discloses an electronic device, which includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;

[0039] The memory is used to store computer programs;

[0040] When the processor executes the program stored in the memory, it implements the network model compression method as described in the first aspect above.

[0041] In another aspect of this application, a computer-readable storage medium is provided, wherein instructions are stored therein, which, when executed on a computer, implement the network model compression method as described in the first aspect above.

[0042] In another aspect of this application, embodiments of this application also provide a computer program product containing instructions that, when run on a computer, cause the computer to perform the network model compression method described in the first aspect above.

[0043] This application provides a network model compression method, which can determine the current network layer to be compressed from the network model according to a preset compression order; for each preset compression method, the current network layer to be compressed is compressed according to the preset compression method to obtain the compressed network model corresponding to the preset compression method; wherein, in the compressed network model, other network layers are obtained by compressing them according to their respective determined optimal compression methods; according to the accuracy and / or compression ratio of the corresponding compressed network model, the optimal compression method of the current network layer to be compressed is determined from each preset compression method, and the process returns to execute the step of determining the current network layer to be compressed from each network layer according to the preset compression order until the optimal compression method of each network layer is determined.

[0044] Based on the above processing, for each network layer, the optimal compression method can be determined by combining the accuracy and / or compression ratio of the compressed network model. That is, the compression method of each network layer is determined separately. Compared with compressing the entire network model uniformly according to a preset compression method, this fully considers the differences between network layers, thereby improving the compression effect.

[0045] Of course, implementing any product or method of this application does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description

[0046] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0047] Figure 1 A flowchart illustrating a network model compression method provided in this application embodiment;

[0048] Figure 2 A flowchart illustrating another network model compression method provided in this application embodiment;

[0049] Figure 3 A flowchart illustrating another network model compression method provided in this application embodiment;

[0050] Figure 4 A schematic diagram illustrating the principle of network model compression provided in an embodiment of this application;

[0051] Figure 5 A flowchart illustrating network model compression provided in this application embodiment;

[0052] Figure 6 A structural diagram of a network model compression device provided in an embodiment of this application;

[0053] Figure 7 This is a structural diagram of an electronic device provided in an embodiment of this application. Detailed Implementation

[0054] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0055] In related technologies, the entire network model is compressed uniformly according to a preset compression method. This method does not take into account the differences between the various network layers in the network model, resulting in poor compression performance.

[0056] To address the aforementioned problems, this application provides a network model compression method. This method can be applied to an electronic device to compress a network model, obtaining a compressed network model. The electronic device can also perform data processing based on the compressed network model, such as speech recognition, image recognition, action classification, trajectory determination, etc. Furthermore, the electronic device can send the compressed network model to other data processing devices, which can then perform data processing based on the compressed network model.

[0057] See Figure 1 , Figure 1 A flowchart of a network model compression method provided in this application embodiment, the method may include the following steps:

[0058] S101: Determine the network layer to be compressed from the network model according to the preset compression order.

[0059] S102: For each preset compression method, compress the current network layer to be compressed according to the preset compression method to obtain the compressed network model corresponding to the preset compression method.

[0060] In the compressed network model, the other network layers are obtained by compressing them according to their respective determined optimal compression methods.

[0061] S103: Based on the accuracy and / or compression ratio of the corresponding compressed network model, determine the optimal compression method for the current network layer to be compressed from each preset compression method, and return to step S101 until the optimal compression method for each network layer is determined.

[0062] The network model compression method provided in this application can determine the optimal compression method for each network layer by combining the accuracy and / or compression ratio of the compressed network model. That is, the compression method for each network layer is determined separately. Compared with compressing the entire network model uniformly according to a preset compression method, this method fully considers the differences between network layers and thus improves the compression effect.

[0063] Regarding step S101, the network model can be a different type of deep learning network model, such as a CNN (Convolutional Neural Network) model or an RNN (Recurrent Neural Network) model, but it is not limited to these. This network model can be pre-trained based on training samples; for example, it can be used for image recognition or speech recognition.

[0064] A network model can contain multiple network layers (e.g., convolutional layers, pooling layers, fully connected layers, etc.). When compressing this network model, you can choose to compress only a subset of network layers, or you can compress all of them. For example, some network layers with fewer parameters (e.g., pooling layers) may not need to be compressed.

[0065] In this embodiment, the compression method (i.e., the optimal compression method) for each network layer can be determined sequentially from among the preset compression methods according to a preset compression order. The compression order can be the order of the network layers in the network model, or it can be a random order, and is not limited to this.

[0066] Regarding step S102, after determining the current network layer to be compressed, the current network layer to be compressed can be compressed according to each preset compression method to obtain the compressed network model corresponding to each preset compression method, that is, multiple compressed network models are obtained. In each compressed network model, the other network layers are obtained by compressing them according to their respective determined optimal compression methods.

[0067] Regarding step S103, for the current network layer to be compressed, after obtaining multiple compressed network models, the optimal compression method for the current network layer to be compressed can be determined based on the accuracy and / or compression ratio of each compressed network model.

[0068] In one implementation, the preset compression method corresponding to the compressed network model with the highest accuracy is determined as the optimal compression method for the current network layer to be compressed.

[0069] For example, the test data can be processed based on the compressed network model, and the similarity between the predicted data output by the compressed network model and the true labels of the test data can be calculated as the accuracy of the compressed network model.

[0070] If a network model is used to detect targets in an image, the intersection-over-union ratio (IoU) of the image region of the target detected by the compressed network model with the ground truth region of the target in the image can be calculated as the accuracy of the compressed network model. Alternatively, the detection rate of the network model in detecting the target can also be used as the accuracy of the compressed network model.

[0071] In another implementation, the preset compression method corresponding to the compressed network model with the highest compression ratio is determined as the optimal compression method for the current network layer to be compressed.

[0072] For example, the ratio of the number of parameters in the compressed network layer to the number of parameters in the original network layer can be used as the compression ratio of the compressed network model.

[0073] In another implementation, a weighted sum of the accuracy and compression ratio of the compressed network model can be calculated, and the preset compression method corresponding to the compressed network model with the largest weighted sum can be determined as the optimal compression method for the current network layer to be compressed.

[0074] Based on the above processing, the optimal compression method for each network layer can be determined sequentially until the optimal compression method for each network layer is determined.

[0075] In one embodiment, the method may further include the following steps:

[0076] The network layer is compressed according to the optimal compression method to obtain the compressed network model, and the optimal compression method of each network layer is marked in the compressed network model.

[0077] In this embodiment, after determining the optimal compression method for each network layer, the network layer can be compressed according to the optimal compression method to obtain a compressed network model (which can be called a compressed network model). Additionally, the optimal compression method for each network layer can be marked in the compressed network model. Correspondingly, the data processing device that obtains the compressed network model can, based on the markings, recover the network layers compressed using a lossless compression method, and process the data based on the recovered network model.

[0078] In one embodiment, each preset compression method includes a lossless compression method; correspondingly, see [link to relevant documentation]. Figure 2 ,exist Figure 1 Based on this, step S103 above may include the following steps:

[0079] S1031: Based on the compression ratio of the corresponding compressed network model, determine the compression method with the highest compression ratio from each preset compression method and use it as the alternative compression method.

[0080] S1032: If the alternative compression method is a lossless compression method, then the alternative compression method is determined as the optimal compression method for the current network layer to be compressed.

[0081] Among them, lossless compression can record the parameters of the network layer in a specified form without modifying the parameters of the network layer, thus not reducing the accuracy of the compressed network model.

[0082] In this embodiment, since lossless compression is used, the accuracy of the compressed network model is not reduced. Therefore, if the compression method with the highest compression ratio (i.e., the alternative compression method) is a lossless compression method, it indicates that the compressed network model obtained by using the alternative compression method has the highest compression ratio and the highest accuracy. Therefore, it can be directly determined that the network layer to be compressed should be compressed using the alternative compression method.

[0083] In one embodiment, each preset compression method also includes a lossy compression method, see [link to relevant documentation]. Figure 3 ,exist Figure 2 Based on this, the method may further include the following steps:

[0084] S104: If the candidate compression method is a lossy compression method, determine whether the accuracy of the compressed network model corresponding to the candidate compression method is greater than the preset accuracy threshold.

[0085] S105: If the accuracy of the compressed network model corresponding to the candidate compression method is greater than the preset accuracy threshold, then the candidate compression method is determined as the optimal compression method for the current network layer to be compressed.

[0086] Lossy compression methods modify the parameters of network layers, which may reduce the accuracy of the compressed network model. For example, the preset accuracy threshold can be 90%, or 95%, but it is not limited to these.

[0087] In this embodiment, the use of lossy compression reduces the accuracy of the compressed network model. Therefore, if the compression method with the highest compression ratio (i.e., the alternative compression method) is a lossy compression method, it can be determined whether the accuracy of the compressed network model corresponding to the alternative compression method is greater than a preset accuracy threshold.

[0088] If the accuracy exceeds the preset accuracy threshold, it indicates that the compressed network model obtained by using this alternative compression method has the highest compression ratio and the accuracy can also meet the usage conditions (i.e. the accuracy has not dropped significantly). It can ensure that the accuracy and compression ratio of the compressed network model are both high. Therefore, it can be directly determined that the current network layer to be compressed should be compressed using the alternative compression method.

[0089] In one embodiment, the method may further include the following steps:

[0090] If the accuracy of the compressed network model corresponding to the candidate compression method is not greater than the preset accuracy threshold, then the lossless compression method with the highest compression ratio of the corresponding compressed network model is determined as the optimal compression method for the current network layer to be compressed.

[0091] In this embodiment, if the accuracy of the compressed network model corresponding to the alternative compression method is not greater than a preset accuracy threshold, it indicates that although the compressed network model obtained by using the alternative compression method has the highest compression ratio, its accuracy does not meet the usage conditions (i.e., the accuracy drops significantly). To ensure that both the accuracy and compression ratio of the compressed network model are high, the method with the highest compression ratio from the lossless compression methods can be determined as the optimal compression method for the current network layer to be compressed, so that both the accuracy and compression ratio of the compressed network model are high.

[0092] In one embodiment, if the accuracy of the compressed network model corresponding to the alternative compression method is not greater than a preset accuracy threshold, it can also be determined that the current network layer to be compressed will not be compressed, that is, there is no optimal compression method for the current network layer to be compressed.

[0093] In one embodiment, lossless compression methods include Huffman coding compression and / or sparse matrix compression; lossy compression methods include quantization compression and / or shift compression.

[0094] Huffman coding compression is suitable for situations where some parameters in the network layer appear frequently. Sparse matrix (Compressed Row Storage, CRS) compression compresses and stores the row information of the network layer parameters, displaying only the position of the first non-zero element in each row, and is suitable for situations where there are many 0 values ​​in the network layer parameters.

[0095] Quantization compression can cluster the parameters of network layers (e.g., using the K-means clustering algorithm) and use cluster centers instead of the original parameters.

[0096] Shift compression can shift the parameters of a network layer. For example, if the original parameters of a network layer are 8 decimal places, the last 4 digits can be deleted to obtain parameters containing only the last 4 decimal places.

[0097] In one embodiment, the original network model can be compressed first using methods such as network pruning, knowledge distillation, parameter quantization, and model structure design to obtain a compressed network model (which can be called a quantized network model). Then, the quantized network model can be compressed based on the above steps S101-S103.

[0098] See Figure 4 , Figure 4 This is a schematic diagram illustrating the principle of network model compression provided in an embodiment of this application.

[0099] The input model is the original network model. Then, it is compressed using existing compression techniques, such as network pruning, knowledge distillation, parameter quantization, and model structure design, to obtain the compressed network model (i.e., the quantized model).

[0100] Then, based on OP (Operator) information and OP weight information, further compression is performed at the OP level. Simultaneously, combined with algorithm performance verification, the final compressed model is output. Here, OP refers to the network layer in this embodiment; that is, based on the above steps S101-S103, for each network layer, its optimal compression method is determined according to the accuracy and / or compression ratio of the compressed network model.

[0101] See Figure 5 , Figure 5 This is a flowchart illustrating a network model compression method provided in an embodiment of this application.

[0102] Analyze the operation components of the neural network, identify all parameterized operation components, and thus determine the network layers that need to be compressed.

[0103] Assuming OPi is the i-th OP with weighted parameters, we analyze the first OP1 with weighted parameters, where i = 1. Then, we compress the current OPi using alternative lossy compression and lossless compression (i.e., each preset compression method) to obtain the optimal compression scheme (i.e., the compression method with the highest compression ratio).

[0104] If the optimal compression scheme for this OPi layer is lossless compression, then the optimal compression scheme for this OPi is determined.

[0105] Then, it can be determined whether the current OP is the last layer. If so, the model compression method used by the current OP is marked, and i = i + 1 is set to determine the compression method of the next OP.

[0106] If the optimal compression scheme for this OPi layer is lossy compression, then the weight parameters of this OPi layer are compressed, the entire neural network is run, the network result is obtained, and it is determined whether the neural network performance meets the requirements. That is, it is determined whether the accuracy of the compressed network model is greater than a preset accuracy threshold.

[0107] If the requirements are met, it can be determined that the current OPi adopts the optimal compression scheme and whether the current OPi is the last layer.

[0108] If the requirements are not met, the optimal lossless compression scheme A is selected from the lossless compression schemes, or no compression is performed. That is, the lossless compression method with the highest compression ratio is determined for the current OPi, or the current OPi is not compressed, and it is determined whether the current OP is the last layer.

[0109] Based on the same inventive concept, this application also provides a network model compression device, see [link to relevant documentation]. Figure 6 , Figure 6 This application provides a structural diagram of a network model compression device, which may include:

[0110] The network layer determination module 601 is used to determine the current network layer to be compressed from each network layer according to a preset compression order;

[0111] Compression module 602 is used to compress the current network layer to be compressed according to each preset compression method to obtain the compressed network model corresponding to the preset compression method; wherein, in the compressed network model, other network layers are obtained by compressing them according to their respective determined optimal compression methods;

[0112] The first optimal compression method determination module 603 is used to determine the optimal compression method of the current network layer to be compressed from each preset compression method according to the accuracy and / or compression ratio of the corresponding compressed network model, and trigger the network layer determination module 601 until the optimal compression method of each network layer is determined.

[0113] Optionally, the preset compression methods include lossless compression.

[0114] The first optimal compression method determination module 603 includes:

[0115] The alternative compression method determination submodule is used to determine the compression method with the highest compression ratio from each preset compression method according to the compression ratio of the corresponding compressed network model, and use it as the alternative compression method.

[0116] The optimal compression method determination submodule is used to determine the candidate compression method as the optimal compression method for the current network layer to be compressed if the candidate compression method is a lossless compression method.

[0117] Optionally, each preset compression method also includes a lossy compression method; the device further includes:

[0118] The judgment module is used to determine whether the accuracy of the compressed network model corresponding to the candidate compression method is greater than a preset accuracy threshold if the candidate compression method is a lossy compression method.

[0119] The second optimal compression method determination module is used to determine the candidate compression method as the optimal compression method for the current network layer to be compressed if the accuracy of the compressed network model corresponding to the candidate compression method is greater than the preset accuracy threshold.

[0120] Optionally, the device further includes:

[0121] The third optimal compression method determination module is used to determine the lossless compression method with the highest compression ratio of the corresponding compressed network model as the optimal compression method for the current network layer to be compressed if the accuracy of the compressed network model corresponding to the candidate compression method is not greater than the preset accuracy threshold.

[0122] Optionally, the lossless compression method includes Huffman coding compression and / or sparse matrix compression; the lossy compression method includes quantization compression and / or shift compression.

[0123] Optionally, the device further includes:

[0124] The network model generation module is used to compress each network layer according to the optimal compression method to obtain the compressed network model, and to mark the optimal compression method of each network layer in the compressed network model.

[0125] This application also provides an electronic device, such as... Figure 7 As shown, it includes a processor 701, a communication interface 702, a memory 703, and a communication bus 704, wherein the processor 701, the communication interface 702, and the memory 703 communicate with each other through the communication bus 704.

[0126] Memory 703 is used to store computer programs;

[0127] The processor 701, when executing the program stored in the memory 703, implements the network model compression method in the above embodiments.

[0128] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not indicate that there is only one bus or one type of bus.

[0129] The communication interface is used for communication between the aforementioned electronic devices and other devices.

[0130] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.

[0131] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0132] This application also provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the network model compression method provided in this application.

[0133] This application also provides another computer program product containing instructions that, when run on a computer, cause the computer to execute the network model compression method provided in this application.

[0134] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).

[0135] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0136] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments of apparatus, electronic devices, computer-readable storage media, and computer program products are basically similar to the method embodiments, and therefore the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0137] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.

Claims

1. A network model compression method, characterized in that, The method includes: According to a preset compression order, the network layer to be compressed is determined from the network model, wherein the network model is used to detect targets in the image; For each preset compression method, the network layer to be compressed is compressed according to the preset compression method to obtain the compressed network model corresponding to the preset compression method; wherein, in the compressed network model, other network layers are obtained by compressing them according to their respective determined optimal compression methods; Based on the accuracy and / or compression ratio of the corresponding compressed network model, the optimal compression method for the current network layer to be compressed is determined from each preset compression method, and the process returns to the step of determining the current network layer to be compressed from each network layer according to the preset compression order, until the optimal compression method for each network layer is determined. The accuracy of the compressed network model is: the intersection-union ratio of the image region of the target detected by the compressed network model to the real region of the target in the image, or the detection rate of the target by the compressed network model. Each preset compression method includes lossless compression method and lossy compression method.

2. The method according to claim 1, characterized in that, The step of determining the optimal compression method for the current network layer to be compressed from among various preset compression methods based on the accuracy and / or compression ratio of the corresponding compressed network model includes: Based on the compression ratio of the corresponding compressed network model, the compression method with the highest compression ratio is determined from each preset compression method and used as the candidate compression method; If the alternative compression method is a lossless compression method, then the alternative compression method is determined as the optimal compression method for the current network layer to be compressed.

3. The method according to claim 2, characterized in that, The method also includes: If the candidate compression method is a lossy compression method, determine whether the accuracy of the compressed network model corresponding to the candidate compression method is greater than a preset accuracy threshold. If the accuracy of the compressed network model corresponding to the candidate compression method is greater than the preset accuracy threshold, then the candidate compression method is determined as the optimal compression method for the current network layer to be compressed.

4. The method according to claim 3, characterized in that, The method further includes: If the accuracy of the compressed network model corresponding to the candidate compression method is not greater than the preset accuracy threshold, then the lossless compression method with the highest compression ratio of the corresponding compressed network model is determined as the optimal compression method for the current network layer to be compressed.

5. The method according to claim 3, characterized in that, The lossless compression method includes Huffman coding compression and / or sparse matrix compression; the lossy compression method includes quantization compression and / or shift compression.

6. The method according to any one of claims 1-5, characterized in that, The method further includes: The network layer is compressed according to the optimal compression method to obtain the compressed network model, and the optimal compression method of each network layer is marked in the compressed network model.

7. A network model compression device, characterized in that, The device includes: The network layer determination module is used to determine the current network layer to be compressed from each network layer according to a preset compression order, wherein the network model is used to detect targets in the image; The compression module is used to compress the network layer to be compressed according to each preset compression method to obtain the compressed network model corresponding to the preset compression method; wherein, in the compressed network model, other network layers are obtained by compressing them according to their respective determined optimal compression methods; The first optimal compression method determination module is used to determine the optimal compression method of the current network layer to be compressed from each preset compression method according to the accuracy and / or compression ratio of the corresponding compressed network model, and to trigger the network layer determination module until the optimal compression method of each network layer is determined. The accuracy of the compressed network model is: the intersection-union ratio of the image region of the target detected by the compressed network model and the real region of the target in the image, or the detection rate of the target by the compressed network model. Each preset compression method includes lossless compression method and lossy compression method.

8. The apparatus according to claim 7, characterized in that, The first optimal compression method determination module includes: The alternative compression method determination submodule is used to determine the compression method with the highest compression ratio from each preset compression method according to the compression ratio of the corresponding compressed network model, and use it as the alternative compression method. The optimal compression method determination submodule is used to determine the candidate compression method as the optimal compression method for the current network layer to be compressed if the candidate compression method is a lossless compression method.

9. The apparatus according to claim 8, characterized in that, The device further includes: The judgment module is used to determine whether the accuracy of the compressed network model corresponding to the candidate compression method is greater than a preset accuracy threshold if the candidate compression method is a lossy compression method. The second optimal compression method determination module is used to determine the candidate compression method as the optimal compression method for the current network layer to be compressed if the accuracy of the compressed network model corresponding to the candidate compression method is greater than the preset accuracy threshold.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method described in any one of claims 1-6.

Citation Information

Patent Citations

  • Lossless compression method and device based on dynamic programming

    CN111628778A

  • Network structure adjustment method, device, storage medium and electronic equipment

    CN113569886A