Image processing method, image processing model optimization method and related equipment

By performing channel expansion and structural pruning on the convolutional neural network model, the problem of slower inference speed caused by the increase in model complexity is solved, and the image processing effect and efficiency can be improved without reducing performance.

CN117710786BActive Publication Date: 2024-10-29HONOR DEVICE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310979725.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-04
Publication Date
2024-10-29
Estimated Expiration
2043-08-04

AI Technical Summary

Technical Problem

When optimizing the accuracy and effect of existing convolutional neural network models, it is easy to increase the complexity of the model and slow down the inference speed. It cannot meet the real-time needs of image processing in mobile phone photography, fireworks detection, face recognition and other scenarios.

Method used

By channel expansion of the second neural network model, a more complex third neural network model is obtained, and structured pruning is performed to obtain a first neural network model with the same structure as the second neural network model but reduced complexity, which is used for images. processing to ensure that model performance does not deteriorate while improving image processing effects.

Benefits of technology

Without extending the image processing time, the image processing effect is improved, the software and hardware adaptation process is saved, the model optimization cost is reduced, the chip utilization is ensured, and the model performance is kept from deteriorating.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117710786B_ABST
    Figure CN117710786B_ABST
Patent Text Reader

Abstract

The present application provides an image processing method, an optimization method for an image processing model, and related equipment. According to the image processing method, after acquiring the image, the electronic device processes the image based on the first neural network model, and outputs the image processed by the first neural network model. Among them, the first neural network model is optimized by the second neural network model adapted to the hardware of the electronic device. Through the expansion and structured pruning of the channels of the convolutional layer, the channels in the model are screened while ensuring that the structure of the model remains unchanged, so that the structure of the first neural network model is the same as that of the second neural network model, thereby improving the image processing effect without extending the time for the electronic device to process the image. According to the optimization method of the image processing model, the first neural network model is obtained by processing the second neural network model, which can optimize the accuracy and effect of the model without deteriorating the performance of the model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of terminal technology, and in particular to an image processing method, an optimization method for an image processing model, and related equipment. Background Art

[0002] Convolutional neural network models are often used for image processing. Generally speaking, the image processing effect can be improved by optimizing the accuracy and effect of the convolutional neural network model. However, optimizing the accuracy and effect of the convolutional neural network model is likely to increase the complexity of the convolutional neural network model, resulting in a deterioration in the performance of the algorithm, that is, the inference speed of the model becomes slower and the image processing time is longer. However, many scenarios that require image processing, such as mobile phone photography, fireworks detection, face recognition, etc., have requirements for the image processing effect and the time required for image processing. Summary of the invention

[0003] The present application provides an image processing method, an optimization method for an image processing model, and related equipment. According to the image processing method, the image processing effect can be improved without prolonging the time for an electronic device to process an image. According to the optimization method for the image processing model, the accuracy and effect of the model can be optimized without deteriorating the performance of the neural network model.

[0004] In a first aspect, an image processing method is provided, which is applied to an electronic device. The method may include: acquiring an image; processing the image based on a first neural network model; and outputting the image processed by the first neural network model; wherein the first neural network model is obtained according to the second neural network model, the second neural network model is used for image processing, the structure of the second neural network model is adapted to the hardware structure of the electronic device, and the structure of the first neural network model is the same as the structure of the second neural network model, wherein the first neural network model is obtained according to the second neural network model, including: the first neural network model includes Y third convolutional layers, the second neural network model includes Y first convolutional layers, the first neural network model is obtained by pruning the channels of the Y second convolutional layers in the third neural network model, and the Y third convolutional layers correspond to the Y second convolutional layers one by one; the third neural network model is obtained by increasing the number of channels in the Y first convolutional layers in the second neural network model, and the Y first convolutional layers correspond to the Y second convolutional layers one by one, Y ≥ 2, and Y is an integer.

[0005] In the image processing method provided in the present application, after acquiring the image, the electronic device processes the image based on the first neural network model obtained according to the second neural network model. Among them, the second neural network model is firstly channel-expanded to obtain a third neural network model that is more complex than the second neural network model. Compared with the second neural network model, the third neural network model has a better effect in processing images, but the model complexity is higher and the reasoning speed is slower. Pruning the third neural network model can reduce the complexity of the third neural network model to improve the reasoning speed of the model without significantly reducing the accuracy of the model. The structure of the first neural network model finally obtained is the same as that of the second neural network model. Therefore, through the above method, the image processing effect can be improved without extending the time for the electronic device to process the image. In addition, since the structure of the second neural network model is compatible with the hardware structure of the electronic device, the structure of the first neural network model is also compatible with the hardware structure of the electronic device. The above scheme can save the process of hardware and software adaptation, reduce the cost of model optimization, and at the same time, ensure that the utilization rate of the chip is not affected.

[0006] It is understandable that the image processed by the first neural network model needs to undergo a series of subsequent processing before it can be displayed on the interface of the electronic device. The subsequent processing here may include brightening, sharpening, color correction, etc. However, the impact of these subsequent processes on the clarity and noise of the final output image is almost negligible compared to the impact of model #a or the third neural network on clarity and noise.

[0007] It can also be understood that the first neural network model has the same structure as the second neural network model, that is, the two models have the same number of convolutional layers, and the number of channels in the corresponding convolutional layers in the two models is equal, for example, the number of channels in the ith convolutional layer of the first neural network model is equal to the number of channels in the ith convolutional layer of the second neural network model. In other words, in order to increase the number of channels in the ith convolutional layer of the second neural network model to obtain the third neural network model, it is necessary to delete the same number of channels as the number of channels added in the ith convolutional layer of the third neural network model in order to make the structure of the first neural network model the same as that of the second neural network model.

[0008] Among them, the structure of the first neural model involved in the present application is designed according to the characteristics of the deployed hardware platform, or in other words, the structure of the first neural model is adapted to the hardware structure of the electronic device, which can be understood by referring to the following example: When the chip in the electronic device runs the convolutional neural network model, the chip will allocate resources for processing channels for each convolutional layer in the convolutional neural network model, and the number of channels that the resource can handle is an integer multiple of a value (for example, represented by G, G≥1 and G is an integer). G is determined by the hardware structure design of the chip, for example, G here can be 16, 64 or 48. For example, if the number of channels in a convolutional layer is G, then the chip calls the resources corresponding to G channels to process the channels of the convolutional layer. For another example, if the number of channels in a convolutional layer is 2G, then the chip calls the resources corresponding to 2G channels to process the channels of the convolutional layer. For another example, if the number of channels in a convolutional layer is G', and G'<G, then the chip still calls the resources corresponding to G channels to process the channels of the convolutional layer. In this case, the utilization rate of the chip will be reduced. When the number of channels of each convolutional layer in the second neural network model is an integer multiple of G, it can be understood that the structure of the first neural model is designed according to the characteristics of the deployed hardware platform, or in other words, the structure of the first neural model is compatible with the hardware structure of the electronic device, and in this case, the chip utilization can be guaranteed as high as possible.

[0009] In combination with the first aspect, in a possible implementation method, the image is processed based on the first neural network model, including: obtaining image data based on the image, the image data being used to indicate all pixels in the image; inputting the image data into the first neural network model; performing convolution calculation on the image data by the i-th third convolution layer among Y third convolution layers, and outputting the i-th calculation result; and inputting the i-th calculation result into the i+1-th third convolution layer after calculation by other non-convolution layers, where 1≤i≤Y-1 and i is an integer.

[0010] It can be understood that after each convolution layer in the neural network model performs convolution calculations on the part of image data #1 that corresponds to each pixel, the calculation results are input to the next layer, and finally the model outputs the processed image. The network structure also contains other layers; for example, the result of the convolution calculation first passes through the activation layer and then is input to the next convolution layer, or there are two convolution layers that perform convolution calculations and obtain two results that pass through the activation layer respectively, and then the two results are added and input to the next convolution layer.

