A Lightweight Model Design Method for Microcontrollers

CN118747521BActive Publication Date: 2026-08-14NINGBO ARTIFICIAL INTELLIGENCE RES INST OF SHANGHAI JIAOTONG UNIV
View PDF 4 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-06
Publication Date
2026-08-14

AI Technical Summary

Technical Problem

但是该方法并未对神经结构搜索技术进额外的限制,并不能保证轻量化模型的参数量满足部署设备的要求

Benefits of technology

[0055]本发明使用神经结构搜索技术进行轻量化模型设计,实现了设计过程自动化,降低了搜索过程的人工成本,大大节省了模型设计的时间成本;本发明设计的轻量化模型,满足在模型参数量、模型计算量、模型内用占用方面的要求,可以部署到微控制器。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118747521B_ABST
    Figure CN118747521B_ABST
Patent Text Reader

Abstract

This invention discloses a lightweight model design method for microcontrollers, relating to the fields of artificial intelligence and deep learning. The method includes: S100, acquiring a dataset; S200, partitioning the dataset; S300, setting search parameters; S400, constructing a supermodel; S500, setting training parameters; S600, training the supermodel; S700, optimizing sub-models; and S800, deploying the model. This invention automates the design process, reduces the manual cost of the search process, and significantly saves time in model design.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of artificial intelligence and deep learning technology, and in particular to a lightweight model design method for microcontrollers. Background Technology

[0002] Lightweight models refer to deep learning models with low computational cost, low parameter count, and low memory usage. A microcontroller, also known as a single-chip microcomputer, is a microcomputer that integrates the main components of a microcomputer onto a single chip. Deploying lightweight models on microcontrollers to handle complex edge tasks has broad application prospects in fields such as smart homes, smart healthcare, smart agriculture, and autonomous driving.

[0003] CN202311765393.0 discloses a lightweight model optimization method and system for embedded platforms. It introduces depthwise convolution, pointwise convolution, and residual modules, stacking them to obtain a lightweight model, achieving low processing time and ensuring the constructed model can be deployed in embedded devices for image classification tasks. However, this method requires stacking different modules to obtain the lightweight model, and the stacking method requires continuous experimentation, demanding a high level of experience and lacking universality.

[0004] CN117114053A discloses a method and apparatus for compressing convolutional neural network models based on structure search and knowledge distillation. The method uses a trained convolutional neural network model as the teacher model, employs neural structure search technology to obtain a lightweight model structure as the student model, and then performs knowledge distillation on the teacher and student models to achieve model compression. However, this method does not impose additional restrictions on neural structure search technology and cannot guarantee that the number of parameters in the lightweight model meets the requirements of the deployment device.

[0005] Therefore, those skilled in the art are dedicated to developing a lightweight model design method for microcontrollers. Summary of the Invention

[0006] In view of the above-mentioned deficiencies of the prior art, the technical problem to be solved by the present invention is: how to design a lightweight deep learning model that can run on a resource-constrained microcontroller.

[0007] The inventors analyzed that microcontrollers (single-chip microcomputers) are characterized by small memory, limited storage space, and limited computing power, while lightweight models are characterized by low computational load, low parameter count, and low memory consumption. Starting with model design and deployment, the inventors used candidate modules to build a supermodel during model design. In neural architecture search, a loss function related to microcontroller resources (including storage space, memory, and computing power) was set to optimize the parameters of the candidate modules in the supermodel. A series of sub-models were sampled from the supermodel, and an evolutionary algorithm was used to optimize the sub-models, ultimately obtaining the optimal sub-model, which is the lightweight model. During model deployment, the lightweight model was deployed to the microcontroller. The inventors achieved automatic model structure determination, saving model design time. The lightweight model can not only be deployed to the microcontroller but also achieves better model accuracy on the microcontroller.

[0008] In one embodiment of the present invention, a lightweight model design method for microcontrollers is provided, comprising:

[0009] S100. Obtain the dataset; obtain the target classification task dataset (Dataset).

[0010] S200. Divide the dataset into a training set (Dataset-train) and a validation set (Dataset-val) from the target classification task dataset (Dataset).

