Processing method of neural network model, electronic device and readable storage medium

By merging and adjusting the multi-branch processing units of the neural network model into single-branch units and fusing parameters on the server, the problems of slow running speed and reduced accuracy on terminal devices are solved, and efficient deployment of neural network models is achieved.

CN116451742BActive Publication Date: 2026-11-20HUAWEI TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310332748.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-23
Publication Date
2026-11-20
Estimated Expiration
2043-03-23

AI Technical Summary

Technical Problem

Because the hardware performance of terminal devices is weaker than that of servers, the neural network models deployed on terminal devices run slower and have lower accuracy. Existing technologies make it difficult to improve the running speed of models on terminal devices while maintaining high accuracy.

Method used

When training a neural network model on a server, multi-branch processing units are configured and merged into a single-branch processing unit through fusion computation. Parameters are adjusted to adapt to the hardware of the terminal device to ensure that the model maintains high accuracy and speed when running on the terminal device.

Benefits of technology

By merging processing units and parameters, the deployed neural network model maintains high accuracy on terminal devices, while reducing hardware requirements and improving operating speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116451742B_ABST
    Figure CN116451742B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of artificial intelligence, and discloses a neural network model processing method, an electronic device and a readable storage medium. The method comprises the following steps: a first electronic device acquires a first neural network model to be processed, the first neural network model comprises M first processing units, the M first processing units can perform parallel processing on data, and M is greater than or equal to 2; the first electronic device combines the M first processing units of the first neural network into S second processing units, thereby obtaining a second neural network, wherein S is less than M; and the first electronic device sends the second neural network model to a second electronic device. The multi-branch processing units in the trained first neural network model are adjusted and combined into single-branch processing units, the accuracy of the deployed second neural network model is ensured, the second neural network model with the single-branch processing units has a lower requirement for the hardware of a terminal device, and the second neural network model has a faster running speed after being deployed on the terminal device.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence technology, and in particular to a method for processing neural network models, an electronic device, and a readable storage medium. Background Technology

[0002] Currently, with the development of artificial intelligence (AI) technology in fields such as image processing and speech recognition, an increasing number of applications based on artificial intelligence neural network models (also known as AI models) are being deployed on terminal devices. For example... Figure 1 As shown, server 3 can train a neural network model and deploy it on terminal device 2. User 1 can use the camera application on terminal device 2 to take an image containing multiple people (i.e., the input data is an image), and the target person can be segmented from the image by the image application based on the neural network model (AI removes passersby), and then saved as another image.

[0003] Servers have powerful hardware, and typically, neural network models are trained on the server before being deployed to terminal electronic devices. For example... Figure 2 As shown, server 3 deploys the trained neural network model 100 to terminal device 2 to obtain neural network model 100a, which includes a classification loss unit 1001 and a distillation loss unit 1002. It can be seen that server 3 did not adjust neural network model 100a; the structures of the two neural network models are roughly the same. Because the hardware performance of terminal device 2 is weaker than that of server 3, neural network model 100a runs slower on terminal device 2. Adjusting neural network model 100a, such as reducing the number of processing units, would decrease its accuracy. Summary of the Invention

[0004] To address the aforementioned shortcomings, this application proposes a method for processing neural network models, an electronic device, and a readable storage medium.

[0005] Firstly, this application provides a method for processing neural network models, including:

[0006] The first electronic device acquires a first neural network model to be processed, wherein the first neural network model includes M first processing units, the M first processing units are capable of parallel processing of data, and M is greater than or equal to 2;

[0007] The first electronic device merges the M first processing units of the first neural network into S second processing units to obtain a second neural network, where S is less than M;

[0008] The first electronic device sends the second neural network model to the second electronic device.

[0009] In this application, the first electronic device herein may be a server, and the second electronic device may be a terminal device. The first neural network herein may be a trained neural network model on the server. The M first processing units of the first neural network may include: N distillation loss units, K sets of convolution units and normalization units, and T sets of convolution units and a plurality of normalization units, where the K sets of convolution units may use 3x3 convolution kernels, and the T sets of convolution units may use 1x1 convolution kernels. The S second processing units of the second neural network model may include: at least one distillation loss unit, at least one set of convolution units (3x3 convolution kernel) and a normalization unit. Each of the M first processing units is configured with a first parameter, and each of the S second processing units is configured with a second parameter. The first electronic device may adjust the first parameters to the second parameters according to the number of the first processing units and the second processing units. When P=M, the M first parameters of all the first processing units may be adjusted to the S second parameters; when P<M, the P first parameters of part of the first processing units may be adjusted to the S second parameters.

[0010] It can be seen that before deploying the first neural network model on the terminal device, the multi-branch processing units in the trained first neural network model can be adjusted and merged into single-branch processing units, and a plurality of first parameters corresponding to the multi-branch processing units can also be subjected to fusion calculation, for example, summing, averaging, or weighted averaging the plurality of parameters, etc., to determine one second parameter (fusion parameter), and the fused parameter is used to configure the merged single-branch processing unit. It can be seen that the merged processing unit configured with the fusion parameter can cover the processing capabilities of the multiple processing units before merging, ensuring the accuracy of the deployed second neural network model. Compared with the first neural network model with multi-branch processing units, the second neural network model with single-branch processing units has lower hardware requirements for the terminal device, and runs faster after being deployed on the terminal device.

