Image classification network generation method and device, electronic equipment and storage medium
Through knowledge distillation technology and dynamic teacher network queue, the problem of insufficient generalization ability of the neural network model is solved, multi-dimensional learning and performance improvement are achieved, and an efficient image classification network is generated.
Patent Information
- Application Number
- CN202410192487.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-20
- Publication Date
- 2024-08-30
AI Technical Summary
The neural network model in the existing technology has poor generalization ability and is difficult to learn from multiple dimensions, resulting in insufficient model performance.
Through knowledge distillation technology, based on the initial teacher network and the dynamically updated teacher network queue, a search space is generated and sub-networks are obtained from it, and multi-dimensional learning is performed until a target image classification network that meets the preset performance parameters is obtained.
It significantly improves the generalization ability of the model, quickly searches and generates a target image classification network that meets the preset performance parameters, and reduces the need for manual adjustment and the difficulty of model training.
Smart Images

Figure CN118570602A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for generating an image classification network. Background Art
[0002] With the continuous development of computer technology, neural network architecture continues to evolve and deeply integrate with other intelligent computing methods, building a powerful artificial intelligence technology system and widely used in various fields. For example, the neural network model based on deep learning is used for image classification, which can accurately locate and extract image content and realize automatic image classification.
[0003] The architectural design of the neural network is the key to determining the performance of the model. Related technologies improve model performance by automatically searching and optimizing the model architecture, thereby reducing the cost of manual design and debugging. However, it is difficult to learn from multiple dimensions, resulting in poor generalization of the model. Summary of the invention
[0004] The present application aims to solve at least one of the technical problems existing in the prior art. To this end, the present application provides an image classification network generation method, device, electronic device and storage medium, which can effectively improve the generalization performance of the model.
[0005] In a first aspect, an embodiment of the present application provides a method for generating an image classification network, comprising:
[0006] Generate a search space according to the network parameters of the image classification network; the search space includes multiple layers of nodes, and the paths between the nodes in different layers constitute a subnetwork;
[0007] Acquire at least one of the sub-networks from the search space, and perform knowledge distillation on the sub-network using the image data set of the image classification network and the initial teacher network to obtain a student network;
[0008] According to the performance parameters of the student network, a teacher network is selected from the student network, and the teacher network is added to a teacher network queue; the network model in the teacher network queue includes the initial teacher network and at least one of the teacher networks;
[0009] The teacher network queue is used to perform knowledge distillation on the sub-network until the teacher network that meets the preset performance parameters is obtained, and the teacher network is used as the target image classification network.
[0010] In some embodiments of the present application, the teacher network queue includes a preset number of the network models; selecting a teacher network from the student network according to the performance parameters of the student network and adding the teacher network to the teacher network queue includes:
[0011] If the number of network models in the teacher network queue is less than the preset number, adding the student network as the teacher network to the teacher network queue;
[0012] Otherwise, calculating a first performance indicator of the student network, and calculating a second performance indicator of each of the network models in the teacher network queue;
[0013] If the minimum value of the second performance indicator is smaller than the first performance indicator, the student network is used as the teacher network to replace the network model corresponding to the minimum value of the second performance indicator.
[0014] In some embodiments of the present application, the image dataset includes a plurality of data samples, and the data samples include data labels; and performing knowledge distillation on the sub-network using the teacher network queue includes:
[0015] Inputting the data sample into the sub-network to obtain a first predicted label;
[0016] Calculating the classification loss of the sub-network according to the first predicted label and the data label;
[0017] Inputting the data sample into each network model of the teacher network queue, and weighting the second prediction label of the network model to obtain a third prediction label;
[0018] Calculate the distillation loss of the sub-network according to the third predicted label and the first predicted label;
[0019] The network parameters of the sub-network are updated according to the classification loss and the distillation loss.
[0020] In some embodiments of the present application, weighting the second prediction label of the network model to obtain a third prediction label includes:
[0021] Generate an attention weight for each of the network models according to a preset attention score indicator;
[0022] The second predicted label of the network model is fused according to the attention weight to obtain the third predicted label.
[0023] In some embodiments of the present application, generating the attention weight of each network model according to a preset attention scoring index includes:
[0024] Calculating an attention score of the network model according to the second performance indicator and a preset attention hyperparameter;
[0025] Adding the attention scores of each of the network models to obtain a total attention score;
[0026] The attention score is divided by the total attention score to obtain the attention weight of the network model.
[0027] In some embodiments of the present application, obtaining the teacher network that meets preset performance parameters and using the teacher network as a target image classification network includes:
[0028] Calculate the performance evaluation score of each teacher network in the teacher network queue according to a preset performance evaluation indicator;
[0029] Sort the teacher networks in descending order according to the performance evaluation scores to obtain a reference teacher network queue;
[0030] The first teacher network is selected from the reference teacher network queue as the target image classification network.
[0031] In some embodiments of the present application, the network parameters include: the number of network layers, network operators, and operator hyperparameters; generating a search space according to the network parameters of the image classification network includes:
[0032] Generate multiple layers of nodes corresponding to the number of network layers; each layer of nodes corresponds to the same network operator, and different nodes in the same layer correspond to different operator hyperparameters;
[0033] generating an initial search space based on the multi-layer nodes;
[0034] Obtaining a performance score of each of the nodes on the target hardware;
[0035] The nodes in the initial search space are pruned according to the performance scores to obtain the search space.
[0036] In a second aspect, the embodiment of the present application further provides an image classification network generation device, which applies the image classification network generation method described in the embodiment of the first aspect of the present application, including:
[0037] A generation module, used to generate a search space according to the network parameters of the image classification network; the search space includes multiple layers of nodes, and the paths between the nodes in different layers constitute a subnetwork;
[0038] A distillation module, used to obtain at least one of the sub-networks from the search space, and perform knowledge distillation on the sub-network using the image data set of the image classification network and the initial teacher network to obtain a student network;
[0039] A selection module, configured to select a teacher network from the student network according to the performance parameters of the student network, and add the teacher network to a teacher network queue; the network model in the teacher network queue includes the initial teacher network and at least one of the teacher networks;
[0040] The target module is used to perform knowledge distillation on the sub-network using the teacher network queue until the teacher network that meets the preset performance parameters is obtained, and the teacher network is used as the target image classification network.
[0041] In a third aspect, an embodiment of the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the image classification network generation method as described in the embodiment of the first aspect of the present application is implemented.
[0042] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the storage medium stores a program, and the program is executed by a processor to implement the image classification network generation method as described in the embodiment of the first aspect of the present application.
[0043] The embodiments of the present application include at least the following beneficial effects:
[0044] The embodiment of the present application provides a method, device, electronic device and storage medium for generating an image classification network, wherein the method first generates a search space according to the network parameters of the image classification network, the search space includes multiple layers of nodes, and the paths between nodes of different layers constitute a sub-network. At least one sub-network is obtained from the search space, and the image data set of the image classification network and the initial teacher network are used to perform knowledge distillation on the sub-network to obtain a student network. Then, according to the performance parameters of the student network, a teacher network is selected from the student network, and the teacher network is added to the teacher network queue. The sub-network is knowledge distilled using the teacher network queue until a teacher network that meets the preset performance parameters is obtained, and the teacher network is used as the target image classification network. Based on the initial teacher network and the dynamically updated teacher network queue, the sub-network can be learned from multiple dimensions through knowledge distillation technology, thereby greatly improving the generalization ability of the model and obtaining a target image classification network that meets the preset performance parameters.
[0045] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:
[0047] Figure 1 It is a flowchart of an image classification network generation method provided by an embodiment of the present application;
[0048] Figure 2 is a schematic diagram of a search space provided by an embodiment of the present application;
[0049] Figure 3 yes Figure 1 Schematic diagram of the process of step S103;
[0050] Figure 4 yes Figure 1 Schematic diagram of the process of step S104;
[0051] Figure 5 yes Figure 1 Another flow chart of step S104;
[0052] Figure 6 This is a schematic diagram of knowledge distillation provided by an embodiment of the present application;
[0053] Figure 7 yes Figure 5 Schematic diagram of the process of step S403;
[0054] Figure 8 yes Figure 7 Schematic diagram of the process of step S501;
[0055] Fig. 9 yes Figure 1 Schematic diagram of the process of step S101;
[0056] Fig.10 It is a schematic diagram of a module of an image classification network generation device provided by an embodiment of the present application;
[0057] Fig.11 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present application.
[0058] Figure numerals: generation module 100, distillation module 200, selection module 300, target module 400, electronic device 1000, processor 1001, memory 1002. DETAILED DESCRIPTION
[0059] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0060] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be understood as limiting the present application.
[0061] In the description of the present application, it should be understood that descriptions involving orientation, such as up, down, front, back, left, right, etc., indicating orientations or positional relationships, are based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the present application.
[0062] In the description of this application, "several" means one or more, "more" means more than two, "greater than", "less than", "exceed", etc. are understood to exclude the number itself, and "above", "below", "within", etc. are understood to include the number itself. If there is a description of "first" or "second", it is only used for the purpose of distinguishing technical features, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features or implicitly indicating the order of the indicated technical features.
[0063] In the description of this application, unless otherwise clearly defined, terms such as setting, installing, connecting, etc. should be understood in a broad sense, and technicians in the relevant technical field can reasonably determine the specific meanings of the above terms in this application based on the specific content of the technical solution.
[0064] With the continuous evolution of deep learning and neural network algorithms, they have been deeply integrated with other intelligent computing methods such as evolutionary algorithms and fuzzy systems to build a powerful artificial intelligence technology system, which plays a core role in the field of computational intelligence. For neural networks based on deep learning, the network structure design and algorithm optimization are the key to determining their performance. In response to practical application needs such as intelligent manufacturing, smart cities, and image processing, neural network algorithms have been widely used and have a far-reaching impact. For example, neural network models based on deep learning are used for image classification, which can accurately locate and extract image content and realize automatic image classification. Neural network algorithms have been widely used and have a far-reaching impact, and the key to their success is largely due to their ingeniously designed architecture. Through specific designs for different tasks, the model framework is optimized to improve model performance.
[0065] There are already some methods for automatically designing and tuning neural network models in related technologies. For example, Automated Machine Learning (AutoML) technology can improve model performance by automatically searching and optimizing model architectures, thereby reducing the cost of manual design and debugging. Neural Architecture Search (NAS) is a technology for automatically designing artificial neural networks, which is used to design networks that are equivalent to or better than manually designed networks. In addition, there are some methods based on evolutionary algorithms that can also be used to automatically design and tune neural network models. They can automatically search and optimize the structure and parameters of the model according to specific task requirements and data sets, thereby obtaining better model effects. However, the methods in related technologies have long calculation cycles, high resource consumption, and are difficult to learn from multiple dimensions, resulting in poor generalization of the model. There are also challenges such as weight sharing problems and multi-objective search.
[0066] Based on this, the embodiments of the present application provide an image classification network generation method, device, electronic device and storage medium, which can be based on the initial teacher network and the dynamically updated teacher network queue, and through the knowledge distillation technology, enable the sub-network to learn from multiple dimensions, thereby greatly improving the generalization ability of the model, and quickly searching and generating a target image classification network that meets the preset performance parameters.
[0067] The embodiments of the present application provide an image classification network generation method, device, electronic device and storage medium, which are specifically described through the following embodiments. First, the image classification network generation method in the embodiments of the present application is described.
[0068] The image classification network generation method provided in the embodiment of the present application relates to the field of computer technology, and in particular to the field of artificial intelligence technology. The image classification network generation method provided in the embodiment of the present application can be applied to a terminal, can be applied to a server side, and can also be a computer program running in a terminal or a server side. For example, a computer program can be a native program or a software module in an operating system; it can be a local application, that is, a program that needs to be installed in an operating system to run, such as a client that supports image classification network generation, that is, a program that can be run only by downloading it to a browser environment. In short, the above-mentioned computer program can be any form of application, module or plug-in. Among them, the terminal communicates with the server via a network. The image classification network generation method can be executed by a terminal or a server, or by a terminal and a server in collaboration.
[0069] In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer or a smart watch. The server can be an independent server, or it can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and big data and artificial intelligence platforms; it can also be a service node in a blockchain system, and each service node in the blockchain system forms a peer-to-peer (Peer To Peer, P2P) network. The P2P protocol is an application layer protocol running on the Transmission Control Protocol (Transmission Control Protocol, TCP) protocol. The server can be installed with the server. The server can interact with the terminal through the server. For example, the corresponding software is installed on the server. The software can be an application that implements the image classification network generation method, etc., but it is not limited to the above form. The terminal and the server can be connected through Bluetooth, Universal Serial Bus (Universal Serial Bus, USB) or network communication connection methods, and this embodiment is not limited here.
[0070] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present invention can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0071] The following describes an image classification network generation method in an embodiment of the present invention.
[0072] Figure 1 is an optional flowchart of the image classification network generation method provided by an embodiment of the present invention. Figure 1 The method in the embodiment may include but is not limited to steps S101 to S104. Figure 1The order of step S101 to step S104 is not specifically limited, and the order of steps can be adjusted or some steps can be reduced or added according to actual needs.
[0073] Step S101, generating a search space according to network parameters of an image classification network.
[0074] In some embodiments, the generated image classification network is a neural network architecture based on deep learning. The search space refers to the range of possible network structures, covering multiple aspects such as the type, number, and connection mode of network layers. It is usually exponentially large or even unbounded, representing all possible network structures. Therefore, in the process of generating an image classification network, the search space defines the possibility of all network structures that can be explored.
[0075] In some embodiments, a low-code generation framework is used to quickly define the scope and usage environment of the search space through simple code configuration and selection of predefined modules or components. This avoids the need to manually write complex neural network structures and parameter configurations. Specifically, the search space is generated according to the network parameters of the image classification network. The network parameters include: the number of network layers, network operators, operator hyperparameters, etc. Various properties of the network can also be configured, such as activation functions, input-output relationships of network layers, and connection methods between different layers, etc. This embodiment does not limit this.
[0076] In some embodiments, the search space includes multiple layers of nodes, and the paths between nodes in different layers constitute a subnetwork. Figure 2 In the search space diagram shown in Figure 1, the neural network architecture is abstracted as a directed acyclic graph without isolated nodes. The nodes represent the layers of the neural network, and the edges represent the data flow. Data flows in from the predecessor node of a node and flows to the subsequent node after calculation by the node. Therefore, a subnetwork can be regarded as a path in the search space.
[0077] Step S102, obtaining at least one sub-network from the search space, performing knowledge distillation on the sub-network using the image data set of the image classification network and the initial teacher network, and obtaining a student network.
[0078] In some embodiments, obtaining at least one sub-network from the search space may be performed by traversing or sampling the search space to obtain at least one sub-network. Then, the sub-network is subjected to knowledge distillation using the image data set of the image classification network and the initial teacher network to obtain a student network. It is understandable that knowledge distillation is a machine learning technique for transferring knowledge from large and complex models to small models. Therefore, using knowledge distillation, the performance or knowledge of the initial teacher network when processing complex tasks can be transferred to the sub-network.
[0079] Specifically, the initial teacher network is a pre-trained large model, which can be obtained from an open source model library (such as Hugging Face) or a closed source large model. It is understandable that although these large models have accumulated rich knowledge and feature representation capabilities after training with a large amount of data, they face some challenges in practical applications due to their huge parameter volume and computational complexity. First, large models are usually difficult to deploy directly on resource-constrained devices, such as mobile devices or embedded systems. Secondly, even on high-performance computing devices, the reasoning time of large models may be long, which is unacceptable for application scenarios that require real-time response. In addition, although the large model has been pre-trained on a large-scale data set, if it is fine-tuned directly on proprietary data, it may encounter catastrophic forgetting and other problems, resulting in a decrease in model performance. Therefore, the embodiment of the present application uses a large model as the initial teacher network, and distills the powerful capabilities of the large model into the sub-network by the method of knowledge distillation. As a result, the sub-network can not only learn from the original data set, but also quickly align to the performance of the large model under the guidance of the large model, providing more abundant supervision information for the student model, reducing its convergence difficulty, and accelerating the convergence speed.
[0080] In some embodiments, the original data set used for the image classification network is an image data set, and for other application fields, a corresponding domain data set is selected. It can be understood that the method of the present application mainly optimizes and adjusts the search space of the neural network under the deep learning model, improves the model search efficiency and model training efficiency, and is not limited to specific scenarios such as image classification and image detection. Therefore, it can be widely used in various fields. Specifically, the definition of the domain data set has an important impact on the effectiveness and performance of the search process. The definition method of the domain data set includes data collection, data preprocessing, data partitioning, data labeling and data expansion, which is not limited in this embodiment.
[0081] To collect and organize a large amount of labeled data representing the characteristics and difficulties of the target task from different fields, and to preprocess and divide the data set, the following process can be followed:
[0082] 1. Data collection: Improve the diversity of the dataset by actively selecting the most informative samples for labeling. Use transfer learning to leverage knowledge from the source domain to enhance the data for the target task, ensuring that the model has a wider generalization capability. Use semi-supervised learning to combine labeled and unlabeled data to increase the size and diversity of the dataset through model self-learning. Set up a real-time data collection mechanism and regularly update the dataset to reflect the latest features and trends of the target task to ensure data timeliness.
[0083] 2. Data preprocessing and partitioning, perform outlier detection on the data, use statistical methods combined with machine learning algorithms to detect and process outliers in the data to ensure data quality. Use methods such as data resampling and interpolation to repair or replace invalid or erroneous data. Through stratified sampling: ensure that the training set, validation set, and test set can represent the distribution of the overall data. For time series data, partition them in chronological order to avoid data leakage and improve model generalization.
[0084] 3. Data labeling and expansion. Based on domain knowledge, use domain expert knowledge to generate accurate labels for multi-category or multi-label tasks, and combine natural language processing or image processing tools to automatically generate labels for data. Ensure that the labels are clearly defined and agreed upon between different annotators. Strengthen the data by increasing the model's adaptability to noise and changes through data expansion, and select expansion strategies such as rotation, flipping, and scaling according to specific domain requirements. Finally, evaluate the search space coverage and analyze the effect of the neural network architecture search algorithm in different search spaces.
[0085] Step S103, selecting a teacher network from the student networks according to the performance parameters of the student networks, and adding the teacher network to the teacher network queue.
[0086] In some embodiments, a dynamically updated teacher network queue is set, and the network models in the queue include an initial teacher network and at least one teacher network. The teacher network is selected from the student network according to the performance parameters of the student network. It is understandable that the initial state of the teacher network queue only has the initial teacher network, and other teacher networks are empty, which is not limited in this embodiment.
[0087] Reference Figure 3 As shown, in some embodiments of the present application, according to the performance parameters of the student network, a teacher network is selected from the student network, and the teacher network is added to the teacher network queue, which may include but is not limited to the following steps S201 to S203.
[0088] Step S201: If the number of network models in the teacher network queue is less than a preset number, the student network is added to the teacher network queue as a teacher network.
[0089] In some embodiments, the teacher network queue includes a preset number of network models. If the number of network models in the teacher network queue is less than the preset number, that is, the queue capacity of the teacher network queue has not been reached, the selected student network is directly added to the teacher network queue as a new teacher network, thereby obtaining a dynamically updated teacher network queue.
[0090] Step S202, otherwise, calculate the first performance index of the student network, and calculate the second performance index of each network model in the teacher network queue.
[0091] In some embodiments, if the teacher network queue includes a preset number of network models, the first performance indicator of the student model is calculated, and the second performance indicator of each network model in the teacher network queue is calculated. It is understandable that the calculation method of the first performance indicator and the second performance indicator is consistent. When the performance parameter is accuracy, the first performance indicator corresponds to the accuracy value of the student network, and the second performance indicator corresponds to the accuracy value of the initial teacher network or the teacher network. It is understandable that those skilled in the art can also set the performance parameters to precision, recall rate, etc. according to actual needs, and this embodiment does not limit this.
[0092] Step S203: If the minimum value of the second performance indicator is smaller than the first performance indicator, the student network is used as the teacher network to replace the network model corresponding to the minimum value of the second performance indicator.
[0093] In some embodiments, if the minimum value of the second performance indicator is less than the first performance indicator, it means that the performance of the student network is better than the performance of the network model corresponding to the minimum value of the second performance indicator in the teacher network queue, so the student network is used as the new teacher network to replace the network model corresponding to the minimum value of the second performance indicator. This dynamic update mechanism ensures that the queue always maintains the most representative and performant network model. It is worth noting that as the search progresses, if the performance of the initial teacher network is no longer competitive, it may also be expelled, which actually achieves a smooth transition from knowledge distillation to self-distillation.
[0094] Step S104, using the teacher network queue to perform knowledge distillation on the sub-network until a teacher network that meets preset performance parameters is obtained, and the teacher network is used as the target image classification network.
[0095] In some embodiments, the search space is repeatedly traversed or sampled to obtain a new sub-network, and the knowledge distillation of the sub-network is performed using the dynamically updated teacher network queue and image data set until a teacher network that meets preset performance parameters is obtained, such as the teacher network with the best performance obtained after traversing the entire search space, so that the teacher network is used as the target image classification network, which is not limited in this embodiment.
[0096] Therefore, in the process of searching and generating the neural network architecture, subnetworks are continuously sampled from the search space until the entire search space is traversed. Each sampled subnetwork will be guided by the network model in the dynamically updated teacher network queue and try to imitate its prediction results for training. This training method allows the subnetwork to learn not only from the annotations of the original data set, but also to acquire knowledge from multiple network models and learn from multiple dimensions, which is more effective than simply learning from hard targets (such as class labels), thereby greatly improving the generalization ability of the model.
[0097] Reference Figure 4 As shown, in some embodiments of the present application, the teacher network that meets the preset performance parameters is obtained in the above step S104, and the teacher network is used as the target image classification network, which may include but is not limited to the following steps S301 to S303.
[0098] Step S301, calculating the performance evaluation score of each teacher network in the teacher network queue according to a preset performance evaluation indicator.
[0099] In some embodiments, the performance evaluation score of each teacher network in the teacher network queue is calculated according to a preset performance evaluation indicator, for example, accuracy is used as a performance evaluation indicator. Each teacher network is evaluated using the data of the validation set or the test set. The performance evaluation score is calculated based on the comparison of the predicted results with the true label, and the accuracy score of each teacher network is calculated. For example, the ratio of the number of correctly classified samples to the total number of samples is calculated, and this embodiment does not limit this.
[0100] Step S302, sorting the teacher networks in descending order according to the performance evaluation scores to obtain a reference teacher network queue.
[0101] In some embodiments, the teacher networks are sorted in descending order according to the performance evaluation scores, for example, by a quick sort or heap sort algorithm, and each teacher network is sorted in descending order according to the performance evaluation score. After sorting, a reference teacher network queue is obtained, and the teacher network with the best performance is located at the front of the reference teacher network queue, which is not limited in this embodiment.
[0102] Step S303, selecting the first teacher network from the reference teacher network queue as the target image classification network.
[0103] In some embodiments, the first teacher network is selected from the reference teacher network queue as the target image classification network. Since the teacher network queue is updated in real time according to the performance and complexity of the network model, after the traversal of the entire search space is completed, the teacher network with the best performance in the teacher network queue (excluding the initial teacher network) is the neural network architecture that meets the constraints and has the best performance on the data set, and has excellent generalization ability, which is not limited in this embodiment.
[0104] Reference Figure 5 As shown, in some embodiments of the present application, the teacher network queue is used to perform knowledge distillation on the sub-network in the above step S104, which may include but is not limited to the following steps S401 to S405.
[0105] Step S401: input the data sample into the sub-network to obtain a first predicted label.
[0106] In some embodiments, the image data set includes multiple data samples, each of which includes a data label. The data sample is input into the subnetwork for prediction to obtain a first predicted label.
[0107] Step S402, calculating the classification loss of the sub-network according to the first predicted label and the data label.
[0108] In some embodiments, the classification loss of the subnetwork can be calculated based on the first predicted label and the data label. Specifically, the cross entropy loss is calculated based on the first predicted label and the data label, and is recorded as It can be understood that the cross entropy loss is used to measure the difference between the predicted output of the sub-network and the true label, focusing on the classification performance of the sub-network on the training data. Its calculation uses the correct data label y and the output p(x,w) of the sub-network a under the input x. a ) Calculate the cross entropy and record it as This embodiment does not limit this.
[0109] Step S403: input the data sample into each network model of the teacher network queue, and weight the second prediction label of the network model to obtain a third prediction label.
[0110] In some embodiments, the data sample is input to each network model in the teacher network queue, including the initial teacher network and the teacher network, to obtain the second prediction label corresponding to each network model. The second prediction labels of each network model are weighted to obtain a third prediction label. It can be understood that the third prediction label is the distribution of the teacher network output, expressed as It is the integration of the outputs of each network model in the teacher network queue, and this embodiment does not impose any restrictions on this.
[0111] Step S404: Calculate the distillation loss of the sub-network according to the third predicted label and the first predicted label.
[0112] In some embodiments, according to the third prediction label and the first predicted label p(x,w a ), the distillation loss of the sub-network can be calculated and recorded as Specifically, the distillation loss is calculated using the Kullback-Leibler (KL) divergence, which is a metric for measuring the difference between two probability distributions. It is used for knowledge distillation and can transfer the knowledge of the network model to the sub-network by minimizing the KL divergence between the network model and the sub-network. This knowledge transfer process can help the sub-network better handle complex tasks, thereby improving the performance of the model.
[0113] Step S405: Update the network parameters of the sub-network according to the classification loss and the distillation loss.
[0114] In some embodiments, according to the classification loss Distillation loss And the preset loss weight ρ, calculate the model loss of the sub-network Recorded as It can be understood that by adjusting the value of ρ, the and The relative importance in knowledge distillation, a larger ρ value will focus more on distilled knowledge, while a smaller ρ value will focus more on classification accuracy. The specific value can be adjusted according to the specific application scenario and requirements, and this embodiment does not impose any restrictions on this.
[0115] In some embodiments, the network parameters of the sub-network are updated by the model loss, referring to Figure 6 The schematic diagram of knowledge distillation shown in the figure repeats the process of performing knowledge distillation on the sub-network, i.e., step S501 to step S505, until a sub-network that meets the preset stop condition is obtained as the student network. For example, when the model loss of the sub-network is less than the preset loss value, the student network after knowledge distillation is obtained. In this way, not only can we learn from the original data, but we can also converge quickly under the guidance of different network models, learn from multiple dimensions and perspectives, and effectively improve the generalization ability of the model.
[0116] Reference Figure 7 As shown, in some embodiments of the present application, the second predicted label of the network model is weighted to obtain the third predicted label in the above step S403, which may include but is not limited to the following steps S501 to S502.
[0117] Step S501, generating the attention weight of each network model according to the preset attention scoring index.
[0118] In the process of knowledge distillation of sub-networks by multi-teacher networks, different network models may produce different outputs for the same input, resulting in knowledge conflicts. This inconsistency may confuse the sub-networks and affect their learning effects. To address this challenge, the present embodiment of the application adopts the attention mechanism in deep learning, which has been proven to effectively assign different weights to different inputs. Drawing on this idea, this embodiment introduces a dynamic "attention scoring indicator" to assign attention weights to each network model.
[0119] Specifically, refer to Figure 8 As shown, in some embodiments of the present application, the attention weight of each network model is generated according to a preset attention scoring index, which may include but is not limited to the following steps S601 to S603.
[0120] Step S601, calculating the attention score of the network model according to the second performance indicator and the preset attention hyperparameter.
[0121] In some embodiments, each time the teacher network queue is updated, the second performance indicator of each network model on the validation set is evaluated, and its weight in the distillation process is set accordingly. Specifically, the attention score of the network model is calculated based on the second performance indicator and the preset attention hyperparameter. Exemplarily, the attention hyperparameter is a temperature hyperparameter (Temperature, referred to as T). Specifically, the temperature hyperparameter is used to adjust the distribution of attention weights. When the temperature value is low, the attention weight will be more concentrated, and the model will pay more attention to certain specific features or areas. When the temperature value is high, the attention weight will be relatively dispersed, and the model will pay attention to more features or areas.
[0122] Step S602, adding up the attention scores of each network model to obtain a total attention score.
[0123] In some embodiments, the attention scores of each network model are summed to obtain a total attention score, which is recorded as Among them, z i represents the second performance index of the i-th network model on the test set, k represents the number of network models, T is the temperature hyperparameter, when T = 1, the temperature softmax is equivalent to the standard softmax. However, when T>1, all probabilities will become closer to uniform distribution, which is not limited in this embodiment.
[0124] Step S603, divide the attention score by the total attention score to obtain the attention weight of the network model.
[0125] In some embodiments, the attention score is divided by the total attention score to obtain the attention weight of the network model, which is expressed as:
[0126]
[0127] Here, i represents the i-th network model. This strategy ensures that the sub-network can obtain multi-dimensional knowledge from the network model with better performance, thus bringing better learning effect.
[0128] Step S502: The second predicted label of the network model is fused according to the attention weight to obtain a third predicted label.
[0129] In some embodiments, the second prediction labels of each network model are fused according to the attention weight to obtain a third prediction label, thereby integrating the outputs of each network model in the teacher network queue. It is understandable that a cache mechanism can also be used to preprocess some calculations for the computing requirements of the network models in the teacher network queue. Some forward calculation results of the network model are stored so that they can be reused in subsequent knowledge distillation training of the sub-network, thereby avoiding the need to perform the same calculations every time training, effectively improving the efficiency of generating the optimal neural network architecture.
[0130] Reference Fig. 9 As shown, in some embodiments of the present application, generating a search space according to network parameters of an image classification network may include but is not limited to the following steps S701 to S704.
[0131] Step S701, generating multiple layers of nodes corresponding to the number of network layers.
[0132] In some embodiments, corresponding multi-layer nodes are generated according to the number of network layers in the network parameters. The number of network layers defines how many layers of nodes there are in the search space. When the number of network layers is 10, 10 layers of nodes are generated, and the number of nodes in each layer is multiple. Each layer of nodes corresponds to the same network operator, and different nodes in the same layer correspond to different operator hyperparameters.
[0133] Specifically, the network operator defines the type of nodes in this layer. Except that the first layer must be the input layer and the last layer must be the output layer, the type of the intermediate layer is optional, representing various types of operations, such as full connection, convolution, deconvolution, dilated convolution, pooling, activation function, etc. The operator hyperparameters define the number of nodes in each layer. The hyperparameters of the convolution layer include the number of convolution kernels, the number of channels of the convolution kernel, the height, width, horizontal step length, vertical step length, etc.; the hyperparameters of the fully connected layer include the number of neurons; the hyperparameters of the activation function layer include the type of activation function, the parameters of the function, etc. Therefore, different operator hyperparameters correspond to different nodes, and this embodiment does not limit this.
[0134] Step S702: Generate an initial search space based on multiple layers of nodes.
[0135] In some embodiments, the initial search space is generated based on multiple layers of nodes, that is, each directed acyclic graph path without isolated nodes between nodes of different layers corresponds to a subnetwork, and all subnetworks constitute the initial search space, which is not limited in this embodiment.
[0136] Step S703, obtaining the performance score of each node on the target hardware.
[0137] In some embodiments, the complexity of the neural network architecture model is measured by parameters, computational complexity, etc. An overly complex model may lead to overfitting, over-adaptation to the training data, and performance degradation on actual test data, and may be limited by computing resources during actual deployment, especially in resource-constrained scenarios such as mobile devices, embedded devices, etc.
[0138] In some embodiments, in order to ensure the performance of the neural network architecture model, considering different deployment environments, such as the end side, edge side or cloud side, with different computing resources and performance requirements, this embodiment adopts a hardware-aware strategy for initial screening. Specifically, the performance score of each node on the target hardware is obtained, for example, the running time and energy consumption of network operators such as convolution and full connection on the target hardware are obtained. In addition, performance parameters such as running time and energy consumption can also be pre-stored in a table, which is not limited in this embodiment.
[0139] Step S704: prune the nodes in the initial search space according to the performance scores to obtain a search space.
[0140] In some embodiments, the nodes corresponding to each network operator are evaluated and sorted. If the performance score does not meet the preset conditions, such as the running time is greater than the preset time and / or the energy consumption is higher than the preset energy consumption, the node is pruned and removed, thereby screening the initial search space to obtain the search space, further improving the generation efficiency of the neural network architecture.
[0141] In some embodiments of the present application, the search space after screening is automatically searched for the target neural network architecture. Specifically, the neural network architecture search is performed in different network layers in the search space according to the search algorithm, and multiple neural network architectures are obtained by searching. The search process essentially traverses the entire search space to obtain the structure with the best performance. * , satisfying the following formula:
[0142]
[0143] in, Represents the search space, Eval val (a) represents the first performance indicator of subnetwork a, such as accuracy, precision, recall rate, etc. on the validation set. Generally speaking, the larger the value of the selected performance evaluation indicator, the better the performance, which is not limited in this embodiment.
[0144] The embodiment of the present application sets a dynamically updated teacher network queue, which maintains a set of K network models with the best performance. During the neural network architecture search process, the individual network models in the teacher network queue can provide more diverse and richer knowledge distillation signals for the training of the sub-networks. Unlike traditional static queues, this queue is dynamically maintained: as the spatial search proceeds, it is constantly updated and new high-performance sub-networks are added to the queue. When the number of network models in the queue exceeds the preset number K, network models with relatively low performance will be excluded, ensuring that the queue always retains the most representative and highest-performing K network models, satisfying:
[0145]
[0146] Therefore, through the teacher network queue, it is possible to provide the sub-network with richer supervision information, reduce its convergence difficulty, and accelerate the convergence speed.
[0147] The image classification network generation method provided by the embodiment of the present application can autonomously explore and determine the high-performance network architecture in the generated search space, thereby significantly reducing the need for manual adjustment. Among them, the pre-trained large model as the initial teacher network plays a vital role. Using its deep pre-training foundation, these rich knowledge and experience are passed to the sub-network through knowledge distillation technology. Not only does it accelerate the training convergence of the sub-network, but it also ensures that it obtains high-quality initialization under the guidance of the large model. What is more unique is that the present embodiment adopts a dynamic multi-teacher network strategy. This strategy is similar to the self-distillation technology, allowing the sub-network to learn from multiple dimensions and multiple perspectives, thereby greatly improving its generalization ability. Combining these technologies, the present embodiment can not only quickly search for the best network architecture, shorten the research and development cycle, but also significantly improve the overall performance of the model.
[0148] The embodiment of the present invention also provides an image classification network generation device, which can implement the above-mentioned image classification network generation method, referring to Fig.10 As shown, in some embodiments of the present application, the device includes:
[0149] A generation module 100 is used to generate a search space according to the network parameters of the image classification network; the search space includes multiple layers of nodes, and the paths between nodes in different layers constitute a subnetwork;
[0150] A distillation module 200 is used to obtain at least one sub-network from the search space, and perform knowledge distillation on the sub-network using the image data set of the image classification network and the initial teacher network to obtain a student network;
[0151] The selection module 300 is used to select a teacher network from the student network according to the performance parameters of the student network, and add the teacher network to the teacher network queue; the network model in the teacher network queue includes an initial teacher network and at least one teacher network;
[0152] The target module 400 is used to perform knowledge distillation on the sub-network using the teacher network queue until a teacher network that meets preset performance parameters is obtained, and the teacher network is used as the target image classification network.
[0153] The specific implementation of the image classification network generation device of this embodiment is basically the same as the specific implementation of the above-mentioned image classification network generation method, and will not be repeated here.
[0154] Fig.11 The electronic device 1000 provided in an embodiment of the present application is shown. The electronic device 1000 includes: a processor 1001, a memory 1002, and a computer program stored in the memory 1002 and executable on the processor 1001, and the computer program is used to execute the above-mentioned image classification network generation method when it is executed.
[0155] The processor 1001 and the memory 1002 may be connected via a bus or other means.
[0156] The memory 1002 is a non-transient computer-readable storage medium that can be used to store non-transient software programs and non-transient computer executable programs, such as the image classification network generation method described in the embodiment of the present application. The processor 1001 implements the above-mentioned image classification network generation method by running the non-transient software program and instructions stored in the memory 1002.
[0157] The memory 1002 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function; the data storage area may store and execute the above-mentioned image classification network generation method. In addition, the memory 1002 may include a high-speed random access memory 1002, and may also include a non-transitory memory 1002, such as at least one storage device storage device, a flash memory device or other non-transitory solid-state storage device. In some embodiments, the memory 1002 may optionally include a memory 1002 remotely arranged relative to the processor 1001, and these remote memories 1002 may be connected to the electronic device 1000 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0158] The non-transient software program and instructions required to implement the above-mentioned image classification network generation method are stored in the memory 1002. When executed by one or more processors 1001, the above-mentioned image classification network generation method is executed, for example, Figure 1 Steps S101 to S104 of the method, Figure 3 Steps S201 to S203 of the method, Figure 4 Steps S301 to S303 of the method, Figure 5 Steps S401 to S405 of the method, Figure 7 Steps S501 to S502 of the method, Figure 8 Steps S601 to S603 of the method, Fig. 9 The method steps S701 to S704.
[0159] The embodiment of the present application also provides a storage medium, which is a computer-readable storage medium, and the storage medium stores a computer program, which implements the above-mentioned image classification network generation method when the computer program is executed by the processor. The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0160] The image classification network generation method, device, electronic device and storage medium provided in the embodiment of the present application first generate a search space according to the network parameters of the image classification network, wherein the search space includes multiple layers of nodes, and the paths between nodes of different layers constitute a subnetwork. At least one subnetwork is obtained from the search space, and the subnetwork is subjected to knowledge distillation using the image data set of the image classification network and the initial teacher network to obtain a student network. Then, according to the performance parameters of the student network, a teacher network is selected from the student network, and the teacher network is added to the teacher network queue. The subnetwork is subjected to knowledge distillation using the teacher network queue until a teacher network that meets the preset performance parameters is obtained, and the teacher network is used as the target image classification network. Based on the initial teacher network and the dynamically updated teacher network queue, the subnetwork can be learned from multiple dimensions through knowledge distillation technology, thereby greatly improving the generalization ability of the model and obtaining a target image classification network that meets the preset performance parameters.
[0161] The embodiment of the present application first quickly defines the search space of the neural network architecture through a fine configuration. Secondly, a preliminary screening is performed based on the parameter quantity, computational complexity and reasoning delay of the model, thereby streamlining the search space and improving the search efficiency. The innovation lies in the introduction of a dynamically updated teacher network queue. In the early stage of the search, the queue is initialized using a pre-trained large model to provide a strong knowledge distillation signal for the sub-network, so that the sub-network converges quickly and ensures good initialization under the guidance of the large model. As the search proceeds, the newly searched high-performance sub-network will be included in the teacher network priority queue, and the number of models in the teacher network priority queue will gradually increase. When the number of network models reaches the preset number of queue capacity, the sub-network with lower performance is expelled, and when the initial large model has poor performance, it may also be expelled, thereby achieving a smooth transition from knowledge distillation to self-distillation. This strategy is actually an integrated learning method that allows sub-networks to learn and teach each other from multiple angles throughout the training process, thereby accelerating convergence and optimizing model performance. Finally, after a comprehensive search, the optimal sub-network in the teacher network queue is determined to be the optimal neural network architecture for the current task.
[0162] The above described embodiments are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.
[0163] It will be appreciated by those skilled in the art that all or some of the steps and systems in the disclosed method above may be implemented as software, firmware, hardware and appropriate combinations thereof. Some physical components or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or a non-transitory medium) and a communication medium (or a temporary medium). As known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, storage device storage or other magnetic storage devices, or any other medium that may be used to store desired information and may be accessed by a computer. Furthermore, it is well known to those skilled in the art that communication media typically include computer readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.
[0164] It should also be understood that the various implementations provided in the embodiments of the present application can be arbitrarily combined to achieve different technical effects. The above is a specific description of the preferred implementation of the present application, but the present application is not limited to the above implementations, and technicians familiar with the art can also make various equivalent modifications or substitutions under the shared conditions that do not violate the spirit of the present application.
Claims
1. A method for generating an image classification network, characterized in that: include: Generating a search space according to network parameters of the image classification network; The search space includes multiple layers of nodes, and the paths between the nodes in different layers constitute a subnetwork; Acquire at least one of the sub-networks from the search space, and perform knowledge distillation on the sub-network using the image data set of the image classification network and the initial teacher network to obtain a student network; According to the performance parameters of the student network, a teacher network is selected from the student network, and the teacher network is added to a teacher network queue; the network model in the teacher network queue includes the initial teacher network and at least one of the teacher networks; The teacher network queue is used to perform knowledge distillation on the sub-network until the teacher network that meets the preset performance parameters is obtained, and the teacher network is used as the target image classification network.
2. The image classification network generation method according to claim 1, characterized in that: The teacher network queue includes a preset number of the network models; selecting a teacher network from the student network according to the performance parameter of the student network, and adding the teacher network to the teacher network queue includes: If the number of network models in the teacher network queue is less than the preset number, adding the student network as the teacher network to the teacher network queue; Otherwise, calculating a first performance indicator of the student network, and calculating a second performance indicator of each of the network models in the teacher network queue; If the minimum value of the second performance indicator is smaller than the first performance indicator, the student network is used as the teacher network to replace the network model corresponding to the minimum value of the second performance indicator.
3. The image classification network generation method according to claim 2, characterized in that: The image data set includes a plurality of data samples, and the data samples include data labels; and performing knowledge distillation on the sub-network using the teacher network queue includes: Inputting the data sample into the sub-network to obtain a first predicted label; Calculating the classification loss of the sub-network according to the first predicted label and the data label; Inputting the data sample into each network model of the teacher network queue, and weighting the second prediction label of the network model to obtain a third prediction label; Calculate the distillation loss of the sub-network according to the third predicted label and the first predicted label; The network parameters of the sub-network are updated according to the classification loss and the distillation loss.
4. The image classification network generation method according to claim 3, characterized in that: The step of weighting the second predicted label of the network model to obtain a third predicted label includes: Generate an attention weight for each of the network models according to a preset attention score indicator; The second predicted label of the network model is fused according to the attention weight to obtain the third predicted label.
5. The image classification network generation method according to claim 4, characterized in that: Generating the attention weight of each network model according to the preset attention scoring index includes: Calculating an attention score of the network model according to the second performance indicator and a preset attention hyperparameter; Adding the attention scores of each of the network models to obtain a total attention score; The attention score is divided by the total attention score to obtain the attention weight of the network model.
6. The image classification network generation method according to claim 1, characterized in that: The step of obtaining the teacher network that meets preset performance parameters and using the teacher network as a target image classification network includes: Calculate the performance evaluation score of each teacher network in the teacher network queue according to a preset performance evaluation indicator; Sort the teacher networks in descending order according to the performance evaluation scores to obtain a reference teacher network queue; The first teacher network is selected from the reference teacher network queue as the target image classification network.
7. The image classification network generation method according to any one of claims 1 to 6, characterized in that: The network parameters include: the number of network layers, network operators, and operator hyperparameters; the generating a search space according to the network parameters of the image classification network includes: Generate multiple layers of nodes corresponding to the number of network layers; each layer of nodes corresponds to the same network operator, and different nodes in the same layer correspond to different operator hyperparameters; generating an initial search space based on the multi-layer nodes; Obtaining a performance score of each of the nodes on the target hardware; The nodes in the initial search space are pruned according to the performance scores to obtain the search space.
8. An image classification network generation device, characterized in that: The method for generating an image classification network according to any one of claims 1 to 7 is applied, comprising: A generation module, used to generate a search space according to the network parameters of the image classification network; the search space includes multiple layers of nodes, and the paths between the nodes in different layers constitute a subnetwork; A distillation module, used to obtain at least one of the sub-networks from the search space, and perform knowledge distillation on the sub-network using the image data set of the image classification network and the initial teacher network to obtain a student network; A selection module, configured to select a teacher network from the student network according to the performance parameters of the student network, and add the teacher network to a teacher network queue; the network model in the teacher network queue includes the initial teacher network and at least one of the teacher networks; The target module is used to perform knowledge distillation on the sub-network using the teacher network queue until the teacher network that meets the preset performance parameters is obtained, and the teacher network is used as the target image classification network.
9. An electronic device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the image classification network generation method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The storage medium stores a program, and the program is executed by a processor to implement the image classification network generation method according to any one of claims 1 to 7.
Citation Information
Cited By
Management control method and device for deep learning model
CN118860479A
Network architecture search synchronous transfer learning method oriented to multi-modal map data
CN120317331A
Synchronous transfer learning method for network architecture search on multimodal graph data
CN120317331B
Method and device for distillation reinforcement learning data set of intelligent computing center for providing computing power
CN120492933A
Image classification model training method, image classification method and related device
CN121640125A
