Tool image classification model compression method and device, computer device and storage medium

By compressing the tool image classification model by setting distillation temperature and dynamic weights, the problems of model complexity and high resource consumption are solved, and an efficient tool image classification model suitable for edge devices is generated.

CN117077757BActive Publication Date: 2026-01-13HANGZHOU EDA PRECISION ELECTROMECHANICAL TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310780492.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2023-06-25
Filing Date
2023-06-28
Publication Date
2026-01-13
Estimated Expiration
2043-06-28

AI Technical Summary

Technical Problem

Existing tool image classification models are complex in structure, have many parameters, consume a lot of computing resources, and are difficult to apply to various hardware platforms.

Method used

A method of dynamically assigning weights based on distillation temperature is used to compress the teacher model for knife image classification. By setting a set of distillation temperatures and dynamically assigning weights, the similarity is calculated using the fully connected classification vectors of the teacher model for knife image classification, resulting in a smaller student model for knife image classification.

Benefits of technology

The model's parameters were reduced, runtime efficiency was improved, resource consumption was reduced, and a smaller and more efficient tool image classification model was generated that can run on edge devices and mobile devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117077757B_ABST
    Figure CN117077757B_ABST
Patent Text Reader

Abstract

The embodiment of the application discloses a tool image classification model compression method and device, computer equipment and a storage medium. The method comprises the following steps: determining the similarity between each tool category and other tool categories according to the full connection classification vector of a tool image classification teacher model; setting a group of distillation temperatures; dynamically allocating the weight corresponding to each distillation temperature according to the similarity between the input model tool category and other tool categories; and distilling the tool image classification teacher model according to the weight and the distillation temperature to obtain a tool image classification student model. By implementing the method of the embodiment of the application, the parameter quantity of the model can be reduced, the running efficiency of the model can be improved, and resource consumption can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to a model compression method, and more specifically to a tool image classification model compression method, apparatus, computer equipment, and storage medium. Background Technology

[0002] The tools in the tool management cabinet have the following characteristics: some tools are significantly different from all other tools, while others are only slightly different. Existing tool image classification models are based on deep neural networks. In recent years, deep neural networks have enabled unprecedented performance in many computer vision tasks. The more complex the neural network model structure and the more parameters it has, the richer the knowledge it can learn and the better the learning effect. However, the high storage space and computational resource consumption make it difficult to widely apply large network models on various hardware platforms.

[0003] In summary, large-scale tool image classification models are complex in structure, have many parameters, and consume a large amount of computational resources.

[0004] Therefore, it is necessary to design a new method to reduce the number of model parameters, improve model runtime efficiency, and reduce resource consumption. Summary of the Invention

[0005] The purpose of this invention is to overcome the shortcomings of the prior art and provide a method, apparatus, computer equipment and storage medium for compressing tool image classification models.

[0006] To achieve the above objectives, the present invention adopts the following technical solution: a tool image classification model compression method, comprising:

[0007] The similarity between each knife category and other knife categories is determined based on the fully connected classification vectors of the knife image classification teacher model.

[0008] Set a set of distillation temperatures;

[0009] The weights corresponding to each distillation temperature are dynamically assigned based on the similarity between the tool category of the input model and other tool categories.

[0010] The teacher model for knife image classification is distilled according to the weights and the distillation temperature to obtain the student model for knife image classification.

[0011] The further technical solution is as follows: determining the similarity between each knife category and other knife categories based on the fully connected classification vector of the knife image classification teacher model includes:

[0012] The similarity between each knife category and other categories is obtained from the classification vectors of the fully connected layer of the knife image classification teacher model.

[0013] The further technical solution is as follows: the similarity between each tool category and other categories is obtained by averaging the similarity between the category most similar to that tool category and the average similarity; wherein, the average similarity refers to the mean similarity of the classification vectors of each tool category and other tool categories, and the similarity of the classification vectors is the cosine value of the angle between the two vectors.

[0014] The further technical solution is as follows: Before determining the similarity between each knife category and other knife categories based on the fully connected classification vector of the knife image classification teacher model, the following steps are included:

[0015] Generate a teacher model for classifying knife images;

[0016] The generated tool image classification teacher model includes:

[0017] Construct a training dataset for tool image classification;

[0018] Construct an initial image classification teacher model;

[0019] The initial image classification teacher model is trained using the training dataset until the model converges, thus obtaining the knife image classification teacher model.