[0011] In a possible implementation of the above first aspect, that the first electronic device merges and processes the M first processing units of the first neural network into S second processing units to obtain the second neural network includes:

[0012] Acquiring first parameters of P first processing units among the M first processing units, where P is less than or equal to M;

[0013] Merging the first parameters of the P first processing units into a second parameter, and configuring the S second processing units with the second parameter, where the value of S is 1.

[0014] In one possible implementation of the first aspect above, merging includes at least one of summing, averaging, or weighted averaging the first parameter.

[0015] In one possible implementation of the first aspect described above, the P first processing units include P data processing units, and the P data processing units are used to perform feature processing on the data to obtain prediction results; or

[0016] The P first processing units include P distillation loss units, and the loss units are used to determine the difference between the predicted results and the actual results output by the data processing units of the first neural network model.

[0017] In this application, the process of merging the first parameters of P data processing units into S second parameters may include: determining the first parameters corresponding to the P data processing units included in the first neural network model using the following formula:

[0018]

[0019] in, Indicates the weight of the data processing unit. This indicates the bias of the data processing unit, and x represents the data input to the data processing unit.

[0020] By x= Substitute into the following formula

[0021]

[0022] in, Indicates precision. Indicates the mean difference. Represents variance. Indicates bias;

[0023] get

[0024]

[0025] in, This represents the weight of the data processing unit after fusion. This indicates the bias of the merged data processing unit.

[0026] This application also includes:

[0027] The second parameters corresponding to the S data processing units included in the second neural network model are determined by the following formula:

[0028] ,

[0029] in, Indicates the weight of the data processing unit. This indicates the bias of the data processing unit.

[0030] In this application, the process of merging the first parameters of P distillation loss units into S second parameters may include:

[0031] The first parameters corresponding to the P distillation loss units included in the first neural network model are determined by the following formula:

[0032]

[0033] in, This indicates the weight of the distillation loss unit. This represents the bias of the distillation loss unit, and x represents the data input to the distillation loss unit.

[0034] This application also includes: determining the second parameters of the S distillation loss units included in the second neural network model using the following formula:

[0035] ,

[0036] in, This indicates the weight of the distillation loss unit. This indicates the bias of the distillation loss unit.

[0037] In this application, the number of data processing units and distillation loss units may be the same or different.

[0038] In one possible implementation of the first aspect described above, the first neural network model includes a convolutional neural network model, and the data processing unit includes a convolutional layer or a pooling layer.

[0039] In one possible implementation of the first aspect described above, the first electronic device includes a server, and the second electronic device includes a terminal device.

[0040] In one possible implementation of the first aspect above, the terminal device includes at least one of the following: a mobile phone, a tablet computer, and a smartwatch.

[0041] In one possible implementation of the first aspect above, the first neural network model or the second neural network model is used to implement at least one of the following functions: image recognition, text recognition, and speech recognition.

[0042] In a second aspect, this application provides an electronic device for processing neural networks, comprising: a memory for storing instructions executed by one or more processors of the electronic device, and a processor, one of the processors of the electronic device, for executing the processing method of the neural network model of the first aspect.

[0043] Thirdly, this application provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the processing method of the neural network model of the first aspect.

[0044] Fourthly, this application provides a computer program product, comprising: a non-volatile computer-readable storage medium, the non-volatile computer-readable storage medium including a processing method for executing a neural network model of the first aspect. Attached Figure Description

[0045] Figure 1 This application illustrates an application scenario using a neural network model, as shown in the embodiments of this application.

[0046] Figure 2 This is a schematic diagram illustrating the deployment of a neural network model on a terminal device according to an embodiment of this application;

[0047] Figure 3 This is a schematic diagram illustrating the deployment of a trained neural network model on a terminal device, as shown in an embodiment of this application.

[0048] Figure 4 This is a schematic diagram illustrating a processing unit that adjusts and merges a neural network model from multiple branches into a single branch, as shown in an embodiment of this application.

[0049] Figure 5 This is an architectural diagram of a server used for training a neural network model, as shown in an embodiment of this application.

[0050] Figure 6 This is an architectural diagram of a terminal device for deploying a neural network model, as shown in an embodiment of this application.

[0051] Figure 7 This is a schematic flowchart illustrating the processing method of the neural network model shown in an embodiment of this application;

[0052] Figure 8 This is a schematic diagram of the multi-branch structure formed by convolutional units and normalization units in the data processing layer of a neural network model shown in an embodiment of this application.

[0053] Figure 9 This is a schematic diagram of the multi-branch structure formed by distillation loss units in the loss layer of a neural network model shown in an embodiment of this application.

[0054] Figure 10 This is a schematic diagram illustrating a scenario where a user uses a terminal device to capture an image of a person, as shown in an embodiment of this application.

[0055] Figure 11 This is a schematic diagram of the data processing layer in a neural network model shown in an embodiment of this application;

[0056] Figure 12 This is a schematic diagram of the data processing layer in a neural network model shown in an embodiment of this application;

[0057] Figure 13 This is a schematic diagram illustrating the data processing of convolutional and attention units in an embodiment of this application. Detailed Implementation

[0058] To make the objectives, embodiments, and advantages of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.

