Compression method, device and storage medium for neural network model

By pruning and quantizing the deep neural network model, the problems of large amount of computing and high storage space occupancy are solved, and resource saving and performance maintenance are achieved.

CN114282670BActive Publication Date: 2025-08-19BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210044856.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-14
Publication Date
2025-08-19
Estimated Expiration
2042-01-14

AI Technical Summary

Technical Problem

The existing deep neural network models have large computing volume and high storage space occupancy, making it difficult to effectively apply to hardware platforms and provide real-time services.

Method used

By determining the pruning ratio of neural networks of each layer, pruning the initial neural network, and combining training data to train and quantify the inter-neural network model to obtain the target neural network model.

Benefits of technology

On the premise of ensuring the performance of neural networks, save computing resources and storage resources and improve the application efficiency of the hardware platform.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114282670B_ABST
    Figure CN114282670B_ABST
Patent Text Reader

Abstract

The present disclosure provides a compression method, device and storage medium for a neural network model, which relates to the field of artificial intelligence technology, specifically the field of deep learning and computer vision technology, and can be applied to scenarios such as image processing. The specific implementation scheme is: in the process of compressing the initial neural network model, combined with the pruning ratio of each layer of the neural network in the initial neural network model, each layer of the neural network is pruned separately to obtain an intermediate neural network model, and the intermediate neural network model is trained based on the training data, and the trained intermediate neural network model is quantized, and the quantized intermediate neural network model is trained in combination with the training data to obtain the final target neural network model. In this way, while ensuring the performance of the neural network model, computing resources, storage and hardware resources are saved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the fields of artificial intelligence technology, specifically deep learning and computer vision technology, and can be applied to scenarios such as image processing, and in particular to compression methods, devices, and storage media for neural network models. Background Art

[0002] The development of deep learning has given rise to many deep neural network models with high computational complexity and large model size. These neural network models have good performance, but their huge storage space and high computing resource consumption make them difficult to be effectively applied on various hardware platforms and provide real-time services. Summary of the Invention

[0003] The present disclosure provides a compression method, device, and storage medium for a neural network model.

[0004] According to one aspect of the present disclosure, a method for compressing a neural network model is provided, the method comprising: obtaining an initial neural network model and corresponding training data, wherein the initial neural network model comprises a multi-layer neural network; determining a pruning ratio for each layer of the neural network; performing pruning processing on each layer of the neural network according to the pruning ratio to obtain an intermediate neural network model; training the intermediate neural network model according to the training data; quantizing the trained intermediate neural network model; and training the quantized intermediate neural network model based on the training data to obtain a target neural network model.

[0005] According to another aspect of the present disclosure, a compression device for a neural network model is provided, the device comprising: a first acquisition module for acquiring an initial neural network model and corresponding training data, wherein the initial neural network model comprises a multi-layer neural network; a second acquisition module for determining a pruning ratio of each layer of the neural network; a pruning module for pruning each layer of the neural network according to the pruning ratio to obtain an intermediate neural network model; a first training module for training the intermediate neural network model according to the training data; a quantization module for quantizing the trained intermediate neural network model; and a second training module for training the quantized intermediate neural network model based on the training data to obtain a target neural network model.

[0006] According to another aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the neural network model compression method of the present disclosure.

[0007] According to another aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the compression method of the neural network model disclosed in the embodiment of the present disclosure.

[0008] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, which implements the neural network model compression method of the present disclosure when the computer program is executed by a processor.

[0009] One embodiment of the above application has the following advantages or beneficial effects:

[0010] In the process of compressing the initial neural network model, each layer of the neural network is pruned separately based on the pruning ratio of each layer of the neural network in the initial neural network model to obtain an intermediate neural network model, and the intermediate neural network model is trained based on the training data, and the trained intermediate neural network model is quantized, and the quantized intermediate neural network model is trained based on the training data to obtain the final target neural network model. In this way, computing resources, storage resources, hardware resources, etc. are saved while ensuring the performance of the neural network model.