[0011] As an example, after the electronic device acquires an image, it obtains image data (hereinafter referred to as image data #1 for the convenience of explanation), and image data #1 is used to indicate all pixels in the image. For example, the image data #1 may be in a raw (RAW) format or a red, green, and blue (RGB) format. In a possible implementation, the image processed by the first neural network model may be image data in a RAW format or an RGB format (hereinafter referred to as image data #3 for the convenience of explanation).

[0012] Exemplarily, in a mobile phone camera scenario, the pixels in the image processed by the first neural network model correspond one-to-one to the pixels indicated by image data #1, or the pixels indicated by image data #3 correspond one-to-one to the pixels indicated by image data #1. For example, the image output by image data #3 after a series of subsequent processing has improved clarity and reduced noise compared to the image acquired by the electronic device; in a face recognition scenario, image data #3 is the coordinate data of a person's facial features in an image composed of all pixels of image data #1; in a fireworks detection scenario, image data #3 is the coordinate data of smoke and fire in an image composed of all pixels of image data #1.

[0013] In combination with the first aspect, in one possible implementation, the third neural network model is obtained by respectively increasing the number of channels in Y first convolutional layers in the second neural network model, including: the third neural network model is obtained by training the fourth neural network model until convergence based on the data set, wherein the data set is a data set used to train the second neural network model; the fourth neural network model is obtained by respectively increasing the number of channels of each first convolutional layer in the Y first convolutional layers.

[0014] In combination with the first aspect, in one possible implementation, the first neural network model is obtained by pruning the channels of the Y second convolutional layers in the third neural network model, including: the first neural network model is obtained by fine-tuning the fifth neural network based on the data set, wherein the data set is a data set for training the second neural network model; the fifth neural network model is obtained by pruning the channels of the Y second convolutional layers in the third neural network model.

[0015] It is understandable that in the present application, in the same scenario, the data sets used to train different neural network models are all the same data set. Among them, the data set includes input data and target data. Taking the face recognition scenario as an example, the input data can be image data obtained by processing the image acquired by the electronic device camera, for example, it can be in the original (RAW) format or the red, green and blue (RGB) format. The target data is the coordinate data of the facial features on the face in the image, such as the coordinates of the eyes and the coordinates of the corners of the mouth. Taking the mobile phone photo scene as an example, the input data can be image data #1 obtained by processing the image #1 acquired by the electronic device camera, for example, it can be in RAW format or RGB format, and the image data #1 is used to indicate all pixels of the image #1. The target data is image data #2, for example, it can be in RAW format or RGB format, and the image data #2 is used to indicate all pixels of the image #2. The content displayed by image #2 is basically the same as that of image #1, except that image #2 has higher clarity and less noise than image #1, or image #2 does not include noise and has high clarity.

[0016] It can also be understood that the purpose of training the model in this application is to ensure that after the model is fed with input data, the output of the model can be as close to the target data as possible. In this way, the better the parameters in the model are learned, the better the effect of the model in processing images will be.

[0017] It can also be understood that although the first neural network model and the second neural network model have the same structure, the parameters of the convolution layer in the model are different. The convolution calculation of the image data is performed using the parameters in the convolution layer. Since the first neural network model is obtained according to the second neural network model, the first neural network model inherits part of the convolution layer parameters from the more complex third neural network model for retraining, and has better parameter initialization than directly training the second neural network model, the effect of the first neural network model processing the image will be significantly optimized relative to the effect of the second neural network model processing the image.

[0018] In combination with the first aspect, in one possible implementation, the first neural network model is obtained by pruning the channels of the Y second convolutional layers in the third neural network model, including: the first neural network model is obtained by respectively calculating the importance scores of the channels in the Y second convolutional layers, and pruning the channels in the Y second convolutional layers according to the importance scores.

[0019] The above scheme prunes channels according to importance scores so as to better filter out unimportant channels and delete them, minimizing the loss of model accuracy.

[0020] In combination with the first aspect, in a possible implementation, channels in Y second convolutional layers are pruned respectively according to importance scores, including: sorting the importance scores of channels of the i-th second convolutional layer in the Y second convolutional layers; deleting X channels in the i-th second convolutional layer, where the importance scores of the X channels are lower than the importance scores of other channels in the i-th second convolutional layer, 1≤i≤Y and i is an integer, and X≥1 and X is an integer.

[0021] The above scheme, for each second convolutional layer, sorts the channels in the convolutional layer according to the importance scores of the channels, filters out unimportant channels and deletes them, which can minimize the reduction of the accuracy of the model.

[0022] In combination with the first aspect, in one possible implementation, the i-th second convolutional layer includes Z channels, and the importance score of the j-th channel within the Z channels is determined based on the L1 norm or L2 norm of the j-th channel weight parameter, Z>X and Z is an integer, 1≤j≤Z and j is an integer.

[0023] Among them, the L1 norm can also be called the L1 value, which is the sum of the absolute values ​​of all weight parameters in the channel; the L2 norm can also be called weight decay. The above scheme is to better score the importance of the channels in the convolution layer.

[0024] In combination with the first aspect, in a possible implementation manner, the number of channels added to the i-th second convolutional layer relative to the i-th first convolutional layer among the Y first convolutional layers is yi, and X=yi.

[0025] In the above scheme, the number of channels added by the Y second convolutional layers in the third neural network model relative to the Y first convolutional layers in the second neural network model is equal to the number of channels deleted by the Y third convolutional layers in the first neural network model relative to the Y second convolutional layers in the third neural network model, so that the structure of the first neural network model is the same as that of the second neural network model.

[0026] In combination with the first aspect, in one possible implementation, yi is determined based on at least one of the following: the importance of the i-th first convolutional layer in all convolutional layers of the second neural network model, and the number of channels within the i-th first convolutional layer.

[0027] In combination with the first aspect, in a possible implementation, yi is greater than or equal to the number of channels in the i-th first convolutional layer. And / or, yi is less than or equal to the number of channels in the i-th first convolutional layer.

[0028] In a second aspect, a method for optimizing an image processing model is provided, which may include: increasing the number of channels in Y first convolutional layers in a second neural network model respectively to obtain a third neural network model, wherein the second neural network model is used for image processing, and the third neural network model includes Y second convolutional layers, and the Y first convolutional layers correspond one-to-one to the Y second convolutional layers; pruning the channels of the Y second convolutional layers in the third neural network model respectively to obtain a first neural network model, the first neural network model is used for image processing, the structure of the first neural network model is the same as that of the second neural network model, the first neural network model includes Y third convolutional layers, and the Y third convolutional layers correspond one-to-one to the Y second convolutional layers, Y ≥ 1, and Y is an integer.

[0029] In the solution provided by the present application, the third neural network model obtained by increasing the number of channels in some or all of the convolutional layers in the second neural network model is a more complex model than the second neural network model. Compared with the second neural network model, the third neural network model has a better effect in processing images, but the model complexity is higher and the reasoning speed is slower. Pruning the third neural network model can reduce the complexity of the third neural network model to improve the reasoning speed of the model without significantly reducing the accuracy of the model. Therefore, through the above method, the accuracy and effect of the model can be optimized without deteriorating the performance of the model.

[0030] It can be understood that the pruning process for channels within the convolution layer involved in the present application is a type of structured pruning, that is, pruning the convolution kernels of certain convolution layers in the neural network model to reduce the number of channels of the convolution layer, and reducing the number of parameters of the model by simplifying the structure of the neural network model, thereby reducing the complexity of the neural network model and improving the reasoning speed of the neural network model.

[0031] For the beneficial effects of possible implementations of the second aspect, refer to the corresponding description in the first aspect.

[0032] In combination with the second aspect, in a possible implementation method, the channels of the Y second convolutional layers in the third neural network model are pruned separately, including: calculating the importance scores of the channels in the Y second convolutional layers respectively; and pruning the channels in the Y second convolutional layers respectively according to the importance scores.

[0033] In combination with the second aspect, in a possible implementation method, channels in Y second convolutional layers are pruned respectively according to importance scores, including: sorting the importance scores of channels of the i-th second convolutional layer in the Y second convolutional layers; deleting X channels in the i-th second convolutional layer, where the importance scores of the X channels are lower than the importance scores of other channels in the i-th second convolutional layer, 1≤i≤Y and i is an integer, and X≥1 and X is an integer.

[0034] In combination with the second aspect, in one possible implementation, the i-th second convolutional layer includes Z channels, and the importance score of the j-th channel within the Z channels is determined based on the L1 norm or L2 norm of the j-th channel weight parameter, Z>X and Z is an integer, 1≤j≤Z and j is an integer.

[0035] In combination with the second aspect, in a possible implementation, the number of channels added to the i-th second convolutional layer relative to the i-th first convolutional layer in the Y first convolutional layers is y i , and X=y i .

[0036] In conjunction with the second aspect, in a possible implementation, y i It is determined according to at least one of the following: the importance of the i-th first convolutional layer in all convolutional layers of the second neural network model, and the number of channels in the i-th first convolutional layer.

[0037] In conjunction with the second aspect, in a possible implementation, y i Greater than or equal to the number of channels in the i-th first convolutional layer and / or, i Less than or equal to the number of channels in the i-th first convolutional layer.

[0038] In combination with the second aspect, in one possible implementation, the number of channels in the Y first convolutional layers in the second neural network model is increased respectively to obtain a third neural network model, including: increasing the number of channels of each of the Y first convolutional layers respectively to obtain a fourth neural network model; training the fourth neural network model to convergence based on the data set to obtain the third neural network model, wherein the data set is a data set used to train the second neural network model.

[0039] In combination with the second aspect, in one possible implementation, the channels of the Y second convolutional layers in the third neural network model are pruned separately to obtain a first neural network model, including: pruning the channels of the Y second convolutional layers in the third neural network model separately to obtain a fifth neural network model; and fine-tuning the fifth neural network based on the data set to obtain the first neural network model, wherein the data set is a data set for training the second neural network model.

[0040] It can be understood that although the structures of the first neural network model and the second neural network model are the same, the parameters of the models are different.

[0041] In combination with the second aspect, in one possible implementation, when the structure of the second neural network model is adapted to the hardware structure of the electronic device, the structure of the first neural network model is adapted to the hardware structure of the electronic device.

[0042] In the solution provided in the present application, the obtained first neural network model is still adapted to the hardware platform of the mobile phone, thereby saving the step of further optimizing the structure of the first neural network model or performing performance evaluation based on the hardware platform characteristics of the mobile phone; thus, the image processing method provided in the present application can be applied to more electronic devices, saving the process of software and hardware adaptation, reducing the cost of model optimization, and at the same time, ensuring that the chip utilization is not affected.

[0043] It can be understood that the structure of the second neural network model is designed to give full play to the performance of the hardware platform of the electronic device and according to the characteristics of the hardware platform on which the second neural network model is deployed. The second neural network model can be understood as the structure of the neural network model for image processing that is currently adapted to the hardware platform of the electronic device. In view of the fact that the first neural network model has the same structure as the second neural network model, the current hardware platform of the electronic device is still adapted to the first neural network model.

[0044] In a third aspect, the present application provides an electronic device, comprising one or more processors and one or more memories; wherein the one or more memories are coupled to the one or more processors, and the one or more memories are used to store computer program code, and the computer program code includes computer instructions. When the one or more processors execute the computer instructions, the electronic device executes the method described in the first aspect or the second aspect and any possible implementation method of the first aspect or the second aspect.

[0045] In a fourth aspect, an embodiment of the present application provides a chip system, which is applied to an electronic device, and the chip system includes one or more processors, which are used to call computer instructions so that the electronic device executes the method described in the first aspect or the second aspect and any possible implementation method of the first aspect or the second aspect.

[0046] In a fifth aspect, a computer-readable storage medium is provided, in which instructions are stored, and when the computer-readable storage medium is run on a computer, the computer executes the optimization method of the image processing model of the first aspect or the second aspect mentioned above.

[0047] In a sixth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute the method for optimizing the image processing model described in the first aspect or the second aspect.

[0048] The technical effects obtained by the third, fourth, fifth and sixth aspects are similar to the technical effects obtained by the corresponding technical means in the first or second aspects, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Figure 1 A schematic diagram showing an example of a neural network channel pruning technology involved in the present application;

[0050] Figure 2 A schematic diagram showing another example of the neural network channel pruning technology involved in the present application;

[0051] Figure 3A A schematic diagram showing a loss function change curve during the model training process provided by the present application is shown;

[0052] Figure 3B and Figure 3C The output graph of model #a and the output graph of the first neural network model provided by the present application are respectively shown in the scene of taking photos by a mobile phone in a night environment;

[0053] Figure 3D Shows Figure 3C and Figure 3B Local comparison diagram of

[0054] Figure 4 A schematic diagram showing an optimization method for an image processing model provided by the present application is shown;

[0055] Figure 5A and Figure 5B A schematic diagram showing another method for optimizing an image processing model provided by the present application is shown;

[0056] Figure 6 A schematic diagram of an image processing method provided by the present application is shown;

[0057] Figure 7 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application is shown;

[0058] Figure 8 A block diagram of a software system of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0059] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below in conjunction with the accompanying drawings.