[0059] To address the issue of reduced accuracy in neural network models deployed on terminal devices due to fewer processing units in a server-trained neural network model, this application proposes a neural network model processing method. During model training, multi-branch processing units are configured in the neural network model on the server. The neural network model is trained using input data (training data), and the parameters of each processing unit in the neural network model are determined. These parameters represent the processing capacity of each processing unit. Before deploying the neural network model on the terminal device, the multi-branch processing units in the trained neural network model can be adjusted and merged into single-branch processing units. In some embodiments, multiple parameters corresponding to the multi-branch processing units can be fused and calculated, for example, by summing, averaging, or weighted averaging multiple parameters, to determine a fusion parameter. This fusion parameter is then used to configure the merged single-branch processing unit. It can be seen that the merged processing unit with the fusion parameter can cover the processing capacity of the multiple processing units before merging, ensuring the accuracy of the deployed neural network model. Compared to multi-branch processing units, neural network models with single-branch processing units have lower hardware requirements for the terminal device and run faster after deployment.

[0060] In some embodiments, Figure 3 This is a schematic diagram illustrating a neural network model 100c obtained by deploying a trained neural network model 100b on a terminal device 2, as shown in an embodiment of this application. Figure 3 In the embodiment shown, the neural network model 100b may include a classification loss 1001b and N distillation loss units 1002b, where N can be a natural number greater than 1, for example, N can be 4.

[0061] The backbone network 101b is used to extract features from input data. For example, for image data, the backbone network 101b can convert image data into feature vectors as prediction results. The feature vectors are used to represent various information included in the image data, such as people, vehicles, animals, etc. The backbone network can also be called an encoder network.

[0062] The classification loss unit 1001b is used to evaluate the performance of the neural network model 100b in performing a classification task on the input data. The classification loss can be calculated by comparing the difference between the prediction result of the neural network model and the actual result. The classification loss can be implemented using classification loss functions, including cross-entropy loss function and squared loss function, etc. For example, a digit recognition application configured with a neural network model needs to classify handwritten digits. The output of the neural network model is a vector containing 10 elements, each element representing the probability distribution of the digits 0-9. For example, if the handwritten digit is 2, its corresponding actual result is [0, 0, 1, 0, 0, 0, 0, 0, 0, 0]. If the model's prediction result is [0.05, 0.1, 0.9, 0.01, 0.02, 0.02, 0.01, 0.01, 0.01, 0.01], then the difference between the actual result and the predicted result is the classification loss.

[0063] The distillation loss unit 1002b is used to represent the generalization performance of the neural network model 100b. Here, generalization performance represents the ability of the neural network model 100b to adapt to new samples; that is, the neural network model 100b can also provide correct prediction results for new data other than input data with the same patterns. For example, in a digit recognition application configured with a neural network model that needs to classify handwritten digits, the output of the neural network model is a vector containing 10 elements, each element representing the probability distribution of the digits 0-9. For example, the handwritten digit is 1, and its corresponding actual result is [0, 0.7, 0, 0, 0, 0, 0, 0.2, 0, 0.1]. This means that 0.7 could be the digit 1, 0.2 could be the digit 7, and 0.1 could be the digit 9. If the model's prediction result is [0.05, 0.9, 0.1, 0.01, 0.02, 0.02, 0.01, 0.01, 0.01, 0.01], the difference between the actual result and the predicted result is the distillation loss. It can be seen that compared to the classification loss unit, the distribution of the actual result corresponding to the distillation loss unit is more extensive. Changing the number of distillation loss units in loss layer 103 can change the generalization performance of the neural network model 100.

[0064] Continue to refer to Figure 3Before deploying the trained neural network model on the terminal device, the neural network model 100b can be adjusted to the neural network model 100c. The neural network model 100c can output the prediction results of a single-branch distillation loss unit (not shown). The parameters of the distillation loss unit are the fusion parameters corresponding to the parameters of the N distillation loss units 1002b of the neural network model 100b.

[0065] In some embodiments, Figure 4 A schematic diagram of a processing unit capable of adjusting and merging multiple branches into a single branch is shown. Figure 4 In the embodiment shown, the processing unit of the neural network model during the model training process may include K sets of convolutional units 1021b and multiple normalization units 1022b, where K can be a natural number greater than 1, for example, K can be 6.

[0066] The convolutional unit 1021b is used to extract features from the input data to obtain feature data (feature vector). For example, when the convolutional unit 1021b is a 3x3 convolutional kernel, the convolutional unit 1021b can extract local features of size 3x3 from the input data.

[0067] The normalization unit 1022b, also known as batch normalization (BN), is used to reduce the data offset between units (nodes) in a neural network model, making the output of the neural network model more stable.

[0068] The neural network model may also include a single-branch linear unit 1023b for transforming the feature data (feature vectors) to produce a prediction result. The linear unit 1023b may include multiple 1x1 convolutional kernel subunits and activation function subunits. The 1x1 convolutional kernel subunits transform the feature data into multiple vectors, reducing the dimensionality of the feature data and improving processing efficiency. The activation function subunit, i.e., the Restricted Linear Activation Function (ReLU), performs a linear transformation on the feature data, such as pruning the negative parts of the feature data to 0 and keeping the positive parts unchanged.