[0011] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] The accompanying drawings are provided to facilitate a better understanding of the present invention and do not constitute a limitation of the present disclosure.

[0013] Figure 1 is a flowchart of a method for compressing a neural network model according to the first embodiment of the present disclosure;

[0014] Figure 2 is a flowchart of a method for compressing a neural network model according to the second embodiment of the present disclosure;

[0015] Figure 3 is a flowchart of a method for compressing a neural network model according to the third embodiment of the present disclosure;

[0016] Figure 4 is a structural diagram of a compression device for a neural network model according to a fourth embodiment of the present disclosure;

[0017] Figure 5 is a structural diagram of a compression device for a neural network model according to a fifth embodiment of the present disclosure;

[0018] Figure 6 It is a block diagram of an electronic device used to implement the compression method of the neural network model of an embodiment of the present disclosure. DETAILED DESCRIPTION

[0019] The following description of exemplary embodiments of the present disclosure is made in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding. These details should be considered as merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0020] The following describes the compression method, device and storage medium of the neural network model of the embodiments of the present disclosure with reference to the accompanying drawings.

[0021] Figure 1 It is a flowchart of the compression method of the neural network model according to the first embodiment of the present disclosure.

[0022] like Figure 1 As shown, the compression method of the neural network model may include:

[0023] Step 101: Acquire an initial neural network model and corresponding training data, wherein the initial neural network model includes a multi-layer neural network.

[0024] The initial neural network model is a model built or trained based on deep learning methods and can be used to perform deep learning tasks, such as image processing and video processing. Image processing may include, but is not limited to, image detection and image classification. Video processing may include, but is not limited to, video detection and video classification.

[0025] In some embodiments, when the initial neural network model is used for image detection, the initial neural network model may be referred to as an image detection model, and the training data may be a training image.

[0026] In other embodiments, when the above-mentioned initial neural network model is used to classify images, the above-mentioned initial neural network model can be called an image classification model, and the training data corresponding to the image classification model can be a training image.

[0027] In other embodiments, when the above-mentioned initial neural network model is used to classify videos, the above-mentioned initial neural network model can be called a video classification model, and the training data corresponding to the video classification model can be a training video.

[0028] In other embodiments, when the above-mentioned initial neural network model is used for video detection, the above-mentioned initial neural network model can be called a video detection model, and the training data corresponding to the video detection model can be a training video.

[0029] It should be noted that the executor of the compression method of the neural network model implemented in this embodiment is the compression device of the neural network model. The compression device of the neural network model can be implemented by software and / or hardware. The compression device of the neural network model can be configured in an electronic device. The electronic device may include but is not limited to a terminal device, a server, etc. This embodiment does not specifically limit the electronic device.

[0030] Step 102: Determine the pruning ratio of each layer of the neural network.

[0031] In some embodiments, the above-mentioned determination of the pruning ratio of each layer of the neural network can be implemented in a variety of ways, and an exemplary description is as follows:

[0032] As an exemplary implementation, a pre-set pruning ratio for each layer of the neural network may be obtained.

[0033] As another exemplary embodiment, the target accuracy loss allowed by the initial neural network model when pruning it can be obtained, and the pruning ratio of each layer of the neural network can be determined based on the target accuracy loss. Therefore, a method is proposed to determine the pruning ratio of each layer of the neural network based on the target accuracy loss allowed by the initial neural network model.

[0034] For example, a loss constraint condition preset for the initial neural network model is: prune the initial neural network model under the condition that the accuracy loss does not exceed 1%. Based on this loss constraint condition, it can be determined that when pruning the initial neural network model, the target accuracy loss allowed for the initial neural network model is 1%.

[0035] In some embodiments, the precision loss corresponding to each layer of the neural network can be obtained based on the precision loss allowed by the pre-saved initial neural network model, and the pruning ratio of each layer of the neural network can be determined based on the precision loss corresponding to each layer of the neural network. In this way, the pruning ratio of each layer of the neural network can be accurately determined by combining the precision loss corresponding to each layer of the neural network.

