CN116011550A - Model pruning method, image processing method and related devices - Google Patents

Model pruning method, image processing method and related devices Download PDF

Info

Publication number
CN116011550A
CN116011550A CN202211659437.7A CN202211659437A CN116011550A CN 116011550 A CN116011550 A CN 116011550A CN 202211659437 A CN202211659437 A CN 202211659437A CN 116011550 A CN116011550 A CN 116011550A
Authority
CN
China
Prior art keywords
pruning
model
pruned
target
channel
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211659437.7A
Other languages
Chinese (zh)
Inventor
陆强
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
International Network Technology Shanghai Co Ltd
Original Assignee
International Network Technology Shanghai Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by International Network Technology Shanghai Co Ltd filed Critical International Network Technology Shanghai Co Ltd
Priority to CN202211659437.7A priority Critical patent/CN116011550A/en
Publication of CN116011550A publication Critical patent/CN116011550A/en
Pending legal-status Critical Current

Links

Images

Abstract

The invention provides a model pruning method, an image processing method and a related device, comprising the following steps: the method comprises the steps of obtaining a model to be pruned and a corresponding pruning target thereof, wherein the model to be pruned is obtained based on image data training, the pruning target comprises pruning proportion information, and the pruning proportion information is used for representing proportion information of primary pruning and iterative pruning in a model pruning process; pruning is carried out on the model to be pruned for one time according to the pruning target, and a first pruned model is obtained; and carrying out iterative pruning on the first pruned model according to the pruning target to obtain a second pruned model, and taking the second pruned model as a target model. The invention can accelerate the training process, and compared with a single pruning method, the pruning upper limit is improved.

Description

