Training method and device of network model of edge device and electronic device
By setting weighted convolutional layers and variable parameter layers in the network model of edge devices, and combining forward inference and backpropagation, the entire network was fine-tuned, which solved the problem of poor recognition performance of edge device models and improved recognition performance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- AXERA SEMICON (SHANGHAI) CO LTD
- Filing Date
- 2023-04-12
- Publication Date
- 2026-07-14
AI Technical Summary
When fine-tuning models on edge devices, existing technologies can only fine-tune the last convolutional layer, resulting in poor recognition performance of the network model.
In the network model of edge devices, multiple convolutional layers with fixed weights and fully connected layers with variable weights are set, and a variable parameter layer is added between every two adjacent convolutional layers. The variable parameters are iteratively updated through forward inference, loss calculation, backpropagation and weight update to achieve fine-tuning of the entire network.
The network model recognition performance of edge devices has been improved by fine-tuning multiple weights in the network without changing the speed of the original convolutional layers, thereby enhancing the model's recognition capability.
Smart Images

Figure CN116384449B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of edge computing technology, and more specifically, to a method, apparatus, and electronic device for training a network model for an edge device. Background Technology
[0002] With the widespread adoption of smart technology, personal smart devices are mostly idle. Migrating training tasks from the cloud to the edge can fully utilize the computing power of edge devices. The amount of data at the edge is far less than in the cloud, and the training time for models is usually not very long. Reducing the amount of data that needs to be uploaded also improves training efficiency. At the same time, sensitive personal data no longer needs to be uploaded to the cloud, effectively addressing privacy concerns. Storage and computing resources on edge devices are limited; to effectively train neural network models on resource-constrained devices, model fine-tuning techniques can be employed.
[0003] Model fine-tuning refers to training a pre-trained model on a server cluster using a large-scale dataset, and then adapting it to numerous downstream tasks by fine-tuning only a few parameters. Edge chips in edge devices generally prioritize low power consumption and small area, often only suitable for model inference and difficult to support model training. However, in some scenarios (such as the rapidly changing environment of an in-vehicle system), the data collected in real time may differ significantly from the data distribution during model training, leading to performance degradation. In such cases, model fine-tuning becomes crucial.
[0004] Currently, model fine-tuning on edge devices typically only allows for fine-tuning the last convolutional layer. The model performance is significantly lower than fine-tuning the entire network, resulting in poor recognition performance of network models on edge devices. Summary of the Invention
[0005] The purpose of this application is to provide a training method, apparatus, and electronic device for network models on edge devices, in order to solve the problem that in the prior art, when fine-tuning models on edge devices, it is generally only possible to fine-tune the last convolutional layer, and the model performance is far from being able to fine-tune the entire network, resulting in poor recognition performance of network models on edge devices.
[0006] This application provides a method for training a network model for an edge device. The network model includes multiple convolutional layers with fixed weights and fully connected layers with variable weights. A variable parameter layer is set between every two adjacent convolutional layers. The method includes:
[0007] The training data is input into the network model, the predicted value is obtained through forward inference, the loss between the predicted value and the true label is calculated, and the weight gradient of the network model is calculated through backpropagation.
[0008] The updated weights are obtained based on the original weights and the corresponding weight gradients.
[0009] In the above technical solution, the network model of the edge device includes multiple convolutional layers with fixed weights. Each convolutional layer has a variable parameter layer at its output, with variable weights. The output of the last convolutional layer is connected to a fully connected layer, which also has variable weights. During network model training on the edge device, the weights of the convolutional layers are fixed and not updated. The main forward and backward propagation parts are quantized data types. Without changing the speed of the original convolutional layers, a learnable weight parameter is added after each convolutional layer. This weight parameter is iteratively updated to achieve the purpose of transforming the feature distribution. The model fine-tuning scheme of this embodiment can fine-tune multiple weights in the network, thereby improving the network model's recognition performance.
[0010] In some alternative implementations, training data is input into the network model, and predicted values are obtained through forward inference, including:
[0011] For the convolutional layer f(·) of the network model, the predicted value y is obtained through forward inference:
[0012] y = f(x) + r;
[0013] Where r is the weight value of the variable parameter layer corresponding to the convolutional layer, and x is the input of the current iteration.
[0014] In some optional implementations, the loss between the predicted value and the true label is calculated, including:
[0015] For the convolutional layer f(·) of the network model, calculate the loss L:
[0016]
[0017] in, This is the actual label value.
[0018] In some optional implementations, the weight gradients of the network model are calculated via backpropagation, including:
[0019] For the convolutional layer f(·) of the network model, the weight gradient is calculated through backpropagation:
[0020]
[0021] In some optional implementations, the updated weights are obtained based on the original weights and the corresponding weight gradients, including:
[0022] For the convolutional layer f(·) of the network model, the updated weight values of the corresponding variable parameter layer are:
[0023]
[0024] In some alternative implementations, training data is input into the network model, and predicted values are obtained through forward inference, including:
[0025] For a fully connected layer with variable weights in the network model, the predicted value y is obtained through forward inference:
[0026] y = W * x;
[0027] Where W is the weight of the fully connected layer, and x is the input of this iteration.
[0028] In some optional implementations, the loss between the predicted value and the true label is calculated, including:
[0029] For a fully connected layer with variable weights in the network model, calculate the loss L:
[0030]
[0031] in, This is the actual label value.
[0032] In some optional implementations, the weight gradients of the network model are calculated via backpropagation, including:
[0033] For a fully connected layer with variable weights in the network model, the weight gradient is calculated through backpropagation:
[0034]
[0035] In some optional implementations, the updated weights are obtained based on the original weights and the corresponding weight gradients, including:
[0036] For a fully connected layer with variable weights in a network model, the updated weight values of the convolutional layer correspond to those of a variable-parameter layer:
[0037]
[0038] This application provides a network model structure for an edge device. The network model includes multiple convolutional layers with fixed weights and fully connected layers with variable weights, with a variable parameter layer set between every two adjacent convolutional layers.
[0039] In the above technical solution, the network model of the edge device includes multiple convolutional layers with fixed weights. Each convolutional layer has a variable parameter layer at its output, and the weights of the variable parameter layer are variable. The output of the last convolutional layer is connected to a fully connected layer, and this fully connected layer also has variable weights. During training, the network model in this embodiment can fine-tune multiple weights within the network, thereby improving the network model's recognition performance.
[0040] This application provides a training apparatus for a network model of an edge device, comprising:
[0041] The inference module is used to input training data into the network model and obtain predicted values through forward inference.
[0042] The loss calculation module is used to calculate the loss between the predicted value and the true label;
[0043] The gradient calculation module is used to calculate the weight gradients of the network model through backpropagation.
[0044] The parameter update module is used to obtain the updated weights based on the original weights and the corresponding weight gradients.
[0045] In the above technical solution, the network model of the edge device includes multiple convolutional layers with fixed weights. Each convolutional layer has a variable parameter layer at its output, with variable weights. The output of the last convolutional layer is connected to a fully connected layer, which also has variable weights. During network model training via inference, loss calculation, gradient calculation, and parameter update modules, the weights of the convolutional layers are fixed and not updated. The main forward and backward propagation parts are quantized data types. Without changing the speed of the original convolutional layers, a learnable weight parameter is added after each convolutional layer. This weight parameter is iteratively updated to transform the feature distribution. The training device in this embodiment can fine-tune multiple weights in the network during training, thereby improving the network model's recognition performance.
[0046] In some optional implementations, the inference module is also used to obtain a predicted value y for the convolutional layer f(·) of the network model through forward inference: y = f(x) + r; where r is the weight value of the variable parameter layer corresponding to the convolutional layer, and x is the input of the current iteration.
[0047] In some optional implementations, the loss calculation module is also used to calculate the loss L for the convolutional layer f(·) of the network model: in, This is the actual label value.
[0048] In some optional implementations, the gradient calculation module is also used to calculate the weight gradients of the convolutional layers f(·) of the network model via backpropagation:
[0049]
[0050] In some optional implementations, the parameter update module is also used to update the weight values of the convolutional layer f(·) of the network model, which corresponds to the variable parameter layer.
[0051] In some optional implementations, the inference module is also used to obtain a predicted value y through forward inference for the fully connected layer with variable weights of the network model: y = W * x; where W is the weight of the fully connected layer and x is the input of the current iteration.
[0052] In some optional implementations, the loss calculation module is also used to calculate the loss L for fully connected layers with variable weights in the network model: in, This is the actual label value.
[0053] In some optional implementations, the gradient calculation module is also used to calculate the weight gradients via backpropagation for fully connected layers with variable weights in the network model:
[0054] In some optional implementations, the parameter update module is also used for the updated weight values of fully connected layers and convolutional layers with variable weights in the network model, corresponding to the variable parameter layers:
[0055] This application provides a network model for an edge device. The network model includes multiple convolutional layers with fixed weights and fully connected layers with variable weights, with a variable parameter layer set between every two adjacent convolutional layers.
[0056] The network model is used to input data collected by edge devices and to perform detection based on the data collected by edge devices to obtain detection results.
[0057] This application provides a training device for a network model of an edge device. The network model includes multiple convolutional layers with fixed weights and fully connected layers with variable weights. A variable parameter layer is set between every two adjacent convolutional layers. The device includes:
[0058] The inference module is used to input training data into the network model and obtain predicted values through forward inference.
[0059] The update module is used to calculate the loss between the predicted value and the true label, and then calculate the weight gradient of the network model through backpropagation; based on the original weights and the corresponding weight gradients, the updated weights are obtained.
[0060] An electronic device provided in this application includes a processor and a memory, wherein the memory stores machine-readable instructions executable by the processor, and the machine-readable instructions, when executed by the processor, perform any of the methods described above.
[0061] This application provides a computer-readable storage medium storing a computer program, which is executed by a processor as described above. Attached Figure Description
[0062] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0063] Figure 1 This application provides a schematic diagram of a network model structure for an edge device.
[0064] Figure 2 A method for training a network model for an edge device is provided in an embodiment of this application;
[0065] Figure 3 A functional block diagram of a training device for a network model of an edge device provided in an embodiment of this application;
[0066] Figure 4 This is a schematic diagram of a possible structure of an electronic device provided in an embodiment of this application.
[0067] Icons: 1-Inference module, 2-Loss calculation module, 3-Gradient calculation module, 4-Parameter update module, 51-Processor, 52-Memory, 53-Communication interface, 54-Communication bus. Detailed Implementation
[0068] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.
[0069] Please refer to Figure 1 , Figure 1 This is a schematic diagram of a network model structure for an edge device provided in an embodiment of this application. The network model includes multiple convolutional layers with fixed weights and fully connected layers with variable weights, with a variable parameter layer set between every two adjacent convolutional layers.
[0070] In this embodiment, the network model of the edge device includes multiple convolutional layers with fixed weights. Each convolutional layer has a variable parameter layer at its output, and the weights of the variable parameter layer are variable. The output of the last convolutional layer is connected to a fully connected layer, which is also configured to have variable weights. During training, the network model of this embodiment can fine-tune multiple weights within the network, thereby improving the network model's recognition performance.
[0071] Please refer to Figure 2 , Figure 2This application provides a method for training a network model for an edge device. The network model includes multiple convolutional layers with fixed weights and fully connected layers with variable weights. A variable parameter layer is set between every two adjacent convolutional layers. The training method of this application specifically includes:
[0072] Step 100: Input the training data into the network model, obtain the predicted value through forward inference, calculate the loss between the predicted value and the true label, and then calculate the weight gradient of the network model through backpropagation.
[0073] Step 200: Obtain the updated weights based on the original weights and the corresponding weight gradients.
[0074] In this embodiment, the network model of the edge device includes multiple convolutional layers with fixed weights. Each convolutional layer has a variable parameter layer at its output, with variable weights. The output of the last convolutional layer is connected to a fully connected layer, which also has variable weights. During network model training on the edge device, the weights of the convolutional layers are fixed and not updated. The main forward and backward propagation parts are quantized data types. Without changing the speed of the original convolutional layers, a learnable weight parameter is added after each convolutional layer. This weight parameter is iteratively updated to achieve the purpose of transforming the feature distribution. The model fine-tuning scheme of this embodiment can fine-tune multiple weights in the network, thereby improving the network model's recognition performance.
[0075] In some alternative implementations, training data is input into the network model, and predicted values are obtained through forward inference, including:
[0076] For the convolutional layer f(·) of the network model, the predicted value y is obtained through forward inference:
[0077] y = f(x) + r;
[0078] Where r is the weight value of the variable parameter layer corresponding to the convolutional layer, and x is the input of the current iteration.
[0079] In some optional implementations, the loss between the predicted value and the true label is calculated, including:
[0080] For the convolutional layer f(·) of the network model, calculate the loss L:
[0081]
[0082] in, This is the actual label value.
[0083] In some optional implementations, the weight gradients of the network model are calculated via backpropagation, including:
[0084] For the convolutional layer f(·) of the network model, the weight gradient is calculated through backpropagation:
[0085]
[0086] In some optional implementations, the updated weights are obtained based on the original weights and the corresponding weight gradients, including:
[0087] For the convolutional layer f(·) of the network model, the updated weight values of the corresponding variable parameter layer are:
[0088]
[0089] In some alternative implementations, training data is input into the network model, and predicted values are obtained through forward inference, including:
[0090] For a fully connected layer with variable weights in the network model, the predicted value y is obtained through forward inference:
[0091] y = W * x;
[0092] Where W is the weight of the fully connected layer, and x is the input of this iteration.
[0093] In some optional implementations, the loss between the predicted value and the true label is calculated, including:
[0094] For a fully connected layer with variable weights in the network model, calculate the loss L:
[0095]
[0096] in, This is the actual label value.
[0097] In some optional implementations, the weight gradients of the network model are calculated via backpropagation, including:
[0098] For a fully connected layer with variable weights in the network model, the weight gradient is calculated through backpropagation:
[0099]
[0100] In some optional implementations, the updated weights are obtained based on the original weights and the corresponding weight gradients, including:
[0101] For a fully connected layer with variable weights in a network model, the updated weight values of the convolutional layer correspond to those of a variable-parameter layer:
[0102]
[0103] Specifically, in one embodiment, the variable parameter layer uses RuntimeVar, a design approach that configures parameters at runtime. The goal is to allow the parameters of certain operators to be dynamically configured or updated while the model is running on hardware. It not only achieves the effect of dynamic changes but also runs quickly on the NPU (Network Processing Unit).
[0104] In this embodiment, the training process of the network model is as follows: training data is input into the model, the model obtains predicted values through forward inference, calculates the loss between the predicted values and the true labels, and then calculates the gradient of each weight of the network through backpropagation. The original weights are subtracted from the corresponding gradients to obtain the updated weights.
[0105] In this embodiment, the training process of the network model is implemented on an edge chip, which is typically only used for model inference. To accelerate inference, the model weights are fixed during inference, preventing them from being updated. This embodiment adds a RuntimeVar after each layer without changing the speed of the original convolutional layers, adding it to the output value of that layer. These RuntimeVars can also obtain corresponding gradients through backpropagation and are updated in real time after each iteration. The weight update process of RuntimeVars in this embodiment is as follows:
[0106] Forward reasoning: y = f(x) + r
[0107] Calculate the loss:
[0108] Backpropagation:
[0109]
[0110] Weight update:
[0111] Where f(·) is a convolutional layer, x is the input of this iteration, r is the RuntimeVar added to this layer, and r ′ This is the new RuntimeVar after the iteration ends. In this design, RuntimeVar can be updated in place without occupying new memory space.
[0112] Furthermore, fully connected layers generally require fine-tuning. In this embodiment, the weights of the fully connected layer are also set to RuntimeVar, and iteratively updated using the same update method. The fully connected layer is actually a matrix multiplication, represented as follows: y = W * x
[0113] Backpropagation:
[0114]
[0115] Weight update:
[0116]
[0117] Where x is the input of this iteration, W is the weight of the fully connected layer, and W ′ These are the new weights after the iteration ends.
[0118] In summary, this embodiment fixes the weights of the convolutional layers in the network model without updating them. The main forward and backward propagation parts are quantized data types. A learnable weight parameter is added after each convolutional layer, and this weight parameter is iteratively updated to transform the feature distribution, thereby enabling fine-tuning of more parameters of the network model and improving model performance. Furthermore, through hardware and software co-design, the learnable parameter is set as RuntimeVar, and the learning process is implemented using the NPU, accelerating the fine-tuning speed of the network model.
[0119] Please refer to Figure 3 , Figure 3 The functional block diagram of a training device for a network model of an edge device provided in this application embodiment specifically includes an inference module 1, a loss calculation module 2, a gradient calculation module 3, and a parameter update module 4.
[0120] The network consists of four modules: Inference Module 1, which inputs training data into the network model and obtains predicted values through forward inference; Loss Calculation Module 2, which calculates the loss between the predicted values and the true labels; Gradient Calculation Module 3, which calculates the weight gradients of the network model through backpropagation; and Parameter Update Module 4, which obtains the updated weights based on the original weights and their corresponding gradients.
[0121] In this embodiment, the network model of the edge device includes multiple convolutional layers with fixed weights. Each convolutional layer has a variable parameter layer at its output, with variable weights. The output of the last convolutional layer is connected to a fully connected layer, which also has variable weights. During training of the network model via inference module 1, loss calculation module 2, gradient calculation module 3, and parameter update module 4, the weights of the convolutional layers are fixed and not updated. The main forward and backward propagation parts are quantized data types. Without changing the speed of the original convolutional layers, a learnable weight parameter is added after each convolutional layer, and this weight parameter is iteratively updated to achieve the purpose of transforming the feature distribution. The training device in this embodiment can fine-tune multiple weights in the network during training, thereby improving the network model's recognition performance.
[0122] In some optional implementations, the inference module 1 is also used to obtain the predicted value y: y = f(x) + r for the convolutional layer f(·) of the network model through forward inference; where r is the weight value of the variable parameter layer corresponding to the convolutional layer, and x is the input of the current iteration.
[0123] In some optional implementations, the loss calculation module 2 is also used to calculate the loss L for the convolutional layer f(·) of the network model: in, This is the actual label value.
[0124] In some optional implementations, gradient calculation module 3 is also used to calculate the weight gradients of the convolutional layer f(·) of the network model via backpropagation:
[0125]
[0126] In some optional implementations, the parameter update module 4 is also used to update the weight values of the convolutional layer f(·) of the network model, which corresponds to the variable parameter layer.
[0127] In some optional implementations, the inference module 1 is also used to obtain a predicted value y: y = W*x for the fully connected layer with variable weights in the network model through forward inference; where W is the weight of the fully connected layer and x is the input of the current iteration.
[0128] In some optional implementations, the loss calculation module 2 is also used to calculate the loss L for fully connected layers with variable weights in the network model: in, This is the actual label value.
[0129] In some optional implementations, gradient calculation module 3 is also used to calculate the weight gradients via backpropagation for fully connected layers with variable weights in the network model:
[0130] In some optional implementations, the parameter update module 4 is also used for the updated weight values of fully connected layers with variable weights in the network model, and convolutional layers corresponding to variable parameter layers:
[0131] This application provides a network model for an edge device. The network model includes multiple convolutional layers with fixed weights and fully connected layers with variable weights, with a variable parameter layer set between every two adjacent convolutional layers.
[0132] The network model is used to input data collected by edge devices and to perform detection based on the data collected by edge devices to obtain detection results.
[0133] This application provides a training device for a network model of an edge device. The network model includes multiple convolutional layers with fixed weights and fully connected layers with variable weights. A variable parameter layer is set between every two adjacent convolutional layers. The device includes:
[0134] The inference module is used to input training data into the network model and obtain predicted values through forward inference.
[0135] The update module is used to calculate the loss between the predicted value and the true label, and then calculate the weight gradient of the network model through backpropagation; based on the original weights and the corresponding weight gradients, the updated weights are obtained.
[0136] Figure 4 This illustration shows a possible structure of an electronic device provided in an embodiment of this application. (Refer to...) Figure 4 The electronic device includes a processor 51, a memory 52, and a communication interface 53, which are interconnected and communicate with each other via a communication bus 54 and / or other forms of connection mechanism (not shown).
[0137] The memory 52 includes one or more (only one is shown in the figure), which may be, but is not limited to, Random Access Memory (RAM), Read Only Memory (ROM), Programmable Read-Only Memory (PROM), Erasable Programmable Read-Only Memory (EPROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), etc. The processor 51 and other possible components may access the memory 52 to read and / or write data therein.
[0138] Processor 51 includes one or more (only one is shown in the figure), which can be an integrated circuit chip with signal processing capabilities. The processor 51 can be a general-purpose processor, including a Central Processing Unit (CPU), a Microcontroller Unit (MCU), a Network Processor (NP), or other conventional processors; it can also be a special-purpose processor, including a Neural-network Processing Unit (NPU), a Graphics Processing Unit (GPU), a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. Furthermore, when there are multiple processors 51, some can be general-purpose processors and others can be special-purpose processors.
[0139] Communication interface 53 includes one or more (only one is shown in the figure) that can be used to communicate directly or indirectly with other devices for data exchange. Communication interface 53 may include interfaces for wired and / or wireless communication.
[0140] One or more computer program instructions may be stored in memory 52, and processor 51 may read and execute these computer program instructions to implement the methods provided in the embodiments of this application.
[0141] Understandable. Figure 4 The structure shown is for illustrative purposes only; the electronic device may also include structures that are more complex than those shown. Figure 4 The more or fewer components shown, or having the same Figure 4 The different structures shown. Figure 4 The components shown can be implemented using hardware, software, or a combination thereof. Electronic devices may be physical devices, such as PCs, laptops, tablets, mobile phones, servers, embedded devices, etc., or they may be virtual devices, such as virtual machines, virtualized containers, etc. Furthermore, electronic devices are not limited to a single device; they can also be a combination of multiple devices or a cluster of a large number of devices.
[0142] This application also provides a computer-readable storage medium storing computer program instructions. These computer program instructions are read and executed by a computer's processor to perform the method provided in this application. For example, the computer-readable storage medium can be implemented as follows: Figure 4 Memory 52 in electronic devices.
[0143] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the displayed or discussed mutual couplings, direct couplings, or communication connections may be through some communication interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.
[0144] Furthermore, the units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0145] Furthermore, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0146] In this document, relational terms such as first and second are used only to distinguish one entity or operation from another entity or operation, without necessarily requiring or implying any such actual relationship or order between these entities or operations.
[0147] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A method for training a network model for an edge device, characterized in that, The edge device includes an edge chip used for model inference; the network model is deployed on the edge chip, and the network model includes multiple convolutional layers with fixed weights and fully connected layers with variable weights. A variable parameter layer is set between every two adjacent convolutional layers. The variable parameter layer uses RuntimeVar, which is a variable whose parameters can be dynamically configured or updated at runtime, and RuntimeVar runs on the NPU. The method includes: The training data is input into the network model, the predicted value is obtained through forward inference, the loss between the predicted value and the true label is calculated, and the weight gradient of the network model is calculated through backpropagation; wherein, the calculated weight gradient includes at least the weight gradient of the variable parameter layer. Based on the original weights and the corresponding weight gradients, the updated weights are obtained, and the updated weights include at least the updated weights of the variable parameter layer.
2. The method as described in claim 1, characterized in that, The step of inputting training data into the network model and obtaining predicted values through forward inference includes: For the convolutional layer f(·) of the network model, the predicted value y is obtained through forward inference: y = f(x) + r; Where r is the weight value of the variable parameter layer corresponding to the convolutional layer, and x is the input of the current iteration.
3. The method as described in claim 2, characterized in that, The calculation of the loss between the predicted value and the true label includes: For the convolutional layer f(·) of the network model, calculate the loss L: ; in, This is the actual label value.
4. The method as described in claim 3, characterized in that, The calculation of the weight gradients of the network model through backpropagation includes: For the convolutional layer f(·) of the network model, the weight gradient is calculated through backpropagation: 。 5. The method as described in claim 4, characterized in that, The step of obtaining the updated weights based on the original weights and the corresponding weight gradients includes: For the convolutional layer f(·) of the network model, the updated weight values of the corresponding variable parameter layer are: 。 6. The method as described in claim 1, characterized in that, The step of inputting training data into the network model and obtaining predicted values through forward inference includes: For the fully connected layer with variable weights in the network model, the predicted value y is obtained through forward inference: ; Where W is the weight of the fully connected layer, and x is the input of this iteration.
7. The method as described in claim 6, characterized in that, The calculation of the loss between the predicted value and the true label includes: For the fully connected layer with variable weights in the network model, calculate the loss L: ; in, This is the actual label value.
8. The method as described in claim 7, characterized in that, The calculation of the weight gradients of the network model through backpropagation includes: For the fully connected layer with variable weights in the network model, the weight gradient is calculated through backpropagation: 。 9. The method as described in claim 8, characterized in that, The step of obtaining the updated weights based on the original weights and the corresponding weight gradients includes: For the fully connected layers with variable weights in the network model, the updated weight values of the convolutional layers correspond to the variable parameter layers: 。 10. A training apparatus for a network model of an edge device, characterized in that, The edge device includes an edge chip used for model inference; the network model is deployed on the edge chip, and the network model includes multiple convolutional layers with fixed weights and fully connected layers with variable weights. A variable parameter layer is set between every two adjacent convolutional layers. The variable parameter layer uses RuntimeVar, which is a variable whose parameters can be dynamically configured or updated at runtime, and RuntimeVar runs on an NPU. The device includes: The inference module is used to input training data into the network model and obtain predicted values through forward inference. The update module is used to calculate the loss between the predicted value and the true label, and then calculate the weight gradient of the network model through backpropagation; based on the original weights and the corresponding weight gradients, the updated weights are obtained; wherein the calculated weight gradients include at least the weight gradients of the variable parameter layer, and the updated weights include at least the updated weights of the variable parameter layer.
11. An electronic device, characterized in that, include: A processor and a memory, the memory storing machine-readable instructions executable by the processor, which, when executed by the processor, perform the method as described in any one of claims 1-9.
12. A computer-readable storage medium, characterized in that, The storage medium stores a computer program that, when executed by a processor, performs the method as described in any one of claims 1-9.