[0036] In some embodiments, for each layer of the neural network, based on the precision loss of the current layer of the neural network, the pruning ratio corresponding to the precision loss of the current layer of the neural network can be obtained from the pre-saved correspondence between the precision loss of each layer of the neural network and the pruning ratio, and the obtained pruning ratio can be used as the pruning ratio corresponding to the current layer of the neural network.

[0037] Step 103: Prune each layer of the neural network according to the pruning ratio to obtain an intermediate neural network model.

[0038] In some embodiments, target neurons to be pruned in each neural network layer can be determined based on the corresponding pruning ratio of each neural network layer, and the target neurons to be pruned in each neural network layer can be pruned to obtain an intermediate neural network model. In this way, accurate pruning of each neural network layer based on the pruning ratio is achieved, compressing the size of the initial neural network model.

[0039] Step 104: Train the intermediate neural network model based on the training data.

[0040] Step 105: quantize the trained intermediate neural network model.

[0041] Among them, quantization is a method of storing floating-point numbers expressed by high-bit values in the intermediate neural network model in the form of low-bit values to reduce the occupied memory space, such as quantizing 64-bit and 32-bit values to 16-bit, 8-bit, 4-bit, 2-bit, etc.

[0042] Step 106: Train the quantized intermediate neural network model based on the training data to obtain a target neural network model.

[0043] The neural network model compression method of the disclosed embodiment, during the process of compressing the initial neural network model, prunes each layer of the neural network in the initial neural network model based on the pruning ratio of each layer to obtain an intermediate neural network model, trains the intermediate neural network model based on training data, quantizes the trained intermediate neural network model, and trains the quantized intermediate neural network model based on the training data to obtain the final target neural network model. Thus, while ensuring the performance of the neural network model, computing resources, storage resources, hardware resources, etc. are saved.

[0044] Based on the above embodiment, in order to accurately determine the pruning ratio corresponding to each layer of the neural network based on the target accuracy loss allowed by the initial neural network model. Figure 2 An exemplary implementation of determining the pruning ratio of each layer of a neural network based on the target accuracy loss is further described.

[0045] like Figure 2 As shown, this may include:

[0046] Step 201: Obtain a first accuracy loss caused by multiple different ratios of pruning each layer of the neural network to the initial neural network model.

[0047] In some embodiments, the accuracy loss of the initial neural network model caused by pruning each neural network layer at different ratios can be pre-calculated, and the ratio and accuracy loss corresponding to each neural network layer can be saved. For example, the ratio and accuracy loss corresponding to each neural network layer can be saved in a database or file.

[0048] Specifically, for each layer of the neural network, an exemplary implementation of calculating the accuracy loss caused to the initial neural network model after the current layer of the neural network in the initial neural network model is: based on the corresponding ratio, the current layer of the neural network can be pruned to obtain the pruned initial neural network model, and multiple sample data can be processed according to the pruned neural network model to obtain a first processing result, and multiple sample data can be processed according to the initial neural network model to obtain a second processing result. Then, based on the first processing result and the second processing result, the accuracy loss caused to the initial neural network model by pruning the current layer of the neural network at the corresponding ratio is determined.

[0049] Step 202: For each layer of the neural network, determine the second precision loss and the third precision loss from the multiple first precision losses corresponding to the current layer of the neural network.

[0050] The second precision loss is smaller than the target precision loss and has the smallest difference with the target precision loss.

[0051] The third precision loss is greater than the target precision loss and has the smallest difference with the target precision loss.

[0052] For example, the corresponding relationship between the pruning ratio and accuracy loss of the current neural network layer is as follows: r0 = 0.1l0 = 0.02; r1 = 0.2l1 = 0.04; r2 = 0.3l2 = 0.06; r3 = 0.4l3 = 0.11. Here, ri represents the pruning ratio of the current neural network layer, and li represents the accuracy loss of the initial neural network model after pruning the current neural network layer by ri, where i = 1, 2, or 3.