[0060] It should be understood that the "multiple" mentioned in this application refers to two or more. In the description of this application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in order to facilitate the clear description of the technical solution of this application, the words "first" and "second" are used to distinguish between the same items or similar items with basically the same functions and effects. Those skilled in the art can understand that the words "first" and "second" do not limit the quantity and execution order, and the words "first" and "second" do not limit them to be different.

[0061] It should be noted that the image processing method and the optimization method of the image processing model provided in the embodiments of the present application are applicable to any electronic device with a shooting function, such as a mobile phone, a tablet computer, a camera, a smart wearable device, etc., and the embodiments of the present application do not limit this. In addition, the image processing method and the optimization method of the image processing model provided in the embodiments of the present application can be applied to a variety of shooting scenes, such as mobile phone photography, fireworks detection, face recognition, etc., and of course can also be applied to other shooting scenes, and the embodiments of the present application do not limit this.

[0062] Taking the mobile phone photography scene as an example, the image can be taken in a scene with extremely low light intensity, such as an image taken under a light intensity equal to or less than 5 Lux, or an image taken in a night environment. Compared with images taken in a normal light environment, when electronic devices shoot at night or in a poor light environment, the electronic devices will automatically adjust the exposure time and photosensitivity (also known as ISO value) to adjust the brightness of the photo (ie, automatic exposure), resulting in more serious image noise. Therefore, electronic devices generally perform noise reduction and brightness adjustment on the image when shooting night scenes. Color noise is particularly prone to appear when shooting night scenes, so the processing of color noise is very important in noise reduction.

[0063] Image noise or image noise is a random change in brightness or color information in an image (the object being photographed does not have it), usually a manifestation of electronic noise. Color noise or chroma noise (also referred to as color noise) is a type of image noise, which refers to the phenomenon that in digital image processing, some color channels in the image have random fluctuations due to the nonlinear characteristics of the sensor, noise and other reasons. This phenomenon usually manifests as colored noise or noise spots. Image noise will reduce the clarity of the photo, especially color noise will also interfere with the color purity. As an example, in a photo of light taken by a mobile phone at night, in an area not illuminated by the light, or in an area with a light intensity equal to or less than 5 lux, color blocks or dots of other colors other than the color seen by the naked eye in the area may appear. These other color blocks or dots are color noise spots or noise spots for the photo. For example, blue and red color noise may appear in the night sky in the photo, and purple or green color noise may appear on the ground with very weak light. In addition, the more colored noise or noise spots there are in a photo, the lower the clarity of the photo will be.

[0064] Currently, the noise of images, especially color noise, is mainly reduced through convolutional neural network models. Generally speaking, to improve the effect of reducing image noise, it can be achieved by optimizing the accuracy and effect of the convolutional neural network model. However, optimizing the accuracy and effect of the convolutional neural network model may require increasing the complexity of the convolutional neural network model, which will lead to deterioration of the performance of the algorithm. Increasing the complexity of the convolutional neural network model usually leads to deterioration of the performance of the algorithm, that is, the inference speed of the model slows down, the electronic device takes longer to take pictures, and the user's photo experience will also deteriorate.

[0065] Similarly, convolutional neural networks can also be used in other scenarios that require image processing, such as face recognition and security tasks. Taking the face recognition scenario as an example, to improve the accuracy of face detection and recognition, it can be achieved by optimizing the accuracy and effect of the convolutional neural network model. However, optimizing the accuracy and effect of the convolutional neural network model may require increasing the complexity of the convolutional neural network model, which will lead to the deterioration of the algorithm's performance. Increasing the complexity of the convolutional neural network model will usually lead to the deterioration of the algorithm's performance, that is, the model's reasoning speed will slow down, the time required for face recognition will be longer, and the user's experience of face recognition will also deteriorate. Taking the fireworks detection scenario in the security task as an example, improving the accuracy of smoke and fire detection and recognition can be achieved by optimizing the accuracy and effect of the convolutional neural network model. However, optimizing the accuracy and effect of the convolutional neural network model may require increasing the complexity of the convolutional neural network model, which will lead to the deterioration of the algorithm's performance. Increasing the complexity of the convolutional neural network model will usually lead to the deterioration of the algorithm's performance, that is, the model's reasoning speed will slow down, the time required for fireworks detection will be longer, and the timely needs of the security task will not be met.

[0066] In the optimization method of the image processing model provided in the present application, the number of channels of some or all convolutional layers in the second neural network model used for image processing is first expanded to obtain a model more complex than the first neural network, and then the model is trained until convergence to obtain a third neural network model. Subsequently, structured pruning is performed in the third neural network model to obtain the first neural network model; and the structure of the first neural network model is the same as that of the second neural network model.

[0067] It can be understood that the structure of the second neural network model is designed to give full play to the performance of the hardware platform of the electronic device and is designed according to the characteristics of the hardware platform on which the second neural network model is deployed. The second neural network model can be understood as the structure of the neural network model for image processing that is currently adapted to the hardware platform of the electronic device. Given that the first neural network model has the same structure as the second neural network model, the current hardware platform of the electronic device is still adapted to the first neural network model.

[0068] It can also be understood that the neural network channel pruning technology involved in the present application belongs to a type of structured pruning, that is, pruning the convolution kernels of certain convolution layers in the neural network model to reduce the number of channels of the convolution layer, and reducing the number of parameters of the model by simplifying the structure of the neural network model, thereby reducing the complexity of the neural network model to improve the reasoning speed of the neural network model. Among them, the number of channels of a certain convolution layer is equal to the number of convolution kernels of the convolution layer. The channel pruning involved in the present application can be understood as pruning the channels of the convolution layer, and can also be understood as pruning the convolution kernels of the convolution layer. In the process of implementing neural network channel pruning, it is necessary to first evaluate the importance of each channel in the convolution layer to be pruned, and then prune the channels in order of importance from small to large. Evaluating the importance of each channel in the pruned convolution layer can be understood as judging the importance of each channel in the convolution layer according to certain standards; for example, the importance of the channel can be determined based on the L1 norm or L2 norm of the channel. Among them, the L1 norm can also be called the L1 value, that is, the sum of the absolute values ​​of all weight parameters in the channel; the L2 norm can also be called weight decay. The following is combined with Figure 1 and Figure 2 , further introduces the neural network channel pruning technology involved in this application in detail.