Model pruning method, image processing method and related devices
Technical Field
The present invention relates to the field of model compression technologies, and in particular, to a model pruning method, an image processing method, and a related device.
Background
With the development of artificial intelligence technology, the application of the neural network model is also becoming wider and wider. Considering that the network model has a large number of parameters and a large amount of computation, the model needs to be compressed in order to increase the computation speed of the model. The model is compressed, so that the purposes of reducing the size of the model, reducing the resource consumption and improving the response time are achieved.
Model pruning is a common model compression method at present, and parameters with smaller weight in a network model are removed after the model is trained, so that the neural network model is compressed. The current model pruning is divided into iterative pruning and one-shot pruning, wherein the iterative pruning needs fine-tuning training after each pruning in the pruning training process, so that the training time is more. Therefore, how to accelerate the training process of iterative pruning in iterative pruning is a technical problem to be solved.
Disclosure of Invention
The invention provides a model pruning method, an image processing method and a related device, which are used for solving the problems.
The invention provides a model pruning method, which comprises the following steps:
obtaining a model to be pruned and a corresponding pruning target; the pruning target comprises pruning proportion information which is used for representing proportion information of primary pruning and iterative pruning in the pruning process of the model;
pruning is carried out on the model to be pruned for one time according to the pruning target, and a first pruned model is obtained;
and carrying out iterative pruning on the first pruned model according to the pruning target to obtain a second pruned model, and taking the second pruned model as a target model.
According to the model pruning method provided by the invention, the pruning target comprises the total number of pruning training iterations;
correspondingly, after pruning the model to be pruned for one time according to the pruning target to obtain a first pruned model, the method further comprises:
performing fine tuning training on the first pruned model according to the first fine tuning times to obtain a first fine tuned model; the first fine tuning times are determined according to the proportion information of one pruning in the pruning proportion information in the model pruning process and the total number of pruning training iterations;
performing iterative pruning on the first pruned model according to the pruning target to obtain a second pruned model, including:
and carrying out iterative pruning on the first fine-tuned model according to the pruning target to obtain a second pruned model.
According to the model pruning method provided by the invention, the pruning target also comprises the target pruning channel number;
correspondingly, the iterative pruning is carried out on the first fine-tuned model according to the pruning target to obtain a second pruned model, which comprises the following steps:
s1, pruning is carried out on one channel in the first fine-tuned model, and a single-channel pruned model is obtained;
s2, performing fine tuning training on the single-channel pruned model according to the second fine tuning times to obtain a second fine tuned model; the second fine tuning times are determined according to the proportion information of iterative pruning in the model pruning process, the target pruning channel number and the pruning training iteration total number in the pruning proportion information;
s3, repeatedly executing S1-S2 on the basis of the second fine-tuned model until the preset iteration times are reached, so as to obtain a latest second fine-tuned model, and taking the latest second fine-tuned model as a second pruned model;
the preset iteration times are determined according to the number of iteration pruning channels, and the number of iteration pruning channels is calculated according to the number of target pruning channels and the duty ratio information of the iteration pruning in the model pruning process in the pruning proportion information.
According to the model pruning method provided by the invention, the second fine tuning times are determined according to the duty ratio information of iterative pruning in the model pruning process, the target pruning channel number and the total number of pruning training iterations in the pruning proportion information, and the method comprises the following steps:
calculating to obtain the total number of iterative pruning fine tuning training according to the duty ratio information of the iterative pruning in the model pruning process and the total number of pruning training iterations;
and calculating the second fine tuning times according to the total times of the iterative pruning fine tuning training and the number of the iterative pruning channels.
According to the model pruning method provided by the invention, the pruning target also comprises the target pruning channel number;
correspondingly, the pruning is carried out on the model to be pruned for one time according to the pruning target to obtain a first pruned model, which comprises the following steps:
acquiring a first norm of each channel in the model to be pruned, and sequencing each channel in the model to be pruned according to the sequence from small to large of the numerical value of the first norm to obtain a channel sequence;
taking the first p channels in the channel sequence as first channels to be pruned, wherein p is calculated according to the number of the target pruning channels and the duty ratio information of primary pruning in the pruning proportion information in the model pruning process;
pruning is carried out on the to-be-pruned model according to the first to-be-pruned channel, and a first pruned model is obtained.
According to the method for pruning the model provided by the invention, the step S1 of pruning one channel in the first fine-tuned model to obtain a single-channel pruned model comprises the following steps:
acquiring a second norm of each channel in the first fine-tuned model;
taking the channel with the smallest second norm value as a second channel to be pruned;
pruning the first fine-tuned model according to the second to-be-pruned channel to obtain a single-channel pruned model.
The invention also provides an image processing method, which comprises the following steps:
acquiring an image to be processed;
inputting the image to be processed into a trained image processing model, and processing the image to be processed through the trained image processing model to obtain a processing result;
the trained image processing model is obtained through the model pruning method.
The invention also provides a model pruning device, which comprises:
the model and pruning target acquisition module is used for acquiring a model to be pruned and a pruning target corresponding to the model to be pruned; the pruning target comprises pruning proportion information which is used for representing proportion information of primary pruning and iterative pruning in the pruning process of the model;
the primary pruning module is used for pruning the model to be pruned for one time according to the pruning target to obtain a first pruned model;
and the iterative pruning module is used for carrying out iterative pruning on the first pruned model according to the pruning target to obtain a second pruned model, and taking the second pruned model as a target model.
The present invention also provides an image processing apparatus including:
the image acquisition module is used for acquiring an image to be processed;
the image processing module is used for inputting the image to be processed into a trained image processing model, and processing the image to be processed through the trained image processing model to obtain a processing result; the trained image processing model is obtained through the model pruning device.
The invention also provides an electronic device comprising a memory, a processor and a computer program stored on the memory and capable of running on the processor, wherein the processor realizes any one of the model pruning method or the image processing method when executing the program.
The present invention also provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a model pruning method or an image processing method as any one of the above.
According to the model pruning method, the image processing method and the related device, the training process can be accelerated through the two modes of primary pruning and iterative pruning, and compared with the method for singly using the primary pruning, the upper limit of pruning is improved.
Drawings
In order to more clearly illustrate the invention or the technical solutions of the prior art, the following description will briefly explain the drawings used in the embodiments or the description of the prior art, and it is obvious that the drawings in the following description are some embodiments of the invention, and other drawings can be obtained according to the drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic flow chart of a model pruning method according to an embodiment of the present invention;
FIG. 2 is a second flow chart of a model pruning method according to the embodiment of the present invention;
fig. 3 is a schematic flow chart of an image processing method according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a model pruning device according to an embodiment of the present invention;
fig. 5 is a schematic structural view of an image processing apparatus according to an embodiment of the present invention;
fig. 6 is a schematic entity structure diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the present invention more apparent, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some embodiments of the present invention, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
FIG. 1 is a schematic flow chart of a model pruning method according to an embodiment of the present invention; FIG. 2 is a second flow chart of a model pruning method according to the embodiment of the present invention; as shown in fig. 1 and 2, the model pruning method includes:
s101, acquiring a model to be pruned and a corresponding pruning target thereof.
The pruning target comprises pruning proportion information which is used for representing proportion information of one-time pruning and iterative pruning in the pruning process of the model.
In this step, the model to be pruned is a pre-training model, which may be specifically a convolutional neural network, and is obtained by training based on a training image and its corresponding image tag, and is used for performing image processing.
The pruning target may be the size of the volume to be reached by the pre-training model, may be the pruning rate of the whole pre-training model, or specifically the number of pruning channels, and may further include the total number of iterations of pruning training. In the invention, the pruning target can also comprise pruning proportion information for representing the proportion of the primary pruning and the iterative pruning in the model pruning process, and the pruning proportion information is used for configuring the proportion of the primary pruning and the iterative pruning in the whole pruning training process.
S102, pruning is carried out on the model to be pruned for one time according to the pruning target, and a first pruned model is obtained.
In this step, a one-time pruning method is adopted to prune (one-shot pruning) the model to be pruned according to a pruning target (such as pruning proportion information), and the pruned model is used as a first pruned model.
And S103, carrying out iterative pruning on the first pruned model according to the pruning target to obtain a second pruned model, and taking the second pruned model as a target model.
In the step, based on the first post-pruning model, pruning is continuously performed according to a pruning target, an iterative pruning method is adopted to prune the first post-pruning model, the pruned model is used as a second post-pruning model, and the second post-pruning model is a final output target model and is used for image processing.
In the prior art, fine-tuning training is performed after each iterative pruning, and the total fine-tuning training times are 10000 if the iterative pruning is performed on a model to be pruned, the iteration times are 10, and the fine-tuning training times after each iterative pruning are 1000; and if the model to be pruned is pruned once and the fine tuning training frequency is set to 2000, the total fine tuning training frequency is 2000. As can be seen from the above examples, the total number of fine tuning training in iterative pruning is too large compared to the one-time pruning method, which results in too long time consumption of the pruning training process, and the upper limit of the pruning model is limited if the pruning is performed only by using one-time pruning. Therefore, the invention combines two methods of one pruning and iterative pruning, for example, one pruning is performed first, in the process of one pruning, the fine tuning training frequency is 1000, in the process of iterative pruning, the iteration frequency is 5, and the fine tuning training frequency is 1000, and in the whole pruning process, the total fine tuning training frequency is 1000+5×1000=6000. As can be seen from the comparison of 6000 and 10000, the fine tuning training times can be greatly reduced by combining the two pruning methods of one pruning and iterative pruning, so that the training time is shortened. In addition, compared with a single pruning method, the pruning upper limit can be improved.
The model pruning method provided by the embodiment of the invention can accelerate the training process through the two modes of primary pruning and iterative pruning, and improves the pruning upper limit compared with the method of single pruning.
In some embodiments of the present invention, the pruning target includes pruning proportion information and a total number of pruning training iterations iters_all, where the pruning proportion information is used to represent proportion information of one pruning and iterative pruning in a model pruning process, the pruning proportion information is more specifically a pruning proportion value, and assuming that a proportion of one pruning is α (α e [0,1 ]), a proportion of one pruning is 1- α.
Correspondingly, after pruning the model to be pruned for one time according to the pruning target to obtain a first pruned model, the method further comprises:
and performing fine tuning training on the first pruned model according to the first fine tuning times to obtain the first fine tuned model.
The first fine tuning times are determined according to the ratio information of one pruning in the pruning proportion information in the model pruning process and the total pruning training iteration number iters_all. Specifically, if the duty ratio of one pruning is α, the first trimming number iter1=0.8×α×iters_all, where 0.8 is a set constant.
Performing iterative pruning on the first pruned model according to the pruning target to obtain a second pruned model, including:
and carrying out iterative pruning on the first fine-tuned model according to the pruning target to obtain a second pruned model. Namely, iterative pruning is performed on the basis of one-shot pruning.
In addition, in order to further accelerate the pruning training process, the proportion alpha of one pruning is set to be 0.8 according to an empirical value, and the corresponding iterative pruning proportion is set to be 0.2, so that the pruning training process is accelerated to the greatest extent while the pruning effect is ensured.
According to the model pruning method provided by the embodiment of the invention, the fine tuning training times of the first pruned model are determined after one pruning according to the duty ratio information of one pruning in the model pruning process, so that the pruning training process is quickened.
In some embodiments of the invention, the pruning target further comprises a target pruning channel number c_target.
Correspondingly, the iterative pruning is carried out on the first fine-tuned model according to the pruning target to obtain a second pruned model, which comprises the following steps:
s1, pruning is carried out on one channel in the first fine-tuned model, and a single-channel pruned model is obtained.
S2, performing fine tuning training on the single-channel pruned model according to the second fine tuning times to obtain a second fine tuned model.
The second fine tuning times are determined according to the proportion information of iterative pruning in the model pruning process, the target pruning channel number and the total number of pruning training iterations in the pruning proportion information.
Specifically, the second fine tuning number is determined according to the ratio information of iterative pruning in the model pruning process, the target pruning channel number and the total number of pruning training iterations in the pruning proportion information, and includes:
and calculating to obtain the total number of iterative pruning fine tuning training= (1-0.8:. Alpha.) iters_all according to the duty ratio information of iterative pruning in the model pruning process (the duty ratio of iterative pruning is 1-alpha).
And calculating the trimming times (namely the second trimming times iter 2) of the model in each iteration according to the total times of the iterative pruning trimming training and the number c2 of the iterative pruning channels. In particular, the method comprises the steps of,
Figure BDA0004013089930000091
s3, repeating the steps S1-S2 on the basis of the second fine-tuning model until the preset iteration times are reached, so that the latest second fine-tuning model is obtained, and the latest second fine-tuning model is used as a second pruning model. Pruning is carried out on one channel in the second fine-tuned model, and a new single-channel pruned model is obtained. And performing fine tuning training on the new single-channel pruned model according to the second fine tuning times to obtain a new second fine tuned model. This loop is repeated until a preset number of iterations is reached (i.e., pruning is completed according to the target pruning lane number).
The preset iteration number iter2 is determined according to the number of iterative pruning channels c2, and the number of iterative pruning channels c2 is calculated according to the number of target pruning channels c_target and the duty ratio information (1- α) of iterative pruning in the model pruning process in the pruning proportion information, specifically, c2=c_target is calculated (1- α).
According to the model pruning method provided by the embodiment of the invention, iterative pruning is performed on the basis of one pruning, so that the pruning training process is accelerated, and the pruning upper limit can be raised.
In some embodiments of the invention, the pruning target further comprises a target pruning channel number c_target.
Correspondingly, the pruning is carried out on the model to be pruned for one time according to the pruning target to obtain a first pruned model, which comprises the following steps:
obtaining a first norm of each channel in the model to be pruned, and sequencing each channel in the model to be pruned according to the sequence of the numerical value of the first norm from small to large to obtain a channel sequence.
Specifically, the sum of the weight norm values in each channel under each layer of network layer in the to-be-pruned model is calculated, and each channel is ordered in the order from small to large according to the sum of the weight norm values (namely, the first norm) corresponding to each channel, and the total channel number is recorded as T.
And taking the first p channels in the channel sequence as first channels to be pruned.
And p is calculated according to the number of the target pruning channels c_target and the duty ratio information alpha of one pruning in the pruning proportion information in the model pruning process. Specifically, p=c_target.
Pruning is carried out on the to-be-pruned model according to the first to-be-pruned channel, and a first pruned model is obtained. Namely, pruning p channels in the to-be-pruned model according to the identification information of the first to-be-pruned channel to obtain a first pruned model.
In this embodiment, the norm value of the weight is obtained by calculating the L1 norm of the weight, and in other aspects of the present invention, the norm value may be calculated by other methods such as the L0 norm and the L2 norm.
According to the model pruning method provided by the embodiment of the invention, the channel with lower pruning sensitivity is determined to be the first channel to be pruned according to the norm value of each channel, and pruning is carried out once, so that a first pruned model is obtained.
In some embodiments of the present invention, the step S1 of pruning one channel in the first trimmed model to obtain a single-channel pruned model includes:
and obtaining a second norm of each channel in the first fine-tuned model. I.e. the sum of the scalar values of the channel weights in all network layers in the first tuned model is calculated.
And taking the channel with the smallest second norm value as a second channel to be pruned.
Pruning the first fine-tuned model according to the second to-be-pruned channel to obtain a single-channel pruned model. I.e. in an iterative pruning process, only one channel is pruned per iteration.
In this embodiment, the norm value of the weight is obtained by calculating the L1 norm of the weight, and in other aspects of the present invention, the norm value may be calculated by other methods such as the L0 norm and the L2 norm.
Fig. 3 is a schematic flow chart of an image processing method according to an embodiment of the present invention; as shown in fig. 3, the image processing method includes:
s301, acquiring an image to be processed.
S302, inputting the image to be processed into a trained image processing model, and processing the image to be processed through the trained image processing model to obtain a processing result.
The trained image processing model is obtained through the model pruning method.
In this embodiment, a trained image processing model is obtained through the model pruning method, and the trained image processing model is transplanted into a terminal with limited computing power, and after the terminal acquires an image to be processed, the terminal inputs the image to be processed into the trained image processing model, so that a prediction result is directly obtained, resource consumption is reduced, and response time is improved. For example, the image processing model is a sign classification model, which is transplanted to the end of the automatic driving after training and pruning on the cloud or other computing resource-rich devices. After the vehicle end acquires the images around the vehicle, the classification prediction is carried out through the signpost classification model, and a classification result is obtained. Or the image processing model is a face attribute recognition model which is used for recognizing the gender, age, race and the like of a person in the input face image, and then the face attribute recognition model is transplanted into a terminal with limited computing resources after training and pruning, and the face image acquired by the terminal is recognized to acquire a face recognition result.
The image processing method provided by the embodiment of the invention obtains the image processing model based on the pruning method, and realizes the image processing in the terminal with limited computing resources by using the image processing model, thereby achieving the purposes of reducing the resource consumption and improving the response time.
The model pruning device and the image processing device provided by the invention are described below, the model pruning device and the model pruning method described above can be correspondingly referred to each other, and the image processing device and the image processing method can be correspondingly referred to each other.
Fig. 4 is a schematic structural diagram of a model pruning device according to an embodiment of the present invention, and as shown in fig. 4, the model pruning device includes a to-be-model and pruning target obtaining module 401, a primary pruning module 402, and an iterative pruning module 403.
The model and pruning target obtaining module 401 is configured to obtain a model to be pruned and a pruning target corresponding to the model.
The pruning target comprises pruning proportion information which is used for representing proportion information of one-time pruning and iterative pruning in the pruning process of the model.
In the module, the model to be pruned is a pre-training model, which can be specifically a convolutional neural network, and is obtained by training based on training images and corresponding image labels and is used for image processing.
The pruning target may be the size of the volume to be reached by the pre-training model, may be the pruning rate of the whole pre-training model, or specifically the number of pruning channels, and may further include the total number of iterations of pruning training. In the invention, the pruning target can also comprise pruning proportion information for representing the proportion of the primary pruning and the iterative pruning in the model pruning process, and the pruning proportion information is used for configuring the proportion of the primary pruning and the iterative pruning in the whole pruning training process.
And the primary pruning module 402 is configured to prune the to-be-pruned model once according to the pruning target to obtain a first pruned model.
In the module, a one-time pruning method is adopted to prune (one-shot pruning) the model to be pruned according to a pruning target (such as pruning proportion information), and the pruned model is used as a first pruned model.
And the iterative pruning module 403 is configured to perform iterative pruning on the first pruned model according to the pruning target, obtain a second pruned model, and use the second pruned model as a target model.
In the module, based on the first post-pruning model, pruning is continuously performed according to a pruning target, an iterative pruning method is adopted to prune the first post-pruning model, the pruned model is used as a second post-pruning model, and the second post-pruning model is a final output target model and is used for image processing.
In the prior art, fine-tuning training is performed after each iterative pruning, and the total fine-tuning training times are 10000 if the iterative pruning is performed on a model to be pruned, the iteration times are 10, and the fine-tuning training times after each iterative pruning are 1000; and if the model to be pruned is pruned once and the fine tuning training frequency is set to 2000, the total fine tuning training frequency is 2000. As can be seen from the above examples, the total number of fine tuning training in iterative pruning is too large compared to the one-time pruning method, which results in too long time consumption of the pruning training process, and the upper limit of the pruning model is limited if the pruning is performed only by using one-time pruning. Therefore, the invention combines two methods of one pruning and iterative pruning, for example, one pruning is performed first, in the process of one pruning, the fine tuning training frequency is 1000, in the process of iterative pruning, the iteration frequency is 5, and the fine tuning training frequency is 1000, and in the whole pruning process, the total fine tuning training frequency is 1000+5×1000=6000. As can be seen from the comparison of 6000 and 10000, the fine tuning training times can be greatly reduced by combining the two pruning methods of one pruning and iterative pruning, so that the training time is shortened. In addition, compared with a single pruning method, the pruning upper limit can be improved.
The model pruning device provided by the embodiment of the invention can accelerate the training process through the two modes of primary pruning and iterative pruning, and improves the pruning upper limit compared with a single pruning method.
Fig. 5 is a schematic structural view of an image processing apparatus according to an embodiment of the present invention; as shown in fig. 5, the image processing apparatus includes an image acquisition module 501 and an image processing module 502.
An image acquisition module 501, configured to acquire an image to be processed.
The image processing module 502 is configured to input the image to be processed into a trained image processing model, and process the image to be processed through the trained image processing model to obtain a processing result.
The trained image processing model is obtained through the model pruning device.
In this embodiment, a trained image processing model is obtained through the model pruning method, and the trained image processing model is transplanted into a terminal with limited computing power, and after the terminal acquires an image to be processed, the terminal inputs the image to be processed into the trained image processing model, so that a prediction result is directly obtained, resource consumption is reduced, and response time is improved. For example, the image processing model is a sign classification model, which is transplanted to the end of the automatic driving after training and pruning on the cloud or other computing resource-rich devices. After the vehicle end acquires the images around the vehicle, the classification prediction is carried out through the signpost classification model, and a classification result is obtained. Or the image processing model is a face attribute recognition model which is used for recognizing the gender, age, race and the like of a person in the input face image, and then the face attribute recognition model is transplanted into a terminal with limited computing resources after training and pruning, and the face image acquired by the terminal is recognized to acquire a face recognition result.
The image processing device provided by the embodiment of the invention obtains the image processing model based on the pruning method, and realizes the image processing in the terminal with limited computing resources by using the image processing model, thereby achieving the purposes of reducing the resource consumption and improving the response time.
Fig. 6 is a schematic physical structure diagram of an electronic device according to an embodiment of the present invention, where, as shown in fig. 6, the electronic device may include: processor 610, communication interface (Communications Interface) 620, memory 630, and communication bus 640, wherein processor 610, communication interface 620, and memory 630 communicate with each other via communication bus 640. The processor 610 may invoke logic instructions in the memory 630 to execute a model pruning method comprising: the method comprises the steps of obtaining a model to be pruned and a corresponding pruning target thereof, wherein the model to be pruned is obtained based on image data training, the pruning target comprises pruning proportion information, and the pruning proportion information is used for representing proportion information of primary pruning and iterative pruning in a model pruning process; pruning is carried out on the model to be pruned for one time according to the pruning target, and a first pruned model is obtained; and carrying out iterative pruning on the first pruned model according to the pruning target to obtain a second pruned model, and taking the second pruned model as a target model.
Or to perform an image processing method comprising: acquiring an image to be processed; inputting the image to be processed into a trained image processing model, and processing the image to be processed through the trained image processing model to obtain a processing result; the trained image processing model is obtained through the model pruning method.
Further, the logic instructions in the memory 630 may be implemented in the form of software functional units and stored in a computer-readable storage medium when sold or used as a stand-alone product. Based on this understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method of the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
In yet another aspect, the present invention also provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, is implemented to perform a model pruning method, the model pruning method comprising: the method comprises the steps of obtaining a model to be pruned and a corresponding pruning target thereof, wherein the model to be pruned is obtained based on image data training, the pruning target comprises pruning proportion information, and the pruning proportion information is used for representing proportion information of primary pruning and iterative pruning in a model pruning process; pruning is carried out on the model to be pruned for one time according to the pruning target, and a first pruned model is obtained; and carrying out iterative pruning on the first pruned model according to the pruning target to obtain a second pruned model, and taking the second pruned model as a target model.
Or to perform an image processing method comprising: acquiring an image to be processed; inputting the image to be processed into a trained image processing model, and processing the image to be processed through the trained image processing model to obtain a processing result; the trained image processing model is obtained through the model pruning method.
The apparatus embodiments described above are merely illustrative, wherein elements illustrated as separate elements may or may not be physically separate, and elements shown as elements may or may not be physical elements, may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
From the above description of the embodiments, it will be apparent to those skilled in the art that the embodiments may be implemented by means of software plus necessary general hardware platforms, or of course may be implemented by means of hardware. Based on such understanding, the foregoing technical solutions may be embodied essentially or in part in the form of a software product, which may be stored in a computer-readable storage medium, such as a ROM/RAM, a magnetic disk, an optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to perform the various embodiments or methods of some parts of the embodiments.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present invention, and are not limiting; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims (11)