[0011] S300, Set search parameters, set the search parameters for neural structure search;

[0012] S400: Construct a supermodel based on relevant parameters and candidate modules;

[0013] S500, set training parameters, including setting training hyperparameters and the loss function for neural architecture search;

[0014] S600, Train the supermodel: Train the supermodel on the training set Dataset-train and the validation set Dataset-val using training parameters and a loss function;

[0015] S700: Optimize the sub-model by sampling candidate modules from the supermodel to form a sub-model, and use an evolutionary algorithm to optimize the sub-model. The optimized sub-model is the lightweight model.

[0016] S800, deployment model, deploys the lightweight model to the microcontroller.

[0017] Optionally, in the lightweight model design method for microcontrollers in the above embodiments, the target classification task is an image classification task, including face recognition, animal recognition, and fruit and vegetable recognition.

[0018] Optionally, in the lightweight model design method for microcontrollers in any of the above embodiments, the candidate modules include a series of lightweight convolutional modules.

[0019] Furthermore, in the lightweight model design method for microcontrollers in the above embodiments, the lightweight convolution module includes a depthwise separable convolution module and a grouped convolution module.

[0020] Optionally, in the lightweight model design method for microcontrollers in any of the above embodiments, step S300 includes:

[0021] S310. Set search parameters, including search parameters for the hypermodel;

[0022] S320, Set limit parameters: Set limit parameters according to the microcontroller's resource limitations;

[0023] S330. Set candidate modules: Set candidate modules in the supermodel.

[0024] Optionally, in the lightweight model design method for microcontrollers in any of the above embodiments, the search parameters include the number of layers n of the supermodel and the number of candidate modules m in each layer. Each layer of the supermodel contains m candidate modules, and each candidate module corresponds to a module weight b. ij and a structural weight v ij , where i∈[1,n], j∈[1,m], i represents the i-th layer, and j represents the j-th candidate module.

[0025] Furthermore, in the lightweight model design method for microcontrollers described in the above embodiments, the limiting parameters include: the maximum number of model parameters x. t Maximum computational cost of the model y t Maximum memory usage of the model z t .

[0026] Optionally, in the lightweight model design method for microcontrollers in any of the above embodiments, step S500 includes:

[0027] S510. Set the hyperparameters for training. The hyperparameters include the number of training epochs, the learning rate, and the optimizer algorithm. Set the number of training epochs to 500, the learning rate to 1e-5, and the optimizer to the stochastic gradient descent (SGD) algorithm.

[0028] S520. Define the loss function for neural structure search. total :

[0029] l total =l base +α*l p (x)+β*l c (y)+γ*lpm (z)

[0030] Among them, l p (x) is the loss of the hypermodel parameters:

[0031]

[0032] l c (y) represents the computational loss of the hypermodel:

[0033]

[0034] l pm (z) represents the hypermodel memory usage loss:

[0035]

[0036] Among them, l base The classification accuracy loss value represents the classification accuracy of the supermodel. Classification accuracy refers to the accuracy in classifying the target. The larger the classification accuracy loss value, the worse the supermodel. α represents the weight of the supermodel parameter loss value; β represents the weight of the supermodel computational cost loss value; γ represents the weight of the supermodel memory usage loss value; i represents the i-th layer of the supermodel, and j represents the j-th candidate module of the i-th layer of the supermodel; v ij x represents the structural weight of the j-th candidate module in the i-th layer of the hypermodel; ij The parameter count of the j-th candidate module in the i-th layer of the hypermodel is represented by x, which is the size of the candidate module. t This indicates the parameter limit of the hypermodel; y ij y represents the computational cost of the j-th candidate module in the i-th layer of the hypermodel, i.e., the computational time complexity of the candidate module, which is proportional to the inference time of the candidate module. t This indicates the computational constraints of the hypermodel; z ij z represents the memory usage of the j-th candidate module in the i-th layer of the hypermodel. t This represents the maximum memory limit of the hypermodel.

[0037] Furthermore, in the lightweight model design method for microcontrollers in the above embodiments, α, β, and γ can be adjusted according to the specific task and the deployed microcontroller.