[0020] The further technical solution is as follows: before dynamically assigning the weight corresponding to each distillation temperature based on the similarity between the tool category of the input model and other tool categories, it further includes:

[0021] Construct an initial student model for tool image classification;

[0022] Select an image from the training dataset and input it into the initial student model for tool image classification and the teacher model for tool image classification, respectively, to obtain the first vector and the second vector.

[0023] The further technical solution is as follows: the weight corresponding to each distillation temperature is: λ2=sim k λ3 = 1, λ4 = 1 - sim k , Where λ1 is the weight corresponding to the first distillation temperature; λ2 is the weight corresponding to the second distillation temperature; λ3 is the weight corresponding to the third distillation temperature; λ4 is the weight corresponding to the fourth distillation temperature; and λ5 is the weight corresponding to the fifth distillation temperature; sim k It represents the similarity between the knife category and other categories.

[0024] The further technical solution is as follows: the distillation of the knife image classification teacher model according to the weights and the distillation temperature to obtain the knife image classification student model includes:

[0025] A loss function is constructed based on the weights and the distillation temperature; wherein... Among them, softmax(T) i p) represents the distillation temperature T i Calculate the softmax vector for the second vector p output by the teacher model for classifying tool images; softmax(T) i ,q) represents the distillation temperature T i The softmax vector is calculated from the first vector q output by the initial tool image classification student model; KL is used to calculate the degree of dissimilarity between the two distributions; p k p refers to the second vector corresponding to image k in the training dataset; j q refers to the second vector corresponding to image j in the training dataset; j It refers to the first vector corresponding to image j in the training dataset;

[0026] The loss of the initial tool image classification student model is calculated using the loss function, and the parameters of the initial tool image classification student model are optimized and updated using the stochastic gradient descent algorithm. The process of selecting an image from the training dataset and inputting it into the initial tool image classification student model and the tool image classification teacher model is repeated to obtain the first vector and the second vector, until the specified number of iterations is reached or the loss of the initial tool image classification student model tends to stabilize, thus obtaining the tool image classification student model.

[0027] The present invention also provides a tool image classification model compression device, comprising:

[0028] The similarity determination unit is used to determine the similarity between each tool category and other tool categories based on the fully connected classification vector of the tool image classification teacher model;

[0029] Temperature setting unit, used to set a set of distillation temperatures;

[0030] The weight allocation unit is used to dynamically allocate the weight corresponding to each distillation temperature based on the similarity between the tool category of the input model and other tool categories.

[0031] A distillation unit is used to distill the tool image classification teacher model according to the weights and the distillation temperature to obtain a tool image classification student model.

[0032] The present invention also provides a computer device, the computer device including a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the above-described method.

[0033] The present invention also provides a storage medium storing a computer program that, when executed by a processor, implements the above-described method.

[0034] The beneficial effects of this invention compared with the prior art are as follows: This invention compresses the tool image classification teacher model by setting a set of distillation temperatures. The weights corresponding to the distillation temperatures are determined by the similarity between the tool category and other categories in the input model. The similarity between the tool category and other tool categories is calculated by the fully connected classification vector of the tool image classification teacher model, thereby reducing the number of model parameters, improving the model's runtime efficiency, and reducing resource consumption.

[0035] The present invention will be further described below with reference to the accompanying drawings and specific embodiments. Attached Figure Description

[0036] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0037] Figure 1 This is a schematic diagram illustrating an application scenario of the tool image classification model compression method provided in this embodiment of the invention.

[0038] Figure 2 A schematic flowchart of the tool image classification model compression method provided in an embodiment of the present invention;

[0039] Figure 3 A schematic diagram of a sub-process of the tool image classification model compression method provided in an embodiment of the present invention;

[0040] Figure 4 A flowchart illustrating a tool image classification model compression method provided in another embodiment of the present invention;

[0041] Figure 5 A schematic block diagram of a tool image classification model compression device provided in an embodiment of the present invention;

[0042] Figure 6 A schematic block diagram of the distillation unit of the tool image classification model compression device provided in an embodiment of the present invention;

[0043] Figure 7 A schematic block diagram of a tool image classification model compression device provided in another embodiment of the present invention; and

[0044] Figure 8A schematic block diagram of a computer device provided for an embodiment of the present invention. Detailed Implementation

[0045] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0046] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.

[0047] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.

[0048] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0049] Please see Figure 1 and Figure 2 , Figure 1 This is a schematic diagram illustrating an application scenario of the tool image classification model compression method provided in this embodiment of the invention. Figure 2This is a schematic flowchart illustrating the tool image classification model compression method provided in this embodiment of the invention. The method is applied in a server. The server interacts with a terminal, inputting a training dataset. This dataset is used to train the tool image classification teacher model. A set of distillation temperatures replaces the traditional single temperature for model distillation, and a corresponding weight is dynamically assigned to each distillation temperature. The weight of each temperature is determined by the similarity between the input tool image category and other categories. This similarity is calculated from the fully connected classification vector of the tool image classification teacher model. When the input tool image is very dissimilar to other categories, the distribution of the tool image classification teacher model's output is relatively steep. In this case, by increasing the weight of a larger temperature, the distribution becomes smoother, allowing the tool image classification student model to learn a smoother classification result and preventing overfitting. When the input tool image is very similar to other tool categories, the distribution of the tool image classification teacher model's output is more even. At this point, adding a smaller temperature weight increases the gap between the correct and incorrect categories, allowing the student model for tool image classification to better distinguish between positive and difficult negative examples. By compressing the tool image classification model through model distillation, a smaller model is generated, thereby reducing the number of model parameters, improving the model's runtime efficiency, and reducing resource consumption.

[0050] Figure 2 This is a schematic flowchart of the tool image classification model compression method provided in an embodiment of the present invention. Figure 2 As shown, the method includes the following steps S110 to S160.

[0051] S11 0. Determine the similarity between each tool category and other categories based on the fully connected classification vector of the tool image classification teacher model.

[0052] In this embodiment, the similarity between each tool category and other tool categories is obtained by averaging the similarity of the category most similar to that tool category and the average similarity; wherein, the average similarity refers to the mean similarity of the classification vectors of each tool category and other tool categories, and the similarity of the classification vectors is the cosine of the angle between the two vectors.

[0053] Specifically, the similarity between each tool category and other categories is obtained based on the classification vector of the fully connected layer of the tool image classification teacher model.

[0054] In this embodiment, it is assumed that the classification vector corresponding to the kth tool category is z. k The similarity between this tool category and other categories is sim k Based on the similarity sim with the closest category to this tool category max and average similarity simavg We obtained, among which, sim max =max i (sim(z k , z i )); Among them, the similarity of the classification vectors sim(z) k , z i ) for z k and z i The cosine of the included angle, z i This refers to the classification vector corresponding to the i-th tool category. max Represents the classification vector z k Other classification vectors z i The maximum similarity. avg Represents the classification vector z k Other classification vectors z i The average similarity.

[0055] S120, Set a set of distillation temperatures.

[0056] In this embodiment, the distillation temperature refers to the temperature at which the distillation compression of the tool image classification teacher model is performed.

[0057] S130. Construct an initial student model for tool image classification.

[0058] In this embodiment, the initial tool image classification student model refers to a neural network model, such as ResNet18, used to classify tool images.

[0059] S140. Select an image from the training dataset and input it into the initial student model for tool image classification and the teacher model for tool image classification, respectively, to obtain the first vector and the second vector.

[0060] In this embodiment, the first vector refers to the vector output by the fully connected layer of the tool image classification student model when the selected tool image is input to it; the second vector refers to the vector output by the fully connected layer of the tool image classification teacher model when the selected tool image is input to it.

[0061] S150. Dynamically assign weights to each distillation temperature based on the similarity between the tool category of the input model and other tool categories.

[0062] In this embodiment, the weight corresponding to each distillation temperature is: λ2=sim k λ3 = 1, λ4 = 1 - sim k , Where λ1 is the weight corresponding to the first distillation temperature; λ2 is the weight corresponding to the second distillation temperature; λ3 is the weight corresponding to the third distillation temperature; λ4 is the weight corresponding to the fourth distillation temperature; λ5 is the weight corresponding to the fifth distillation temperature; sim k It represents the similarity between the knife category and other categories.

[0063] Specifically, assuming the fully connected layer output of the teacher model for knife image classification is vector p, and the fully connected layer output of the student model for knife image classification is vector q, a set of distillation temperatures T is set. This embodiment sets five distillation temperatures, namely: T3 = 1, T4 = 2, T5 = 4; each distillation temperature T i The corresponding weight is λ i Based on the tool category of the input tool image and the similarity between that tool category and other tool categories, the weight λ for each temperature is dynamically set. i Assuming the input tool image belongs to the k-th class, then the weight λ i Determined by the following method: λ2=sim k λ3 = 1, λ4 = 1 - sim k ,

[0064] S160. Distill the tool image classification teacher model according to the weights and the distillation temperature to obtain the tool image classification student model.

[0065] In this embodiment, the student model for knife image classification refers to a model that can better distinguish between positive samples and difficult negative examples, with low computational cost and few parameters.

[0066] In one embodiment, please refer to Figure 3 The above-mentioned step S160 may include steps S161 to S162.

[0067] S161. Construct a loss function based on the weights and the distillation temperature;

[0068] in, Among them, softmax(T) i p) represents the distillation temperature T i Calculate the softmax vector for the second vector p output by the teacher model for classifying tool images; softmax(T) i q) represents the distillation temperature T i The softmax vector is calculated from the first vector q output by the initial tool image classification student model; KL stands for KL-divergence, which is used to calculate the degree of dissimilarity between two distributions; pk p refers to the second vector corresponding to image k in the training dataset; j q refers to the second vector corresponding to image j in the training dataset; j It refers to the first vector corresponding to image j in the training dataset;

[0069] S162. Calculate the loss of the initial tool image classification student model using the loss function, and optimize and update the parameters of the initial tool image classification student model using the stochastic gradient descent algorithm. Repeatedly select an image from the training dataset and input it into the initial tool image classification student model and the tool image classification teacher model respectively to obtain the first vector and the second vector, until the specified number of iterations is reached or the loss of the initial tool image classification student model tends to stabilize, so as to obtain the tool image classification student model.

[0070] The loss of the initial tool image classification student model is calculated using the loss function, and the parameters of the initial tool image classification student model are optimized and updated using the stochastic gradient descent algorithm. Step S140 is repeated until the specified number of iterations is reached or the loss of the initial tool image classification student model tends to stabilize, so as to obtain the tool image classification student model.

[0071] Model compression methods reduce the computational space and time consumption of large models by pruning channels, decomposing weights, or using model distillation. This embodiment employs model distillation for a tool image classification model. Model distillation refers to transferring knowledge from a larger deep neural network model (called the teacher model) to a smaller neural network model (called the student model). This process aims to enable the student model to learn the same tasks as the teacher model and achieve similar performance, but with fewer parameters and lower computational complexity. This technique has been widely used to train smaller, faster models for operation on edge and mobile devices.

[0072] The aforementioned tool image classification model compression method compresses the tool image classification teacher model by setting a set of distillation temperatures. The weights corresponding to the distillation temperatures are determined by the similarity between the tool category and other categories in the input model. The similarity between the tool category and other categories is calculated from the fully connected classification vector of the tool image classification teacher model. This reduces the number of model parameters, improves the model's runtime efficiency, and reduces resource consumption.

[0073] Figure 4 This is a flowchart illustrating a tool image classification model compression method according to another embodiment of the present invention. Figure 4As shown, the tool image classification model compression method of this embodiment includes steps S210-S270. Steps S220-S270 are similar to steps S110-S160 in the above embodiment, and will not be described again here. The following details the added step S210 in this embodiment.

[0074] S210, Generate a teacher model for classifying tool images.

[0075] Specifically, a training dataset for tool image classification is constructed; an initial image classification teacher model is constructed; the initial image classification teacher model is trained using the training dataset until the model converges to obtain the tool image classification teacher model.

[0076] In this embodiment, a training dataset for tool image classification is constructed. This dataset contains a large number of tool images and the corresponding tool category for each image. An initial neural network image classification teacher model, such as ResNet101, is built. The image classification model is then trained using the tool training dataset until it converges, resulting in the final tool classification teacher model.

[0077] Figure 5 This is a schematic block diagram of a tool image classification model compression device 300 provided in an embodiment of the present invention. Figure 5 As shown, corresponding to the above-described tool image classification model compression method, the present invention also provides a tool image classification model compression apparatus 300. This tool image classification model compression apparatus 300 includes a unit for performing the above-described tool image classification model compression method, and the apparatus can be configured in a server. Specifically, please refer to... Figure 5 The tool image classification model compression device 300 includes a similarity determination unit 302, a temperature setting unit 303, a weight allocation unit 306, and a distillation unit 307.

[0078] The similarity determination unit 302 is used to determine the similarity between each tool category and other tool categories based on the fully connected classification vector of the tool image classification teacher model; the temperature setting unit 303 is used to set a set of distillation temperatures; the weight allocation unit 306 is used to dynamically allocate the weights corresponding to each distillation temperature based on the similarity between the tool category of the input model and other tool categories; the distillation unit 307 is used to distill the tool image classification teacher model according to the weights and the distillation temperature to obtain the tool image classification student model.

[0079] The tool image classification model compression device 300 also includes: a first construction unit 304 and an input unit 305;

[0080] The first construction unit 304 is used to construct an initial tool image classification student model; the input unit 305 is used to select an image from the training dataset and input it into the initial tool image classification student model and the tool image classification teacher model respectively to obtain a first vector and a second vector.

[0081] In one embodiment, such as Figure 6 As shown, the distillation unit 307 includes a function construction subunit 3071 and an optimization subunit 3072.

[0082] Function construction subunit 3071 is used to construct a loss function based on the weights and the distillation temperature; wherein... Among them, soffmax(T) i p) represents the distillation temperature T i Calculate the softmax vector soffmax(T) of the second vector p output by the teacher model for classifying tool images. i ,q) represents the distillation temperature T i The softmax vector is calculated from the first vector q output by the initial tool image classification student model; KL is used to calculate the degree of dissimilarity between the two distributions; p k p refers to the second vector corresponding to image k in the training dataset; j q refers to the second vector corresponding to image j in the training dataset; j This refers to the first vector corresponding to image j in the training dataset; the optimization subunit 3072 is used to calculate the loss of the initial tool image classification student model using the loss function, and to optimize and update the parameters of the initial tool image classification student model using the stochastic gradient descent algorithm. The process of selecting an image from the training dataset and inputting it into the initial tool image classification student model and the tool image classification teacher model is repeated to obtain the first vector and the second vector, until the specified number of iterations is reached or the loss of the initial tool image classification student model tends to stabilize, so as to obtain the tool image classification student model.

[0083] In one embodiment, the similarity determination unit 302 is used to obtain the similarity between each tool category and other categories based on the classification vector of the fully connected layer of the tool image classification teacher model.

[0084] Figure 7 This is a schematic block diagram of a tool image classification model compression device 300 provided in another embodiment of the present invention. Figure 7 As shown, the tool image classification model compression device 300 in this embodiment is based on the above embodiment with the addition of a model generation unit 301.

[0085] Model generation unit 301 is used to generate a teacher model for tool image classification;

[0086] The model generation unit 301 includes: a dataset construction subunit for constructing a training dataset for tool image classification; a teacher model construction subunit for constructing an initial image classification teacher model; and a model training subunit for training the initial image classification teacher model using the training dataset until the model converges to obtain the tool image classification teacher model.

[0087] It should be noted that those skilled in the art can clearly understand that the specific implementation process of the above-mentioned tool image classification model compression device 300 and each unit can be referred to the corresponding description in the foregoing method embodiments. For the sake of convenience and brevity, it will not be repeated here.

[0088] The aforementioned tool image classification model compression device 300 can be implemented as a computer program, which can, for example, Figure 8 It runs on the computer device shown.

[0089] Please see Figure 8 , Figure 8 This is a schematic block diagram of a computer device provided in an embodiment of this application. The computer device 500 can be a server, wherein the server can be a standalone server or a server cluster composed of multiple servers.

[0090] See Figure 8 The computer device 500 includes a processor 502, a memory, and a network interface 505 connected via a system bus 501. The memory may include a non-volatile storage medium 503 and internal memory 504.

[0091] The non-volatile storage medium 503 may store an operating system 5031 and a computer program 5032. The computer program 5032 includes program instructions that, when executed, cause the processor 502 to perform a tool image classification model compression method.

[0092] The processor 502 provides computing and control capabilities to support the operation of the entire computer device 500.

[0093] The internal memory 504 provides an environment for the operation of the computer program 5032 in the non-volatile storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute a tool image classification model compression method.

[0094] This network interface 505 is used for network communication with other devices. Those skilled in the art will understand that... Figure 8The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device 500 to which the present application is applied. The specific computer device 500 may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0095] The processor 502 is used to run a computer program 5032 stored in the memory to perform the following steps:

[0096] The similarity between each knife category and other categories is determined based on the fully connected classification vector of the knife image classification teacher model; a set of distillation temperatures is set; weights corresponding to each distillation temperature are dynamically assigned based on the similarity between the input model's knife category and other knife categories; the knife image classification teacher model is distilled based on the weights and the distillation temperatures to obtain the knife image classification student model.

[0097] In one embodiment, when the processor 502 implements the step of determining the similarity between each knife category and other categories based on the fully connected classification vector of the knife image classification teacher model, the specific steps are as follows:

[0098] The similarity between each knife category and other categories is obtained from the classification vectors of the fully connected layer of the knife image classification teacher model.

[0099] The similarity between each tool category and other categories is obtained by averaging the similarity of the category most similar to that tool category and the average similarity; where the average similarity refers to the mean similarity of the classification vectors of each tool category and other tool categories, and the similarity of the classification vectors is the cosine of the angle between the two vectors.

[0100] In one embodiment, before implementing the step of determining the similarity between each tool category and other categories based on the fully connected classification vector of the tool image classification teacher model, the processor 502 further implements the following steps:

[0101] Generate a teacher model for classifying knife images.

[0102] In one embodiment, when implementing the step of generating the tool image classification teacher model, the processor 502 specifically implements the following steps:

[0103] Construct a training dataset for tool image classification; construct an initial image classification teacher model; train the initial image classification teacher model using the training dataset until the model converges to obtain the tool image classification teacher model.

[0104] In one embodiment, before implementing the step of dynamically assigning weights to each distillation temperature based on the similarity between the tool category of the input model and other tool categories, the processor 502 further implements the following steps:

[0105] Construct an initial student model for tool image classification; select an image from the training dataset and input it into both the initial student model and the teacher model for tool image classification to obtain the first vector and the second vector.

[0106] The weight corresponding to each distillation temperature is as follows: λ2=sim k λ3 = 1, λ4 = 1 - sim k , Where λ1 is the weight corresponding to the first distillation temperature; λ2 is the weight corresponding to the second distillation temperature; λ3 is the weight corresponding to the third distillation temperature; λ4 is the weight corresponding to the fourth distillation temperature; and λ5 is the weight corresponding to the fifth distillation temperature; sim k It represents the similarity between the knife category and other categories.

[0107] In one embodiment, when the processor 502 performs the step of distilling the knife image classification teacher model according to the weights and the distillation temperature to obtain the knife image classification student model, the processor 502 specifically implements the following steps:

[0108] A loss function is constructed based on the weights and the distillation temperature; wherein... Among them, softmax(T) i p) represents the distillation temperature T i Calculate the softmax vector for the second vector p output by the teacher model for classifying tool images; softmax(T) i ,q) represents the distillation temperature T i The softmax vector is calculated from the first vector q output by the initial tool image classification student model; KL is used to calculate the degree of dissimilarity between the two distributions; p k p refers to the second vector corresponding to image k in the training dataset; j q refers to the second vector corresponding to image j in the training dataset; jThis refers to the first vector corresponding to image j in the training dataset. The loss function is used to calculate the loss of the initial tool image classification student model, and the parameters of the initial tool image classification student model are optimized and updated using the stochastic gradient descent algorithm. This process is repeated, selecting an image from the training dataset and inputting it into both the initial tool image classification student model and the tool image classification teacher model to obtain the first and second vectors, until a specified number of iterations is reached or the loss of the initial tool image classification student model tends to stabilize, thus obtaining the tool image classification student model. It should be understood that in this embodiment, the processor 502 can be a Central Processing Unit (CPU), or it can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.

[0109] It will be understood by those skilled in the art that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program includes program instructions and can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiments of the above methods.

[0110] Therefore, the present invention also provides a storage medium. This storage medium can be a computer-readable storage medium. The storage medium stores a computer program, wherein when executed by a processor, the computer program causes the processor to perform the following steps:

[0111] The similarity between each knife category and other categories is determined based on the fully connected classification vector of the knife image classification teacher model; a set of distillation temperatures is set; weights corresponding to each distillation temperature are dynamically assigned based on the similarity between the input model's knife category and other knife categories; the knife image classification teacher model is distilled based on the weights and the distillation temperatures to obtain the knife image classification student model.

[0112] In one embodiment, when the processor executes the computer program to implement the step of determining the similarity between each knife category and other categories based on the fully connected classification vector of the knife image classification teacher model, it specifically implements the following steps:

[0113] The similarity between each knife category and other categories is obtained from the classification vectors of the fully connected layer of the knife image classification teacher model.

[0114] The similarity between each tool category and other categories is obtained by averaging the similarity of the category most similar to that tool category and the average similarity; where the average similarity refers to the mean similarity of the classification vectors of each tool category and other tool categories, and the similarity of the classification vectors is the cosine of the angle between the two vectors.

[0115] In one embodiment, before executing the computer program to perform the step of determining the similarity between each knife category and other categories based on the fully connected classification vector of the knife image classification teacher model, the processor further performs the following steps:

[0116] Generate a teacher model for classifying knife images.

[0117] In one embodiment, when the processor executes the computer program to implement the step of generating the knife image classification teacher model, it specifically implements the following steps:

[0118] Construct a training dataset for tool image classification; construct an initial image classification teacher model; train the initial image classification teacher model using the training dataset until the model converges to obtain the tool image classification teacher model.

[0119] In one embodiment, after executing the computer program to implement the step of dynamically assigning weights to each distillation temperature based on the similarity between the tool category of the input model and other tool categories, the processor further implements the following steps:

[0120] Construct an initial student model for tool image classification; select an image from the training dataset and input it into both the initial student model and the teacher model for tool image classification to obtain the first vector and the second vector.

[0121] The weight corresponding to each distillation temperature is as follows: λ2=sim k λ3 = 1, λ4 = 1 - sim k , Where λ1 is the weight corresponding to the first distillation temperature; λ2 is the weight corresponding to the second distillation temperature; λ3 is the weight corresponding to the third distillation temperature; λ4 is the weight corresponding to the fourth distillation temperature; and λ5 is the weight corresponding to the fifth distillation temperature; sim k It represents the similarity between the knife category and other categories.

[0122] In one embodiment, when the processor executes the computer program to perform the step of distilling the knife image classification teacher model according to the weights and the distillation temperature to obtain the knife image classification student model, the processor specifically implements the following steps:

[0123] A loss function is constructed based on the weights and the distillation temperature; wherein... Among them, softmax(T) i p) represents the distillation temperature T i Calculate the softmax vector for the second vector p output by the teacher model for classifying tool images; softmax(T) i q) represents the distillation temperature T i The softmax vector is calculated from the first vector q output by the initial tool image classification student model; KL is used to calculate the degree of dissimilarity between the two distributions; p k p refers to the second vector corresponding to image k in the training dataset; j q refers to the second vector corresponding to image j in the training dataset; j This refers to the first vector corresponding to image j in the training dataset; the loss of the initial tool image classification student model is calculated using the loss function, and the parameters of the initial tool image classification student model are optimized and updated using the stochastic gradient descent algorithm. The process of selecting an image from the training dataset and inputting it into the initial tool image classification student model and the tool image classification teacher model is repeated to obtain the first vector and the second vector, until the specified number of iterations is reached or the loss of the initial tool image classification student model tends to stabilize, thus obtaining the tool image classification student model.

[0124] The storage medium can be any computer-readable storage medium capable of storing program code, such as a USB flash drive, portable hard drive, read-only memory (ROM), magnetic disk, or optical disk.

[0125] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0126] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For example, the division of each unit is merely a logical functional division, and there may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.

[0127] The steps in the method of this invention can be adjusted, merged, or reduced in order according to actual needs. The units in the device of this invention can be merged, divided, or reduced according to actual needs. Furthermore, the functional units in the various embodiments of this invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0128] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.

[0129] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A tool image classification model compression method, characterized in that, The method comprises the steps of: determining the similarity of each tool category to other categories according to the full connection classification vector of the tool image classification teacher model; setting a set of distillation temperatures; dynamically assigning a weight corresponding to each of the distillation temperatures according to the similarity of the input model's tool category to other tool categories; distilling the tool image classification teacher model according to the weight and the distillation temperature to obtain a tool image classification student model; the weight corresponding to each of the distillation temperatures is: wherein, is a weight corresponding to the first distillation temperature; is a weight corresponding to the second distillation temperature; is a weight corresponding to the third distillation temperature; is a weight corresponding to the fourth distillation temperature; is a weight corresponding to the fifth distillation temperature; is a similarity of the tool class to other classes; the distillation of the tool image classification teacher model according to the weight and the distillation temperature to obtain a tool image classification student model comprises: constructing a loss function according to the weight and the distillation temperature; wherein, ; wherein, denotes the distillation temperature computes a softmax vector for the second vector p output by the tool image classification teacher model; denotes the distillation temperature computes a softmax vector for the first vector computes a softmax vector; KL is used to compute the dissimilarity of two distributions; ; ; denotes the second vector corresponding to image k in the training data set; denotes the second vector corresponding to image j in the training data set; denotes the first vector corresponding to image j in the training data set; calculating the loss of the initial tool image classification student model using the loss function, and optimizing and updating the parameters of the initial tool image classification student model using a stochastic gradient descent algorithm, and repeatedly executing the steps of selecting an image from the training data set, inputting the image into the initial tool image classification student model and the tool image classification teacher model respectively to obtain a first vector and a second vector, until a specified number of iterations is reached or the loss of the initial tool image classification student model tends to be stable, to obtain a tool image classification student model.

2. The tool image classification model compression method of claim 1, wherein, The similarity of each tool category to other categories is determined according to the full connection classification vector of the tool image classification teacher model, which comprises: obtaining the similarity of each tool category to other categories according to the classification vector of the full connection layer of the tool image classification teacher model.

3. The tool image classification model compression method of claim 2, wherein, The similarity of each tool category to other categories is obtained by averaging the similarity of the closest category to the tool category and the average similarity; wherein the average similarity refers to the average of the classification vectors of each tool category to other tool categories, wherein the similarity of the classification vector is the cosine value of the included angle of two vectors.

4. The tool image classification model compression method of claim 1, wherein, Before determining the similarity of each tool category to other categories according to the full connection classification vector of the tool image classification teacher model, the method comprises the steps of: generating a tool image classification teacher model; wherein the generation of the tool image classification teacher model comprises: constructing a training data set for tool image classification; constructing an initial image classification teacher model; training the initial image classification teacher model using the training data set until the model converges to obtain a tool image classification teacher model.

5. The tool image classification model compression method of claim 1, wherein, Before dynamically assigning a weight corresponding to each of the distillation temperatures according to the similarity of the input model's tool category to other tool categories, the method further comprises the steps of: constructing an initial tool image classification student model; selecting an image from the training data set and inputting the image into the initial tool image classification student model and the tool image classification teacher model respectively to obtain a first vector and a second vector.

6. The tool image classification model compression apparatus, characterized by, The method comprises the steps of: a similarity determination unit for determining the similarity of each tool category to other categories according to the full connection classification vector of the tool image classification teacher model; a temperature setting unit for setting a set of distillation temperatures; a weight assignment unit for dynamically assigning a weight corresponding to each of the distillation temperatures according to the similarity of the input model's tool category to other tool categories; a distillation unit, configured to distill the tool image classification teacher model according to the weights and the distillation temperatures to obtain a tool image classification student model; a weight corresponding to each of the distillation temperatures is: wherein, is the weight corresponding to the first distillation temperature; is the weight corresponding to the second distillation temperature; is the weight corresponding to the third distillation temperature; is the weight corresponding to the fourth distillation temperature; is the weight corresponding to the fifth distillation temperature; is the similarity of the tool class to other classes; the distillation unit comprises a function construction subunit and an optimization subunit; the function construction subunit is configured to construct a loss function according to the weights and the distillation temperatures; wherein, ; wherein, represents the distillation temperature calculating a softmax vector for the second vector p output by the tool image classification teacher model; represents the distillation temperature calculating a softmax vector for the first vector calculating a softmax vector; KL is used to calculate the degree of dissimilarity of two distributions; ; ; refers to the second vector corresponding to the image k in the training data set; refers to the second vector corresponding to the image j in the training data set; refers to the first vector corresponding to the image j in the training data set; an optimization subunit is configured to calculate the loss of the initial tool image classification student model by using the loss function, and update and optimize the parameters of the initial tool image classification student model by using a stochastic gradient descent algorithm; the process of selecting an image from the training data set, inputting the image into the initial tool image classification student model and the tool image classification teacher model respectively to obtain the first vector and the second vector is repeatedly executed until a specified number of iterations is reached or the loss of the initial tool image classification student model tends to be stable, so as to obtain the tool image classification student model.

7. A computer device, characterized by the computer device comprises a memory and a processor, the memory stores a computer program, and the processor implements the method in any one of claims 1 to 5 when executing the computer program.

8. A storage medium, characterized by The storage medium stores a computer program, and the computer program is executed by the processor to implement the method in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Knowledge distillation method and system based on multi-student discussion

    CN114049513A

  • Target key point detection method based on cascade temperature control distillation

    CN114898086A