[0053] Step 203: Obtain a target ratio corresponding to the second precision loss.

[0054] In some embodiments, after the second precision loss is determined, a target ratio corresponding to the second precision loss can be determined based on the correspondence between the ratio corresponding to the current layer of the neural network and the precision loss.

[0055] Step 204: Determine the pruning ratio corresponding to the current layer of the neural network based on the target ratio, the second precision loss, the target precision loss, and the third precision loss.

[0056] In this embodiment, in combination with the target ratio, a second precision loss that is less than the target precision loss and has the smallest difference with the target precision loss is determined from multiple first precision losses corresponding to each layer of the neural network, and a third precision loss that is greater than the target precision loss and has the smallest difference with the target precision loss is determined. In addition, the second precision loss, the target precision loss, the third precision loss and the target ratio corresponding to the second precision loss are combined to accurately determine the pruning ratio corresponding to each layer of the neural network.

[0057] It is understandable that in different application scenarios, the above-mentioned implementation methods of determining the pruning ratio corresponding to the current layer neural network according to the target ratio, the second precision loss, the target precision loss and the third precision loss are different. The exemplary implementation methods are as follows:

[0058] As an exemplary embodiment, the pruning ratio corresponding to the target ratio, the second precision loss, the target precision loss and the third precision loss can be determined based on the correspondence between the pre-stored ratio, the second precision loss, the target precision loss, the third precision loss and the pruning ratio.

[0059] As another exemplary embodiment, the target ratio, the second precision loss, the target precision loss, and the third precision loss may be input into a computational model for calculating the pruning ratio, so as to obtain the pruning ratio corresponding to the current layer of the neural network through the computational model.

[0060] In some embodiments, the calculation model calculates the calculation formula corresponding to the pruning ratio A corresponding to the current layer of the neural network:

[0061] A=R+(x-L0) / (L1-L0)

[0062] Among them, R represents the target ratio corresponding to the second precision loss L0, x represents the target precision loss allowed by the initial neural network model, and L1 represents the third precision loss.

[0063] Continuing with the above example, assuming x is 0.1, based on the correspondence between the pruning ratio and the precision loss corresponding to the current layer of the neural network, it can be determined that the precision loss that is less than the target precision loss and has the smallest difference with the target precision loss is l2. In other words, the above-mentioned second precision loss can be determined to be 0.06, and the target ratio R corresponding to the second precision loss is 0.2 (that is, r1 is used as the target ratio). In addition, it can also be determined that the precision loss that is greater than the target precision loss and has the smallest difference with the target precision loss is l3. In other words, the third precision loss L1 can be determined to be 0.11 (that is, l3 is used as the third precision loss L1). According to the above formula, the value of the pruning ratio A corresponding to the current layer of the neural network can be determined.

[0064] As another exemplary embodiment, a possible method of the above step 204 is as follows: Figure 3 This can include:

[0065] Step 301: Obtain a first difference between a target precision loss and a second precision loss.

[0066] Step 302: Obtain a second difference between the third precision loss and the second precision loss.

[0067] Step 303: Obtain the ratio of the first difference to the second difference.

[0068] Step 304: Determine the pruning ratio corresponding to the current layer of the neural network based on the ratio and the target ratio.

[0069] In some exemplary implementations, a sum obtained by adding the ratio and the target ratio may be obtained, and the sum may be used as the pruning ratio corresponding to the current layer of the neural network.

[0070] In this embodiment, the pruning ratio corresponding to the current layer of the neural network is accurately determined by combining the first difference between the target precision loss and the second precision loss, the second difference between the third precision loss and the second precision loss, and the target ratio.

[0071] In order to implement the above embodiment, the embodiment of the present disclosure also provides a compression device for a neural network model.