[0038] Preferably, in the lightweight model design method for microcontrollers in the above embodiments, α = 0.5, β = 0.5, and γ = 0.5 are set.

[0039] Optionally, in the lightweight model design method for microcontrollers in any of the above embodiments, step S600 includes:

[0040] S610. Update module weights and freeze the structural weights v of all candidate modules in the supermodel. ij And update the module weights b in the supermodel via backpropagation on the training set Dataset-train. ij , where i∈[1,n],j∈[1,m], i represents the i-th layer, and j represents the j-th candidate module;

[0041] S620. Update the structural weights and freeze the module weights b of all candidate modules in the supermodel. ij And update the structural weights v in the supermodel via backpropagation on the validation set Dataset-val. ij , where i∈[1,n],j∈[1,m], i represents the i-th layer, and j represents the j-th candidate module;

[0042] S630. End training. During training, record the loss function value. When the loss function value of the supermodel on the validation set does not decrease, the supermodel training ends.

[0043] Optionally, in the lightweight model design method for microcontrollers in any of the above embodiments, step S700 includes:

[0044] S710. Generate sub-models: Based on the structural weights of candidate modules in the supermodel, sample 1+n sub-models s0, s1, s2, ..., sn. n ;

[0045] S720, Sub-model optimization: For the above 1+n sub-models s0, s1, s2, ..., s n Optimize.

[0046] Furthermore, in the lightweight model design method for microcontrollers in the above embodiments, step S710 includes:

[0047] S711, sampled sub-model, sampled the candidate modules with the largest structural weights in each layer of the supermodel to form a sub-model s0;

[0048] S712, Copy the sub-model. Copy the sub-model s0 n times to obtain n sub-models s1, s2, s3, ..., s n ;

[0049] S713, Enhanced Submodel s i For i∈[1,n], add the candidate module with the second largest structural weight in the i-th, i∈[1,n]th layer of the supermodel to the submodel s. i ,i∈[1,n].

[0050] Furthermore, in the lightweight model design method for microcontrollers in the above embodiments, step S720 includes:

[0051] S721, train the above 1+n sub-models using the training set Dataset-train until the 1+n sub-models converge;

[0052] S722, optimize the sub-models, sorting them from highest to lowest classification accuracy of the above 1+n sub-models on the validation set Dataset-val, and find the top two sub-models s. max1 and s max2 Merging sub-models s max1 and s max2 From the candidate modules, a new sub-model s is obtained. new Train sub-models s on the training set Dataset-train new Until convergence, use the new sub-model s new Replace the sub-model with the lowest classification accuracy (the largest classification accuracy loss value, classification accuracy loss = 1 - classification accuracy) among the above 1+n sub-models to obtain a new set of 1+n sub-models;

[0053] S723, iteratively optimize the sub-model, repeat S722, until the classification accuracy no longer improves;

[0054] S724, determine the optimal sub-model. The sub-model with the highest accuracy in the last round is the optimal sub-model, i.e., the lightweight model.

[0055] This invention uses neural architecture search technology for lightweight model design, which automates the design process, reduces the manual cost of the search process, and greatly saves the time cost of model design. The lightweight model designed by this invention meets the requirements in terms of the number of model parameters, model computation, and model internal space, and can be deployed on a microcontroller.

[0056] The following will further explain the concept, specific structure, and technical effects of the present invention in conjunction with the accompanying drawings, so as to fully understand the purpose, features, and effects of the present invention. Attached Figure Description

[0057] Figure 1 This is a flowchart illustrating a lightweight model design method for microcontrollers according to an exemplary embodiment. Detailed Implementation

[0058] The following description, with reference to the accompanying drawings, illustrates several preferred embodiments of the present invention to make its technical content clearer and easier to understand. The present invention can be embodied in many different forms, and the scope of protection of the present invention is not limited to the embodiments mentioned herein.