[0069] Figure 1 A schematic diagram showing an example of the neural network channel pruning technology involved in the present application. Figure 1 The convolution layer shown includes n convolution kernels, i.e., convolution kernel #1 to convolution kernel #n, where n ≥ 3 and n is an integer; each convolution kernel has several weight parameters. Taking the importance evaluation based on the L1 value of each convolution kernel as an example, the L1 values ​​of the n convolution kernels are arranged from small to large, and the first m convolution kernels are pruned, where 1 ≤ m < n and m is an integer. Assuming m = 2, after arranging the L1 values ​​of the n convolution kernels from small to large, convolution kernel #1 and convolution kernel #n are the first two convolution kernels and need to be pruned.

[0070] Figure 2 A schematic diagram showing another example of the neural network channel pruning technology involved in the present application is shown. Figure 2As shown, neural network model #1 is channel pruned to obtain neural network model #2. Assume that the channels from convolution layer #2 to convolution layer #4 in neural network model #1 are pruned. Specifically, convolution layer #2, convolution layer #3 and convolution layer #4 of neural network model #1 have 64, 96 and 128 channels respectively; after pruning 16, 32 and 48 channels of convolution layer #2, convolution layer #3 and convolution layer #4 respectively, convolution layer #2, convolution layer #3 and convolution layer #4 of neural network model #2 have 48, 65 and 80 channels respectively. In addition, in neural network model #1 and neural network model #2, the number of channels of the unpruned convolution layers is the same. Compared with neural network model #1, neural network model #2 after channel pruning has lower structural complexity and better performance.