[0072] Figure 4 3 is a structural diagram of a compression device for a neural network model according to the fourth embodiment of the present disclosure.

[0073] like Figure 4 As shown, the compression device 400 of the neural network model may include a first acquisition module 401, a second acquisition module 402, a pruning module 403, a first training module 404, a quantization module 405, and a second training module 406, wherein:

[0074] The first acquisition module 401 is used to acquire an initial neural network model and corresponding training data, wherein the initial neural network model includes a multi-layer neural network.

[0075] The second acquisition module 402 is used to determine the pruning ratio of each layer of the neural network.

[0076] The pruning module 403 is used to prune each layer of the neural network according to the pruning ratio to obtain an intermediate neural network model.

[0077] The first training module 404 is used to train the intermediate neural network model according to the training data.

[0078] The quantization module 405 is used to quantize the trained intermediate neural network model.

[0079] The second training module 406 is used to train the quantized intermediate neural network model based on the training data to obtain a target neural network model.

[0080] It should be noted that the aforementioned explanation of the embodiment of the compression method of the neural network model is also applicable to this embodiment, and will not be repeated in this embodiment.

[0081] The neural network model compression device of the disclosed embodiment, during the process of compressing the initial neural network model, prunes each layer of the neural network in combination with the pruning ratio of each layer in the initial neural network model to obtain an intermediate neural network model, trains the intermediate neural network model based on training data, quantizes the trained intermediate neural network model, and trains the quantized intermediate neural network model in combination with the training data to obtain the final target neural network model. Thus, while ensuring the performance of the neural network model, computing resources, storage resources, hardware resources, etc. are saved.

[0082] In one embodiment of the present disclosure, Figure 5 As shown, the compression device 500 of the neural network model may include: a first acquisition module 501, a second acquisition module 502, a pruning module 503, a first training module 504, a quantization module 505, and a second training module 506. The second acquisition module 502 may include: an acquisition submodule 5021 and a determination submodule 5022. The determination submodule 5022 includes: a first acquisition unit 50221, a first determination unit 50222, a second acquisition unit 50223, and a second determination unit 50224.

[0083] It should be noted that the detailed description of the first acquisition module 501, the first training module 504, the quantization module 505, and the second training module 506 can be found in Figure 4 The description of the first acquisition module 401, the first training module 404, the quantization module 405, and the second training module 406 in the illustrated embodiment will not be repeated here.

[0084] In one embodiment of the present disclosure, the second acquisition module 502 includes:

[0085] The acquisition submodule 5021 is used to obtain the target accuracy loss allowed by the initial neural network model when pruning the initial neural network model.

[0086] Determine submodule 5022, used to determine the pruning ratio of each layer of the neural network according to the target accuracy loss

[0087] In one embodiment of the present disclosure, the determining submodule 5022 includes:

[0088] The first acquisition unit 50221 is used to obtain a first accuracy loss caused to the initial neural network model by multiple different proportions of pruning each layer of the neural network.

[0089] The first determination unit 50222 is used to determine, for each layer of the neural network, a second precision loss and a third precision loss from multiple first precision losses corresponding to the current layer of the neural network, wherein the second precision loss is a first precision loss that is smaller than the target precision loss and has the smallest difference with the target precision loss, and the third precision loss is a first precision loss that is greater than the target precision loss and has the smallest difference with the target precision loss.

[0090] The second acquisition unit 50223 is used to acquire a target ratio corresponding to the second precision loss.

[0091] The second determining unit 50224 is used to determine the pruning ratio corresponding to the current layer of the neural network according to the target ratio, the second precision loss, the target precision loss and the third precision loss.

[0092] In one embodiment of the present disclosure, the above-mentioned second determination unit 50224 is specifically used to: obtain a first difference between the target precision loss and the second precision loss; obtain a second difference between the third precision loss and the second precision loss; obtain a ratio of the first difference to the second difference; and determine the pruning ratio corresponding to the current layer of the neural network based on the ratio and the target ratio.