[0059] In the accompanying drawings, components with the same structure are indicated by the same numerical designation, and components with similar structures or functions are indicated by similar numerical designations. The dimensions and thicknesses of each component shown in the drawings are arbitrary, and the present invention does not limit the dimensions and thicknesses of each component. To make the illustrations clearer, the thickness of components is schematically exaggerated in some places in the drawings.

[0060] The inventors designed a lightweight model design method for microcontrollers, such as... Figure 1 As shown, it includes the following steps:

[0061] S100. Obtain the dataset; obtain the target task dataset (Dataset).

[0062] S200. Divide the dataset into a training set (Dataset-train) and a validation set (Dataset-val) from the target task dataset (Dataset).

[0063] S300. Set search parameters. Specifically, set the search parameters for neural structure searching, including:

[0064] S310. Set the search parameters. The search parameters include the number of layers n in the supermodel and the number of candidate modules m in each layer. Each layer of the supermodel contains m candidate modules, and each candidate module corresponds to a module weight b. ij and a structural weight v ij ,That

[0065] In the context of i∈[1,n], j∈[1,m], i represents the i-th layer, and j represents the j-th candidate module;

[0066] S320. Set limiting parameters. Set limiting parameters according to the microcontroller's resource limitations. Limiting parameters include: maximum number of model parameters x. t Maximum computational cost of the model y t Maximum memory usage of the model z t ;

[0067] S330. Set candidate modules: Set candidate modules in the supermodel.

[0068] S400, Construct a super model. Construct a super model based on relevant parameters and candidate modules. The candidate modules include a series of lightweight convolutional modules, including depthwise separable convolutional modules and grouped convolutional modules.

[0069] S500, Set training parameters, including setting training hyperparameters and the loss function for neural structure search; Step S500 includes:

[0070] S510. Set the hyperparameters for training. The hyperparameters include the number of training epochs, the learning rate, and the optimizer algorithm. Set the number of training epochs to 500, the learning rate to 1e-5, and the optimizer to the stochastic gradient descent (SGD) algorithm.

[0071] S520. Define the loss function for neural structure search. total :

[0072] l total =l base +α*l p (x)+β*l c (y)+γ*l pm (z)

[0073] Among them, l p (x) is the loss of the hypermodel parameters:

[0074]

[0075] l c (y) represents the computational loss of the hypermodel:

[0076]

[0077] l pm (z) represents the hypermodel memory usage loss:

[0078]

[0079] Among them, l base α represents the classification accuracy loss value of the supermodel; β represents the weight of the model parameter loss value; γ represents the weight of the model computational cost loss value; γ represents the weight of the model memory usage loss value; α, β, and γ can be adjusted according to the specific task and the microcontroller deployed, preferably set to α = 0.5, β = 0.5, and γ = 0.5; i represents the i-th layer of the supermodel, and j represents the j-th candidate module of the i-th layer of the supermodel; v ij x represents the structural weight of the j-th candidate module in the i-th layer of the hypermodel; ij x represents the number of module parameters of the j-th candidate module in the i-th layer of the hypermodel, i.e., the size of the candidate module. t This indicates the parameter limit of the hypermodel; y ij y represents the computational complexity of the j-th module in the i-th layer of the hypermodel, i.e., the computational time complexity of the candidate module, which is proportional to the inference time of that candidate module. t This indicates the computational constraints of the hypermodel; z ij z represents the memory usage of the j-th module in the i-th layer of the hypermodel. t This represents the maximum memory limit of the hypermodel.

[0080] S600, Training the supermodel: The supermodel is trained on the training set (Dataset-train) and the validation set (Dataset-val) using training parameters and a loss function; specifically including:

[0081] S610. Update module weights and freeze the structural weights of all candidate modules in the supermodel.

[0082] v ij And update the module weights b in the supermodel via backpropagation on the training set Dataset-train. ij , where i∈[1,n],j∈[1,m], i represents the i-th layer, and j represents the j-th candidate module;

[0083] S620. Update the structural weights and freeze the module weights of all candidate modules in the supermodel.

[0084] b ij The structural weights in the supermodel are updated via backpropagation on the validation set Dataset-val.

[0085] v ij , where i∈[1,n],j∈[1,m], i represents the i-th layer, and j represents the j-th candidate module;