1. A method of pruning a model, comprising:
obtaining a model to be pruned and a corresponding pruning target; the pruning target comprises pruning proportion information which is used for representing proportion information of primary pruning and iterative pruning in the pruning process of the model;
pruning is carried out on the model to be pruned for one time according to the pruning target, and a first pruned model is obtained;
and carrying out iterative pruning on the first pruned model according to the pruning target to obtain a second pruned model, and taking the second pruned model as a target model.
2. The model pruning method of claim 1, wherein the pruning target further comprises a total number of pruning training iterations;
correspondingly, after pruning the model to be pruned for one time according to the pruning target to obtain a first pruned model, the method further comprises:
performing fine tuning training on the first pruned model according to the first fine tuning times to obtain a first fine tuned model; the first fine tuning times are determined according to the proportion information of one pruning in the pruning proportion information in the model pruning process and the total number of pruning training iterations;
performing iterative pruning on the first pruned model according to the pruning target to obtain a second pruned model, including:
and carrying out iterative pruning on the first fine-tuned model according to the pruning target to obtain a second pruned model.
3. The model pruning method according to claim 2, wherein the pruning target further comprises a target pruning channel number;
correspondingly, the iterative pruning is carried out on the first fine-tuned model according to the pruning target to obtain a second pruned model, which comprises the following steps:
s1, pruning is carried out on one channel in the first fine-tuned model, and a single-channel pruned model is obtained;
s2, performing fine tuning training on the single-channel pruned model according to the second fine tuning times to obtain a second fine tuned model; the second fine tuning times are determined according to the proportion information of iterative pruning in the model pruning process, the target pruning channel number and the pruning training iteration total number in the pruning proportion information;
s3, repeatedly executing S1-S2 on the basis of the second fine-tuned model until the preset iteration times are reached, so as to obtain a latest second fine-tuned model, and taking the latest second fine-tuned model as a second pruned model;
the preset iteration times are determined according to the number of iteration pruning channels, and the number of iteration pruning channels is calculated according to the number of target pruning channels and the duty ratio information of the iteration pruning in the model pruning process in the pruning proportion information.
4. The method of model pruning according to claim 3, wherein the second fine tuning number is determined according to the ratio information of iterative pruning in the model pruning process, the target pruning channel number and the total number of pruning training iterations in the pruning proportion information, and includes:
calculating to obtain the total number of iterative pruning fine tuning training according to the duty ratio information of the iterative pruning in the model pruning process and the total number of pruning training iterations;
and calculating the second fine tuning times according to the total times of the iterative pruning fine tuning training and the number of the iterative pruning channels.
5. The model pruning method according to claim 2, wherein the pruning target further comprises a target pruning channel number;
correspondingly, the pruning is carried out on the model to be pruned for one time according to the pruning target to obtain a first pruned model, which comprises the following steps:
acquiring a first norm of each channel in the model to be pruned, and sequencing each channel in the model to be pruned according to the sequence from small to large of the numerical value of the first norm to obtain a channel sequence;
taking the first p channels in the channel sequence as first channels to be pruned, wherein p is calculated according to the number of the target pruning channels and the duty ratio information of primary pruning in the pruning proportion information in the model pruning process;
pruning is carried out on the to-be-pruned model according to the first to-be-pruned channel, and a first pruned model is obtained.
6. The method for pruning a model according to claim 3, wherein said step S1 of pruning one channel in said first trimmed model to obtain a single channel pruned model comprises:
acquiring a second norm of each channel in the first fine-tuned model;
taking the channel with the smallest second norm value as a second channel to be pruned;
pruning the first fine-tuned model according to the second to-be-pruned channel to obtain a single-channel pruned model.
7. An image processing method, comprising:
acquiring an image to be processed;
inputting the image to be processed into a trained image processing model, and processing the image to be processed through the trained image processing model to obtain a processing result;
wherein the trained image processing model is obtained by the model pruning method according to any one of claims 1-6.
8. A model pruning device, comprising:
the model and pruning target acquisition module is used for acquiring a model to be pruned and a pruning target corresponding to the model to be pruned; the pruning target comprises pruning proportion information which is used for representing proportion information of primary pruning and iterative pruning in the pruning process of the model;
the primary pruning module is used for pruning the model to be pruned for one time according to the pruning target to obtain a first pruned model;
and the iterative pruning module is used for carrying out iterative pruning on the first pruned model according to the pruning target to obtain a second pruned model, and taking the second pruned model as a target model.
9. An image processing apparatus, comprising:
the image acquisition module is used for acquiring an image to be processed;
the image processing module is used for inputting the image to be processed into a trained image processing model, and processing the image to be processed through the trained image processing model to obtain a processing result; wherein the trained image processing model is obtained by the model pruning device according to claim 8.
10. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the model pruning method of any one of claims 1 to 6 or the image processing method of claim 7 when executing the program.
11. A non-transitory computer readable storage medium having stored thereon a computer program, characterized in that the computer program, when executed by a processor, implements the model pruning method of any one of claims 1 to 6 or the image processing method of claim 7.
CN202211659437.7A 2022-12-22 2022-12-22 Model pruning method, image processing method and related devices Pending CN116011550A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211659437.7A CN116011550A (en) 2022-12-22 2022-12-22 Model pruning method, image processing method and related devices

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211659437.7A CN116011550A (en) 2022-12-22 2022-12-22 Model pruning method, image processing method and related devices