[0071] In a possible related technology, the second neural network model used for image processing is directly trained to obtain a model with better image processing effect (for the convenience of explanation, referred to as model #a below). The image processing model optimization method provided in the present application first trains the neural model after the channel expansion of the second neural network model, and the third neural network model with a larger structure that has been trained and converged. Subsequently, a part of the weight parameters are inherited from the third neural network model with a larger structure that has been trained and converged through pruning to obtain a fifth neural network model, and the fifth neural network model is fine-tuned to obtain a first neural network model with the same structure as the second neural network model. Compared with the related technology, the image processing model optimization method provided in the present application inherits the weights of the parameters in the neural network model, and finally obtains a model with better accuracy and effect. The following will be combined FIG. 3A to FIG. 3D This is explained.

[0072] Figure 3A The figure shows the loss function change curve during the model training process provided by the present application. Figure 3A As shown, the horizontal axis is the training round (epoch), and the vertical axis is the value of the loss function (loss); the value of the loss function corresponding to each training round is the average value of the loss function of all iterations in a single training round. Loss function #2 is the loss function of the training process of directly training the second neural network model to obtain model #a in the related art. Figure 3A The curve pointed by loss function #2 is the change curve of the value of loss function #2. Loss function #1 is the loss function in the training process of the first neural network model obtained by the optimization method of the image processing model provided in this application. Figure 3A The curve pointed to by loss function #1 is the curve of the change of the value of loss function #1.

[0073] It is understandable that the loss function is used to measure the accuracy of the model. The smaller the value of the loss function corresponding to a model, the better the model converges on the data set, indicating that the gap between the model output and the true value is smaller, that is, the higher the accuracy of the model. Figure 3A It can be seen that the value of loss function #1 is about 10% lower than that of loss function #2. Therefore, the accuracy and effect of the first neural network model obtained by the optimization method of the image processing model provided by the present application are better than those of model #a.

[0074] In the image processing method provided in the present application, after the electronic device acquires an image, it processes the image based on the first neural network model provided in the present application, and then outputs the processed image. The specific implementation method can refer to the description of method 300 below.

[0075] Figure 3B and Figure 3C The output graphs of model #a and the output graphs of the first neural network model provided in this application are respectively shown in the scene of a mobile phone taking a photo in a night environment. Specifically, after the electronic device acquires an image, it processes the image based on model #a and the first neural network model provided in this application respectively, and the processed images are respectively subjected to the same subsequent processing, and the final output images are respectively as follows: Figure 3B He Ru Figure 3C As shown. For example, the subsequent processing here may include brightening, sharpening, color correction, etc., but the impact of these subsequent processes on the clarity and noise of the final output image is almost negligible compared to the impact of model #a or the third neural network on clarity and noise. It should be noted that only grayscale images are given here to assist in the explanation. In fact, the effect of color images is more intuitive. Figure 3B and Figure 3C As shown in the figure, the output image includes the night sky, buildings, stones, soil, stone roads, and trees. Figure 3B , Figure 3C Both color noise and clarity are significantly optimized. Figure 3D Shows Figure 3C and Figure 3B A local comparison diagram of Figure 3D As shown, select Figure 3C and Figure 3B Specifically, Figure 3D The area in the two solid circles in the Figure 3B There are still many noise points of different gray levels in the solid circle, and the corresponding Figure 3C The grayscale in the solid circle is almost the same. This shows that Figure 3B and Figure 3C When presented in color, Figure 3C Compared to Figure 3B, the color noise in the sky is significantly reduced, and the color of the dark area is more uniform, so the color blocks are significantly weakened, the night sky is purer, and the color noise is significantly reduced. Specifically, Figure 3D As shown, compared with the corresponding Figure 3B The area outlined by the dotted line corresponds to Figure 3C In the area outlined by the dotted line, the textures on the small branches and trunks are clearer. Figure 3B and Figure 3C When presented in color, Figure 3C Compared to Figure 3B , the clarity is significantly improved. Therefore, the optimization method of the image processing model provided in this application can reduce the noise of night scene photography and improve the clarity, while keeping the structure of the model fixed, that is, it optimizes the noise and clarity of the night scene photography algorithm without deteriorating the model performance.

[0076] Taking the face recognition scenario as an example, compared with the output image of model #a, the output image of the first neural network model of the present application is more accurate in the recognition and positioning of various parts of the face and the micro-expressions corresponding to each part, thereby improving the success rate of face recognition while not deteriorating the model performance, that is, not increasing the time for face recognition.

[0077] Taking the detection of smoke and fire in security mission scenarios as an example, compared with the output graph of model #a, the output graph of the first neural network model of the present application is more accurate in identifying whether there is smoke or fire source. In the case of smoke or fire source, the positioning of the smoke or fire source is more accurate, thereby improving the success rate of smoke and flame recognition without deteriorating the model performance, that is, without delaying the time of discovering dangerous situations.

[0078] The optimization method of the image processing model provided in the present application may have an alternative solution. A sixth neural network model with a more complex structure than the second neural network model is trained to convergence, and then a seventh neural network model with a more streamlined structure is obtained by structured pruning. Among them, the sixth neural network model is not obtained by channel expansion of the second neural network model, so the structure of the sixth neural network model is different from that of the sixth neural network model; the sixth neural network model may be a model for image processing obtained by other means. Moreover, the structure of the seventh neural network model is likely to be different from that of the second neural network model. This alternative solution can improve the image processing effect to a certain extent. However, taking the actual application of taking pictures with a mobile phone in a night environment as an example, as mentioned above, the structure of the second neural network model is designed to give full play to the performance of the hardware platform of the electronic device, according to the characteristics of the hardware platform deployed by the second neural network model. The structure of the first neural model involved in the present application is designed according to the characteristics of the deployed hardware platform, or in other words, the structure of the first neural model is adapted to the hardware structure of the electronic device, which can be understood by referring to the following example: When the chip in the electronic device runs the convolutional neural network model, the chip will allocate resources for processing channels for each convolutional layer in the convolutional neural network model, and the number of channels that the resources can handle is an integer multiple of a value (for example, represented by G, G≥1 and G is an integer). G is determined by the hardware structure design of the chip, for example, G here can be 16, 64 or 48. For example, if the number of channels in a convolutional layer is G, then the chip calls the resources corresponding to G channels to process the channels of the convolutional layer. For another example, if the number of channels in a convolutional layer is 2G, then the chip calls the resources corresponding to 2G channels to process the channels of the convolutional layer. For another example, if the number of channels in a convolutional layer is G', and G'<G, then the chip still calls the resources corresponding to G channels to process the channels of the convolutional layer. In this case, the utilization rate of the chip will be reduced. When the number of channels of each convolutional layer in the second neural network model is an integer multiple of G, it can be understood that the structure of the first neural model is designed according to the characteristics of the deployed hardware platform, or in other words, the structure of the first neural model is compatible with the hardware structure of the electronic device, and in this case, the chip utilization can be guaranteed as high as possible.

[0079] Therefore, if the structure of the seventh neural network model is different from that of the second neural network model, that is, the structure of the model used for image processing is adjusted, even if the complexity of the structure of the seventh neural network model is comparable to that of the second neural network model, the performance benefits of the second neural network model may not be obtained, and the structure of the seventh neural network model needs to be further optimized or performance evaluated according to the hardware platform characteristics of the mobile phone. Therefore, compared with the alternative solution, the first neural network model obtained by the optimization method of the image processing model provided in the present application is still adapted to the hardware platform of the mobile phone, and the step of further optimizing the structure of the first neural network model or performing performance evaluation according to the hardware platform characteristics of the mobile phone is saved; thereby, it can be applied to more electronic devices, saving the process of hardware and software adaptation.

[0080] Therefore, in the image processing method provided by the present application, after acquiring the image, the electronic device processes the image based on the first neural network model obtained according to the second neural network model. When the structure of the second neural network model is compatible with the hardware structure of the electronic device, the process of software and hardware adaptation can be saved, the cost of model optimization can be reduced, and at the same time, the utilization rate of the chip can be ensured not to be affected.

[0081] from above Figure 3AIt can be seen from the relevant description that the optimization method of the image processing model provided by the present application, the effect of the first neural network model in processing the image, compared with the effect of the second neural network model in processing the image, is not or is not only achieved by training the neural network model obtained in the optimization process, but is largely achieved by the technical means of first expanding the number of channels in the optimization method, and then pruning the number of channels that is the same as the expanded number through structured pruning. At the same time, the performance of the first neural network model in processing the image is improved while the performance is not deteriorated, which is also due to this technical means. In other words, what the optimization method of the image processing model provided by the present application wants to protect is not the abstract model algorithm itself, nor the means of improving the algorithm simply by training the model, but the technical means of optimizing the trained second neural network model. Accordingly, the technical effect of the optimization method of the image processing model provided by the present application is also brought about by this technical means. Further, the image processing method provided by the present application applies the first neural network model to the electronic device. On the one hand, due to the technical means corresponding to the optimization method of the first neural network model, the effect of the image processing of the electronic device is improved and the image processing time is not extended. On the other hand, the optimization method of the image processing model is combined with the hardware characteristics of the electronic device to first expand the number of channels and then prune away the same number of channels as the expanded number through structured pruning. This technical means also brings other technical effects, such as saving the process of software and hardware adaptation, reducing the cost of model optimization, and at the same time ensuring that the chip utilization is not affected.

[0082] Combine the following Figure 4 , Figure 5A and Figure 5B , a detailed introduction to the optimization method of the image processing model provided in this application. Figure 4 FIG. 1 is a schematic diagram of an optimization method 100 for an image processing model provided by the present application. Figure 4 As shown, the method 100 includes S101 to S102.

[0083] S101, respectively increase the number of channels in the Y first convolutional layers in the second neural network model to obtain a third neural network model.

[0084] The second neural network model is used for image processing, and the third neural network model includes Y second convolutional layers, and the Y first convolutional layers correspond one to one with the Y second convolutional layers. It can be understood that the Y first convolutional layers are part or all of the convolutional layers in the second neural network model.

[0085] In a possible example of S101, the number of channels of each of the Y first convolutional layers is increased to obtain a fourth neural network model; the fourth neural network model is trained until convergence based on the data set to obtain a third neural network model, wherein the data set is a data set used to train the second neural network model.

[0086] It is understandable that in the present application, in the same scenario, the data sets used to train different neural network models are all the same data set. Among them, the data set includes input data and target data. Taking the face recognition scene as an example, the input data can be the image data obtained by processing the image acquired by the electronic device camera, for example, it can be in the original (RAW) format or the red, green and blue (RGB) format. The target data is the coordinate data of the facial features on the face in the image, such as the coordinates of the eyes and the coordinates of the corners of the mouth. Taking the mobile phone photo scene as an example, the input data can be the image data #1 obtained by processing the image #1 acquired by the electronic device camera, for example, it can be in the original (RAW) format or the red, green and blue (RGB) format, and the image data #1 is used to indicate all pixels of the image #1. The target data is image data #2, which is used to indicate all pixels of image #2. The content displayed by image #2 is basically the same as that of image #1, except that image #2 has higher clarity and less noise than image #1.

[0087] It can also be understood that the purpose of training the model in this application is to ensure that after the model is fed with input data, the output of the model can be as close to the target data as possible. In this way, the better the parameters in the model are learned, the better the effect of the model in processing images will be.

[0088] For example, the number of channels added to the i-th second convolutional layer in the Y second convolutional layers is y relative to the i-th first convolutional layer in the Y first convolutional layers. i .

[0089] Specifically, i The determining factors include but are not limited to any one or more of the following: the importance of the i-th first convolutional layer in all convolutional layers of the second neural network model, and the number of channels in the i-th first convolutional layer.

[0090] For example, i is greater than or equal to the number of channels in the i-th first convolutional layer and / or, i Less than or equal to the number of channels in the i-th first convolutional layer. Exemplarily, for a convolutional layer with higher importance in the first neural network, the number of channels that can be added can be appropriately increased; for a convolutional layer with lower importance in the first neural network, the number of channels that can be added can be appropriately reduced.

[0091] S102, pruning the channels of the Y second convolutional layers in the third neural network model respectively to obtain the first neural network model.

[0092] Among them, the structure of the first neural network model is the same as that of the second neural network model. The first neural network model includes Y third convolutional layers, and the Y third convolutional layers correspond one-to-one to the Y second convolutional layers. Y≥1, and Y is an integer.

[0093] Among them, the channels of the Y second convolutional layers in the third neural network model are pruned respectively, which can be understood as calculating the importance scores of the channels in the Y second convolutional layers respectively; and pruning the channels in the Y second convolutional layers respectively according to the importance scores.

[0094] Exemplarily, the importance scores of channels of the i-th second convolutional layer in the Y second convolutional layers are sorted; and X channels in the i-th second convolutional layer are pruned, and the importance scores of the X channels are lower than the importance scores of other channels in the i-th second convolutional layer, 1≤i≤Y and i is an integer, and X≥1 and X is an integer.

[0095] For example, X=y i That is, pruning is performed on the convolutional layers whose number of channels is increased in S101, and no pruning is performed on the convolutional layers whose number of channels is not increased in S101.

[0096] The i-th second convolutional layer includes Z channels, the importance score of the j-th channel within the Z channels is determined according to the L1 norm or L2 norm of the j-th channel weight parameter, Z>X and Z is an integer, 1≤j≤Z and j is an integer.

[0097] In a possible example of S102, the channels of the Y second convolutional layers in the third neural network model are pruned respectively to obtain a fifth neural network model; the fifth neural network is fine-tuned based on the data set to obtain the first neural network model, wherein the data set is a data set used to train the second neural network model.

[0098] In an embodiment of the present application, by performing channel expansion on some or all of the convolutional layers in the second neural network model for image processing, that is, increasing the number of channels of some or all of the convolutional layers, a large model with more channels and more complex structure is obtained, and then the large model is trained until convergence to obtain a third neural network model, and then channel structured pruning is performed based on the third neural network model, and the channels with lower importance in some or all of the above convolutional layers are pruned according to importance evaluation, and the number of increased channels is the same as the number of pruned channels, to obtain a first neural network model, so that the structure of the first neural network model is the same as that of the second neural network model. Through the above scheme, the second neural network model is optimized to obtain the first neural network model, and the accuracy and effect of the model are significantly improved. Moreover, compared with directly training the second neural network model to obtain a more structurally complex model, the first neural network model maintains the same structure as the second neural network model, and can optimize the accuracy and effect of the model without deteriorating the performance of the model.

[0099] Figure 5A and Figure 5B FIG. 2 is a schematic diagram of an optimization method 200 for an image processing model provided by the present application. The method 200 can be understood as a specific example of the method 100. Figure 5A As shown, method 200 includes S201 to S205.

[0100] S201 and S202 may be used as a possible example of S101.

[0101] S201, for the neural network model m to be processed, select some convolution layers to add a certain number of convolution kernels to obtain a model structure M with more parameters and more complex structure.

[0102] It is assumed that the convolutional layer in the neural network model m to be processed is L = [L1, L2, L3, ..., L K-1 ,L K ], the number of convolution kernels (i.e. the number of channels) is N m =[N1,N2,N3,……,N K-1 ,N K ]. It can be understood that the neural network model m has a total of K first convolutional layers, K ≥ 1 and K is an integer, and the number of convolution kernels corresponding to the i-th first convolutional layer is N m N mi , 1≤i≤K and i is an integer. The number of convolution kernels added in the K first convolution layers is n=[n1,n2,n3,……,n K-1 ,n K ], that is, the number of convolution kernels added in the first convolution layer of the i-th layer is n iIt can be understood that among the K first convolutional layers, Y first convolutional layers perform channel expansion, 1≤Y≤K and Y is an integer. When Y=K, n1 to n k are both greater than 0; when Y<K, the nth of the first convolutional layers without channel expansion in the K first convolutional layers i =0.

[0103] Thus, the convolutional layer of the neural network model M is L = [L1, L2, L3, ..., L K-1 ,L K ], the number of convolution kernels of the neural network model M is N M =[N1+n1,N2+n2,N3+n3,……,N K-1 +n K-1 ,N K +n K ]. It can be understood that the neural network model M has a total of K second convolutional layers, K ≥ 1 and K is an integer, and the number of convolution kernels corresponding to the i-th second convolutional layer is N M In That is N i +n i , 1≤i≤K and i is an integer. It can be understood that the K second convolutional layers correspond one-to-one to the K first convolutional layers, and the Y second convolutional layers also correspond one-to-one to the Y first convolutional layers.

[0104] For example, Figure 5B As shown in the figure, the number of convolution kernels of L1 of model m is 32, n1=16, and the number of convolution kernels of L1 of model M is 48; the number of convolution kernels of L2 of model m is 64, n2=32, and the number of convolution kernels of L2 of model M is 96; the number of convolution kernels of L3 of model m is 64, n3=32, and the number of convolution kernels of L3 of model M is 96; the number of convolution kernels of L4 of model m is 96, n4=48, and the number of convolution kernels of L4 of model M is 144; ...the number of convolution kernels of L K-1 The number of convolution kernels is 32, n K-1 =48, L of model M K-1 The number of convolution kernels is 32; the L K The number of convolution kernels is 3, n K = 0, L of model M K The number of convolution kernels is 3.

[0105] S202, training the neural network model M until it converges on the data set, and the neural network model after the training converges is M'.

[0106] The data set used in training the model in method 200 is the same data set.

[0107] For example, Figure 5BAs shown, the number of convolution kernels of L1 of model M' is 48; the number of convolution kernels of L2 of model M' is 96; the number of convolution kernels of L3 of model M' is 96; the number of convolution kernels of L4 of model M is 144; ... the number of convolution kernels of L K-1 The number of convolution kernels of model M' is 32; K The number of convolution kernels is 3.

[0108] It can be understood that the neural network model m and the neural network model M' in S201 and S202 correspond to the second neural network model and the third neural network model in S101 respectively.

[0109] S203 to S205 may be taken as a possible example of S102.

[0110] S203, evaluate the importance of all channels in the second convolutional layer of the neural network model M' to which the channels have been added, and calculate L i L1 value of each channel in .

[0111] Among them, the second convolution layer of the channel has been added, that is, n i >0 for the second convolutional layer L i , or it is Y second convolutional layers, or it is the second convolutional layer after channel expansion.

[0112] Assume that n i >0 for the second convolutional layer L i The importance of each channel is It can be understood that the i-th second convolutional layer L i The number of channels in In this Among the channels, the importance of the jth channel is p j ,in, And j is an integer.

[0113] S204, for the neural network model M' i >0 for the second convolutional layer L i , for the second convolutional layer L i The importance of each channel within P i , according to the importance p j Prune the corresponding channels in order from small to large until the number of pruned channels reaches n i For all n i >0 for the second convolutional layer L i After the channel pruning is completed, the neural network model is m'.

[0114] For example, Figure 5BAs shown, for the L1 of model M', the first 16 channels in ascending order of importance are pruned; for the L2 of model M', the first 32 channels in ascending order of importance are pruned; for the L3 of model M', the first 32 channels in ascending order of importance are pruned; for the L4 of model M', the first 48 channels in ascending order of importance are pruned... for the L K-1 No need to trim channels; L for model M' K No trimming channels are required.

[0115] It can be understood that the structure of model m' is the same as that of model m, that is, the number of convolutional layers of model m' and model m is the same, both K, and the number of channels of the i-th convolutional layer of model m' is the same as the number of channels of the i-th convolutional layer of model m. After the above processing flow, the channel parameters of each convolutional layer of model m' and model m are different.

[0116] For example, Figure 5B As shown, the number of convolution kernels of L1 of model m' is 32; the number of convolution kernels of L2 of model m' is 64; the number of convolution kernels of L3 of model m' is 64; the number of convolution kernels of L4 of model m is 96; ... the number of convolution kernels of L K-1 The number of convolution kernels is 32; the L of model m' K The number of convolution kernels is 3.

[0117] S205, fine-tune the model m' on the data set, that is, train until convergence.

[0118] It can be understood that the neural network model M' and the neural network model m' in S203 to S205 correspond to the third neural network model and the first neural network model in S101 respectively.

[0119] Subsequently, the electronic device uses the neural network model m' to process the image. The specific effect that can be achieved can be found in the FIG. 3A to FIG. 3D The relevant description in the description.

[0120] Figure 6 FIG. 3 is a schematic diagram of an image processing method 300 provided by the present application. Figure 6 As shown, the method 300 includes S301 to S302. The method 300 is executed by an electronic device.

[0121] S301, acquiring an image.

[0122] It is understandable that the electronic device can obtain the image processed by the first neural network model in a variety of ways, such as the electronic device can capture the image through an image capturing device (such as a camera); for example, the electronic device can download the image, etc.; for example, the electronic device can exchange information such as images with other electronic devices through some applications. This application does not limit this.

[0123] S302: Process the image based on a first neural network model.

[0124] The first neural network model is obtained according to the second neural network model, the structure of the second neural network model is adapted to the hardware structure of the electronic device, and the structure of the first neural network model is the same as that of the second neural network model.

[0125] S303, output the image processed by the first neural network model.

[0126] It is understandable that the image processed by the first neural network model needs to undergo a series of subsequent processing before it can be displayed on the interface of the electronic device. The subsequent processing here may include brightening, sharpening, color correction, etc. However, the impact of these subsequent processes on the clarity and noise of the final output image is almost negligible compared to the impact of model #a or the third neural network on clarity and noise.

[0127] As an example of method 300, after the electronic device acquires an image, it obtains image data (hereinafter referred to as image data #1 for the convenience of explanation), and image data #1 is used to indicate all pixels in the image. For example, the image data #1 can be in the original (RAW) format or the red, green and blue (RGB) format. Image data #1 is input into the first neural network model. Specifically, the i-th third convolutional layer among the Y third convolutional layers performs convolution calculation on image data #1 and outputs the i-th calculation result; the i-th calculation result is input into the i+1-th third convolutional layer after being calculated by other non-convolutional layers, 1≤i≤Y-1 and i is an integer. It can be understood that after each convolutional layer in the neural network model performs convolution calculation on the feature map input to the convolutional layer, the calculation result is calculated by other non-convolutional layers and then input into the next convolutional layer, and finally the model outputs the processed image. In a possible implementation, the image processed by the first neural network model can be image data in RAW format or RGB format (hereinafter referred to as image data #2 for the convenience of explanation).

[0128] Illustratively, in a mobile phone camera scenario, the pixels in the image processed by the first neural network model correspond one-to-one to the pixels indicated by image data #1, or the pixels indicated by image data #2 correspond one-to-one to the pixels indicated by image data #1. For example, the image output by image data #2 after a series of subsequent processing has improved clarity and reduced noise compared to the image acquired by the electronic device; in a face recognition scenario, image data #2 is the coordinate data of a person's facial features in an image composed of all pixels of image data #1; in a fireworks detection scenario, image data #2 is the coordinate data of smoke and fire in an image composed of all pixels of image data #1.

[0129] Specifically, the method of obtaining the first neural network model according to the second neural network model can refer to the relevant description of the optimization methods 100 and 200 of the image processing model in the above text.

[0130] In the image processing method provided in the present application, after acquiring the image, the electronic device processes the image based on the first neural network model obtained according to the second neural network model. Among them, the second neural network model is firstly channel-expanded to obtain a third neural network model that is more complex than the second neural network model. Compared with the second neural network model, the third neural network model has a better effect in processing images, but the model complexity is higher and the reasoning speed is slower. Pruning the third neural network model can reduce the complexity of the third neural network model to improve the reasoning speed of the model without significantly reducing the accuracy of the model. Thus, through the above method, the image processing effect can be improved without extending the time for the electronic device to process the image. In addition, since the structure of the second neural network model is compatible with the hardware structure of the electronic device, and the structure of the first neural network model is the same as the structure of the second neural network model, the structure of the first neural network model is also compatible with the hardware structure of the electronic device. The above scheme can save the process of hardware and software adaptation, reduce the cost of model optimization, and at the same time, ensure that the utilization rate of the chip is not affected.

[0131] Please refer to Figure 7 , Figure 7 FIG. 1 is a schematic diagram showing a hardware structure of an electronic device 1000 provided in an embodiment of the present application. Figure 7The electronic device 1000 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.

[0132] It is understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 1000. In other embodiments of the present application, the electronic device 1000 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0133] The processor 110 may include one or more processing units, for example: the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc.

[0134] The controller may be the nerve center and command center of the electronic device 1000. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.

[0135] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0136] In some embodiments, the processor 110 may include one or more interfaces, such as an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0137] The MIPI interface can be used to connect the processor 110 with peripheral devices such as the display screen 194 and the camera 193. The MIPI interface includes a camera serial interface (CSI), a display serial interface (DSI), etc. In some embodiments, the processor 110 and the camera 193 communicate via the CSI interface to realize the shooting function of the electronic device 1000. The processor 110 and the display screen 194 communicate via the DSI interface to realize the display function of the electronic device 1000.