[0086] S630. End training. During training, record the loss function value. When the loss function value of the supermodel on the validation set does not decrease, the supermodel training ends.

[0087] S700: Optimize the sub-model. Candidate modules are sampled from the supermodel to form a sub-model. An evolutionary algorithm is used to optimize the sub-model, resulting in a lightweight model. Specifically, this includes:

[0088] S710. Generate sub-models based on the structural weights of candidate modules in the supermodel.

[0089] The model is sampled to obtain 1+n sub-models; specifically including:

[0090] S711, sampled sub-model, sampled the candidate modules with the largest structural weights in each layer of the supermodel to form a sub-model s0;

[0091] S712, Copy the sub-model. Copy the sub-model s0 n times to obtain n sub-models s1, s2, s3, ..., s n ;

[0092] S713, Enhanced Submodel s i For i∈[1,n], add the candidate module with the second largest structural weight in the i-th, i∈[1,n]th layer of the supermodel to the submodel s. i ,i∈[1,n].

[0093] S720, Sub-model optimization: Optimize the above 1+n sub-models, specifically including:

[0094] S721, train the above 1+n sub-models using the training set Dataset-train until the 1+n sub-models converge;

[0095] S722, optimize the sub-models, sorting them from highest to lowest classification accuracy of the above 1+n sub-models on the validation set Dataset-val, and find the top two sub-models s. max1 and s max2 Merging sub-models s max1 and s max2 From the candidate modules, a new sub-model s is obtained. new Train sub-models s on the training set Dataset-train new Until convergence, use the new sub-model s new Replace the sub-model with the lowest classification accuracy (the largest classification accuracy loss value, classification accuracy loss = 1 - classification accuracy) among the above 1+n sub-models to obtain a new set of 1+n sub-models;

[0096] S723, iteratively optimize the sub-model, repeat S722, until the classification accuracy no longer improves;

[0097] S724, determine the optimal sub-model. The sub-model with the highest accuracy in the last round is the optimal sub-model, i.e., the lightweight model.

[0098] S800, deployment model, deploys the lightweight model to the microcontroller.

[0099] The preferred embodiments of the present invention have been described in detail above. It should be understood that those skilled in the art can make numerous modifications and variations based on the concept of the present invention without creative effort. Therefore, all technical solutions that can be obtained by those skilled in the art based on the concept of the present invention through logical analysis, reasoning, or limited experimentation on the basis of existing technology should be within the scope of protection defined by the claims.

Claims

1. A lightweight model design method for microcontrollers, characterized in that, include: S100. Obtain the dataset; obtain the target classification task dataset (Dataset). S200. Divide the dataset into a training set (Dataset-train) and a validation set (Dataset-val) from the target classification task dataset (Dataset). S300, Set search parameters, set the search parameters for neural structure search; S400: Construct a supermodel based on relevant parameters and candidate modules; S500, set training parameters, including setting training hyperparameters and the loss function for neural architecture search; Step S500 includes: S510. Set the hyperparameters for training, including the number of training epochs, learning rate, and optimizer algorithm. Set the number of training epochs to 500 and the learning rate to [value missing]. 1e-5 The optimizer is set to the stochastic gradient descent algorithm (SGD). S520. Define the loss function for neural structure search. : in, It is the loss of hypermodel parameters: The loss is due to the computational cost of the hypermodel. It is the memory usage loss of the hypermodel: ; in, This represents the classification accuracy loss value of the hypermodel. Classification accuracy refers to the accuracy in classifying the target. The larger the classification accuracy loss value, the worse the hypermodel is. The weights represent the loss values ​​of the hypermodel parameters; The weights represent the computational cost of the hypermodel loss value; Weights representing the loss value of hypermodel memory usage ; The first part represents the hypermodel. layer, The first part represents the hypermodel. The first layer One candidate module; The first part represents the hypermodel. The first layer The structural weights of each candidate module; The first part represents the hypermodel. The first layer The number of parameters of each candidate module, i.e., the size of the candidate module. Indicates the parameter limit of the hypermodel; The first part represents the hypermodel. The first layer The computational cost of each candidate module, i.e., the computational time complexity of the candidate module, is proportional to the inference time of the candidate module. This indicates the computational limitations of the hypermodel; The first part represents the hypermodel. The first layer Memory usage of each candidate module Indicates the maximum memory limit of the hypermodel; S600. Train the supermodel: Train the supermodel on the training set Dataset-train and the validation set Dataset-val using the training parameters and the loss function. S700. Optimize the sub-model: Sample candidate modules from the supermodel to form a sub-model, and use an evolutionary algorithm to optimize the sub-model. The optimized sub-model is the lightweight model. S800, Deployment Model: Deploy the lightweight model to the microcontroller.

