Compression method, device, equipment, and medium for neural network
By obtaining a multi-objective optimization method for hardware performance indicators and accuracy, the conflict between hardware performance and accuracy in neural network compression is resolved, and efficient deployment of neural network compression on different hardware platforms is achieved.
Patent Information
- Application Number
- CN202111311435.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-08
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2041-11-08
AI Technical Summary
Existing neural network compression methods cannot optimize hardware performance while ensuring accuracy, resulting in a conflict between hardware performance and accuracy, and cannot meet the needs of rapid deployment.
By directly obtaining hardware performance indicators such as memory and power consumption, combined with accuracy, a multi-objective optimization method is used to compress the neural network, generate multiple compressed neural networks, and obtain the target compressed neural network through a screening and merging process.
It achieves high-accuracy and high-performance neural network compression on hardware, adapting to rapid deployment on different hardware platforms.
Smart Images

Figure CN114154634B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer application technology, and in particular to a neural network compression method, device, equipment, and medium. Background Art
[0002] In related technologies, most neural network compression methods use proxy metrics such as the number of parameters, compression ratio, floating-point operations per second, or the number of multiply-accumulate operations per second to reduce hardware metrics such as latency, memory usage, and power consumption. However, these proxy metrics are non-monotonic with hardware metrics such as latency, memory usage, and power consumption, are insensitive to hardware, and cannot meet the requirements for rapid deployment of deep neural network applications.
[0003] Accuracy and hardware performance indicators are both key performance indicators for neural network compression, but they conflict with each other, and hardware performance indicators such as latency and memory also conflict with each other, making it impossible to achieve a balance between accuracy and hardware performance indicators. Summary of the Invention
[0004] The main purpose of the embodiments of the present application is to propose a neural network compression method and apparatus, equipment, and medium that can resolve the conflict between the hardware performance and accuracy of the compressed neural network.
[0005] To achieve the above objectives, a first aspect of an embodiment of the present application provides a neural network compression method, comprising:
[0006] Get a preset neural network running on the hardware;
[0007] Performing compression processing on the preset neural network to generate at least two first compressed neural networks;
[0008] Obtaining a hardware performance indicator of each of the first compressed neural networks corresponding to the hardware;
[0009] Calculating a first accuracy rate of the preset neural network and a second accuracy rate of each of the first compressed neural networks;
[0010] Preliminarily screening the plurality of first compressed neural networks according to the hardware performance indicator, the first accuracy rate, and the plurality of second accuracy rates to obtain an initial neural network set;
[0011] The initial neural network set is screened twice according to preset conditions to obtain a target compressed neural network.
[0012] In some embodiments, the preliminarily screening the first compressed neural network according to the hardware performance indicator, the first accuracy rate, and the plurality of second accuracy rates to obtain an initial neural network set includes:
[0013] Establishing an accuracy constraint condition for each of the first compressed neural networks according to the first accuracy of the preset neural network, the second accuracy of each of the first compressed neural networks, and a preset constraint parameter;
[0014] If the number of first compressed neural networks that satisfy the accuracy constraint is less than a preset threshold, sorting the plurality of first compressed neural networks according to the accuracy constraint of each first compressed neural network and the second accuracy of each first compressed neural network to obtain a sorted first compressed neural network, and performing a preliminary screening on the sorted first compressed neural networks according to a preset strategy to obtain an initial neural network set;
[0015] If the number of first compressed neural networks that meet the accuracy constraint condition is greater than or equal to the preset threshold, then the multiple first compressed neural networks are grouped and processed according to the hardware performance indicators of each first compressed neural network and the second accuracy of each first compressed neural network to obtain a first group and a second group, and the first group compression network is obtained from the first group according to the preset first selection strategy, and the second group compression network is obtained from the second group according to the preset second selection strategy, and the first group compression network and the second group compression network are used as the initial neural network set.
[0016] In some embodiments, grouping the plurality of first compressed neural networks to obtain first and second groups based on the hardware performance indicator of each first compressed neural network and the second accuracy rate of each first compressed neural network includes:
[0017] establishing an objective function for each of the first compressed neural networks based on a hardware performance indicator of each of the first compressed neural networks and a second accuracy rate of each of the first compressed neural networks;
[0018] The first compression neural network is grouped according to the hardware performance indicator, the second accuracy rate and the objective function to obtain a first group and a second group.
[0019] In some embodiments, obtaining the first packet compression network from the first packet according to a preset first selection strategy includes:
[0020] sorting the first compressed neural networks that satisfy the accuracy constraint according to the objective function corresponding to the first group to obtain a second-sorted first compressed neural network;
[0021] According to the first selection strategy, a corresponding first grouped compressed neural network is obtained from the first compressed neural network after secondary sorting.
[0022] In some embodiments, obtaining the second packet compression network from the second packet according to a preset second selection strategy includes:
[0023] sorting the first compressed neural networks that satisfy the accuracy constraint according to the objective function corresponding to the second group to obtain a first compressed neural network after three sortings;
[0024] According to the second selection strategy, a corresponding second grouping compression network is obtained from the first compression neural network after three sortings.
[0025] In some embodiments, after preliminarily screening the first compressed neural network based on the hardware performance indicator, the first accuracy rate, and the plurality of second accuracy rates to obtain an initial neural network set, the method further includes:
[0026] If the initial neural network set does not meet the preset conditions, and the plurality of first compressed neural networks generated according to the preset neural network meet the strengthening conditions,
[0027] Get the constraints set by the preset proxy model;
[0028] Pruning each layer of the first compressed neural network according to the limiting conditions and the layer-level pruning operator to obtain at least two second compressed neural networks;
[0029] merging the first compressed neural network and the second compressed neural network to obtain a third compressed neural network;
[0030] A third compressed neural network that meets the preset conditions is obtained as a target compressed neural network.
[0031] In some embodiments, after preliminarily screening the first compressed neural network based on the hardware performance indicator, the first accuracy rate, and the plurality of second accuracy rates to obtain an initial neural network set, the method further includes:
[0032] If the initial neural network set does not meet the preset conditions, and the plurality of first compressed neural networks generated according to the preset neural network do not meet the strengthening conditions,
[0033] performing a crossover mutation process on the first compressed neural network to obtain at least two fourth compressed neural networks;
[0034] merging the first compressed neural network and the fourth compressed neural network to obtain a fifth compressed neural network;
[0035] A fifth compressed neural network that meets the preset conditions is obtained as a target compressed neural network.
[0036] A second aspect of the embodiments of the present application provides a neural network compression device, comprising:
[0037] A first acquisition module is used to acquire a preset neural network running on hardware;
[0038] A compression module, configured to compress the preset neural network to generate at least two first compressed neural networks;
[0039] A second acquisition module is configured to acquire a hardware performance indicator of each of the first compressed neural networks corresponding to the hardware;
[0040] a calculation module, configured to calculate a first accuracy rate of the preset neural network and a second accuracy rate of each of the first compressed neural networks;
[0041] a third acquisition module, configured to preliminarily screen the first compressed neural network according to the hardware performance indicator, the first accuracy rate, and a plurality of the second accuracy rates to obtain an initial neural network set;
[0042] The fourth acquisition module is used to perform secondary screening on the initial neural network set according to preset conditions to obtain a target compressed neural network.
[0043] A third aspect of the embodiments of the present application provides an electronic device, comprising a memory and a processor, wherein the memory stores a program, and when the program is executed by the processor, the processor is used to execute the method described in any one of the embodiments of the first aspect of the present application.
[0044] The fourth aspect of the embodiments of the present application proposes a storage medium, which is a computer-readable storage medium. The computer-readable storage medium stores a computer program. When the computer program is executed by a computer, the computer is used to execute the method described in any one of the embodiments of the first aspect of the present application.
[0045] The neural network compression method, apparatus, device, and medium proposed in the embodiments of the present application obtain a preset neural network running on hardware, compress the preset neural network, generate at least two first compressed neural networks, obtain the hardware performance index of each first compressed neural network corresponding to the hardware, calculate the first accuracy of the preset neural network and the second accuracy of each first compressed neural network, preliminarily screen the multiple first compressed neural networks based on the hardware performance index, the first accuracy, and the multiple second accuracy rates to obtain an initial neural network set, and perform a secondary screening on the initial neural network set based on preset conditions to obtain a target compressed neural network. By directly obtaining the hardware performance index of the hardware corresponding to the neural network to guide the compression of the neural network, and performing multi-objective optimization based on the hardware performance index and accuracy, the conflict between hardware performance and accuracy can be resolved, thereby obtaining a compressed neural network that is more adaptable to the hardware and has high accuracy, and realizing the rapid deployment of neural networks on various hardware. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 This is a first flow chart of the neural network compression method provided in an embodiment of the present application;
[0047] Figure 2 yes Figure 1 Flowchart of step S150 in FIG.
[0048] Figure 3 yes Figure 2 The first flow chart of step S240 in FIG.
[0049] Figure 4 yes Figure 2 A second flow chart of step S240 in FIG.
[0050] Figure 5 yes Figure 2 The third flow chart of step S240 in FIG.
[0051] Figure 6 is a second flow chart of the neural network compression method provided in an embodiment of the present application;
[0052] Figure 7 is a third flow chart of the neural network compression method provided in an embodiment of the present application;
[0053] Figure 8 is a fourth flow chart of the neural network compression method provided in an embodiment of the present application;
[0054] Figure 9 is a fifth flow chart of the neural network compression method provided in an embodiment of the present application;
[0055] Figure 10This is a first three-dimensional rendering of the neural network compression method provided in an embodiment of the present application;
[0056] Figure 11 yes Figure 10 Two-dimensional plane rendering;
[0057] Figure 12 This is a second three-dimensional rendering of the neural network compression method provided in an embodiment of the present application;
[0058] Figure 13 yes Figure 12 Two-dimensional plane rendering;
[0059] Figure 14 This is a block diagram of the module structure of the neural network compression device provided in an embodiment of the present application;
[0060] Figure 15 This is a schematic diagram of the hardware structure of the electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0061] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application.
[0062] It should be noted that although the device schematics illustrate functional module divisions and the flowcharts illustrate logical sequences, in certain circumstances, the steps shown or described may be performed in a sequence that differs from the module divisions in the device or the sequence in the flowcharts. The terms "first," "second," and so on, in the specification, claims, and drawings, are used to distinguish similar items and are not necessarily used to describe a specific sequence or precedence.
[0063] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which the present invention pertains. The terms used herein are for the purpose of describing embodiments of the present invention only and are not intended to limit the present invention.
[0064] Deep neural networks are currently widely used in many fields, including image recognition, object detection, and natural language processing. While ensuring the functional effectiveness of neural networks, neural network compression methods are used to streamline given neural networks, enabling their deployment on diverse hardware platforms, such as mobile devices, wearables, and military equipment. However, existing neural network compression methods mostly rely on proxy metrics such as the number of parameters, compression ratio, floating-point operations per second, or the number of multiplication-accumulation operations to reduce hardware performance indicators such as latency, memory, and power consumption. However, these proxy metrics are non-monotonic with hardware performance indicators such as latency, memory, and power consumption, and are insensitive to hardware. Therefore, neural network compression methods based on these proxy metrics cannot achieve optimal hardware performance. Meanwhile, intelligent chips have experienced rapid development in recent years. Given the current proliferation of new intelligent hardware, these methods are unable to meet the demands for rapid deployment of deep neural network applications.
[0065] Based on this, the main purpose of the embodiments of the present application is to propose a method, device, equipment, and medium for compressing a neural network, which guides the compression of the neural network by directly sensing the hardware performance indicators such as hardware delay, memory, and power consumption, and performs multi-objective optimization based on the hardware performance indicators and accuracy to resolve the conflict between the hardware performance indicators and the accuracy. Compression of a neural network based on hardware performance indicators and accuracy can be regarded as a multi-objective optimization problem. Unlike single-objective optimization, the multiple objectives of a multi-objective optimization problem are mutually opposed. There is no unified measurement standard or dimension between the objectives, and there is no solution that makes all objectives reach the optimal level. The solution of multi-objective optimization is a set of equilibrium solutions, namely the Pareto solution set, which makes multiple objectives reach the optimal level as much as possible under given conditions. Through multi-objective optimization, the conflict between the hardware performance and accuracy of the compressed neural network is resolved, so that the compressed neural network can obtain high hardware performance and high accuracy at the same time, thereby obtaining a compressed neural network that is more adaptable to the hardware and has both accuracy, and realizing the rapid deployment of neural networks on hardware.
[0066] The neural network compression method, apparatus, device, and medium provided in the embodiments of the present application are specifically illustrated through the following embodiments. First, the neural network compression method in the embodiments of the present application is described.
[0067] Reference Figure 1 According to the first aspect of the embodiments of the present application, the neural network compression method includes but is not limited to steps S110 to S160.
[0068] S110, obtaining a preset neural network running on the hardware;
[0069] S120, compressing the preset neural network to generate at least two first compressed neural networks;
[0070] S130, obtaining hardware performance indicators corresponding to hardware of each first compressed neural network;
[0071] S140, calculating a first accuracy rate of the preset neural network and a second accuracy rate of each first compressed neural network;
[0072] S150, preliminarily screening the plurality of first compressed neural networks based on the hardware performance index, the first accuracy rate, and the plurality of second accuracy rates to obtain an initial neural network set;
[0073] S160, performing secondary screening on the initial neural network set according to preset conditions to obtain a target compressed neural network.
[0074] In step S110, the preset neural network can be a pre-trained neural network or a trained neural network. The purpose of obtaining the preset neural network running on the hardware is to facilitate the direct acquisition of hardware feedback information such as hardware performance indicators corresponding to the hardware, and to use the hardware feedback information to guide the compression of the neural network to streamline the neural network and achieve rapid deployment of the compressed neural network on the hardware. During the compression process of the neural network, hardware performance indicators are used instead of proxy indicators such as the number of parameters, compression rate, number of floating-point operations per second, or number of multiplication and accumulation operations to evaluate the compression effect of the neural network, which solves the problem that the neural network compression method based on proxy indicators cannot obtain the best hardware performance.
[0075] In step S120, the preset neural network is compressed using different compression algorithms to generate N first compressed neural networks, where N ≥ 2. Each first neural network has a different network structure, weights, biases, and other characteristics. Using compression algorithms to process the preset neural network can reduce the hardware storage space occupied by the preset neural network, reduce the number of parameters, and speed up computation. The compression algorithm can consist of one or more methods such as model pruning, weight sharing, quantization, and convolutional layer Batch Normalization (BN) layer merging. Model pruning involves pruning redundant connections or filters based on an effective evaluation method, retaining the connections with the highest information content. Weight sharing clusters weights, replacing each weight in a cluster with its mean weight, so that multiple connections in the same cluster share the same weight. Quantization reduces the number of bits in the weights. Weights are generally represented using 32-bit floating-point numbers. However, when weights are mostly concentrated near 0, using a 32-bit representation can waste storage space. Convolutional layer BN layer merging combines the parameters of the BN layer into the convolutional layer to increase the speed of forward inference of the neural network. By processing a group of different compressed neural networks, the diversity of the final compressed neural network is guaranteed.
[0076] In step S130, a preset neural network is compressed on a dataset to obtain a first compressed neural network. The dataset can be image, audio, or other data, such as the CIFAR-10 dataset. The CIFAR-10 dataset is an image dataset containing 60,000 32×32 color images, divided into 10 classes, with 6,000 images per class. It should be noted that these 10 classes are independent and non-overlapping. The hardware used to run the preset neural network can be some artificial intelligence hardware or chip, such as the NVDIA Jetson Nano. The NVDIA Jetson Nano is a GPU computing platform that uses a microSD card as primary storage. The system image is written to the microSD card via an internet-connected computer. It should be noted that those skilled in the art can select microSD cards with different memory capacities based on actual needs, for example, a 32GB microSD card can be used. Hardware performance indicators can be hardware-sensitive indicators or direct feedback from the hardware, such as memory, latency, and power consumption. Since the neural network runs directly on the hardware to be deployed, hardware performance indicators of the corresponding hardware can be directly obtained, facilitating the deployment of the neural network on the hardware.
[0077] In step S140, the unlabeled dataset is input into the neural network, which classifies the dataset and outputs the probability that an image belongs to multiple classes. The class with the highest probability is used as the class to which the image belongs, and the image is labeled as that class. After all images in the dataset are classified, the classified images are compared with the labeled sample dataset, and the proportion of correctly classified images out of all images is used as the accuracy rate. If the first accuracy rate is calculated, the unlabeled dataset is input into the preset neural network for calculation; if the second accuracy rate of the first compressed neural network is calculated, the unlabeled dataset is input into the first compressed neural network for calculation.
[0078] In step S150, a plurality of first compressed neural networks are preliminarily screened, i.e., multi-objective selection, based on hardware performance indicators, the first accuracy rate, and the second accuracy rate to obtain an initial neural network set.
[0079] In step S160, the initial neural network set is secondary screened according to preset conditions. If the initial neural network set meets the preset conditions, the initial neural network set is used as the target compressed neural network. If the initial neural network set does not meet the preset conditions, a heuristic or meta-heuristic method, such as a genetic algorithm, a distributed estimation algorithm, a differential evolution algorithm, an evolutionary strategy, etc., is used to search for a neural network that meets the preset conditions. The preset conditions are termination conditions. The preset conditions can be that one or more indicators such as the hardware performance indicators and accuracy of the neural network to be secondary screened reach the standard reference value of the indicator, the number of searches of the neural network to be secondary screened reaches the reference value of the upper limit, or the number of neural networks to be secondary screened reaches a preset number threshold reference value.
[0080] In some embodiments, as Figure 2 As shown, based on the different groups of the first neural network, different selection strategies are adopted for different groups, and the accuracy constraint conditions are integrated to form a multi-target selection mechanism. Step S150 specifically includes the following steps:
[0081] S210, establishing an accuracy constraint condition for each first compressed neural network based on the first accuracy of the preset neural network, the second accuracy of each first compressed neural network, and a preset constraint parameter;
[0082] S220, determining whether the number of the first compression neural network that meets the accuracy constraint condition is less than a preset threshold, if the determination result is yes, executing step S230, if the determination result is no, executing step S240;
[0083] S230, sorting the plurality of first compressed neural networks according to the accuracy constraint of each first compressed neural network and the second accuracy of each first compressed neural network to obtain a sorted first compressed neural network, and performing preliminary screening on the sorted first compressed neural networks according to a preset strategy to obtain an initial neural network set;
[0084] S240, based on the hardware performance indicators of each first compression neural network and the second accuracy rate of each first compression neural network, multiple first compression neural networks are grouped to obtain a first group and a second group, a first group compression network is obtained from the first group according to a preset first selection strategy, and a second group compression network is obtained from the second group according to a preset second selection strategy, and the first group compression network and the second group compression network are used as the initial neural network set.
[0085] In step S210, if the preset neural network is represented as The number of layers is D, and the residual ratio of each layer is used to define how the channels of the layer are deleted. Let r i 0Represents a preset neural network The number of filters in the i-th layer, then the number of filters in the i-th layer of the compressed neural network is r i 0 ×x i , the first compressed neural network is represented as x={x1,x2,…,x D},x∈(0,1], then the second accuracy of the first compressed neural network is expressed as ACC(x), and the first accuracy of the preset neural network is Set the accuracy constraint parameter to c, then according to the first accuracy of the preset neural network The accuracy constraint condition established by the second accuracy ACC(x) of the first compression neural network and the preset constraint parameter c is:
[0086] After step S210, it is determined whether the number of the first compression neural networks that meet the accuracy constraint condition is less than a preset threshold. If the determination result is yes, step S230 is executed; if the determination result is no, step S240 is executed.
[0087] In step S230, statistics satisfy the accuracy constraint condition The number a of the first compressed neural networks x is obtained. If the number a of x is less than a preset threshold b, the multiple first compressed neural networks are sorted according to the accuracy constraint. The first compressed neural networks that meet the accuracy constraint are arranged in the same order, and the first compressed neural networks that do not meet the accuracy constraint are arranged in descending order of their accuracy to obtain the first compressed neural networks after one sort. The preset strategy can be a combination of selecting the first compressed neural networks that meet the accuracy constraint and the individuals with higher accuracy among the first compressed neural networks that do not meet the accuracy constraint. The first compressed neural networks after one sort are preliminarily screened according to the preset strategy to obtain an initial neural network set.
[0088] In step S240, statistics satisfy the accuracy constraint condition The number a of the first compressed neural network x is determined. If the number a of x is greater than or equal to a preset threshold b, the first compressed neural network is grouped to obtain a first group and a second group according to the hardware performance index and the second accuracy rate. Different selection strategies are adopted for the first group and the second group to obtain a first group compression network and a second group compression network. The first group compression network and the second group compression network are used as the initial neural network set.
[0089] In some embodiments, as Figure 3 As shown, step S240 specifically includes the following steps:
[0090] S310, establishing an objective function for each first compressed neural network based on the hardware performance index of each first compressed neural network and the second accuracy rate of each first compressed neural network;
[0091] S320 , performing grouping processing on the first compression neural network according to the hardware performance indicator, the second accuracy rate, and the objective function to obtain a first group and a second group.
[0092] In step S310, the neural network is preset Based on this, a set of different first compressed neural networks x are randomly generated, and the jth hardware performance index H of the hardware corresponding to the first compressed neural network x is obtained. j (x), obtain the second accuracy ACC(x) of the first compressed neural network x, according to the hardware performance index {H1(x),H j (x),…,H m (x)} and the second accuracy ACC(x) are used to establish the objective function of the first compression neural network x, namely formula (1), where m is the number of hardware performance indicators, and the objective function is expressed as:
[0093]
[0094] The compression performance of the first compression neural network is evaluated using hardware performance indicators and the second accuracy rate.
[0095] In step S320, first, a plurality of first compressed neural networks are non-dominatedly sorted according to the hardware performance index of each first compressed neural network and the second accuracy rate of each first compressed neural network, and the first compressed neural network A at the first layer after sorting is recorded; then, from {H1(x), H j (x),…,H m (x)}, any two indicators are selected from the m hardware performance indicators and the second accuracy, and a plurality of first compressed neural networks are non-dominated sorted according to the two indicators of each first compressed neural network, and the first compressed neural network A1 located at the first layer after sorting is recorded, until any combination of two indicators is selected, and the first compressed neural network located at the first layer is recorded as {A1,…,A k}, where k is the number of any two-way combinations of m hardware performance indicators and accuracy rates; finally, from {A1,…,A k}Select the closest {A i} as the first group, from {A1,…,A k}Select the one that is most different from A j} and previously {A j} is not sorted according to the accuracy index, then {A j} as the second group. A and {Ai} is closest, that is, A and {A i} has a strong conflict in the objective function, so the first group {A i} corresponding to the objective function as a strong conflict group. A and {A j} is the most different, that is, A and {A j} has a weaker conflict in the objective function, so the second group {A j The objective functions corresponding to the first and second groups are added to the weak conflict group. The objective functions that do not appear in the first and second groups are also added to the weak conflict group. Based on the conflict strength of the objective functions, the set of multiple first compression neural network objective functions is divided into a strong conflict group and a weak conflict group.
[0096] In some embodiments, as Figure 4 As shown, step S240 specifically further includes the following steps:
[0097] S410, sorting the first compressed neural networks that meet the accuracy constraint condition according to the objective function corresponding to the first group to obtain a second-sorted first compressed neural network;
[0098] S420: Obtain a corresponding first grouped compressed neural network from the secondarily sorted first compressed neural network according to the first selection strategy.
[0099] In step S410, according to the first group {A i}The corresponding objective function is the strong conflict group, and a multi-objective sorting is performed on the multiple first compressed neural networks that meet the accuracy constraint conditions to obtain the first compressed neural network after secondary sorting. The multi-objective sorting is implemented using a multi-objective selection operator, which can be a decomposition-based, indicator-based, and non-dominated sorting and crowding distance-based selection operator. When using the selection operator based on non-dominated sorting and crowding distance for multi-objective sorting, firstly, a non-dominated sorting is performed on the multiple first compressed neural networks that meet the accuracy constraint conditions based on the objective function of the first grouping, thereby completing the stratification of the first compressed neural networks, and then the crowding distance of the first compressed neural networks in the same layer is calculated, and the first compressed neural networks in the same layer are sorted in descending order according to the crowding distance to obtain the first compressed neural network after secondary sorting. In the process of non-dominated sorting, firstly, non-dominated individuals are selected from the multiple first compressed neural networks that meet the accuracy constraint conditions based on the objective function of the first grouping, and a shared virtual fitness value is assigned to these non-dominated individuals to obtain the first dominated optimal layer, and then the above steps are repeated until all the multiple first compressed neural networks that meet the accuracy constraint are stratified. When using a decomposition-based selection operator for multi-objective sorting, a set weight vector, such as a weight vector based on uniform distribution, is used to decompose the multi-objective optimization problem into multiple single-objective optimization problems, that is, the multi-objective function in the first group is decomposed into multiple single-objective functions, and then the multiple first compressed neural networks are sorted in ascending order according to the values of these single-objective functions. When using an indicator-based selection operator for multi-objective sorting, the objective function of the first group is used as the objective function of the multi-objective sorting, and a set indicator, such as hypervolume, is used to calculate the contribution of each first compressed neural network to the value of the indicator, and then the multiple first compressed neural networks are sorted in descending order based on the contribution rate.
[0100] In step S420, the first compressed neural network with the top η proportion of the first compressed neural networks after the secondary sorting is selected, and the selected first compressed neural network is used as the first grouped compressed neural network.
[0101] In some embodiments, as Figure 5 As shown, step S240 specifically further includes the following steps:
[0102] S510, sorting the first compressed neural networks that meet the accuracy constraint condition according to the objective function corresponding to the second group to obtain a first compressed neural network after three sortings;
[0103] S520: Obtain a corresponding second grouped compression network from the first compression neural network after three sortings according to the second selection strategy.
[0104] In step S510, according to the second group {A j}The corresponding objective function and the objective function that does not appear in the first group and the second group, that is, the accuracy constraint condition is satisfied according to the weak conflict group pair The first compressed neural network is non-dominated sorted to layer multiple first compressed neural networks, and then based on the first group {A i The objective function in} is used to sort the first neural network of the same layer in ascending order to obtain the first compressed neural network after three sortings. The smaller the objective function of the first compressed neural network after three sortings, the higher the ranking of the neural network.
[0105] In step S520, a first compressed neural network that is at the top of the first compressed neural network after the three sorting steps and that does not appear in the first grouped compressed neural network is selected and used as the second grouped compressed neural network. It should be noted that those skilled in the art can set the value of η according to actual needs, for example, η is 0.6.
[0106] In some embodiments, as Figure 6 As shown, a heuristic search method based on a proxy model is used to obtain a target compressed neural network. If the initial neural network set does not meet the preset conditions, but multiple first compressed neural networks generated according to the preset neural network meet the strengthening conditions, the neural network compression method further includes:
[0107] S610, obtaining the limiting conditions set by the preset proxy model;
[0108] S620, pruning each layer of the first compressed neural network according to the limiting conditions and the layer pruning operator to obtain at least two second compressed neural networks;
[0109] S630, merging the first compressed neural network and the second compressed neural network to obtain a third compressed neural network;
[0110] S640: Obtain a third compressed neural network that meets preset conditions as a target compressed neural network.
[0111] In step S610, the strengthening condition determines the way the offspring is generated, that is, the way the first compressed neural network is updated. If the initial neural network set obtained after the multi-target selection of the first compressed neural network in steps S210 to S240 does not meet the preset condition, but multiple first compressed neural networks generated according to the preset neural network meet the strengthening condition, a random one that meets the accuracy constraint condition is selected from the multiple first compressed neural networks. The first compressed neural network is given as the neural network Given a neural network The number of parameters is used as the proxy model. The constraints are defined by the proxy model, let A represent the given neural network The error rate, B represents the maximum acceptable error rate, that is Where c is the accuracy constraint parameter, is the accuracy of the preset neural network, then the given neural network The improvement ratio can be expressed as A / B, where C represents the given neural network The value of the number of parameters, the constraint is defined as the minimum acceptable number of parameters C×A / B of the pruned neural network.
[0112] In step S620, for a given neural network Each layer of is pruned separately, and the pruned layers are performed under limited conditions to avoid excessive accuracy loss. The number of layers is L. Pruning each layer separately will generate a separate neural network. When pruning the i-th layer, the filters are first sorted based on the l2-norm, and then the number of pruned filters is continuously increased until the limit conditions are met to generate the i-th neural network.
[0113] In step S630, the first compressed neural network and the plurality of second compressed neural networks generated after trimming are combined as a whole to form a third compressed neural network. By combining the first compressed neural network with its descendant second compressed neural networks as the third compressed neural network, individuals with high fitness from the previous generation are retained in the next generation, thus avoiding poor performance of the compressed neural network due to missing local optimal solutions during the neural network compression process.
[0114] In step S640, N neural networks that meet preset conditions are selected from the entire system using the multi-target selection method of steps S210 to S240 as target compressed neural networks. If the neural network selected from the entire system does not meet the preset conditions, the selected neural network is used as a new first compressed neural network to update the first compressed neural network. It is then determined whether the first compressed neural network meets a strengthening condition. If so, steps S610 to S640 are executed. The strengthening condition can be that the number of updates to the first compressed neural network is greater than or equal to a reference value, or that one or more indicators of the first compressed neural network reach a reference value.
[0115] In some embodiments, as Figure 7 As shown, a heuristic search algorithm is used to obtain a target compressed neural network. If the initial neural network set does not meet the preset conditions, and the first compressed neural network generated according to the preset neural network does not meet the strengthening conditions, the neural network compression method further includes:
[0116] S710, performing crossover mutation processing on the first compressed neural network to obtain at least two fourth compressed neural networks;
[0117] S720, merging the first compressed neural network and the fourth compressed neural network to obtain a fifth compressed neural network;
[0118] S730: Obtain a fifth compressed neural network that meets preset conditions as a target compressed neural network.
[0119] In step S710, if the initial neural network set obtained after the multi-target selection in steps S210 to S240 does not meet the preset conditions and the first compressed neural network does not meet the strengthening conditions, the first compressed neural network is cross-mutated to obtain at least two fourth compressed neural networks.
[0120] In step S720, the first compressed neural network and the fourth compressed neural network are taken as a whole, and the whole is taken as the fifth compressed neural network. Similar to step S630, step S720 also avoids missing some local optimal solutions by retaining the excellent individuals of the previous generation.
[0121] In step S730, the multi-target selection of steps S210 to S240 is used to perform a preliminary screening of the entire set to obtain an initial neural network set. This initial neural network set is then subjected to a secondary screening based on preset conditions. Specifically, N neural networks that meet the preset conditions are obtained from the initial neural network set as target compressed neural networks, where N ≥ 2, which is the same as the value of N in step S120. The specific value of N is not limited in this embodiment of the present application. If the neural network selected from the entire set does not meet the preset conditions, the selected neural network is used as a new first compressed neural network to update the first compressed neural network. It is then determined whether the new first compressed neural network meets the strengthening conditions. If the determination result is no, steps S710 to S730 are repeated to continue the search. If the determination result is yes, steps S610 to S640 are repeated to continue the search.
[0122] In some embodiments, as Figure 8 As shown, in practical applications, the compression method of the neural network includes but is not limited to steps S810 to S850.
[0123] S810, training the neural network to obtain a trained neural network or directly using the trained neural network;
[0124] S820, compressing the trained neural network using a suitable compression algorithm to generate multiple different compressed neural networks;
[0125] S830, evaluating the compressed neural network using hardware-sensitive indicators or direct hardware feedback, accuracy, or other functional indicators, and selecting the neural network using a multi-objective selection mechanism based on the evaluation;
[0126] S840, determining whether the selected neural network meets the termination condition. If so, executing step S850; if not, returning to step S820 to generate multiple different compressed neural networks and continue searching.
[0127] S850, terminate the search.
[0128] In some embodiments, as Figure 9 As shown, in actual use, the compression method of the neural network includes but is not limited to steps S9010 to S9120.
[0129] S9010, obtaining a set of initial compressed neural networks;
[0130] S9020, obtaining hardware performance indicators and accuracy of the compressed neural network group, and completing the evaluation of the compressed neural network;
[0131] S9030, based on the evaluation, groups the targets based on the strength of the conflicts between the target functions;
[0132] S9040, based on target grouping, adopts different selection strategies for strong conflict groups and weak conflict groups, and integrates accuracy constraints to establish a multi-target selection mechanism;
[0133] S9050, determining whether the selected neural network has reached the termination condition. If so, executing step S9120; if not, executing step S9060;
[0134] S9060, determining whether the initial compressed neural network meets the strengthening condition, if the determination result is yes, executing step S9070, if the determination result is no, executing step S9080;
[0135] S9070, randomly selecting a neural network that meets the accuracy constraint from the initial compressed neural network as a given neural network, applying a layered pruning operator based on a proxy model to the given neural network to generate a new set of neural networks, and executing step S9090;
[0136] S9080, using crossover mutation to generate a new neural network on the initial compression neural network, and executing step S9090;
[0137] S9090, merges the new neural network with the initial compressed neural network and selects a neural network from the merged neural network using a multi-objective selection mechanism;
[0138] S9100, determining whether the selected neural network meets the termination condition, if the determination result is yes, executing step S9120, if the determination result is no, executing step S9110;
[0139] S9110, updating the initial compressed neural network, using the selected neural network as a new initial compressed neural network, and repeating steps S9010 to S9120;
[0140] S9120, terminate the search.
[0141] The above neural network compression method is used to compress AlexNet on the CIFAR-10 dataset and deployed on NVIDIA Jetson Nano. Without retraining the neural network, the accuracy of the original neural network can be obtained at least 90%, that is, the error rate is 10%. The compression effect is as follows: Figure 10 and Figure 11 As shown. Figure 10 and Figure 11 It can be seen that compared with the existing hardware-aware neural network compression method NetAdapt, under the same accuracy constraint, the neural network compression method of the embodiment of the present application can simultaneously achieve significant improvements in latency and memory, and can provide a set of diverse solutions for users to choose from.
[0142] The above neural network compression method is used to compress AlexNet on the CIFAR-10 dataset and deployed on NVIDIA Jetson Nano. Without retraining the neural network, the accuracy of the original neural network can be obtained at least 90%, that is, the error rate is 10%. The compression effect is as follows: Figure 12 and Figure 13 As shown. Figure 12 and Figure 13 It can be seen that compared with the existing multi-objective optimization algorithm NSGA-II, the neural network compression method of the embodiment of the present application can achieve significant improvements in accuracy, latency and memory.
[0143] The embodiment of the present application proposes a neural network compression method, which obtains a preset neural network running on hardware, compresses the preset neural network, generates at least two first compressed neural networks, obtains the hardware performance index corresponding to the hardware of each first compressed neural network, calculates the first accuracy of the preset neural network and the second accuracy of each first compressed neural network, preliminarily screens the first compressed neural networks based on the hardware performance index, the first accuracy, and the second accuracy to obtain an initial neural network set, obtains a neural network that meets the preset conditions from the initial neural network set, and uses the neural network as the target compressed neural network. By directly obtaining the hardware performance index of the hardware corresponding to the neural network to guide the compression of the neural network, and establishing a multi-objective selection mechanism based on the hardware performance index and the accuracy to perform multi-objective optimization, the conflict between hardware performance and accuracy can be resolved, and a target compressed neural network with both high hardware performance and high accuracy can be obtained, which facilitates the deployment of neural networks on various hardware platforms without being limited to a specific hardware platform.
[0144] Reference Figure 14 The embodiment of the present application also provides a neural network compression device that can implement the above-mentioned neural network compression method. The device includes a first acquisition module 1410, a compression module 1420, a second acquisition module 1430, a calculation module 1440, a third acquisition module 1450, and a fourth acquisition module 1460. Among them, the first acquisition module 1410 is used to obtain a preset neural network running on hardware; the compression module 1420 is used to compress the preset neural network to generate at least two first compressed neural networks; the second acquisition module 1430 is used to obtain the hardware performance index corresponding to the hardware of each first compressed neural network; the calculation module 1440 is used to calculate the first accuracy of the preset neural network and the second accuracy of each first compressed neural network; the third acquisition module 1450 is used to perform preliminary screening of the first compressed neural networks based on the hardware performance index, the first accuracy, and the multiple second accuracy rates to obtain an initial neural network set; the fourth acquisition module 1460 is used to perform secondary screening of the initial neural network set based on preset conditions to obtain a target compressed neural network.
[0145] The neural network compression device of the embodiment of the present application is used to execute the neural network compression method in the above embodiment. Its specific processing process is the same as the neural network compression method in the above embodiment, and will not be repeated here.
[0146] The neural network compression device proposed in the embodiments of the present application, by implementing the aforementioned neural network compression method, can directly obtain the hardware performance indicators and accuracy of the first compressed neural network corresponding to the hardware. This device then establishes a multi-target selection mechanism based on the hardware performance indicators and accuracy to obtain a first compressed neural network that meets preset conditions as a target compressed neural network. Because the target compressed neural networks obtained are multiple different compressed neural networks, the diversity of the ultimately obtained compressed neural networks is ensured. Furthermore, a compressed neural network that meets the requirements can be selected based on scenario needs, meeting the needs of different users on different hardware and enabling rapid deployment of neural networks on various hardware.
[0147] An embodiment of the present application also provides an electronic device, comprising a memory and a processor, wherein a program is stored in the memory, and when the program is executed by the processor, the processor is used to execute a method as described in any one of the embodiments of the first aspect of the present application.
[0148] The following combination Figure 15 The hardware structure of the electronic device is described in detail. The electronic device includes: a processor 1510 , a memory 1520 , an input / output interface 1530 , a communication interface 1540 , and a bus 1550 .
[0149] The processor 1510 may be implemented as a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is configured to execute relevant programs to implement the technical solutions provided in the embodiments of the present application.
[0150] The memory 1520 can be implemented in the form of a ROM (Read Only Memory), a static storage device, a dynamic storage device, or a RAM (Random Access Memory). The memory 1520 can store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1520 and is called by the processor 1510 to execute the neural network compression method of the embodiments of this application.
[0151] Input / output interface 1530, used to implement information input and output;
[0152] Communication interface 1540, used to implement communication interaction between this device and other devices, which can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WiFi, Bluetooth, etc.); and
[0153] bus 1550 , which transmits information between the various components of the device (e.g., processor 1510 , memory 1520 , input / output interface 1530 , and communication interface 1540 );
[0154] The processor 1510 , the memory 1520 , the input / output interface 1530 , and the communication interface 1540 are communicatively connected to each other within the device via a bus 1550 .
[0155] An embodiment of the present application also provides a storage medium, which is a computer-readable storage medium. The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the neural network compression method of the embodiment of the present application.
[0156] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0157] The embodiments described in the embodiments of this application are intended to more clearly illustrate the technical solutions of the embodiments of this application and do not constitute a limitation on the technical solutions provided by the embodiments of this application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.
[0158] It will be understood by those skilled in the art that Figures 1 to 9 The technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than those shown in the figures, or a combination of certain steps, or different steps.
[0159] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, i.e., they may be located in one place or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of this embodiment.
[0160] Those skilled in the art will appreciate that all or some of the steps in the methods, systems, and functional modules / units in the devices disclosed above may be implemented as software, firmware, hardware, or appropriate combinations thereof.
[0161] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0162] It should be understood that in this application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0163] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0164] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0165] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0166] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store programs, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0167] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but are not intended to limit the scope of the present invention. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and essence of the present invention should be within the scope of the present invention.
Claims
1. A method for compressing a neural network, characterized in that: include: Get a preset neural network to run on your hardware; Performing compression processing on the preset neural network to generate at least two first compressed neural networks; Obtaining a hardware performance indicator of each of the first compressed neural networks corresponding to the hardware; calculating a first accuracy of the preset neural network and a second accuracy of each of the first compressed neural networks; Preliminarily screening the plurality of first compressed neural networks according to the hardware performance indicator, the first accuracy rate, and the plurality of second accuracy rates to obtain an initial neural network set; Performing secondary screening on the initial neural network set according to preset conditions to obtain a target compressed neural network; The preliminarily screening the first compressed neural network according to the hardware performance indicator, the first accuracy rate, and the plurality of second accuracy rates to obtain an initial neural network set includes: Establishing an accuracy constraint condition for each of the first compressed neural networks according to the first accuracy of the preset neural network, the second accuracy of each of the first compressed neural networks, and a preset constraint parameter; If the number of first compressed neural networks that satisfy the accuracy constraint is less than a preset threshold, sorting the plurality of first compressed neural networks according to the accuracy constraint of each first compressed neural network and the second accuracy of each first compressed neural network to obtain a sorted first compressed neural network, and performing a preliminary screening on the sorted first compressed neural networks according to a preset strategy to obtain an initial neural network set; If the number of first compressed neural networks that meet the accuracy constraint condition is greater than or equal to the preset threshold, then the multiple first compressed neural networks are grouped and processed according to the hardware performance indicators of each first compressed neural network and the second accuracy of each first compressed neural network to obtain a first group and a second group, and the first group compression network is obtained from the first group according to the preset first selection strategy, and the second group compression network is obtained from the second group according to the preset second selection strategy, and the first group compression network and the second group compression network are used as the initial neural network set.
2. The method according to claim 1, characterized in that The grouping of the plurality of first compressed neural networks to obtain first and second groups according to the hardware performance index of each first compressed neural network and the second accuracy rate of each first compressed neural network includes: establishing an objective function for each of the first compressed neural networks based on a hardware performance indicator of each of the first compressed neural networks and a second accuracy rate of each of the first compressed neural networks; The first compression neural network is grouped according to the hardware performance indicator, the second accuracy rate and the objective function to obtain a first group and a second group.
3. The method according to claim 2, characterized in that The obtaining a first group compression network from the first group according to a preset first selection strategy includes: sorting the first compressed neural networks that satisfy the accuracy constraint according to the objective function corresponding to the first group to obtain a second-sorted first compressed neural network; According to the first selection strategy, a corresponding first grouped compressed neural network is obtained from the first compressed neural network after secondary sorting.
4. The method according to claim 2, characterized in that The obtaining a second group compression network from the second group according to a preset second selection strategy includes: sorting the first compressed neural networks that satisfy the accuracy constraint according to the objective function corresponding to the second group to obtain a first compressed neural network after three sortings; According to the second selection strategy, a corresponding second grouping compression network is obtained from the first compression neural network after three sortings.
5. The method according to any one of claims 1 to 4, characterized in that After preliminarily screening the first compressed neural network according to the hardware performance indicator, the first accuracy rate, and the plurality of second accuracy rates to obtain an initial neural network set, the method further includes: If the initial neural network set does not meet the preset conditions, and the plurality of first compressed neural networks generated according to the preset neural network meet the strengthening conditions, Get the constraints set by the preset proxy model; Pruning each layer of the first compressed neural network according to the limiting conditions and the layer-level pruning operator to obtain at least two second compressed neural networks; merging the first compressed neural network and the second compressed neural network to obtain a third compressed neural network; A third compressed neural network that meets the preset conditions is obtained as a target compressed neural network.
6. The method according to any one of claims 1 to 4, characterized in that After preliminarily screening the first compressed neural network according to the hardware performance indicator, the first accuracy rate, and the plurality of second accuracy rates to obtain an initial neural network set, the method further includes: If the initial neural network set does not meet the preset conditions, and the plurality of first compressed neural networks generated according to the preset neural network do not meet the strengthening conditions, performing a crossover mutation process on the first compressed neural network to obtain at least two fourth compressed neural networks; merging the first compressed neural network and the fourth compressed neural network to obtain a fifth compressed neural network; A fifth compressed neural network that meets the preset conditions is obtained as a target compressed neural network.
7. A compression device for a neural network, characterized in that: include: A first acquisition module is used to acquire a preset neural network running on hardware; A compression module, configured to compress the preset neural network to generate at least two first compressed neural networks; A second acquisition module is configured to acquire a hardware performance indicator of each of the first compressed neural networks corresponding to the hardware; a calculation module, configured to calculate a first accuracy rate of the preset neural network and a second accuracy rate of each of the first compressed neural networks; a third acquisition module, configured to preliminarily screen the first compressed neural network according to the hardware performance indicator, the first accuracy rate, and a plurality of the second accuracy rates to obtain an initial neural network set; a fourth acquisition module, configured to perform a secondary screening of the initial neural network set according to preset conditions to obtain a target compressed neural network; The compression device of the neural network is further used for: Establishing an accuracy constraint condition for each of the first compressed neural networks according to the first accuracy of the preset neural network, the second accuracy of each of the first compressed neural networks, and a preset constraint parameter; If the number of first compressed neural networks that satisfy the accuracy constraint is less than a preset threshold, sorting the plurality of first compressed neural networks according to the accuracy constraint of each first compressed neural network and the second accuracy of each first compressed neural network to obtain a sorted first compressed neural network, and performing a preliminary screening on the sorted first compressed neural networks according to a preset strategy to obtain an initial neural network set; If the number of first compressed neural networks that meet the accuracy constraint condition is greater than or equal to the preset threshold, then the multiple first compressed neural networks are grouped and processed according to the hardware performance indicators of each first compressed neural network and the second accuracy of each first compressed neural network to obtain a first group and a second group, and the first group compression network is obtained from the first group according to the preset first selection strategy, and the second group compression network is obtained from the second group according to the preset second selection strategy, and the first group compression network and the second group compression network are used as the initial neural network set.
8. An electronic device, characterized in that: The electronic device includes a memory and a processor, wherein a program is stored in the memory, and when the program is executed by the processor, the processor is configured to execute the method according to any one of claims 1 to 6.
9. A storage medium, wherein the storage medium is a computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program. When the computer program is executed by a computer, the computer is configured to perform the method according to any one of claims 1 to 6.