[0138] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device 1000. In other embodiments of the present application, the electronic device 1000 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0139] The charging management module 140 is used to receive charging input from a charger. The charger can be a wireless charger or a wired charger. The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, and supplies power to the processor 110, the internal memory 121, the external memory, the display screen 194, the camera 193 and the wireless communication module 160.

[0140] The wireless communication function of the electronic device 1000 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.

[0141] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 1000 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.

[0142] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 1000. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, etc. the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1.

[0143] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) network), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 1000. The wireless communication module 160 can be one or more devices integrating at least one communication processing module.

[0144] The electronic device 1000 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.

[0145] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 1000 may include 1 or N display screens 194, where N is an integer greater than 1.

[0146] The electronic device 1000 can realize the shooting function through ISP, camera 193, video codec, GPU, display screen 194 and application processor.

[0147] ISP is used to process the data fed back by camera 193. For example, when taking a photo, the shutter is opened, and the light is transmitted to the camera photosensitive element through the lens. The light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to ISP for processing and converts it into an image visible to the naked eye. ISP can also perform algorithm optimization on the noise, brightness, and skin color of the image. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some embodiments, ISP can be set in camera 193.

[0148] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the ISP to be converted into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the electronic device 1000 may include 1 or N cameras 193, where N is an integer greater than 1.