[0093] In one embodiment of the present disclosure, the pruning module 503 is specifically used to: determine the target neurons to be pruned in each layer of the neural network according to the pruning ratio corresponding to each layer of the neural network; and prune the target neurons to be pruned in each layer of the neural network to obtain an intermediate neural network model.

[0094] It should be noted that the aforementioned explanation of the embodiment of the compression method of the neural network model is also applicable to the compression device of the neural network model in this embodiment, and will not be repeated here.

[0095] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium, and a computer program product.

[0096] Figure 6A schematic block diagram of an example electronic device 600 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are provided as examples only and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0097] like Figure 6 As shown, the electronic device 600 may include a computing unit 601, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 602 or a computer program loaded from a storage unit 608 into a random access memory (RAM) 603. Various programs and data required for the operation of the device 600 may also be stored in the RAM 603. The computing unit 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0098] Various components in device 600 are connected to I / O interface 605, including an input unit 606, such as a keyboard, mouse, etc.; an output unit 607, such as various types of displays, speakers, etc.; a storage unit 608, such as a magnetic disk, optical disk, etc.; and a communication unit 609, such as a network card, modem, wireless communication transceiver, etc. The communication unit 609 allows device 600 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.

[0099] The computing unit 601 can be a variety of general-purpose and / or specialized processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units that run machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The computing unit 601 performs the various methods and processes described above, such as the neural network model compression method. For example, in some embodiments, the neural network model compression method can be implemented as a computer software program that is tangibly contained in a machine-readable medium, such as the storage unit 608. In some embodiments, part or all of the computer program can be loaded and / or installed on the device 600 via the ROM 602 and / or the communication unit 609. When the computer program is loaded into the RAM 603 and executed by the computing unit 601, one or more steps of the neural network model compression method described above can be performed. Alternatively, in other embodiments, the computing unit 601 can be configured to perform the neural network model compression method by any other appropriate means (e.g., by means of firmware).

[0100] Various embodiments of the systems and techniques described above can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0101] The program code for implementing the method of the present disclosure can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device so that when the program code is executed by the processor or controller, the functions / operations specified in the flow chart and / or block diagram are implemented. The program code can be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.

[0102] In the context of the present disclosure, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in conjunction with an instruction execution system, device or equipment. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0103] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0104] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), the Internet, and a blockchain network.

[0105] A computer system may include a client and a server. The client and server are generally remote from each other and typically interact via a communication network. The client-server relationship is established by computer programs running on the respective computers and establishing a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, a host product within the cloud computing service ecosystem that addresses the management difficulties and poor scalability of traditional physical hosts and VPS services ("Virtual Private Servers" or simply "VPS"). The server may be a cloud server, a server in a distributed system, or a server integrated with blockchain.

[0106] It's important to note that artificial intelligence (AI) is the study of how computers can simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, and planning). This encompasses both hardware and software technologies. AI hardware technologies generally include sensors, specialized AI chips, cloud computing, distributed storage, and big data processing. AI software technologies primarily encompass computer vision, speech recognition, natural language processing, machine learning / deep learning, big data processing, and knowledge graphs.

[0107] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in this disclosure can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved. This is not a limitation herein.

[0108] The above specific embodiments do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure shall be included within the scope of protection of this disclosure.

Claims

1. A method for compressing a neural network model, comprising: Obtaining an initial neural network model and corresponding training data, wherein the initial neural network model includes a multi-layer neural network and the training data includes images or videos; Obtaining a target accuracy loss allowed by the initial neural network model when pruning the initial neural network model; Obtaining a first accuracy loss caused to the initial neural network model by a plurality of different proportions of pruning each layer of the neural network; For each layer of the neural network, determine a second precision loss and a third precision loss from the multiple first precision losses corresponding to the current layer of the neural network, wherein the second precision loss is the first precision loss that is smaller than the target precision loss and has the smallest difference with the target precision loss, and the third precision loss is the first precision loss that is larger than the target precision loss and has the smallest difference with the target precision loss; Obtaining a target ratio corresponding to the second precision loss; Determining a pruning ratio corresponding to the current layer neural network according to the target ratio, the second precision loss, the target precision loss, and the third precision loss; According to the pruning ratio, each layer of the neural network is pruned to obtain an intermediate neural network model; Training the intermediate neural network model according to the training data; quantizing the trained intermediate neural network model; The quantized intermediate neural network model is trained based on the training data to obtain a target neural network model.