[0069] In some embodiments, T sets of convolutional units 1024b and multiple normalization units 1025b are added to the multi-branch structure formed by K sets of convolutional units 1021b and multiple normalization units 1022b. Here, T can be a natural number greater than or equal to 1; for example, T can be 1. The convolutional units 1024b can be 1x1 convolutional kernels, used to transform the feature data into multiple vectors to reduce the dimensionality of the feature data and improve processing efficiency. (Continue to refer to...) Figure 4Before deploying the trained neural network model on a terminal device, K groups of convolutional units 1021b and multiple normalized units 1022b, as well as T groups of convolutional units 1024b and multiple normalized units 1025b, can be adjusted and merged into single-branch convolutional units 1021c and normalized units 1022c. The parameters of convolutional unit 1021c are the fusion parameters corresponding to the parameters of the K groups of convolutional units 1021b and multiple normalized units 1022b. Here, the linear unit 1023c can be the same as the linear unit 1023b. The specific process of determining the fusion parameters and performing the fusion calculation will be discussed later. Figure 8 The interactive process of the processing method for the neural network model shown is described in detail in the diagram.

[0070] Figure 5 This diagram illustrates the architecture of a server 3 for training a neural network model, as shown in an embodiment of this application. Server 3 may include a processor 500, internal memory 510, power management module 520, and communication module 530. Server 3 may include an application server, a cloud server, etc.

[0071] The processor 500 may include one or more processing units, such as a central processing unit (CPU). The processor 500 is used to train a neural network model stored in the internal memory 510, adjusting the neural network model before deploying it on a terminal device. For example, it can be used to adjust and merge multi-branch processing units in a trained neural network model into a single-branch processing unit to obtain the target neural network model.

[0072] Internal memory 50 can be used to store computer executable program code, including instructions. Internal memory 510 may include a program storage area and a data storage area. The program storage area can store neural network models and training data.

[0073] The power management module 520 is used to supply power to the processor 500 and the internal memory 510.

[0074] The communication module 530 is used to communicate with at least one terminal device and send the adjusted neural network model to the terminal device.

[0075] Figure 6This is an architectural diagram illustrating a terminal device 2 for deploying a neural network model, as shown in an embodiment of this application. The terminal device 2 may include devices with a display screen such as mobile phones, tablets, wearable devices, in-vehicle devices, augmented reality (AR) / virtual reality (VR) devices, laptops, ultra-mobile personal computers (UMPCs), netbooks, and personal digital assistants (PDAs). This application embodiment does not impose any limitations on the specific type of terminal device.

[0076] Terminal device 2 may include a processor 600, an external memory interface 620, an internal memory 621, a universal serial bus (USB) interface 630, a charging management module 640, a power management module 641, a battery 642, an antenna 1, an antenna 2, a mobile communication module 650, a wireless communication module 660, an audio module 670, a speaker 670A, a receiver 670B, a microphone 670C, a headphone jack 670D, a sensor module 680, buttons 690, a motor 691, an indicator 692, a camera 693, a display screen 694, and a subscriber identification module (SIM) card interface 695, etc. The sensor module 680 may include a pressure sensor 680A, a gyroscope sensor 680B, a barometric pressure sensor 680C, a magnetic sensor 680D, an accelerometer sensor 680E, a distance sensor 680F, a proximity light sensor 680G, a fingerprint sensor 680H, a temperature sensor 680J, a touch sensor 680K, an ambient light sensor 680L, a bone conduction sensor 680M, etc.

[0077] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the terminal device. In other embodiments of this application, the terminal device may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0078] Processor 600 may include one or more processing units, such as: a central processing unit (CPU), a micro-programmed control unit (MCU), an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural network processing unit (NPU), etc.

[0079] The processor can generate operation control signals based on the instruction opcode and timing signals to control the instruction fetching and execution.

[0080] The processor 600 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 600 is a cache memory. This memory can store instructions or data that the processor 600 has just used or that are used repeatedly.

[0081] The wireless communication function of the terminal device can be implemented through antenna 1, antenna 2, mobile communication module 650, wireless communication module 660, modem processor, and baseband processor.

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

[0083] The mobile communication module 650 can provide solutions for wireless communication, including 2G / 3G / 4G / 5G, applied to terminal devices. In some embodiments, at least some functional modules of the mobile communication module 650 may be housed in the same device as at least some modules of the processor 600.

[0084] In some embodiments, antenna 1 of the terminal device is coupled to mobile communication module 650, and antenna 2 is coupled to wireless communication module 660, enabling the terminal device to communicate with networks and other devices via wireless communication technology.

[0085] The external storage interface 620 can be used to connect an external storage card, such as a Micro SD card, to expand the storage capacity of the terminal device. The external storage card communicates with the processor 600 through the external storage interface 620 to perform data storage functions. For example, music, video, and other files can be saved on the external storage card.

[0086] Internal memory 621 can be used to store computer executable program code, which includes instructions. Internal memory 621 may include a program storage area and a data storage area. Processor 600 executes various functional applications and data processing of the terminal device by running instructions stored in internal memory 621 and / or instructions stored in memory disposed in the processor. In some embodiments, internal memory 621 may store a neural network model.

[0087] The SIM card interface 795 is used to connect a SIM card.

[0088] All methods and implementations of this application can be implemented in the form of software, magnetic files, firmware, etc.