[0149] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the electronic device 1000 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.

[0150] Video codecs are used to compress or decompress digital videos. The electronic device 1000 may support one or more video codecs. Thus, the electronic device 1000 may play or record videos in various coding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.

[0151] NPU is a neural network (NN) computing processor. By drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, it can quickly process input information and can also continuously self-learn. Through NPU, applications such as intelligent cognition of electronic device 1000 can be realized, such as image recognition, face recognition, voice recognition, text understanding, etc.

[0152] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 1000. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function, such as storing music, video and other files in the external memory card.

[0153] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device 1000 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created by the electronic device 1000 during use (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.

[0154] The electronic device 1000 can implement audio functions, such as music playback, recording, etc., through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone interface 170D and the application processor. The button 190 includes a power button, a volume button, etc. The button 190 can be a mechanical button or a touch button. The electronic device 1000 can receive key input and generate key signal input related to the user settings and function control of the electronic device 1000. The motor 191 can generate a vibration prompt. The indicator 192 can be an indicator light, which can be used to indicate the charging status, the change of power, and can also be used to indicate messages, missed calls, notifications, etc. The SIM card interface 195 is used to connect a SIM card.

[0155] The sensor module 180 may include one or more sensors, which may be of the same type or of different types. Figure 7 The sensor module 180 shown is only an exemplary division method. There may be other division methods, which are not limited in this application.

[0156] The pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be set on the display screen 194. When a touch operation is applied to the display screen 194, the electronic device detects the touch operation intensity according to the pressure sensor 180A. The electronic device can also calculate the touch position according to the detection signal of the pressure sensor 180A. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions.

[0157] The gyro sensor 180B can be used to determine the motion posture of the electronic device. In some embodiments, the angular velocity of the electronic device around three axes (i.e., x, y, and z axes) can be determined by the gyro sensor 180B. The gyro sensor 180B can be used for anti-shake shooting.

[0158] The acceleration sensor 180E can detect the magnitude of the acceleration of the electronic device in all directions (generally three axes). When the electronic device is stationary, it can detect the magnitude and direction of gravity. It can also be used to identify the posture of the electronic device and is applied to applications such as horizontal and vertical screen switching and pedometers.

[0159] The distance sensor 180F is used to measure the distance. The electronic device can measure the distance by infrared or laser. In some embodiments, when shooting a scene, the electronic device can use the distance sensor 180F to measure the distance to achieve fast focusing.

[0160] The touch sensor 180K is also called a "touch panel". The touch sensor 180K can be set on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, also called a "touch screen". The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor 180K can also be set on the surface of the electronic device, which is different from the position of the display screen 194.

[0161] The air pressure sensor 180C is used to measure air pressure. The magnetic sensor 180D includes a Hall sensor. The proximity light sensor 180G may include, for example, a light emitting diode (LED) and a light detector, such as a photodiode. The electronic device uses a photodiode to detect infrared reflected light from nearby objects. The ambient light sensor 180L is used to sense the brightness of ambient light. The fingerprint sensor 180H is used to obtain fingerprints. The temperature sensor 180J is used to detect temperature. The bone conduction sensor 180M can obtain vibration signals.

[0162] Next, the software system of the electronic device 1000 will be described.

[0163] Exemplarily, the electronic device 1000 may be a mobile phone. The software system of the electronic device 1000 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to exemplify the software system of the electronic device 1000.

[0164] Figure 8 1 shows a block diagram of a software system of an electronic device 1000 provided in an embodiment of the present application. Figure 8 The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom: application layer, application framework layer, Android runtime and system layer, kernel layer and hardware abstraction layer (HAL).

[0165] The application layer can include a series of application packages. Figure 8 As shown, the application package may include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications.

[0166] The application framework layer provides application programming interface (API) and programming framework for the applications in the application layer. The application framework layer includes some predefined functions. Figure 8 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, etc. The window manager is used to manage window programs. The window manager can obtain the size of the display screen, determine whether there is a status bar, lock the screen, capture the screen, etc. The content provider is used to store and obtain data and make these data accessible to applications. These data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc. The view system includes visual controls, such as controls for displaying text, controls for displaying pictures, etc. The view system can be used to build the display interface of the application, and the display interface can be composed of one or more views, such as a view for displaying a text message notification icon, a view for displaying text, and a view for displaying pictures. The phone manager is used to provide communication functions of the electronic device 1000, such as management of call status (including connecting, hanging up, etc.). The resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, etc. The notification manager enables the application to display notification information in the status bar, which can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of an icon or scroll bar text, such as a notification of an application running in the background. The notification manager can also be a notification that appears on the screen in the form of a dialog window, such as a text message in the status bar, a reminder sound, an electronic device vibrating, an indicator light flashing, etc.

[0167] Android runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system. The core library consists of two parts: one is the function that the Java language needs to call, and the other is the Android core library. The application layer and the application framework layer run in the virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform object life cycle management, stack management, thread management, security and exception management, and garbage collection.

[0168] The system library can include multiple functional modules, such as: surface manager, media library, 3D graphics processing library (such as: OpenGL ES), 2D graphics engine (such as: SGL), etc. The surface manager is used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications. The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc. The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, synthesis, and layer processing, etc. The 2D graphics engine is a drawing engine for 2D drawing.

[0169] The Hardware Abstraction Layer (HAL) is an interface layer between the operating system kernel and the upper software, and its purpose is to abstract the hardware. The hardware abstraction layer is an abstract interface driven by the device kernel, which is used to implement the application programming interface that provides access to the underlying device to the higher-level Java API framework. HAL contains multiple library modules, such as camera, display, Bluetooth, audio, etc. Each library module implements an interface for a specific type of hardware component. When the system framework layer API requires access to the hardware of the portable device, the Android operating system will load the library module for the hardware component.

[0170] The kernel layer is the layer between hardware and software. The kernel layer contains at least device drivers such as camera driver, processor driver, display driver, audio driver, etc. The device driver is the interface between the I / O system and related hardware, used to drive the corresponding hardware devices.

[0171] It should be noted that the application provides Figure 8 The software structure diagram of the electronic device shown is only an example and does not limit the specific module division in different layers of the Android operating system. For details, please refer to the introduction of the Android operating system software structure in conventional technology.

[0172] The following is an example of the workflow of the software and hardware of the electronic device 1000 with reference to a scene of taking photos with a mobile phone in a night environment.

[0173] As a possible example of S301: When the touch sensor receives a touch operation, the corresponding hardware interrupt is sent to the kernel layer. The kernel layer processes the touch operation into an original input event (including touch coordinates, timestamp of the touch operation and other information). The original input event is stored in the kernel layer. The application framework layer obtains the original input event from the kernel layer and identifies the control corresponding to the original input event. Taking the touch operation as a single-click operation, and the control corresponding to the single-click operation as the control of the camera application icon as an example, the camera application calls the interface of the application framework layer, starts the camera application, and then calls the kernel layer to start the camera driver to capture the image through the camera. As a possible example of S302, after capturing the image through the camera, the camera application can also call the processor through the HAL layer, and perform image processing on the image captured by the camera through the neural network processor in the processor. Among them, the neural network processor uses the first neural network model provided in the present application for image processing. As a possible example of S303, the image processed by the first neural network model is input into other neural models in the processor for subsequent processing.

[0174] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access, or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a digital versatile disc (DVD)), or a semiconductor medium (eg, a solid state disk (SSD)).

[0175] The above are optional embodiments provided for the present application and are not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the technical scope disclosed in the present application shall be included in the protection scope of the present application.

Claims

1. An image processing method, applied to an electronic device, characterized in that: include: Get the image; Processing the image based on a first neural network model; Outputting the image processed by the first neural network model; Wherein, the first neural network model is obtained according to the second neural network model, the second neural network model is used for image processing, the structure of the second neural network model is adapted to the hardware structure of the electronic device, the second neural network model includes Y first convolutional layers, the chip of the electronic device is used to allocate resources for processing channels to each of the first convolutional layers according to the number of channels of each of the first convolutional layers of the second neural network model, the structure of the first neural network model is the same as the structure of the second neural network model, and the structure of the first neural network model is also adapted to the hardware structure of the electronic device, wherein, The first neural network model is obtained according to the second neural network model, including: The first neural network model includes Y third convolutional layers, and the Y third convolutional layers correspond one-to-one to the Y first convolutional layers; The first neural network model is obtained by pruning channels of Y second convolutional layers in the third neural network model respectively, and the Y third convolutional layers correspond one-to-one to the Y second convolutional layers; The third neural network model is obtained by respectively increasing the number of channels in the Y first convolutional layers in the second neural network model, the Y first convolutional layers correspond one to one to the Y second convolutional layers, Y ≥ 2, and Y is an integer; The third convolutional layer of the first neural network model is equal to the number of channels in the corresponding first convolutional layer in the second neural network model, and the number of channels added in the first convolutional layer of the second neural network model is the same as the number of channels pruned in the corresponding second convolutional layer in the third neural network model.

2. The method according to claim 1, characterized in that The processing of the image based on the first neural network model includes: Obtaining image data according to the image, wherein the image data is used to indicate all pixels in the image; Inputting the image data into the first neural network model; Performing convolution calculation on the image data by the i-th third convolution layer among the Y third convolution layers, and outputting the i-th calculation result; The i-th calculation result is input into the i+1-th third convolutional layer after being calculated by other non-convolutional layers, where 1≤i≤Y-1 and i is an integer.

3. The method according to claim 1, characterized in that The first neural network model is obtained by pruning the channels of Y second convolutional layers in the third neural network model respectively, including: The first neural network model is obtained by respectively calculating the importance scores of the channels in the Y second convolutional layers, and respectively pruning the channels in the Y second convolutional layers according to the importance scores.

4. The method according to claim 3, characterized in that Pruning the channels in the Y second convolutional layers respectively according to the importance scores, comprising: Sorting the importance scores of the channels of the i-th second convolutional layer in the Y second convolutional layers; Delete X channels in the i-th second convolutional layer, where the importance scores of the X channels are lower than the importance scores of other channels in the i-th second convolutional layer, 1≤i≤Y and i is an integer, and X≥1 and X is an integer.

5. The method according to claim 4, characterized in that The i-th second convolutional layer includes Z channels, and the importance score of the j-th channel within the Z channels is determined according to the L1 norm or L2 norm of the j-th channel weight parameter, Z>X and Z is an integer, 1≤j≤Z and j is an integer.

6. The method according to claim 4 or 5, characterized in that The number of channels added to the i-th second convolutional layer is y relative to the i-th first convolutional layer in the Y first convolutional layers. i , and X=y i .

7. The method according to claim 6, characterized in that y i It is determined according to at least one of the following: the importance of the i-th first convolutional layer in all convolutional layers of the second neural network model, and the number of channels in the i-th first convolutional layer.

8. The method according to claim 7, characterized in that y i is greater than or equal to the number of channels in the i-th first convolutional layer and / or, i is less than or equal to the number of channels in the i-th first convolutional layer.

9. The method according to claim 2, characterized in that The third neural network model is obtained by respectively increasing the number of channels in the Y first convolutional layers in the second neural network model, including: The third neural network model is obtained by training a fourth neural network model to convergence based on a data set, wherein the data set is a data set used to train the second neural network model; The fourth neural network model is obtained by respectively increasing the number of channels of each of the Y first convolutional layers.

10. The method according to claim 2 or 9, characterized in that The first neural network model is obtained by pruning the channels of Y second convolutional layers in the third neural network model respectively, including: The first neural network model is obtained by fine-tuning a fifth neural network based on a data set, wherein the data set is a data set used to train the second neural network model; The fifth neural network model is obtained by pruning the channels of the Y second convolutional layers in the third neural network model respectively.

11. A method for optimizing an image processing model, characterized in that: include: Respectively increase the number of channels in the Y first convolutional layers in the second neural network model to obtain a third neural network model, wherein the second neural network model is used for image processing, and the third neural network model includes Y second convolutional layers, and the Y first convolutional layers correspond to the Y second convolutional layers one by one; Pruning the channels of the Y second convolutional layers in the third neural network model respectively to obtain a first neural network model, wherein the structure of the first neural network model is the same as that of the second neural network model, the first neural network model is used for image processing, and the first neural network model includes Y third convolutional layers, the Y third convolutional layers correspond one-to-one to the Y second convolutional layers, Y ≥ 1, and Y is an integer; Among them, the structure of the second neural network model is adapted to the hardware structure of the electronic device, and the chip of the electronic device is used to allocate resources for processing channels to each of the first convolutional layers according to the number of channels of each of the first convolutional layers of the second neural network model. The structure of the first neural network model is the same as that of the second neural network model, and the structure of the first neural network model is also adapted to the hardware structure of the electronic device. The Y third convolutional layers correspond one-to-one to the Y first convolutional layers. The third convolutional layer of the first neural network model is equal to the number of channels in the corresponding first convolutional layer in the second neural network model, and the number of channels added in the first convolutional layer of the second neural network model is the same as the number of channels pruned in the corresponding second convolutional layer in the third neural network model.

12. The method according to claim 11, characterized in that The pruning process is performed on the channels of the Y second convolutional layers in the third neural network model respectively, comprising: Calculate the importance scores of the channels in the Y second convolutional layers respectively; The channels within the Y second convolutional layers are pruned respectively according to the importance scores.

13. The method according to claim 12, characterized in that Pruning the channels in the Y second convolutional layers respectively according to the importance scores, comprising: Sorting the importance scores of the channels of the i-th second convolutional layer in the Y second convolutional layers; Delete X channels in the i-th second convolutional layer, where the importance scores of the X channels are lower than the importance scores of other channels in the i-th second convolutional layer, 1≤i≤Y and i is an integer, and X≥1 and X is an integer.

14. The method according to claim 13, characterized in that The i-th second convolutional layer includes Z channels, and the importance score of the j-th channel within the Z channels is determined according to the L1 norm or L2 norm of the j-th channel weight parameter, Z>X and Z is an integer, 1≤j≤Z and j is an integer.

15. The method according to claim 13 or 14, characterized in that The number of channels added to the i-th second convolutional layer is y relative to the i-th first convolutional layer in the Y first convolutional layers. i , and X=y i .

16. The method according to claim 15, characterized in that y i It is determined according to at least one of the following: the importance of the i-th first convolutional layer in all convolutional layers of the second neural network model, and the number of channels in the i-th first convolutional layer.

17. The method according to claim 16, characterized in that y i is greater than or equal to the number of channels in the i-th first convolutional layer and / or, i is less than or equal to the number of channels in the i-th first convolutional layer.

18. The method according to claim 11, characterized in that The method of increasing the number of channels in the Y first convolutional layers in the second neural network model respectively to obtain a third neural network model includes: respectively increasing the number of channels of each of the Y first convolutional layers to obtain a fourth neural network model; The fourth neural network model is trained to convergence based on a data set to obtain the third neural network model, wherein the data set is a data set used to train the second neural network model.

19. The method according to claim 11 or 18, characterized in that The pruning process is performed on the channels of the Y second convolutional layers in the third neural network model respectively to obtain the first neural network model, including: Performing pruning processing on the channels of the Y second convolutional layers in the third neural network model respectively to obtain a fifth neural network model; The fifth neural network is fine-tuned based on a data set to obtain the first neural network model, wherein the data set is a data set for training the second neural network model.

20. The method of claim 11, wherein: When the structure of the second neural network model is adapted to the hardware structure of the electronic device, the structure of the first neural network model is adapted to the hardware structure of the electronic device.

21. An electronic device comprising a memory and one or more processors, characterized in that: The memory is used to store a computer program; the processor is used to call the computer program so that the electronic device executes the method according to any one of claims 1 to 10 or 11 to 20.

22. A computer storage medium, characterized in that include: Computer instructions; when the computer instructions are executed on an electronic device, the electronic device executes the method according to any one of claims 1 to 10 or 11 to 20.

Citation Information

Patent Citations

  • Model compression method and device, electronic equipment and storage medium

    CN116108752A

  • Neural network pruning method and device, equipment and storage medium

    CN116306888A