2. The method according to claim 1, wherein The determining, according to the target ratio, the second precision loss, the target precision loss, and the third precision loss, of the pruning ratio corresponding to the current layer neural network includes: Obtaining a first difference between the target precision loss and the second precision loss; Obtaining a second difference between the third precision loss and the second precision loss; Obtaining a ratio of the first difference to the second difference; According to the ratio and the target ratio, the pruning ratio corresponding to the current layer of the neural network is determined.

3. The method according to any one of claims 1 to 2, wherein: The pruning process is performed on each layer of the neural network according to the pruning ratio to obtain an intermediate neural network model, including: According to the pruning ratio corresponding to each layer of the neural network, the target neurons to be pruned in each layer of the neural network are determined respectively; The target neurons to be pruned in each layer of the neural network are pruned to obtain the intermediate neural network model.

4. A compression device for a neural network model, comprising: A first acquisition module is configured to acquire an initial neural network model and corresponding training data, wherein the initial neural network model includes a multi-layer neural network, and the training data includes images or videos; The second acquisition module is used to obtain the pruning ratio of each layer of the neural network; A pruning module is used to prune each layer of the neural network according to the pruning ratio to obtain an intermediate neural network model; A first training module, configured to train the intermediate neural network model based on the training data; A quantization module, used to quantize the trained intermediate neural network model; A second training module is used to train the quantized intermediate neural network model based on the training data to obtain a target neural network model; The second acquisition module includes: An acquisition submodule, configured to acquire a target accuracy loss allowed by the initial neural network model when pruning the initial neural network model; A determination submodule, configured to determine a pruning ratio for each layer of the neural network according to the target accuracy loss; The determining submodule includes: A first acquisition unit is configured to acquire a first accuracy loss caused to the initial neural network model by pruning each layer of the neural network at different ratios; A first determining unit is configured to determine, for each layer of the neural network, a second precision loss and a third precision loss from a plurality of first precision losses corresponding to the current layer of the neural network, wherein the second precision loss is a first precision loss that is smaller than the target precision loss and has a minimum difference with the target precision loss, and the third precision loss is a first precision loss that is larger than the target precision loss and has a minimum difference with the target precision loss; A second acquiring unit, configured to acquire a target ratio corresponding to the second precision loss; The second determining unit is used to determine the pruning ratio corresponding to the current layer neural network according to the target ratio, the second precision loss, the target precision loss and the third precision loss.

5. The device according to claim 4, wherein The second determining unit is specifically configured to: Obtaining a first difference between the target precision loss and the second precision loss; Obtaining a second difference between the third precision loss and the second precision loss; Obtaining a ratio of the first difference to the second difference; According to the ratio and the target ratio, the pruning ratio corresponding to the current layer of the neural network is determined.

6. The device according to any one of claims 4 to 5, wherein: The pruning module is specifically used to: According to the pruning ratio corresponding to each layer of the neural network, the target neurons to be pruned in each layer of the neural network are determined respectively; The target neurons to be pruned in each layer of the neural network are pruned to obtain the intermediate neural network model.

7. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 3.

8. A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 3.

9. A computer program product comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the steps of the method according to any one of claims 1 to 3.

Citation Information

Patent Citations

  • Deep neural network model compression method and device, electronic equipment and storage medium

    CN112861996A

  • Neural network pruning method based on feature map

    CN113537245A