2. The lightweight model design method for microcontrollers as described in claim 1, characterized in that, The candidate modules include a series of lightweight convolutional modules.

3. The lightweight model design method for microcontrollers as described in claim 2, characterized in that, The lightweight convolution module includes a depthwise separable convolution module and a grouped convolution module.

4. The lightweight model design method for microcontrollers as described in claim 1, characterized in that, The S300 includes: S310. Set search parameters, including the search parameters of the hypermodel; S320. Set the limiting parameters according to the resource limitations of the microcontroller; S330. Set candidate modules, set candidate modules in the supermodel.

5. The lightweight model design method for microcontrollers as described in claim 4, characterized in that, The search parameters include the number of layers in the hypermodel. and the number of candidate modules in each layer Each layer of the hypermodel contains m There are 1 candidate module, and each candidate module corresponds to a module weight. and a structural weight .

6. The lightweight model design method for microcontrollers as described in claim 1, characterized in that, Step S600 includes: S610. Update module weights and freeze the structural weights of all candidate modules in the supermodel. The module weights in the supermodel are updated via backpropagation on the training set Dataset-train. ; S620. Update the structural weights and freeze the module weights of all candidate modules in the supermodel. And update the structural weights in the supermodel via backpropagation on the validation set Dataset-val. ; S630. End training. During training, record the loss function value. When the loss function value of the supermodel on the validation set Dataset-val does not decrease, the training of the supermodel ends.

7. The lightweight model design method for microcontrollers as described in claim 1, characterized in that, Step S700 includes: S710. Generate a sub-model by sampling from the supermodel based on the structural weights of the candidate modules in the supermodel. Sub-model ; S720, Sub-model Optimization, for the aforementioned Sub-model Optimize.

8. The lightweight model design method for microcontrollers as described in claim 1, characterized in that, Step S710 includes: S711, Sampling Sub-model: Sample the candidate modules with the largest structural weights in each layer of the hypermodel to form one sub-model. ; S712, Copy the sub-model, and copy the sub-model copy A portion, received n Sub-model ; S713, Enhanced Submodel The first of the hypermodel The candidate module with the second largest structural weight in the layer is added to the sub-model. middle.

9. The lightweight model design method for microcontrollers as described in claim 1, characterized in that, Step S720 includes: S721, Training Each sub-model, using the training set Dataset-train, is used to train the... Each sub-model is trained until the... The sub-model converged; S722, the optimized sub-model, sorted from high to low. Based on the classification accuracy of each sub-model on the validation set Dataset-val, find the top two sub-models. and Merging sub-models and From the candidate modules, a new sub-model is obtained. Train the sub-model on the training set Dataset-train Until convergence, use the new sub-model. Replace the The sub-model with the lowest classification accuracy among the sub-models is used to obtain a new set of sub-models. Sub-model; S723, Iteratively optimize the sub-model, repeat S722, until the classification accuracy no longer improves; S724, determine the optimal sub-model. The sub-model with the highest accuracy in the last round is the optimal sub-model, i.e., the lightweight model.

Citation Information

Patent Citations

  • Convolutional neural network model compression method and device based on structure search and knowledge distillation

    CN117114053A

  • Lightweight model optimization method and system applied to embedded platform

    CN117709412A

  • Classification task label noise-oriented robustness loss function search method and system

    CN115618935A

  • Structured pruning method for deep pedestrian search model

    CN117217282A