[0089] Program code can be applied to input instructions to perform the functions described herein and generate output information. The output information can be applied to one or more output devices in a known manner. For the purposes of this application, the processing system includes any system having a processor such as, for example, a digital signal processor (DSP), a microcontroller, an application-specific integrated circuit (ASIC), or a microprocessor.

[0090] The program code can be implemented using a high-level procedural language or an object-oriented programming language to communicate with the processing system. Assembly language or machine language can also be used when needed. In fact, the mechanisms described in this paper are not limited to any particular programming language. In either case, the language can be a compiled language or an interpreted language.

[0091] One or more aspects of at least one embodiment can be implemented by representational instructions stored on a computer-readable storage medium, the instructions representing various logics in a processor, which, when read by a machine, cause the machine to create logic for performing the technical solutions described herein. These representations, referred to as “IP cores,” can be stored on a tangible computer-readable storage medium and provided to multiple customers or production facilities for loading into manufacturing machines that actually manufacture the logic or processor.

[0092] The following is based on Figure 7 The schematic diagram shown is used to describe in detail the processing method provided in the embodiments of this application. Figure 7 The method shown can be implemented by the processors of server 3 and terminal device 2 executing the relevant instructions.

[0093] refer to Figure 7 The processing method may include the following steps:

[0094] S701: Server 3 obtains input data.

[0095] For example, the input data here can be training data used to train a neural network model. In some embodiments, assuming the neural network model is a smart cursor matting function for an image application of terminal device 2, the input data can be foreground image data and background image data in an image of an unknown category with labels, denoted as dataset I. To prepare dataset I, a set of samples containing foreground and background images can be prepared in advance and divided into two parts, for example: a foreground dataset and a background dataset.

[0096] In some embodiments, dataset I can be obtained by manually segmenting or processing existing images (including images from public datasets or domain-specific datasets) using computer vision techniques. The public dataset could be ImageNet1k, containing over 1 million images across 1000 categories and 50,000 test images. Once segmentation is complete, each image needs to be assigned a label indicating whether it is foreground or background. When preparing dataset I, the following factors can also be considered:

[0097] Data quantity: The dataset should contain enough samples so that the neural network model can learn enough features to improve classification accuracy.

[0098] Data quality: The images in the dataset can be high-quality (high-resolution) images with good sharpness and contrast, enabling the images to be accurately segmented into foreground and background.

[0099] Data diversity: The images in the dataset should cover different types of foreground and background, so that the neural network model can learn from different types of samples and improve the generalization performance of the neural network model.

[0100] S702: Server 3 configures the neural network model with a first preset number of multi-branch convolutional units and normalization units.

[0101] For example, server 3 can configure convolutional units and normalization units for the data processing layer of the neural network model according to a first preset number. The convolutional units can be used to extract image features. The normalization units can be a regularization technique used to prevent overfitting of the convolutional unit outputs. By configuring normalization units for the convolutional units, the output of each convolutional unit can be standardized, accelerating the training of the neural network model and improving its generalization performance.

[0102] In some embodiments, the first preset quantity can be represented by K, which can be a natural number greater than 1. For example, K can be 6. In this case, 6 sets of convolutional units and normalization units can form a multi-branch architecture, that is, multiple parallel convolutional units are added to the neural network model so that different features can be extracted from the input data simultaneously. It is understood that 6 here is exemplary, and other values ​​can also be used in the embodiments of this application, which are not limited thereto. As the value of K is different, the number of branches formed by the convolutional units and normalization units in the neural network model is also different.

[0103] The following is for reference. Figure 8 , Figure 8 This application illustrates a multi-branch structure formed by convolutional units and normalization units in the data processing layer of a neural network model.

[0104] like Figure 8 As shown, when K is 6, the neural network model can include six branches consisting of convolutional units and normalization units, namely, branches 1 to 6, which receive input data 1 and input data 2. The convolutional units and normalization units in each branch can include their respective parameters.

[0105] For example, a convolutional unit can be represented by formula (1): This means that x represents the input data, such as a feature vector. Indicates weight, This represents the bias. The weights here represent the probability that the input data belongs to a certain category, while the bias is a constant used to adjust... The value is set to prevent it from being too large or too small, that is, exceeding the normal range.

[0106] For example, a normalized unit can be represented by formula (2): This means that x represents the input data. Indicates precision. Indicates the mean difference. Represents variance. The bias is indicated. Formula (2) can limit the output of the convolution unit to a certain range, for example: [0, 1], which is between 0 and 1.

[0107] Continue to refer to Figure 8The convolutional units in branches 1 to 6 can be 3x3 convolutional kernels. In some embodiments, a parallel branch 0 can also be set for branches 1 to 6. Branch 0 can also consist of a convolutional unit and a normalization unit, and the convolutional unit in branch 0 can be a 1x1 convolutional kernel. The 1x1 convolutional kernel can work in conjunction with the 3x3 convolutional kernel to process the input data simultaneously, transforming the input data into multiple vectors to reduce the dimensionality of the input data and improve processing efficiency.

[0108] S703: Server 3 configures a second preset number of multi-branch distillation loss units for the neural network model.

[0109] For example, server 3 can configure distillation loss units for the loss layer of the neural network model according to a second preset number.