Publications (1)

Publication Number Publication Date
CN116011550A true CN116011550A (en) 2023-04-25

Family

ID=86025997

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211659437.7A Pending CN116011550A (en) 2022-12-22 2022-12-22 Model pruning method, image processing method and related devices

Country Status (1)

Country Link
CN (1) CN116011550A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116188878A (en) * 2023-04-25 2023-05-30 之江实验室 Image classification method, device and storage medium based on neural network structure fine adjustment

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116188878A (en) * 2023-04-25 2023-05-30 之江实验室 Image classification method, device and storage medium based on neural network structure fine adjustment

Similar Documents

Publication Publication Date Title
US10332507B2 (en) Method and device for waking up via speech based on artificial intelligence
EP4239585A1 (en) Video loop recognition method and apparatus, computer device, and storage medium
CN111523324B (en) Named entity recognition model training method and device
CN112598110B (en) Neural network construction method, device, equipment and medium
CN116011550A (en) Model pruning method, image processing method and related devices
CN112233102A (en) Method, device and equipment for identifying noise in image sample set and storage medium
WO2019232723A1 (en) Systems and methods for cleaning data
CN115512238A (en) Method and device for determining damaged area, storage medium and electronic device
CN113807166B (en) Image processing method, device and storage medium
CN116128044A (en) Model pruning method, image processing method and related devices
CN112561054A (en) Neural network filter pruning method based on batch characteristic heat map
CN116071472A (en) Image generation method and device, computer readable storage medium and terminal
CN114385876B (en) Model search space generation method, device and system
CN112200275B (en) Artificial neural network quantification method and device
CN114065920A (en) Image identification method and system based on channel-level pruning neural network
CN114004974A (en) Method and device for optimizing images shot in low-light environment
CN112733932A (en) Model accelerated training method and device based on training data similarity aggregation
CN113706470A (en) Iris image segmentation method and device, electronic equipment and storage medium
CN113033422A (en) Face detection method, system, equipment and storage medium based on edge calculation
CN113392867A (en) Image identification method and device, computer equipment and storage medium
CN111062477A (en) Data processing method, device and storage medium
CN115881103B (en) Speech emotion recognition model training method, speech emotion recognition method and device
CN112396613B (en) Image segmentation method, device, computer equipment and storage medium
CN117421657A (en) Sampling and learning method and system for noisy labels based on oversampling strategy
CN113705598A (en) Data classification method and device and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination