Model training method, device, electronic device and computer-readable storage medium

By using the distillation-while-training approach, the student model simultaneously learns the logits and feature information of the teacher model, solving the problem of improving the training accuracy of the target detection model and achieving performance optimization of the student model.

CN116486204BActive Publication Date: 2025-09-26BEIJING SHANMA ZHIJIAN TECH CO LTD +2
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310444554.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-04-23
Publication Date
2025-09-26
Estimated Expiration
2043-04-23

AI Technical Summary

Technical Problem

In the target detection scenario, existing technologies find it difficult to effectively combine the two training modes of logits distillation and feature distillation to improve the training accuracy of the target detection model.

Method used

By adopting the method of training and distillation, the student model simultaneously learns the logits information and feature information of the teacher model, and optimizes the training process of the student model by constructing a loss function.

Benefits of technology

It enriches the information content of the student model and improves the accuracy of the student model, making its performance better than the teacher model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116486204B_ABST
    Figure CN116486204B_ABST
Patent Text Reader

Abstract

The embodiments of the present application provide a model training method, device, electronic device and computer-readable storage medium, the method comprising: obtaining an image sample; obtaining a first image feature, a first positioning feature and a first classification feature of the image sample using a teacher model; obtaining a second image feature, a second positioning feature and a second classification feature of the image sample using a student model; constructing a loss function based on the first image feature, the first positioning feature, the first classification feature, the second image feature, the second positioning feature and the second classification feature; and training the student model using a training-while-distillation method according to the loss function. In the present application, the student model can simultaneously learn the teacher model's logits information and feature information, enriching the amount of information of the student model, and the logits information and feature information are learned simultaneously, which can complement and promote each other, thereby optimizing the training of the student model and improving the accuracy of the student model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of machine learning technology, and in particular to a model training method, device, electronic device, and computer-readable storage medium. Background Art

[0002] Knowledge distillation transfers knowledge from one network to another, either homogeneous or heterogeneous. This involves first training a teacher model, then using the teacher model's output and the true labels of the data to train a student model. Knowledge distillation can be used to transform a large network into a smaller one while retaining performance close to that of the larger network, thereby addressing the issue of limited hardware for model deployment at the edge.

[0003] In the target detection scenario, target classification and target localization need to be completed simultaneously. The feature map is equivalent to the trunk, which contains all the information of the leaves. The downstream tasks are equivalent to the leaves. Logits distillation can directly transfer the information of the teacher leaves to the student, and feature distillation can transfer the information of the teacher trunk to the student. However, because the trunk information is high-dimensional abstract information, it is different from the information directly transferred by logits distillation. Based on this, we hope to apply these two training modes to target detection training to improve the training accuracy of the target detection model. Summary of the Invention

[0004] Without solving the above technical problems, the embodiments of the present application provide a model training method, device, electronic device and computer-readable storage medium.

[0005] In a first aspect of the present application, a model training method is provided, comprising:

[0006] Get image samples;

[0007] Obtaining a first image feature, a first positioning feature, and a first classification feature of the image sample using a teacher model;

[0008] Obtaining a second image feature, a second positioning feature, and a second classification feature of the image sample using a student model;

[0009] constructing a loss function based on the first image feature, the first positioning feature, the first classification feature, the second image feature, the second positioning feature, and the second classification feature;

[0010] According to the loss function, the student model is trained by adopting a training-while-distillation method.

[0011] In one possible implementation, obtaining the first image feature, the first positioning feature, and the first classification feature of the image sample using the teacher model includes:

[0012] The image sample is input into the teacher model, and the feature output by the FPN of the teacher model is obtained as the first image feature, the feature output by the positioning head of the teacher model is obtained as the first positioning feature, and the feature output by the classification head of the teacher model is obtained as the first classification feature.

[0013] In a possible implementation, obtaining the second image feature, the second positioning feature, and the second classification feature of the image sample using the student model includes:

[0014] The image sample is input into the student model to obtain the feature output by the FPN of the student model as the second image feature, the feature output by the positioning head of the student model as the second positioning feature, and the feature output by the classification head of the student model as the second classification feature.

[0015] In a possible implementation, constructing a loss function based on the first image feature, the first positioning feature, the first classification feature, the second image feature, the second positioning feature, and the second classification feature includes:

[0016] According to the first image feature and the second image feature, the l2 loss function is used to obtain a first loss function:

[0017] ,

[0018] Among them, F t is the first image feature, F s is the second image feature;

[0019] According to the first positioning feature and the second positioning feature, a cross entropy loss function is used to obtain a second loss function:

[0020] ,

[0021] in, is the first positioning feature, is the second positioning feature;

[0022] According to the first classification feature and the second classification feature, the cross entropy loss function is used to obtain the third loss function:

[0023] ,

[0024] in, is the first classification feature, It is the second classification feature;

[0025] According to the first loss function, the second loss function and the third loss function, the loss function is obtained:

[0026] ,

[0027] in, is the positioning loss function during student model training, The classification loss function when training the student model.

[0028] In a second aspect of the present application, a model training device is provided, comprising:

[0029] A sample acquisition module, used to acquire image samples;

[0030] A first training module is used to obtain a first image feature, a first positioning feature, and a first classification feature of the image sample using a teacher model;

[0031] A second training module is used to obtain a second image feature, a second positioning feature, and a second classification feature of the image sample using a student model;

[0032] a third training module, configured to construct a loss function based on the first image feature, the first positioning feature, the first classification feature, the second image feature, the second positioning feature, and the second classification feature;

[0033] The fourth training module is used to train the student model by adopting a training-while-distillation method according to the loss function.

[0034] In a possible implementation, the first training module is specifically configured to:

[0035] The image sample is input into the teacher model, and the feature output by the FPN of the teacher model is obtained as the first image feature, the feature output by the positioning head of the teacher model is obtained as the first positioning feature, and the feature output by the classification head of the teacher model is obtained as the first classification feature.

[0036] In a possible implementation, the second training module is specifically configured to:

[0037] The image sample is input into the student model to obtain the feature output by the FPN of the student model as the second image feature, the feature output by the positioning head of the student model as the second positioning feature, and the feature output by the classification head of the student model as the second classification feature.

[0038] In a possible implementation, the third training module is specifically configured to:

[0039] According to the first image feature and the second image feature, the l2 loss function is used to obtain a first loss function:

[0040] ,

[0041] Among them, F t is the first image feature, F s is the second image feature;

[0042] According to the first positioning feature and the second positioning feature, a cross entropy loss function is used to obtain a second loss function:

[0043] ,

[0044] in, is the first positioning feature, is the second positioning feature;

[0045] According to the first classification feature and the second classification feature, the cross entropy loss function is used to obtain the third loss function:

[0046] ,

[0047] in, is the first classification feature, It is the second classification feature;

[0048] According to the first loss function, the second loss function and the third loss function, the loss function is obtained:

[0049] ,

[0050] in, is the positioning loss function during student model training, The classification loss function when training the student model.

[0051] In a third aspect of the present application, an electronic device is provided, comprising a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the method as described in any one of the first aspects is implemented.

[0052] In a fourth aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the method as described in any one of the first aspects is implemented.

[0053] In the model training method, device, electronic device and computer-readable storage medium provided in the embodiments of the present application, an image sample is obtained, a first image feature, a first positioning feature and a first classification feature of the image sample are obtained using a teacher model, and a second image feature, a second positioning feature and a second classification feature of the image sample are obtained using a student model. A loss function is constructed based on the first image feature, the first positioning feature, the first classification feature, the second image feature, the second positioning feature and the second classification feature. According to the loss function, the student model is trained by a training-while-distillation method. It can be seen that the student model in the present application can simultaneously learn the teacher model logits information and feature information, enriching the amount of information of the student model, and the logits information and feature information are learned at the same time, which can complement and promote each other, thereby optimizing the training of the student model and improving the accuracy of the student model. At the same time, the student model is trained by a training-while-distillation method, and the training loss of the student model is optimized while optimizing the distillation loss, so that the training and distillation complement each other, which can improve the upper limit of the student model and make the student model greater than or equal to the teacher model.

[0054] It should be understood that the contents described in the Summary of the Invention are not intended to limit the key or important features of the embodiments of the present application, nor are they intended to limit the scope of the present application. Other features of the present application will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] The above and other features, advantages and aspects of the embodiments of the present application will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, wherein:

[0056] Figure 1 A flow chart of a model training method according to an embodiment of the present application is shown;

[0057] Figure 2 shows a structural diagram of a teacher model and a student model according to an embodiment of the present application;

[0058] Figure 3 A schematic diagram of a model training process according to an embodiment of the present application is shown;

[0059] Figure 4 A block diagram of a model training device according to an embodiment of the present application is shown;

[0060] Figure 5 A structural diagram of an electronic device according to an embodiment of the present application is shown. Implementation Method

[0061] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.

[0062] In recent years, deep learning has developed rapidly, being applied to computer vision, speech recognition, and natural language processing. As data volumes accumulate and scenarios become more complex, more complex model structures are often used. This not only requires greater computing power but also poses storage challenges. This has led to the development of technical solutions such as model optimization, compression, pruning, and distillation, with model distillation being a common one.

[0063] Currently, the mainstream distillation methods include logits distillation and feature distillation. Logits distillation enables the student model to directly learn the final result distribution and is mainly used in classification model training. Feature distillation enables the student model to directly learn the feature distribution of the teacher model, thereby obtaining more information for training and improving the student model's results. This distillation method has been widely studied in classification and detection model training.

[0064] In the target detection scenario, target classification and target positioning need to be completed simultaneously. The feature map is equivalent to the trunk, which contains all the information in the leaves. The downstream tasks are equivalent to the leaves. Logits distillation can directly transfer the information of the teacher model leaves to the student model, and feature distillation can transfer the information of the teacher model trunk to the student model. However, since the information of the trunk is high-dimensional abstract information, it is different from the information directly transferred by logits distillation. Based on this, this application hopes to apply the two training modes to target detection training to improve the training accuracy of the target detection model.

[0065] Therefore, the embodiment of the present application provides a model training method that can simultaneously learn the logits information and feature information of the teacher model, enriching the amount of information of the student model. Moreover, the logits information and feature information are learned simultaneously, which can complement and promote each other, thereby optimizing the training of the student model and improving the accuracy of the student model.

[0066] The model training method provided in the embodiments of the present application can be executed by an electronic device, which can be a server or a terminal device. The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. The terminal device can be a smartphone, tablet computer, laptop computer, desktop computer, etc., but is not limited thereto.

[0067] Figure 1 1 shows a flow chart of a model training method according to an embodiment of the present application. In some embodiments, Figure 1 The model training method shown can be executed by the above electronic device. Figure 1 As shown, the method includes steps 101, 102, 103, 104 and 105, wherein:

[0068] Step 101: Obtain an image sample.

[0069] In the embodiment of the present application, the image sample may be a picture or a video. If the image sample is a video, it needs to be processed to obtain a video frame as the image sample.

[0070] The pictures or videos can be taken in real time by a camera, or can be stored historical pictures or videos, or can be online materials. Therefore, the pictures or videos can be obtained in the following ways: they can be taken by a camera, obtained from a storage medium, or downloaded from the Internet.

[0071] After acquiring an image or video frame, it needs to be annotated, for example, by labeling the object's category and location. The annotated image or video frame can be used as an image sample. It should be noted that annotating an image or video frame can be done directly on the image or video frame or outside of it (i.e., the image or video frame and the annotation content are two separate files).

[0072] Step 102: Use the teacher model to obtain a first image feature, a first positioning feature, and a first classification feature of the image sample.

[0073] It should be noted that since the model training method provided in the embodiment of the present application is applied to the field of target detection, both the teacher model and the student model are target detection models.

[0074] In some embodiments, see Figure 2 The teacher model can include a backbone network part, a feature pyramid part, and a detection head part. The feature pyramid part is used to extract image features of image samples, and the detection head part is used to extract positioning features and classification features of image samples.

[0075] See also Figure 3 , the image sample is input into the teacher model, and the output feature of the feature pyramid part can be used as the first image feature, the feature output by the positioning head can be used as the first positioning feature, and the feature output by the classification head can be used as the first classification feature.

[0076] The first image feature, the first positioning feature, and the first classification feature are introduced below.

[0077] First image feature:

[0078] After the image sample is processed by the backbone network, a feature map is obtained. The feature map is input into the feature pyramid for feature extraction, and the image features of the feature map can be obtained: b*w*h*c, where b represents the number of images, w represents the row dimension of the image, h represents the column dimension of the image, and c represents the number of channels of the image.

[0079] The image features of the feature map: b*w*h*c, are used as the first image features.

[0080] First positioning feature:

[0081] The output of the positioning head of the teacher model is the coordinate corner point and the width and height of the prediction box (i.e. xywh) or the offset from the center point of the prediction box to the four sides (i.e. ltbr).

[0082] In one feasible approach, each of the four offsets ltbr output by the positioning head of the teacher model is mapped into a probability distribution of n categories through matrix operations, for a total of 4*n bbox logits distributions. Bbox logits distillation can be achieved by treating the logits distribution of each offset as an independent class logits distillation.

[0083] The matrix operation uses the following formula:

[0084] ,

[0085] Where f is the positioning information with a dimension of (b*w*h)*4, and k is a matrix with a dimension of 4*(4*n) that satisfies a specific distribution (such as normal distribution or Dirichlet distribution).

[0086] The positioning information of (b*w*h)*4 is converted into the positioning information of (b*w*h)*(4*n) through matrix multiplication as the first positioning feature.

[0087] First classification characteristics:

[0088] The classification head of the teacher model outputs a logits z, which is transformed into a probability distribution through a softmax transformation with a temperature coefficient t. , as the first classification feature.

[0089] Step 103: Use the student model to obtain a second image feature, a second positioning feature, and a second classification feature of the image sample.

[0090] Continue to see Figure 2 In the embodiment of the present application, the structure of the student model is the same as that of the teacher model. The method of using the student model to obtain the second image feature, the second positioning feature and the second classification feature of the image sample is the same as the method of obtaining the first image feature, the first positioning feature and the first classification feature mentioned above, and will not be repeated here.

[0091] Step 104 : constructing a loss function based on the first image feature, the first positioning feature, the first classification feature, the second image feature, the second positioning feature, and the second classification feature.

[0092] In an embodiment of the present application, the loss function includes a first loss function composed of a first image feature and a second image feature, a second loss function composed of a first positioning feature and a second positioning feature, a third loss function composed of a first classification feature and a second classification feature, a positioning loss function during student model training, and a classification loss function during student model training.

[0093] It should be noted that the positioning loss function and the classification loss function during the student model training are not described in detail in the embodiment of this application. The following describes the construction method of the first loss function, the second loss function and the third loss function.

[0094] In one achievable manner, based on the first image feature and the second image feature, an l2 loss function is used to construct a first loss function as follows:

[0095] ,

[0096] Among them, F t is the first image feature, F s is the second image feature.

[0097] In one possible implementation, a cross entropy loss function is used according to the first positioning feature and the second positioning feature to obtain a second loss function:

[0098] ,

[0099] in, is the first positioning feature, It is the second positioning feature.

[0100] In one possible implementation, a cross entropy loss function is used based on the first classification feature and the second classification feature to obtain a third loss function:

[0101] ,

[0102] in, is the first classification feature, It is the second classification feature.

[0103] Therefore, the loss function is as follows:

[0104] ,

[0105] in, is the positioning loss function during student model training, The classification loss function when training the student model.

[0106] Step 105: Train the student model using a training-while-distillation method based on the loss function.

[0107] In the examples of this application, see Figure 3 , sample images are input into the teacher model and student model respectively. Since the sample images are labeled, the student model can autonomously learn based on the sample images. In addition, while the student model is autonomously training, knowledge distillation is performed by combining the first image feature output by the feature pyramid of the teacher model, the first positioning feature output by the positioning head of the teacher model, the first classification feature output by the classification head of the teacher model, the second image feature output by the feature pyramid of the student model, the second positioning feature output by the positioning head of the student model, and the second classification feature output by the classification head of the student model. This allows training and distillation to complement each other, improving the upper limit of the student model and making the student model equal to or greater than the teacher model.

[0108] According to the embodiments of the present application, the student model can simultaneously learn the teacher model's logits information and feature information, enriching the student model's information content. Furthermore, the simultaneous learning of logits information and feature information can complement and promote each other, thereby optimizing the student model's training. At the same time, the student model is trained using a training-while-distillation approach. While optimizing the distillation loss, the student model's training loss is also optimized, allowing training and distillation to complement each other, raising the student model's upper limit and making the student model equal to or greater than the teacher model.

[0109] It should be noted that for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that this application is not limited by the order of the actions described, because according to this application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all optional embodiments, and the actions and modules involved are not necessarily required by this application.

[0110] The above is an introduction to the method embodiment. The following is a device embodiment to further illustrate the solution described in this application.

[0111] Figure 4 FIG1 shows a block diagram of a model training device according to an embodiment of the present application. In some embodiments, the device may be included in the above-mentioned electronic device or implemented as the above-mentioned electronic device. Figure 4 As shown, the apparatus includes a sample training module 401, a first training module 402, a second training module 403, a third training module 404, and a fourth training module 405, wherein:

[0112] The sample acquisition module 401 is used to acquire image samples.

[0113] The first training module 402 is used to obtain the first image feature, the first positioning feature and the first classification feature of the image sample by using the teacher model.

[0114] The second training module 403 is used to obtain the second image feature, the second positioning feature and the second classification feature of the image sample by using the student model.

[0115] The third training module 404 is configured to construct a loss function based on the first image feature, the first positioning feature, the first classification feature, the second image feature, the second positioning feature, and the second classification feature.

[0116] The fourth training module 405 is used to train the student model using a training-while-distillation method based on the loss function.

[0117] In some embodiments, the first training module 402 is specifically used to: input the image sample into the teacher model, obtain the features output by the FPN of the teacher model as the first image features, the features output by the positioning head of the teacher model as the first positioning features, and the features output by the classification head of the teacher model as the first classification features.

[0118] In some embodiments, the second training module 403 is specifically used to: input the image sample into the student model, obtain the features output by the FPN of the student model as the second image features, the features output by the positioning head of the student model as the second positioning features, and the features output by the classification head of the student model as the second classification features.

[0119] In some embodiments, the third training module 404 is specifically configured to:

[0120] According to the first image feature and the second image feature, the l2 loss function is used to obtain a first loss function:

[0121] ,

[0122] Among them, F t is the first image feature, F s is the second image feature;

[0123] According to the first positioning feature and the second positioning feature, a cross entropy loss function is used to obtain a second loss function:

[0124] ,

[0125] in, is the first positioning feature, is the second positioning feature;

[0126] According to the first classification feature and the second classification feature, the cross entropy loss function is used to obtain the third loss function:

[0127] ,

[0128] in, is the first classification feature, It is the second classification feature;

[0129] According to the first loss function, the second loss function and the third loss function, the loss function is obtained:

[0130] ,

[0131] in, is the positioning loss function during student model training, The classification loss function when training the student model.

[0132] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the described module can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0133] An electronic device is provided in an embodiment of the present application, such as Figure 5 As shown, Figure 5 The electronic device 500 shown includes a processor 501 and a memory 503. The processor 501 and the memory 503 are connected, for example, via a bus 502. Optionally, the electronic device 500 may further include a transceiver 504. It should be noted that in actual applications, the number of transceivers 504 is not limited to one, and the structure of the electronic device 500 does not constitute a limitation on the embodiments of the present application.

[0134] Processor 501 can be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 501 can also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0135] Bus 502 may include a path for transmitting information between the above components. Bus 502 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. Bus 502 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the diagram, but this does not mean that there is only one bus or one type of bus.

[0136] The memory 503 may be a ROM (Read Only Memory) or other type of static storage device that can store static information and instructions, a RAM (Random Access Memory) or other type of dynamic storage device that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compact discs, laser discs, optical discs, digital versatile discs, Blu-ray discs, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto.

[0137] The memory 503 is used to store application code for executing the solution of the present application, and the execution is controlled by the processor 501. The processor 501 is used to execute the application code stored in the memory 503 to implement the content shown in the above method embodiment.

[0138] Among them, electronic devices include but are not limited to: mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The electronic device shown is merely an example and should not limit the functions and scope of use of the embodiments of the present application.

[0139] An embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer-readable storage medium is run on a computer, the computer can execute the corresponding contents of the aforementioned method embodiment.

[0140] It should be understood that although the steps in the flowcharts of the accompanying drawings are shown in sequence as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some of the steps in the flowcharts of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.

[0141] The above description is only part of the implementation methods of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A model training method, characterized in that: include: Get image samples; Obtaining a first image feature, a first positioning feature, and a first classification feature of the image sample using a teacher model; Obtaining a second image feature, a second positioning feature, and a second classification feature of the image sample using a student model; constructing a loss function based on the first image feature, the first positioning feature, the first classification feature, the second image feature, the second positioning feature, and the second classification feature; According to the loss function, the student model is trained by adopting a training-while-distillation method; Obtaining a first image feature, a first positioning feature, and a first classification feature of the image sample using the teacher model, including: inputting the image sample into the teacher model, obtaining a feature output by an FPN of the teacher model as the first image feature, a feature output by a positioning head of the teacher model as the first positioning feature, and a feature output by a classification head of the teacher model as the first classification feature; Obtaining a second image feature, a second positioning feature, and a second classification feature of the image sample using the student model, including: inputting the image sample into the student model, obtaining a feature output by an FPN of the student model as the second image feature, a feature output by a positioning head of the student model as the second positioning feature, and a feature output by a classification head of the student model as the second classification feature; Constructing a loss function based on the first image feature, the first positioning feature, the first classification feature, the second image feature, the second positioning feature, and the second classification feature, including: According to the first image feature and the second image feature, Loss function, get the first loss function: , in, is the first image feature, is the second image feature; According to the first positioning feature and the second positioning feature, a cross entropy loss function is used to obtain a second loss function: , in, is the first positioning feature, is the second positioning feature; According to the first classification feature and the second classification feature, the cross entropy loss function is used to obtain the third loss function: , in, is the first classification feature, It is the second classification feature; According to the first loss function, the second loss function and the third loss function, the loss function is obtained: , in, is the positioning loss function during student model training, The classification loss function when training the student model.

2. A model training device, characterized in that: include: A sample acquisition module, used to acquire image samples; A first training module is used to obtain a first image feature, a first positioning feature, and a first classification feature of the image sample using a teacher model; A second training module is used to obtain a second image feature, a second positioning feature, and a second classification feature of the image sample using a student model; a third training module, configured to construct a loss function based on the first image feature, the first positioning feature, the first classification feature, the second image feature, the second positioning feature, and the second classification feature; A fourth training module is used to train the student model using a training-while-distillation method according to the loss function; The first training module is specifically configured to: input the image sample into the teacher model, obtain the feature output by the FPN of the teacher model as the first image feature, the feature output by the positioning head of the teacher model as the first positioning feature, and the feature output by the classification head of the teacher model as the first classification feature; The second training module is specifically configured to: input the image sample into the student model, obtain the feature output by the FPN of the student model as the second image feature, the feature output by the positioning head of the student model as the second positioning feature, and the feature output by the classification head of the student model as the second classification feature; The third training module is specifically used for: According to the first image feature and the second image feature, Loss function, get the first loss function: , in, is the first image feature, is the second image feature; According to the first positioning feature and the second positioning feature, a cross entropy loss function is used to obtain a second loss function: , in, is the first positioning feature, is the second positioning feature; According to the first classification feature and the second classification feature, the cross entropy loss function is used to obtain the third loss function: , in, is the first classification feature, It is the second classification feature; According to the first loss function, the second loss function and the third loss function, the loss function is obtained: , in, is the positioning loss function during student model training, The classification loss function when training the student model.

3. An electronic device comprising a memory and a processor, wherein a computer program is stored in the memory, wherein: When the processor executes the computer program, the method according to claim 1 is implemented.

4. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to claim 1 is implemented.

Citation Information

Patent Citations

  • Image recognition model training method, device and equipment and storage medium

    CN111639710A

  • Method and apparatus for training student model for image processing

    WO2022077646A1