[0110] In some embodiments, the second preset quantity can be represented by N, which can be a natural number greater than 1. For example, N can be 4. In this case, 4 sets of distillation loss units can form a multi-branch architecture, that is, multiple parallel distillation loss units are added to the neural network model so that the prediction results of the neural network model can be compared with the actual results simultaneously to obtain the difference. It is understood that 4 here is exemplary, and other values ​​can also be used in the embodiments of this application, which are not limited thereto. As the value of N is different, the number of branches formed by the distillation loss units in the neural network model is also different.

[0111] The following is for reference. Figure 9 , Figure 9 This application illustrates a multi-branch structure formed by distillation loss units in the loss layer of a neural network model.

[0112] like Figure 9 As shown, when N is 4, the neural network model can include four branches consisting of distillation loss units, namely, branches 1 to 4, which receive prediction result 1 and prediction result 2 as input data. Each branch's distillation loss unit can include its own parameters. For example, a distillation loss unit can be represented by formula (1): This means that x represents the input data, such as a feature vector. Representing the weight, denoted as , To represent the bias, denoted as .

[0113] Continue to refer to Figure 10 Furthermore, a parallel branch 0 can be set for branches 1 to 4. Branch 0 can consist of a classification loss unit.

[0114] S704: Server 3 uses input data to train the neural network model.

[0115] For example, after configuring the neural network model on server 3, the neural network model is trained using dataset I. The output result is compared with the actual result (true result) corresponding to the label, the loss (difference) is calculated, and the model parameters of the neural network model are updated in reverse using the obtained loss. This step is repeated until the preset number of training times is reached.

[0116] In some embodiments, during training, taking dataset I, which includes foreground and background image data, as an example, the image data in dataset I is used as input to obtain output results. The difference (loss) between each output result and the actual result corresponding to the label is calculated, and the model parameters of the neural network model are updated using the backpropagation algorithm to minimize the loss. Server 3 can repeat this process until a preset number of training iterations is reached or the loss reaches a preset value.

[0117] In some embodiments, after server 3 has trained a neural network model, it can be saved for future use. Server 3 can achieve this by saving the structure and parameters of the neural network model to a file so that it can be reloaded when needed. When saving the neural network model, server 3 can also save some metadata (such as network architecture, model parameters, etc.).

[0118] S705: Server 3 adjusts the distillation loss unit, convolution unit, and normalization unit of the trained neural network model into a single-branch target convolution unit and target distillation loss unit to obtain the target neural network model.

[0119] For example, server 3 can adjust the multi-branch distillation loss unit, convolution unit and normalization unit in the trained neural network model to a single branch. That is, the loss layer of the adjusted target neural network model is configured with a single-branch target distillation loss unit, and the data processing layer is configured with a single-branch target convolution unit.

[0120] S706: Server 3 reparameterizes the parameters of the multi-branch convolutional units and normalization units corresponding to the first preset number into the first fusion parameters.

[0121] For example, taking the value of the first preset number K as 6, the parameter reparameterization here can be to fuse the parameters of the convolutional units and normalization units (including the convolutional units and normalization units in branch 0) in the seven branches of the data processing layer of the neural network model into one parameter, that is, the first fusion parameter, and use the first fusion parameter to configure the target convolutional unit of the data processing layer of the target neural network model.

[0122] In some embodiments, with Figure 8 Taking branch 1 as an example, the convolutional unit passes through This indicates that the normalization unit is determined by the formula. This means that the convolutional units and normalization units in each branch are merged. Since the normalization unit is used to process the output of the convolutional units, it will... Substituting x into the normalization unit yields... After simplification, we get formula (3). It can be seen that formula (3) is equivalent to the formula for a convolution unit, where, Representing the weight, denoted as , To represent the bias, denoted as .

[0123] In some embodiments, for Figure 9 For branch 0, the convolutional units and normalization units in branch 0 also need to be fused. Here, the 1x1 convolutional kernel needs to be converted into a new convolutional kernel by padding the kernel with zeros, so that the original 1x1 convolutional kernel is centered on the 3x3 convolutional kernel. The parameters after fusing the convolutional units and normalization units of the seven branches are obtained sequentially. These parameters are then summed to obtain the first fusion parameter used to configure the target convolutional unit. For example, the first fusion parameter may include... and ,in, , This means summing the parameters of the merged multi-branch convolutional units and normalized units.

[0124] S707: Server 3 reparameterizes the parameters of the multi-branch distillation loss units corresponding to the second preset number into the second fusion parameters.

[0125] For example, taking the value of the second preset number N as 4, the parameter reparameterization here can be to fuse the parameters of the distillation loss units (excluding the classification loss unit in branch 0) in the four branches of the loss layer of the neural network model into one parameter, that is, the second fusion parameter, and use the first fusion parameter to configure the target distillation loss unit of the data processing layer of the target neural network model.

[0126] In some embodiments, with Figure 9 Taking branch 1 as an example, the distillation loss unit passes through This means that the parameters of the distillation loss units of the four branches are obtained sequentially, and the parameters are summed to obtain the second fusion parameter used to configure the target convolutional unit. For example, the second fusion parameter may include... and ,in, , , where i=1,2,3...N, is the average sum of the parameters of the fused multi-branch convolutional units and normalized units.

[0127] S708: Server 3 uses the first fusion parameter and the second fusion parameter to configure the target convolutional unit and the target distillation loss unit of the target neural network model.

[0128] For example, the target convolutional unit of the target neural network model can be expressed by formula (4). It means that, among them, Represents weights and sums This indicates the bias. The target distillation loss unit of the target neural network model can be expressed by formula (5). It means that, among them, Represents weights and sums Indicates bias.

[0129] S709: Server 3 sends the adjusted target neural network model to terminal device 2.

[0130] For example, server 3 can send the adjusted target neural network model to terminal device 2. Taking the target neural network model as an example for the intelligent cursor matting function of the image application of terminal device 2, terminal device 2 can use the target neural network model to configure the image application and improve the efficiency of the image application in matting.

[0131] In some embodiments, after the target neural network model is deployed on the terminal device 2, the user can use an application based on the target neural network model. Figure 10 This embodiment of the application illustrates a scenario where a user uses a terminal device to capture an image of a person, selects the person within the image, and the terminal device's image processing application performs background removal on the person.

[0132] like Figure 10As shown, terminal device 2 can first acquire an image. Image 1001 can be an image captured by the user's camera on terminal device 2 or an image selected from the local photo album of terminal device 2. The image application on terminal device 2 can open image 1001. In some embodiments, the image application on terminal device 2 can also perform RGB domain normalization processing on image 1001. The user can perform a frame operation on image 1001, selecting a region of interest 1002 on image 1001. Terminal device 2 receives the user's operation, and the image application based on a neural network model can perform salient segmentation on the region of interest 1002. That is, the image application can use a pre-trained and adjusted neural network model to identify the salient target in the region of interest 1002 on image 1001, specifically, segmenting a person 1003 from the region of interest 1002 and saving it as image 1004. In some embodiments, since the neural network model used in the image application is already able to distinguish between the person 1003 and the background or foreground in the region of interest 1002, the final image 1004 may only contain the person 1003 and may not contain the background or foreground of image 1001. Users can copy image 1004 into a PowerPoint or Word document for presentation and application.

[0133] In some embodiments, the target neural network model can also be applied to applications that support speech recognition or text recognition.

[0134] The above Figure 7 The document describes a first preset quantity K and a second preset quantity N used by the server to configure the neural network model. The values ​​of K and N can be determined during the training process of the neural network model through ablation experiments. Ablation experiments can be used to determine the optimal values ​​of K and N. This can be achieved by first fixing the value of K and adjusting the value of N to optimize the performance parameters of the neural network model, thus obtaining the optimal value of N. Then, based on the optimal value of N, N is fixed, and the value of K is adjusted to optimize the performance parameters of the neural network model, thus obtaining the optimal value of K. Table 1 shows the correspondence between the values ​​of K and N determined by ablation experiments and the performance parameters of the neural network model, as illustrated in the embodiments of this application. It can be seen that the model name can represent the name of the neural network model; here, "Model 1" represents the neural network model being trained by the server. The first preset quantity K and the second preset quantity N represent the number of branches composed of convolutional units and normalization units, and the number of branches composed of distillation loss units, respectively, in the neural network model being trained. The performance parameters represent the accuracy of the neural network model. Referring to Table 1, during the training process of the neural network model on the server, the values ​​of K and N are continuously adjusted. When K=6 and N=4, the performance parameters of the neural network model reach their optimal state.

[0135] Table 1

[0136] The values ​​in Table 1 above are all exemplary. In some embodiments, the values ​​in Table 1 can also take any other arbitrary values, and this application embodiment does not limit this.

[0137] Figure 11 This is a schematic diagram of a data processing layer in a neural network model 100 according to an embodiment of this application. Figure 11 In the illustrated embodiment, the data processing layer may include a convolutional unit 1121, a normalization unit 1122, and a linear unit 1123. The convolutional unit 1121 is used to extract features from the input data to obtain feature data (feature vectors). The normalization unit 1122 can be called batch normalization (BN). It is used to reduce data skew between units (nodes) in the neural network model, making the output of the neural network model more stable.

[0138] The activation function subunit in linear unit 1123, namely the Rectified Linear Activation Function (ReLU), is used to perform linear transformations on the feature data, such as pruning the negative part of the feature data to 0 and keeping the positive part unchanged.

[0139] Compared to Figure 11 , Figure 12 This is a schematic diagram of a data processing layer in a neural network model 100 according to an embodiment of this application. Figure 12 In the illustrated embodiment, the data processing layer may include a self-attention unit 1221, a layer normalization unit 1222, and a linear unit 1223. The self-attention unit 1221 is a module used to calculate feature data at various positions in the input data, typically used in language processing, to determine the relationships between words at different positions in the input sentence. Compared to the convolutional unit 1121, the self-attention unit 1221 has a larger number of parameters and slower data processing speed.

[0140] The layer normalization unit 1222, also known as layer normalization (LN), can be used to reduce data skew between units (nodes) in a neural network model, making the output of the neural network model more stable. However, the data processing speed of the layer normalization unit 1222 is slower than that of batch normalization (BN). Similarly, the activation function subunit in the linear unit 1223, namely the Gaussian Linear Activation Function (GeLU), also has a slower data processing speed than ReLU.

[0141] Figure 13 This is a schematic diagram illustrating a scenario where a convolutional unit and a self-attention unit process data, as shown in an embodiment of this application. Figure 13 In the illustrated embodiment, the self-attention unit can be used to determine the local positional relationships of the various objects included in the image 1301 and capture the local representation 1302 corresponding to the local position. The convolution unit 1303 is used to directly capture the local representation from the input data 1304 to obtain the output result.

[0142] While the description of this application is presented in conjunction with preferred embodiments, this does not imply that the features of this application are limited to this implementation. On the contrary, the purpose of describing the invention in conjunction with embodiments is to cover other options or modifications that may arise based on the claims of this application. To provide a thorough understanding of this application, numerous exemplary details will be included in the following description. This application may also be implemented without using these details. Furthermore, to avoid confusion or obscuring the focus of this application, some specific details will be omitted in the description. It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other.

[0143] Furthermore, the various operations will be described as multiple discrete operations in a manner most conducive to understanding the illustrative embodiments; however, the order of description should not be construed as implying that these operations must depend on the order. In particular, these operations do not need to be performed in the order presented.

[0144] As used herein, the terms “module” or “unit” may refer to, be, or include: application-specific integrated circuits (ASICs), electronic circuits, (shared, dedicated, or group) processors and / or memories that execute one or more software or firmware programs, combinational logic circuits, and / or other suitable components that provide the described functionality.

[0145] In the accompanying drawings, certain structural or methodological features are shown in a specific arrangement and / or order. However, it should be understood that such a specific arrangement and / or order may not be necessary. In some embodiments, these features may be arranged in a manner and / or order different from that shown in the illustrative drawings. Furthermore, the inclusion of structural or methodological features in a particular figure does not imply that such features are required in all embodiments, and in some embodiments, these features may be omitted or may be combined with other features.

[0146] Various embodiments of the mechanisms disclosed in this application can be implemented in hardware, software, firmware, or a combination of these implementation methods. Embodiments of this application can be implemented as computer programs or program code executable on a programmable system, which includes multiple processors, a storage system (including volatile and non-volatile memories and / or storage elements), multiple input devices, and multiple output devices.

[0147] Such computer-readable storage media can include, but are not limited to, non-transient tangible arrangements of articles made or formed by a machine or device, including storage media such as: hard disks and any other type of disk, including floppy disks, optical disks, compact disc read-only memory (CD-ROM), compact disc rewritable (CD-RW), and magneto-optical disks; semiconductor devices such as read-only memory (ROM), random access memory (RAM) such as dynamic random access memory (DRAM) and static random access memory (SRAM), erasable programmable read-only memory (EPROM), flash memory, electrically erasable programmable read-only memory (EEPROM); phase-change memory (PCM); magnetic cards or optical cards; or any other type of medium suitable for storing electronic instructions.

[0148] Therefore, embodiments of this application also include a non-transient computer-readable storage medium containing instructions or design data, such as a hardware description language (HDL), which defines the structures, circuits, devices, processors, and / or system features described in this application.

Claims

1. A method for processing a neural network model, characterized in that, include: A first electronic device acquires a first neural network model to be processed, wherein the first neural network model includes M first processing units, the M first processing units are capable of parallel processing of data, M is greater than or equal to 2, the M first processing units include K data processing units and N distillation loss units, the data processing units are used to perform feature processing on the data to obtain prediction results, the distillation loss units are used to determine the difference between the prediction results output by the data processing units and the actual results, K is a natural number greater than 1, and N is a natural number greater than 1; The first electronic device merges the K data processing units of the first neural network model into S second data processing units, and merges the N distillation loss units into S second distillation loss units to obtain a second neural network model, wherein the value of S is 1; The first electronic device sends the second neural network model to the second electronic device; wherein, The first neural network model or the second neural network model is used to achieve at least one of the following functions: image recognition, text recognition, and speech recognition.

2. The method according to claim 1, characterized in that, The first electronic device merges the K data processing units of the first neural network model into S second data processing units, and merges the N distillation loss units into S second distillation loss units to obtain a second neural network model, including: Obtain the parameters of the K data processing units, merge the parameters of the K data processing units into a first fusion parameter, and use the first fusion parameter to configure S second data processing units; Obtain the parameters of the N distillation loss units, merge the parameters of the N distillation loss units into a second fusion parameter, and use the second fusion parameter to configure S second distillation loss units.

3. The method according to claim 2, characterized in that, The merging includes at least one of the following methods: summing, averaging, or weighted averaging the parameters.

4. The method according to claim 1, characterized in that, The first neural network model includes a convolutional neural network model, and the data processing unit includes a convolutional layer or a pooling layer.

5. The method according to claim 1, characterized in that, The first electronic device includes a server, and the second electronic device includes a terminal device.

6. The method according to claim 5, characterized in that, The terminal device includes at least one of the following: mobile phone, tablet computer and smartwatch.

7. An electronic device for processing neural networks, characterized in that, include: One or more processors; One or more memories; the one or more memories store one or more programs that, when executed by the one or more processors, cause the electronic device to perform the processing method of the neural network model according to any one of claims 1 to 6.

8. A computer-readable storage medium, characterized in that, The storage medium stores instructions that, when executed on a computer, cause the computer to perform the processing method of the neural network model according to any one of claims 1 to 6.

9. A computer program product, characterized in that, It includes a computer program / instruction that, when executed by a processor, implements the processing method of the neural network model according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Feature detection method, model merging method, equipment and medium

    CN114663941A