Relational self-distillation method, device, system and storage medium

By using the student model to perform self-distillation using its own historical intra-class and inter-class relationships, it solves the problem that existing technologies fail to model high-level semantic correlation relationships, achieving more efficient network performance and saving computing resources.

CN113762331BActive Publication Date: 2024-09-10FORCE POLYMERIZATION (CHONGQING) INFORMATION TECHNOLOGY CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202110805977.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-07-16
Publication Date
2024-09-10
Estimated Expiration
2041-07-16

AI Technical Summary

Technical Problem

Existing knowledge distillation methods fail to effectively model relationships at the classification level related to high-level semantics. They are limited to sample granularity and do not involve relationship modeling of high-level semantics.

Method used

A relational self-distillation method is proposed. The student model performs self-distillation through its own accumulated historical intra-class and/or inter-class relationships, and uses historical and current intra-class and/or inter-class relationships to perform self-distillation to achieve correlation with high-level semantics. Relationship modeling at the classification level.

Benefits of technology

It achieves superior network performance, reduces the consumption of computing resources on processing devices, and omits complex teacher models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113762331B
    Figure CN113762331B
Patent Text Reader

Abstract

The embodiment of the present invention provides a relational self-distillation method, device, system and storage medium. The method includes: obtaining N i sample images and corresponding annotation data; input the image into the student model to obtain image classification information; when i ≥ preset threshold: for K i For each category in the categories, determine the current classification information based on the classification information corresponding to all sample images included; for each category pair in at least one category pair, calculate the distance between the current classification information corresponding to the two categories to obtain the current intra-class / inter-class distance information; obtain the historical intra-class / inter-class distance information of each category pair in at least one category pair, which is obtained based on the image classification information corresponding to the previous iteration; distill the student model by matching the current intra-class / inter-class distance information of each same category pair with the historical intra-class / inter-class distance information. Relationship modeling at the classification level related to high-level semantics can be achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of machine learning technology, and more specifically to a relational self-distillation method, device, system and storage medium. Background Art

[0002] In recent years, neural network models have been increasingly widely used in more and more fields. As the difficulty of the problems handled by neural network models increases, the network structure of neural network models is becoming more and more complex. Some complex models are huge in size, with millions (or even billions) of parameters, making them difficult to deploy on edge devices. To solve this problem, a knowledge distillation method has been developed, which can be used to train a simpler network model. Knowledge distillation mainly adopts the idea of ​​model compression, using a larger, already trained neural network model to teach a smaller neural network model so that the small model can learn the fitting ability of the large model. The large model has strong fitting ability, but low computational efficiency and long time consumption, while the small model has weak fitting ability but high computational efficiency. The purpose of distillation learning is to allow the small model to learn the fitting ability of the large model, so as to improve the fitting ability of the small model without changing the computational efficiency.

[0003] In general distillation methods, the same sample is input into the teacher model and the student model respectively to obtain their respective classification responses (logits), and then the cross entropy loss between the two responses is calculated to achieve the purpose of distilling the capabilities of the teacher model into the student model. In addition to the above-mentioned sample-based direct distillation method, a relationship-based distillation method is currently proposed. This type of method mainly considers the distance between different samples. The core is to hope that the sample distance modeled by the student model is close to the sample distance modeled by the teacher model.

[0004] However, the above existing methods are all sample-level relationship modeling, which does not involve relationship modeling at the classification level related to high-level semantics and has great limitations. Summary of the invention

[0005] The present invention is proposed in view of the above problems. The present invention provides a relational self-distillation method, device, system and storage medium.

[0006] According to one aspect of the present invention, a relational self-distillation method is provided. The method includes performing a current iteration operation at the i-th iteration in the training process of the student model, and the current iteration operation includes: obtaining N i sample images and corresponding annotation data, where the annotation data is used to indicate N i The categories corresponding to the sample images are N i The sample images are divided into K i categories, among which Ni and K i are all positive integers greater than or equal to 1, i = 1, 2...M, M is a positive integer greater than 1; N i sample images are input into the student model to obtain image classification information corresponding to the i-th iteration. The image classification information corresponding to the i-th iteration includes i classification information corresponding to each sample image; when i is greater than or equal to a preset threshold, a distillation operation is performed, wherein the distillation operation includes: for K i For each category in the categories, the current classification information corresponding to the category is determined based on the classification information corresponding to all sample images included in the category; for each category pair in at least one category pair, the distance between the current classification information corresponding to the two categories in the category pair is calculated to obtain the current intra-class / inter-class distance information of the category pair, wherein each category in each category pair in at least one category pair is K i one of the categories; obtaining historical intra-class / inter-class distance information of each category pair in at least one category pair, where the historical intra-class / inter-class distance information is obtained based on image classification information corresponding to previous iterations, respectively, and the previous iterations include one or more iterations before the i-th iteration; and distilling the student model by matching the current intra-class / inter-class distance information of each same category pair in at least one category pair with the historical intra-class / inter-class distance information.

[0007] For example, when N i After a sample image is input into the student model to obtain image classification information corresponding to the ith iteration, the current iteration operation also includes: obtaining the library storage classification information currently stored in the information library, the library storage classification information includes historical classification information corresponding one-to-one to multiple preset categories, and the multiple preset categories include all categories in at least one category pair; combining the image classification information corresponding to the ith iteration with the obtained library storage classification information to obtain new library storage classification information; replacing the library storage classification information currently stored in the information library with the new library storage classification information; wherein, obtaining the historical intra-class / inter-class distance information of each category pair in at least one category pair includes: for each category pair in at least one category pair, calculating the distance between the historical classification information corresponding to each of the two categories in the category pair to obtain the historical intra-class / inter-class distance information of the category pair.

[0008] Exemplarily, the classification information stored in the library includes C historical average features corresponding to C preset categories one by one, and the historical average feature is the historical classification information, K i The categories are subsets of C preset categories, and the C preset categories are all categories to which all sample images used in the 1st to Mth iterations belong.

[0009] Exemplarily, the image classification information corresponding to the i-th iteration includes N output by the intermediate network layer of the student model i Intermediate features, N i The intermediate features and N i The sample images correspond one to one, and the intermediate feature corresponding to any sample image is the classification information corresponding to the sample image. For each category pair in at least one category pair, for K i For each category in the categories, determining the current classification information corresponding to the category based on the classification information corresponding to all sample images included in the category includes: i For each category in the categories, the intermediate features corresponding to all sample images included in the category are averaged to obtain the current average feature corresponding to the category, and the current average feature is the current classification information.

[0010] Exemplarily, the dimension of each intermediate feature, each current average feature, and each historical average feature is equal to d, the library storage classification information is represented by a historical feature matrix of size C×d, and the C rows in the historical feature matrix correspond to the C historical average features one by one, wherein, for each category pair in at least one category pair, the distance between the current classification information corresponding to the two categories in the category pair is calculated to obtain the current intra-class / inter-class distance information of the category pair, the distillation operation further includes: based on K i The current average features construct a current feature matrix of size C×d, where the C rows in the current feature matrix correspond one-to-one to the C preset categories. i The values ​​of the rows corresponding to the categories are the current average features corresponding to each category, and the elements in the remaining rows are all set to 0; for each category pair in at least one category pair, calculating the distance between the current classification information corresponding to the two categories in the category pair to obtain the current intra-class / inter-class distance information of the category pair includes: using the current feature matrix to calculate the current intra-class / inter-class distance information of at least one category pair; for each category pair in at least one category pair, calculating the distance between the historical classification information corresponding to the two categories in the category pair to obtain the historical intra-class / inter-class distance information of the category pair includes: using the historical feature matrix to calculate the historical intra-class / inter-class distance information of at least one category pair.

[0011] Exemplarily, using the current feature matrix to calculate the current intra-class / inter-class distance information of at least one category pair includes: calculating the product of the current feature matrix and the transposed matrix of the current feature matrix to obtain a first product; dividing the first product by the modulus of the current feature matrix to obtain a first distance matrix; obtaining the current intra-class / inter-class distance information of at least one category pair based on the first distance matrix; using the historical feature matrix to calculate the historical intra-class / inter-class distance information of each category pair in at least one category pair includes: calculating the product of the historical feature matrix and the transposed matrix of the historical feature matrix to obtain a second product; dividing the second product by the modulus of the historical feature matrix to obtain a second distance matrix; obtaining the historical intra-class / inter-class distance information of at least one category pair based on the second distance matrix.

[0012] Exemplarily, combining the image classification information corresponding to the i-th iteration with the acquired library storage classification information to obtain new library storage classification information includes: using an exponential sliding average method to superimpose the image classification information corresponding to the i-th iteration onto the acquired library storage classification information to obtain new library storage classification information.

[0013] Exemplarily, when i=1, all elements in the acquired library storage classification information have a value of 0.

[0014] Exemplarily, the image classification information corresponding to the i-th iteration includes N output by the intermediate network layer of the student model i Intermediate features, N i The intermediate features and N i The sample images correspond one to one, and the intermediate feature corresponding to any sample image is the classification information corresponding to the sample image. For each category pair in at least one category pair, for K i For each category in the categories, determining the current classification information corresponding to the category based on the classification information corresponding to all sample images included in the category includes: i For each category in the categories, the intermediate features corresponding to all sample images included in the category are averaged to obtain the current average feature corresponding to the category, and the current average feature is the current classification information.

[0015] Exemplarily, distilling the student model by matching the current intra-class / inter-class distance information of each same category pair in at least one category pair with the historical intra-class / inter-class distance information includes: calculating the distance loss value based on the current intra-class / inter-class distance information and the historical intra-class / inter-class distance information of each same category pair in at least one category pair; and distilling the student model at least based on the distance loss value.

[0016] Exemplarily, all the categories to which all sample images used in the 1st to the Mth iteration belong are C categories, Ki The categories are subsets of C categories, the current intra-class / inter-class distance information of at least one category pair is represented by a first distance matrix of size C×C, and the historical intra-class / inter-class distance information of at least one category pair is represented by a second distance matrix of size C×C. In the first distance matrix, element M1 i′j′ It is used to represent the current intra-class / inter-class distance information between the i'th class and the j'th class in C classes. In the second distance matrix, the element M2 i′j′ For representing the historical intra-class / inter-class distance information between the i'th category and the j'th category in C categories, i'=1, 2...C, j'=1, 2...C, calculating the distance loss value based on the current intra-class / inter-class distance information and the historical intra-class / inter-class distance information of each same category pair in at least one category pair includes: generating a mask matrix of size C×C, wherein in the mask matrix, element M3 i′j′ The value of the i'th category and the j'th category in the C categories belong to K i When there are 1 categories, the element M i′j′ The value of is not in K in either the i'th category or the j'th category. i When there are multiple categories, the value is taken as 0; the mean square error loss value between the first distance matrix and the second distance matrix is ​​calculated; the mean square error loss value is multiplied by the mask matrix to obtain the distance loss value.

[0017] Exemplarily, distilling the student model based at least on the distance loss value includes: calculating an additional loss value; adding the distance loss value to the additional loss value to obtain a distillation loss value; and distilling the student model based on the distillation loss value.

[0018] Exemplarily, the image classification information corresponding to the i-th iteration includes the image classification result output by the last network layer of the student model, and the image classification result includes i N sample images correspond one to one i The additional loss value is calculated based on N classification results: i The cross entropy loss value is calculated based on the classification results and the first labeled data, and the additional loss value includes the cross entropy loss value.

[0019] According to another aspect of the present invention, a relational self-distillation device is provided, comprising: a current iteration operation module, for performing a current iteration operation at the i-th iteration in the training process of the student model, the current iteration operation module comprising: a first acquisition submodule, for acquiring N i sample images and corresponding annotation data, where the annotation data is used to indicate N i The categories corresponding to the sample images are N i The sample images are divided into K icategories, among which N i and K i are all positive integers greater than or equal to 1, i = 1, 2...M, M is a positive integer greater than 1; the input submodule is used to convert N i sample images are input into the student model to obtain image classification information corresponding to the i-th iteration. The image classification information corresponding to the i-th iteration includes i The information determination submodule is used to determine the classification information of K when i is greater than or equal to the preset threshold. i for each category in the categories, determining the current classification information corresponding to the category based on the classification information corresponding to all sample images included in the category; a calculation submodule, for each category pair in at least one category pair, calculating the distance between the current classification information corresponding to the two categories in the category pair when i is greater than or equal to a preset threshold, so as to obtain the current intra-class / inter-class distance information of the category pair, wherein each category in each category pair in at least one category pair is K i one of the categories; a second acquisition submodule, used to obtain historical intra-class / inter-class distance information of each category pair in at least one category pair when i is greater than or equal to a preset threshold, the historical intra-class / inter-class distance information is obtained based on image classification information corresponding to previous iterations, and the previous iterations include one or more iterations before the ith iteration; a distillation submodule, used to distill the student model by matching the current intra-class / inter-class distance information of each same category pair in at least one category pair with the historical intra-class / inter-class distance information when i is greater than or equal to a preset threshold.

[0020] According to another aspect of the present invention, a relational self-distillation system is provided, comprising a processor and a memory, wherein the memory stores computer program instructions, and the computer program instructions are used to execute the above-mentioned relational self-distillation method when the processor is executed.

[0021] According to another aspect of the present invention, a storage medium is provided, on which program instructions are stored, and the program instructions are used to execute the above-mentioned relational self-distillation method when running.

[0022] According to the relational self-distillation method, device, system and storage medium of the embodiment of the present invention, the student model can use the historical intra-class and / or inter-class relationships accumulated by itself as "teacher" knowledge, and perform self-distillation based on the historical intra-class and / or inter-class relationships and the current intra-class and / or inter-class relationships. This self-distillation method can realize relational modeling at the classification level related to high-level semantics, and can obtain more superior network performance. In addition, the method is a self-distillation method, which only involves the student model from beginning to end, and omits the existing complex teacher model, which is conducive to reducing the consumption of computing resources of processing equipment (such as computer video memory). BRIEF DESCRIPTION OF THE DRAWINGS

[0023] The above and other purposes, features and advantages of the present invention will become more apparent by describing the embodiments of the present invention in more detail in conjunction with the accompanying drawings. The accompanying drawings are used to provide a further understanding of the embodiments of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings, the same reference numerals generally represent the same components or steps.

[0024] Figure 1 A schematic block diagram showing an example electronic device for implementing a relational self-distillation method and apparatus according to an embodiment of the present invention;

[0025] Figure 2 A schematic flow chart showing a relational self-distillation method according to an embodiment of the present invention;

[0026] Figure 3 A schematic block diagram showing a relational self-distillation apparatus according to one embodiment of the present invention; and

[0027] Figure 4 A schematic block diagram of a relational self-distillation system according to an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0028] In recent years, research on computer vision, deep learning, machine learning, image processing, image recognition and other technologies based on artificial intelligence has made important progress. Artificial Intelligence (AI) is an emerging science and technology that studies and develops theories, methods, technologies and application systems for simulating and extending human intelligence. Artificial intelligence is a comprehensive discipline involving many types of technologies such as chips, big data, cloud computing, the Internet of Things, distributed storage, deep learning, machine learning, neural networks, etc. Computer vision, as an important branch of artificial intelligence, specifically allows machines to recognize the world. Computer vision technology usually includes face recognition, liveness detection, fingerprint recognition and anti-counterfeiting verification, biometric recognition, face detection, pedestrian detection, target detection, pedestrian recognition, image processing, image recognition, image semantic understanding, image retrieval, text recognition, video processing, video content recognition, behavior recognition, 3D reconstruction, virtual reality, augmented reality, simultaneous localization and mapping (SLAM), computational photography, robot navigation and positioning and other technologies. With the research and advancement of artificial intelligence technology, this technology has been applied in many fields, such as security, urban management, traffic management, building management, park management, facial access, facial attendance, logistics management, warehouse management, robots, intelligent marketing, computational photography, mobile phone imaging, cloud services, smart homes, wearable devices, unmanned driving, automatic driving, smart medical care, facial payment, facial unlocking, fingerprint unlocking, identity verification, smart screens, smart TVs, cameras, mobile Internet, live streaming, beauty, makeup, medical beauty, and smart temperature measurement.

[0029] In order to make the purpose, technical scheme and advantages of the present invention more obvious, the exemplary embodiments according to the present invention will be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments of the present invention, and it should be understood that the present invention is not limited to the exemplary embodiments described herein. Based on the embodiments of the present invention described in the present invention, all other embodiments obtained by those skilled in the art without creative work should fall within the protection scope of the present invention.

[0030] The embodiment of the present invention provides a relational self-distillation method, device, system and storage medium. According to the relational self-distillation method of the embodiment of the present invention, the student model can use the historical intra-class and / or inter-class relationships accumulated by itself as "teacher" knowledge, and perform self-distillation based on the historical intra-class and / or inter-class relationships and the current intra-class and / or inter-class relationships. This self-distillation method can realize relationship modeling at the classification level related to high-level semantics, and can obtain more superior network performance.

[0031] First, refer to Figure 1An example electronic device 100 for implementing the relational self-distillation method and apparatus according to an embodiment of the present invention is described.

[0032] like Figure 1 As shown, the electronic device 100 includes one or more processors 102 and one or more storage devices 104. Optionally, the electronic device 100 may also include an input device 106, an output device 108, and an image acquisition device 110, and these components are interconnected via a bus system 112 and / or other forms of connection mechanisms (not shown). It should be noted that Figure 1 The components and structures of the electronic device 100 shown are merely exemplary and non-limiting. The electronic device may also have other components and structures as required.

[0033] The processor 102 can be implemented in at least one hardware form of a digital signal processor (DSP), a field programmable gate array (FPGA), a programmable logic array (PLA), and a microprocessor. The processor 102 can be a central processing unit (CPU), a graphics processing unit (GPU), an application specific integrated circuit (ASIC), or one or a combination of other forms of processing units with data processing capabilities and / or instruction execution capabilities, and can control other components in the electronic device 100 to perform desired functions.

[0034] The storage device 104 may include one or more computer program products, and the computer program product may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, random access memory (RAM) and / or cache memory (cache), etc. The non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 102 may run the program instructions to implement the client functions (implemented by the processor) and / or other desired functions in the embodiments of the present invention described below. Various applications and various data, such as various data used and / or generated by the application, may also be stored in the computer-readable storage medium.

[0035] The input device 106 may be a device used by a user to input instructions, and may include one or more of a keyboard, a mouse, a microphone, a touch screen, and the like.

[0036] The output device 108 can output various information (such as images and / or sounds) to the outside (such as a user), and can include one or more of a display, a speaker, etc. Optionally, the input device 106 and the output device 108 can be integrated together and implemented using the same interactive device (such as a touch screen).

[0037] The image acquisition device 110 can acquire images and store the acquired images in the storage device 104 for use by other components. The image acquisition device 110 can be a separate camera or a camera in a mobile terminal, etc. It should be understood that the image acquisition device 110 is only an example, and the electronic device 100 may not include the image acquisition device 110. In this case, other devices with image acquisition capabilities can be used to acquire images and send the acquired images to the electronic device 100.

[0038] Exemplarily, an example electronic device for implementing the relational self-distillation method and apparatus according to an embodiment of the present invention may be implemented on a device such as a personal computer or a remote server.

[0039] Next, we will refer to Figure 2 A relational self-distillation method according to an embodiment of the present invention is described. Figure 2 FIG. 2 is a schematic flow chart of a relational self-distillation method 200 according to an embodiment of the present invention. Figure 2 As shown, the relational self-distillation method 200 includes: performing a current iteration operation at the i-th iteration in the training process of the student model. The current iteration operation includes the following steps S210, S220, S230, S240, S250 and S260.

[0040] In step S210, obtain N i sample images and corresponding annotation data, where the annotation data is used to indicate N i The categories corresponding to the sample images are N i The sample images are divided into K i categories, among which N i and K i are all positive integers greater than or equal to 1, i=1, 2,...M, M is a positive integer greater than 1.

[0041] M is the number of all iterations included in the training process of the student model, which can be a preset value or can be determined according to the actual training situation (that is, it can be a non-fixed value).

[0042] The sample images can be static images or frames from a video. In the latter case, N iA sample image may be a video. The sample image may be an original image acquired by an image acquisition device, or an image obtained after preprocessing (such as digitization, normalization, smoothing, etc.) the original image.

[0043] The sample image may come from an external device and be transmitted to the electronic device 100 for relational self-distillation. In addition, the sample image may also be acquired by the electronic device 100 itself. For example, the electronic device 100 may acquire N i The image acquisition device 110 may transmit the acquired sample images to the processor 102, and the processor 102 may perform relational self-distillation.

[0044] The student model can be any suitable neural network model, which can be set as needed, and the present invention is not limited to this.

[0045] The training of the neural network model can be divided into multiple cycles (epochs), and each epoch corresponds to a number of iterations that just go through the sample images contained in the entire data set. Each iteration (iteration, referred to as "iter") processes a small division unit of the data set. That is, one iteration refers to taking a batch of sample images and inputting them into the neural network model for training. A batch of sample images usually contains multiple images. Therefore, the sample images in different batches within the same epoch are different, and the number of sample images in different batches can be the same or different. Two batches in different epochs may have the same sample images.

[0046] The labeled data (ground truth) may be the category information of each sample image that has been labeled in advance by manual methods, etc. Each sample image corresponds to a specific category.

[0047] In step S220, N i sample images are input into the student model to obtain image classification information corresponding to the i-th iteration. The image classification information corresponding to the i-th iteration includes i The classification information of each sample image corresponds to each other.

[0048] Exemplarily, the image classification information may include i The intermediate features and / or final classification results corresponding to each sample image. That is, the classification information corresponding to any sample image in the image classification information may include the intermediate features and / or final classification results corresponding to the sample image. For example, the image classification information may include N outputs of the intermediate network layer of the student model. i Intermediate features, Ni The intermediate features and N i The sample images correspond one to one.

[0049] The intermediate network layer may be any network layer in the student model except the first input layer and the last output layer. Optionally, the intermediate network layer may be the nearest network layer before the last output layer. The last output layer may be, for example, a softmax layer.

[0050] Those skilled in the art will appreciate that an intermediate feature is a feature map, which can be represented by a vector. Each intermediate feature has a certain dimension, which can be represented by d. For example, d can be 256, that is, each intermediate feature is a 256-dimensional feature vector.

[0051] Each sample image has corresponding real category annotation information, and the intermediate features and / or final classification results obtained by forward propagation of each sample image through the neural network also belong to the corresponding category.

[0052] After step S220, the method 200 may further include: performing a distillation operation. Each step of the distillation operation is performed when i is greater than or equal to a preset threshold. The distillation operation may include at least the following steps S230, S240, S250 and S260.

[0053] The preset threshold value may be represented by j. In one example, j=1. That is, starting from the first iteration, the distillation operation is performed in each iteration, that is, all steps S210-S260 are performed. In another example, j≥2. That is, in the first one or more iterations (from the 1st to the j-1th) at the beginning of training, the distillation operation may not be performed first, and only steps S210-S220 are performed. Instead, starting from the jth iteration, the distillation operation is performed in each iteration, that is, all steps S210-S260 are performed.

[0054] In step S230, when i is greater than or equal to a preset threshold, for K i For each category in the categories, current classification information corresponding to the category is determined based on classification information corresponding to all sample images included in the category.

[0055] For example, for K i For each category in K categories, determining the current classification information corresponding to the category based on the classification information corresponding to all sample images included in the category may include: i For each category in the categories, the classification information corresponding to all sample images included in the category is averaged to obtain the current classification information corresponding to the category.

[0056] For example, in the image classification information including N i In the case of N intermediate features, i The intermediate features corresponding to the same category are averaged to obtain K i K i The current average feature is the current classification information.

[0057] For any category, there may be 0, 1 or more intermediate features in the current batch that belong to it. In the current batch, if there are multiple intermediate features corresponding to the same category, all the intermediate features corresponding to the category can be averaged to obtain the current average feature corresponding to the category. If there is only one intermediate feature corresponding to a category, the current average feature obtained by averaging all the intermediate features corresponding to the category is still the intermediate feature. Traverse and calculate all categories under the current batch, and finally get the same average feature as K. i K i The current average features. It can be understood that K i ≤N i .

[0058] The dimension of the intermediate feature can be represented by d. The dimension of the current average feature is consistent with that of the intermediate feature, so the dimension of the current average feature can also be represented by d.

[0059] In step S240, when i is greater than or equal to a preset threshold, for each category pair in at least one category pair, the distance between the current classification information corresponding to the two categories in the category pair is calculated to obtain the current intra-class / inter-class distance information of the category pair, wherein each category in each category pair in at least one category pair is K i The intra-class / inter-class distance information of a class pair can represent the “relationship” between the two classes in the class pair. Therefore, the distillation method of the present application can be understood as a relational distillation method.

[0060] Each category pair contains two categories. Any two category pairs in at least one category pair contain different categories. However, the two categories contained in any category pair can be the same or different from each other. For example, any category pair in at least one category pair can contain a first category and a second category, wherein the first category and the second category can both be category X, or one can be category X and the other can be category Y. When the first category and the second category are the same category, the distance corresponding to the category pair is an intra-class distance, which is a modeling of intra-class relationships. When the first category and the second category are different categories, the distance corresponding to the category pair is an inter-class distance, which is a modeling of inter-class relationships.

[0061] The number of category pairs in at least one category pair may be set as required. i All category pairs that can be composed of K categories, that is, at least one category pair can include K i ×K i For example, K i The first category of the K categories is respectively related to the first category, the second category, the third category, and so on. i categories to form category pairs, we can get K i Category pairs; K i The second category of the K categories is respectively connected to the first category, the second category, the third category, and so on. i categories to form category pairs, and we can also get K i category pairs; and so on, we can finally get K i ×K i In another example, at least one category pair may include K i Some of the category pairs among all the category pairs that can be composed of categories. For example, we can i ×K i Select some of the category pairs from the category pairs as at least one category pair.

[0062] For each category pair, the distance between the current classification information (e.g., two current average features) corresponding to the two categories can be calculated. The distance can be, for example, a cosine distance, but this is only an example and not a limitation of the present invention, and the distance can also be other types of distances.

[0063] In step S250, when i is greater than or equal to a preset threshold, historical intra-class / inter-class distance information of each category pair in at least one category pair is obtained, and the historical intra-class / inter-class distance information is obtained based on the image classification information corresponding to the previous iterations, and the previous iterations include one or more iterations before the i-th iteration.

[0064] The historical intra-class / inter-class distance information can be obtained based on the image classification information corresponding to the previous iteration. For example, the image classification information obtained in each current iteration can be superimposed on the image classification information obtained in the previous iteration, so that the image classification information can be accumulated as the iteration proceeds. In the current iteration, the currently accumulated image classification information (such as the classification information stored in the library described below) can be obtained, and the historical intra-class / inter-class distance information of each category pair can be calculated using the accumulated image classification information.

[0065] The category pairs involved in step S250 are consistent with the category pairs involved in step S240.

[0066] In step S260, when i is greater than or equal to a preset threshold, the student model is distilled by matching the current intra-class / inter-class distance information of each same class pair in at least one class pair with the historical intra-class / inter-class distance information.

[0067] The matching can be understood as adjusting the parameters of the student model so that the current intra-class / inter-class distance information of each same class pair in at least one class pair is closer and closer to its historical intra-class / inter-class distance information until the preset requirements are met. Those skilled in the art can understand the implementation principle of the distillation of the student model, which will not be elaborated in this article.

[0068] According to the relational self-distillation method of an embodiment of the present invention, the student model can use its own accumulated historical intra-class and / or inter-class relationships as "teacher" knowledge, and perform self-distillation based on the historical intra-class and / or inter-class relationships and the current intra-class and / or inter-class relationships. This self-distillation method can achieve relational modeling at the classification level related to high-level semantics, and can obtain more superior network performance. In addition, the method is a self-distillation method, which only involves the student model from beginning to end, and omits the existing complex teacher model, which is conducive to reducing the consumption of computing resources of processing equipment (such as computer video memory).

[0069] Please note that Figure 2 The order of the steps shown is only an example and not a limitation of the present invention, and steps S210-S260 may have other suitable execution orders. For example, step S250 may be executed before, after or simultaneously with any step in steps S210-S240.

[0070] Exemplarily, the relational self-distillation method according to an embodiment of the present invention may be implemented in a device, apparatus or system having a memory and a processor.

[0071] The relational self-distillation method according to an embodiment of the present invention can be deployed at the image acquisition end, for example, can be deployed at a personal terminal or a server end.

[0072] Alternatively, the relational self-distillation method according to an embodiment of the present invention can also be deployed in a distributed manner on the server side (or cloud side) and the personal terminal. For example, an image can be acquired on the client side, and the client side transmits the acquired image to the server side (or cloud side), and the server side (or cloud side) performs relational self-distillation.

[0073] According to an embodiment of the present invention, when N iAfter a sample image is input into the student model to obtain image classification information corresponding to the ith iteration, the current iteration operation also includes: obtaining the library storage classification information currently stored in the information library, the library storage classification information includes historical classification information corresponding one-to-one to multiple preset categories, and the multiple preset categories include all categories in at least one category pair; combining the image classification information corresponding to the ith iteration with the obtained library storage classification information to obtain new library storage classification information; replacing the library storage classification information currently stored in the information library with the new library storage classification information; wherein, obtaining the historical intra-class / inter-class distance information of each category pair in at least one category pair includes: for each category pair in at least one category pair, calculating the distance between the historical classification information corresponding to each of the two categories in the category pair to obtain the historical intra-class / inter-class distance information of the category pair.

[0074] The above steps of acquiring the library storage classification information currently stored in the information library, combining the image classification information corresponding to the i-th iteration with the acquired library storage classification information, and replacing the library storage classification information currently stored in the information library with the new library storage classification information (the above three steps can be referred to as library storage classification information update steps) can be performed in each iteration, that is, in the cases of i=1, 2...M.

[0075] In one example, j≥2. At this time, in each iteration from the 1st to the j-1th iteration, only the image classification information may be calculated and the library storage classification information in the information library may be updated using the image classification information, without distilling the student model. Of course, optionally, steps S210-S260 and the library storage classification information update step may be performed in each iteration starting from the 1st iteration, that is, the student model may be distilled starting from the 1st iteration.

[0076] Since the categories corresponding to the historical classification information in the library storage classification information are not complete during the previous one or more iterations, and the historical classification information of each category is not accurate enough due to the short accumulation time, the training effect of distilling the student model at this time may not be very good. Therefore, you can choose to skip the previous one or more iterations, and only update the library storage classification information in these iterations without distilling the student model. When the library storage classification information is updated to a certain extent, so that the categories corresponding to its historical classification information are relatively complete and the historical classification information is relatively accurate, the distillation of the student model can be started. The size of j, that is, the timing of starting distillation, can be set as needed, and the present invention is not limited to this. For example, j=2. In this case, only the first iteration does not perform distillation, and the remaining iterations perform distillation.

[0077] Exemplarily, the library storage classification information may include C historical average features corresponding to C preset categories (ie, C categories), and the historical average feature is the historical classification information, K i The categories are subsets of C preset categories, and the C preset categories are all categories to which all sample images used in iterations from the 1st to the Mth belong. In this embodiment, the plurality of preset categories are C preset categories.

[0078] The C categories can be all the categories to which the sample images belong in the entire dataset used in the training process of the student model (i.e., the dataset used in the above epoch). For different datasets, the C value can be the same or different. However, in a complete training process of the student model, the C value is fixed.

[0079] Usually, too many images cannot be included in a batch because of the limited computing resources of the processing device (such as computer video memory). In addition, the sample images of each batch are usually obtained by random sampling, so it is difficult to sample sample images of all categories in the current batch. Therefore, K i ≤C, i.e. K i K categories are subsets of C categories. i It refers to the number of categories involved in the current batch, which can be a variable related to the current batch rather than a fixed constant.

[0080] By way of example and not limitation, the library storage classification information may be represented by a historical feature matrix of size C×d, wherein the C rows of the historical feature matrix may correspond one-to-one to the C categories.

[0081] The library stored classification information can be obtained by combining the image classification information corresponding to the previous iteration. The library stored classification information can be updated by accumulating the current average features of each category in each iteration previously experienced. Therefore, the historical average features in the library stored classification information are consistent with the dimensions of the intermediate features and the current average features described above, that is, they are all d-dimensional.

[0082] For example, before the first iteration, the library storage classification information in the information library may be initialized to obtain the initial library storage classification information. Each element in the initial library storage classification information may be 0. After the first iteration, K is obtained. 1 The current average features, then the K 1 The current average features are added to the library storage classification information to update the previously stored library storage classification information. Then, after the second iteration, K 2 The current average features, then the K 2The current average features and the previously stored library storage classification information (this time only includes the K added previously) 1 The current average feature) is superimposed to update the library storage classification information again. The rest of the iterations are analogous. Through the above method, the library storage classification information can be continuously updated, so that the data corresponding to each category in the library storage classification information is more and more complete. In this way, after several iterations, all categories may have data.

[0083] It can be seen from the above that the library storage classification information currently obtained and stored in the information library is the library storage classification information updated in the last iteration.

[0084] The embodiment of accumulating the library storage classification information in the information library and calculating the historical intra-class / inter-class distance information of each category pair through the library storage classification information is only an example and not a limitation. For example, the image classification information obtained in each iteration can be optionally stored in the information library. In the current iteration, the image classification information obtained in all previous iterations stored in the information library can be obtained, and the historical intra-class / inter-class distance information of each category pair can be calculated based on the image classification information.

[0085] According to an embodiment of the present invention, the image classification information corresponding to the i-th iteration includes N output by the intermediate network layer of the student model i Intermediate features, N i The intermediate features and N i The sample images correspond one to one, and the intermediate feature corresponding to any sample image is the classification information corresponding to the sample image. For each category pair in at least one category pair, for K i For each category in the categories, determining the current classification information corresponding to the category based on the classification information corresponding to all sample images included in the category includes: i For each category in the categories, the intermediate features corresponding to all sample images included in the category are averaged to obtain the current average feature corresponding to the category, and the current average feature is the current classification information.

[0086] The above has described an embodiment of using intermediate features as classification information and averaging the intermediate features to obtain current classification information, which will not be repeated here.

[0087] According to an embodiment of the present invention, the dimension of each intermediate feature, each current average feature and each historical average feature is equal to d, the library storage classification information is represented by a historical feature matrix of size C×d, and the C rows in the historical feature matrix correspond to the C historical average features one by one, wherein, for each category pair in at least one category pair, the distance between the current classification information corresponding to the two categories in the category pair is calculated to obtain the current intra-class / inter-class distance information of the category pair, the distillation operation further includes: based on K i The current average features construct a current feature matrix of size C×d, where the C rows in the current feature matrix correspond one-to-one to the C preset categories. i The values ​​of the rows corresponding to the categories are the current average features corresponding to each category, and the elements in the remaining rows are all set to 0; for each category pair in at least one category pair, calculating the distance between the current classification information corresponding to the two categories in the category pair to obtain the current intra-class / inter-class distance information of the category pair includes: using the current feature matrix to calculate the current intra-class / inter-class distance information of at least one category pair; for each category pair in at least one category pair, calculating the distance between the historical classification information corresponding to the two categories in the category pair to obtain the historical intra-class / inter-class distance information of the category pair includes: using the historical feature matrix to calculate the historical intra-class / inter-class distance information of at least one category pair.

[0088] K i The current average features (i.e., image classification information) are constructed into a current feature matrix of size C×d, and the library storage classification information is represented by a historical feature matrix of size C×d. In this way, the image classification information and the library storage classification information are represented in a unified form, which is convenient for subsequent comparison of the intra-class / inter-class relationships reflected by the two.

[0089] It can be understood that in the above-mentioned l In an embodiment of updating the classification information stored in the library by using the current average feature, the above K l The current average features are also constructed as a current feature matrix of size C×d.

[0090] According to an embodiment of the present invention, using the current feature matrix to calculate the current intra-class / inter-class distance information of at least one category pair includes: calculating the product of the current feature matrix and the transposed matrix of the current feature matrix to obtain a first product; dividing the first product by the modulus of the current feature matrix to obtain a first distance matrix; obtaining the current intra-class / inter-class distance information of at least one category pair based on the first distance matrix; using the historical feature matrix to calculate the historical intra-class / inter-class distance information of each category pair in at least one category pair includes: calculating the product of the historical feature matrix and the transposed matrix of the historical feature matrix to obtain a second product; dividing the second product by the modulus of the historical feature matrix to obtain a second distance matrix; obtaining the historical intra-class / inter-class distance information of at least one category pair based on the second distance matrix.

[0091] In this embodiment, the first distance matrix is ​​calculated by multiplying the current feature matrix with its own transposed matrix to obtain the current intra-class / inter-class distance information. It can be understood that in this calculation process, K is calculated. i All the category pairs that can be formed by categories (i.e., K i ×K i Therefore, the first distance matrix calculated at this time includes K i All the category pairs that can be formed by categories (i.e., K i ×K i The first distance matrix can be regarded as K i ×K i The current intra-class / inter-class distance information corresponding to the category pairs. Correspondingly, the second distance matrix is ​​calculated by multiplying the historical feature matrix with its own transposed matrix to obtain the historical intra-class / inter-class distance information. It can be understood that in this calculation process, the distances corresponding to all category pairs that can be composed of C categories (i.e., C×C category pairs) are calculated. Therefore, the second distance matrix calculated at this time includes the distance information corresponding to all category pairs that can be composed of C categories (i.e., C×C category pairs). Optionally, the second distance matrix can be regarded as the historical intra-class / inter-class distance information corresponding to C×C category pairs. Optionally, the second distance matrix can be further masked to obtain a matrix containing only K i ×K i The distance matrix corresponding to the distances of the class pairs is used as K i ×K i The historical intra-class / inter-class distance information corresponding to each class pair.

[0092] In the above scheme, the first distance matrix represents the current intra-class and inter-class cosine distances (ie, intra-class and inter-class relationships), and the second distance matrix represents the historical intra-class and inter-class cosine distances (ie, intra-class and inter-class relationships).

[0093] According to an embodiment of the present invention, combining the image classification information corresponding to the i-th iteration with the acquired library storage classification information to obtain new library storage classification information includes: using an exponential moving average (EMA) method to superimpose the image classification information corresponding to the i-th iteration onto the acquired library storage classification information to obtain new library storage classification information.

[0094] For example, K can be added by a predetermined superposition algorithm. i The current average features are superimposed on the C historical average features to update the library storage classification information in the information library.

[0095] The predetermined superposition algorithm may be any suitable superposition algorithm, including but not limited to the exponential moving average (EMA) method. The updated library storage classification information may be used for calculating historical intra-class / inter-class distance information in the next iteration.

[0096] It should be noted that in the above superposition process, K is divided into i The current average features are superimposed on the C historical average features. That is, for K i For each category in the categories, the current average feature corresponding to the category is superimposed with the historical average feature corresponding to the category (such as EMA method) to obtain a new historical average feature corresponding to the category. Subsequently, the new historical average feature can be used to replace the historical average feature corresponding to the category originally included in the classification information stored in the library. i For each category other than the category, the historical average characteristics corresponding to the category originally included in the classification information stored in the library remain the same without replacement.

[0097] According to the embodiment of the present invention, when i=1, all elements in the obtained library storage classification information have a value of 0. The obtained library storage classification information described here is the library storage classification information obtained from the information library in the current iteration, which is the library storage classification information that has not been updated in the current iteration.

[0098] As described above, before the first iteration, the library storage classification information can be initialized to obtain the initial library storage classification information and store it in the information library. All elements in the initial library storage classification information are 0. For example, the library storage classification information can be represented by a historical feature matrix of size C×d. Each row in the initial library storage classification information is a zero vector. When the current average feature corresponding to any category is obtained in subsequent iterations, the current average feature of the category can be superimposed on the row vector corresponding to the category in the historical feature matrix.

[0099] As mentioned above, the current average feature corresponding to each category appearing in the current batch can be represented by a d-dimensional vector, which uniquely corresponds to a row in the historical feature matrix according to the category. The row vector in the historical feature matrix is ​​also a d-dimensional vector. The above two vectors are superimposed, for example, using exponential sliding average superposition, and the superposition result obtained is also a d-dimensional vector. The original row vector of the historical feature matrix can be replaced by the d-dimensional vector obtained by superposition to complete the update of the row vector.

[0100] According to an embodiment of the present invention, distilling the student model by matching the current intra-class / inter-class distance information of each same category pair in at least one category pair with the historical intra-class / inter-class distance information includes: calculating the distance loss value based on the current intra-class / inter-class distance information and the historical intra-class / inter-class distance information of each same category pair in at least one category pair; and distilling the student model at least based on the distance loss value.

[0101] Calculating the difference between the current intra-class / inter-class distance information and the historical intra-class / inter-class distance information can conveniently determine the difference between the current intra-class and / or inter-class relationship and the historical intra-class and / or inter-class relationship to better teach the student model for training.

[0102] In one example, the distance loss value may be directly used as the distillation loss value and distillation may be performed based on the distillation loss value. In another example, the distance loss value may be further added to the additional loss value, and the result of the addition may be used as the distillation loss value and distillation may be performed based on the distillation loss value.

[0103] According to the embodiment of the present invention, all the categories to which all sample images used in the 1st to the Mth iteration belong are C categories, K i The categories are subsets of C categories, the current intra-class / inter-class distance information of at least one category pair is represented by a first distance matrix of size C×C, and the historical intra-class / inter-class distance information of at least one category pair is represented by a second distance matrix of size C×C. In the first distance matrix, element M1 i′j′ It is used to represent the current intra-class / inter-class distance information between the i'th class and the j'th class in C classes. In the second distance matrix, the element M2 i′j′ For representing the historical intra-class / inter-class distance information between the i'th category and the j'th category in C categories, i'=1, 2...C, j'=1, 2...C, calculating the distance loss value based on the current intra-class / inter-class distance information and the historical intra-class / inter-class distance information of each same category pair in at least one category pair includes: generating a mask matrix of size C×C, wherein in the mask matrix, element M3 i′j′ The value of the i'th category and the j'th category in the C categories belong to Ki When there are 1 categories, the element M i′j′ The value of is not in K in either the i'th category or the j'th category. i When there are multiple categories, the value is taken as 0; the mean square error (L2) loss value between the first distance matrix and the second distance matrix is ​​calculated; the mean square error loss value is multiplied by the mask matrix to obtain the distance loss value.

[0104] The first distance matrix and the second distance matrix in this embodiment may be consistent with the first distance matrix and the second distance matrix described above, and will not be described in detail here.

[0105] As mentioned above, not all categories may appear in a batch, so K i It is very likely to be smaller than C. Therefore, when calculating the loss value, a binary mask matrix can be used for masking to avoid distilling some meaningless information (i.e., matrix elements corresponding to categories that have not appeared in the current batch). This solution can reduce the interference of invalid information, thereby helping to improve the training accuracy of the student model.

[0106] According to the embodiment of the present invention, all the categories to which all sample images used in the 1st to the Mth iteration belong are C categories, K i The categories are subsets of C categories. The current intra-class / inter-class distance information of at least one category pair is represented by a first distance matrix of size C×C. The historical intra-class / inter-class distance information of all category pairs composed of C categories is represented by a second distance matrix of size C×C. In the first distance matrix, element M1 i′j′ It is used to represent the current intra-class / inter-class distance information between the i'th class and the j'th class in C classes. In the second distance matrix, the element M2 i′j′ For representing the historical intra-class / inter-class distance information between the i'th category and the j'th category in C categories, i'=1, 2...C, j'=1, 2...C, calculating the distance loss value based on the current intra-class / inter-class distance information and the historical intra-class / inter-class distance information of each same category pair in at least one category pair includes: generating a mask matrix of size C×C, wherein in the mask matrix, element M3 i′j′ The value of the i'th category and the j'th category in the C categories belong to K i When there are 1 categories, the element M i′j′ The value of is not in K in either the i'th category or the j'th category. i When there are multiple categories, the value is taken as 0; the second distance matrix is ​​multiplied by the mask matrix to obtain a third distance matrix; the mean square error loss value between the first distance matrix and the third distance matrix is ​​calculated, and the above distance loss value is the calculated mean square error loss value.

[0107] In addition to using the mask matrix when calculating the loss value, the mask matrix can also be used to calculate the historical intra-class / inter-class distance information of at least one class pair. No matter where the mask matrix is ​​used, it is to ensure that the elements of the non-appearing class are not included in the final calculated loss value, thereby reducing the interference of invalid information.

[0108] According to an embodiment of the present invention, distilling the student model at least based on the distance loss value includes: calculating an additional loss value; adding the distance loss value to the additional loss value to obtain a distillation loss value; and distilling the student model based on the distillation loss value.

[0109] In addition to the loss values ​​calculated based on the intra-class and / or inter-class distances, other loss values ​​may be further added. By combining multiple loss values, the accuracy of student model training can be further improved.

[0110] Illustratively, the additional loss value may be a loss value adopted in any suitable existing or future distillation method for sample particle size.

[0111] According to an embodiment of the present invention, the first classification information also includes an image classification result output by the last network layer of the student model, and the image classification result includes i N sample images correspond one to one i The additional loss value is calculated based on N classification results: i The cross entropy loss value is calculated based on the classification results and the first labeled data, and the additional loss value includes the cross entropy loss value.

[0112] In step S220, the image classification information corresponding to the i-th iteration includes i The classification information of each sample image corresponds to N i The classification information corresponding to each sample image only includes i N sample images correspond one to one i In the case of N intermediate features, an additional step of obtaining image classification results may be performed in addition to step S220. i The classification information corresponding to each sample image includes i N sample images correspond one to one i In the case of a classification result, there is no need to perform an additional step of obtaining the image classification result outside of step S220.

[0113] Those skilled in the art can understand how to calculate the distance loss value and the cross entropy loss value and how to perform gradient calculation based on these loss values ​​to train the learning model, which will not be described in detail herein.

[0114] Distillation is a method of knowledge transfer in the field of transfer learning. Distillation can improve the generalization of the distilled object (in simple terms, improve its effect on the test set). Generally speaking, the knowledge in the large model (called the teacher) is distilled to the small model (called the student). However, according to an embodiment of the present invention, the historical intra-class and / or inter-class distance information is regarded as the teacher's knowledge, and the intra-class and / or inter-class distance information under the current iteration is regarded as the student's knowledge. Distilling the student model based on these two types of information can also achieve the purpose of model optimization.

[0115] According to another aspect of the present invention, a relational self-distillation device is provided. Figure 3 A schematic block diagram of a relational self-distillation apparatus 300 according to an embodiment of the present invention is shown.

[0116] like Figure 3 As shown, the relational self-distillation device 300 according to an embodiment of the present invention includes a current iteration operation module, which is used to perform the current iteration operation at the i-th iteration in the training process of the student model. The current iteration operation module includes a first acquisition submodule 310, an input submodule 320, an information determination submodule 330, a calculation submodule 340, a second acquisition submodule 350 and a distillation submodule 360. The modules can respectively perform the above combined Figure 2 The following describes the various steps / functions of the relational self-distillation method. Only the main functions of the various components of the relational self-distillation device 300 are described below, and the details already described above are omitted.

[0117] The first acquisition submodule 310 is used to acquire N i sample images and corresponding annotation data, wherein the annotation data is used to indicate the N i The categories corresponding to the sample images are N i The sample images are divided into K i categories, among which N i and K i are all positive integers greater than or equal to 1, i=1, 2, ..., M, where M is a positive integer greater than 1. The first acquisition submodule 310 can be composed of Figure 1 The processor 102 in the electronic device shown executes program instructions stored in the storage device 103 to implement it.

[0118] The input submodule 320 is used to convert the N i sample images are input into the student model to obtain image classification information corresponding to the i-th iteration, wherein the image classification information corresponding to the i-th iteration includes i The input submodule 320 can be composed of Figure 1 The processor 102 in the electronic device shown executes program instructions stored in the storage device 103 to implement it.

[0119] The information determination submodule 330 is used for determining the K i For each category in the categories, the current classification information corresponding to the category is determined based on the classification information corresponding to all sample images included in the category. The information determination submodule 330 can be composed of Figure 1 The processor 102 in the electronic device shown executes program instructions stored in the storage device 103 to implement it.

[0120] The first calculation submodule 340 is used to calculate the distance between the current classification information corresponding to the two categories in each category pair in at least one category pair when i is greater than or equal to a preset threshold, so as to obtain the current intra-class / inter-class distance information of the category pair, wherein each category in each category pair in the at least one category pair is the K i The first calculation submodule 340 can be composed of Figure 1 The processor 102 in the electronic device shown executes program instructions stored in the storage device 103 to implement it.

[0121] The second acquisition submodule 350 is used to acquire historical intra-class / inter-class distance information of each category pair in the at least one category pair when i is greater than or equal to a preset threshold, wherein the historical intra-class / inter-class distance information is obtained based on image classification information corresponding to previous iterations, wherein the previous iterations include one or more iterations before the i-th iteration. The second acquisition submodule 350 may be composed of Figure 1 The processor 102 in the electronic device shown executes program instructions stored in the storage device 103 to implement it.

[0122] The distillation submodule 360 ​​is used to distill the student model by matching the current intra-class / inter-class distance information of each same class pair in the at least one class pair with the historical intra-class / inter-class distance information when i is greater than or equal to a preset threshold. The distillation submodule 360 ​​can be composed of Figure 1 The processor 102 in the electronic device shown executes program instructions stored in the storage device 103 to implement it.

[0123] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0124] Figure 4 FIG. 4 is a schematic block diagram of a relational self-distillation system 400 according to an embodiment of the present invention. The relational self-distillation system 400 includes an image acquisition device 410 , a storage device (ie, memory) 420 , and a processor 430 .

[0125] The image acquisition device 410 is used to acquire images. The image acquisition device 410 is optional, and the relational self-distillation system 400 may not include the image acquisition device 410. In this case, other image acquisition devices may be used to acquire images, and the acquired images may be sent to the relational self-distillation system 400.

[0126] The storage device 420 stores computer program instructions for implementing corresponding steps in the relational self-distillation method according to an embodiment of the present invention.

[0127] The processor 430 is used to run the computer program instructions stored in the storage device 420 to perform corresponding steps of the relational self-distillation method according to an embodiment of the present invention.

[0128] In one embodiment, the computer program instructions are used by the processor 430 to perform the following steps when executed: in the i-th iteration of the training process of the student model, perform the current iteration operation, the current iteration operation includes: obtaining N i sample images and corresponding annotation data, where the annotation data is used to indicate N i The categories corresponding to the sample images are N i The sample images are divided into K i categories, among which N i and K i are all positive integers greater than or equal to 1, i = 1, 2...M, M is a positive integer greater than 1; N i sample images are input into the student model to obtain image classification information corresponding to the i-th iteration. The image classification information corresponding to the i-th iteration includes i classification information corresponding to each sample image; when i is greater than or equal to a preset threshold, a distillation operation is performed, wherein the distillation operation includes: for K iFor each category in the categories, the current classification information corresponding to the category is determined based on the classification information corresponding to all sample images included in the category; for each category pair in at least one category pair, the distance between the current classification information corresponding to the two categories in the category pair is calculated to obtain the current intra-class / inter-class distance information of the category pair, wherein each category in each category pair in at least one category pair is K i one of the categories; obtaining historical intra-class / inter-class distance information of each category pair in at least one category pair, where the historical intra-class / inter-class distance information is obtained based on image classification information corresponding to previous iterations, respectively, and the previous iterations include one or more iterations before the i-th iteration; and distilling the student model by matching the current intra-class / inter-class distance information of each same category pair in at least one category pair with the historical intra-class / inter-class distance information.

[0129] In addition, according to an embodiment of the present invention, a storage medium is also provided, on which program instructions are stored, and when the program instructions are executed by a computer or a processor, they are used to execute the corresponding steps of the relational self-distillation method of the embodiment of the present invention, and are used to implement the corresponding modules in the relational self-distillation device according to the embodiment of the present invention. The storage medium may include, for example, a memory card of a smart phone, a storage component of a tablet computer, a hard disk of a personal computer, a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a portable compact disk read-only memory (CD-ROM), a USB memory, or any combination of the above storage media.

[0130] In one embodiment, when the program instructions are executed by a computer or processor, the computer or processor can implement the various functional modules of the relational self-distillation device according to the embodiment of the present invention, and / or can execute the relational self-distillation method according to the embodiment of the present invention.

[0131] In one embodiment, the program instructions are used to perform the following steps when running: in the i-th iteration of the training process of the student model, perform the current iteration operation, the current iteration operation includes: obtaining N i sample images and corresponding annotation data, where the annotation data is used to indicate N i The categories corresponding to the sample images are N i The sample images are divided into K i categories, among which N i and K i are all positive integers greater than or equal to 1, i = 1, 2...M, M is a positive integer greater than 1; N i sample images are input into the student model to obtain image classification information corresponding to the i-th iteration. The image classification information corresponding to the i-th iteration includesi classification information corresponding to each sample image; when i is greater than or equal to a preset threshold, a distillation operation is performed, wherein the distillation operation includes: for K i For each category in the categories, the current classification information corresponding to the category is determined based on the classification information corresponding to all sample images included in the category; for each category pair in at least one category pair, the distance between the current classification information corresponding to the two categories in the category pair is calculated to obtain the current intra-class / inter-class distance information of the category pair, wherein each category in each category pair in at least one category pair is K i one of the categories; obtaining historical intra-class / inter-class distance information of each category pair in at least one category pair, where the historical intra-class / inter-class distance information is obtained based on image classification information corresponding to previous iterations, respectively, and the previous iterations include one or more iterations before the i-th iteration; and distilling the student model by matching the current intra-class / inter-class distance information of each same category pair in at least one category pair with the historical intra-class / inter-class distance information.

[0132] Each module in the relational self-distillation system according to an embodiment of the present invention can be implemented by running computer program instructions stored in a memory by a processor of an electronic device implementing relational self-distillation according to an embodiment of the present invention, or can be implemented when computer instructions stored in a computer-readable storage medium of a computer program product according to an embodiment of the present invention are executed by a computer.

[0133] Although example embodiments have been described herein with reference to the accompanying drawings, it should be understood that the above example embodiments are merely exemplary and are not intended to limit the scope of the present invention thereto. Various changes and modifications may be made therein by one of ordinary skill in the art without departing from the scope and spirit of the present invention. All such changes and modifications are intended to be included within the scope of the present invention as required by the appended claims.

[0134] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0135] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed.

[0136] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.

[0137] Similarly, it should be understood that in order to streamline the present invention and help understand one or more of the various inventive aspects, in the description of the exemplary embodiments of the present invention, the various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, the method of the present invention should not be interpreted as reflecting the following intention: the claimed invention requires more features than the features explicitly stated in each claim. More specifically, as reflected in the corresponding claims, the inventive point is that the corresponding technical problem can be solved with less than all the features of a single disclosed embodiment. Therefore, the claims following the specific embodiment are hereby expressly incorporated into the specific embodiment, wherein each claim itself serves as a separate embodiment of the present invention.

[0138] It will be understood by those skilled in the art that, except for mutually exclusive features, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this specification may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature that provides the same, equivalent or similar purpose.

[0139] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present invention and form different embodiments. For example, in the claims, any one of the claimed embodiments may be used in any combination.

[0140] The various component embodiments of the present invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or a digital signal processor (DSP) may be used in practice to implement some or all of the functions of some modules in the relational self-distillation device according to an embodiment of the present invention. The present invention may also be implemented as a device program (e.g., a computer program and a computer program product) for executing part or all of the methods described herein. Such a program for implementing the present invention may be stored on a computer-readable medium, or may be in the form of one or more signals. Such a signal may be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.

[0141] It should be noted that the above embodiments illustrate the present invention rather than limit it, and that those skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be construed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention may be implemented by means of hardware comprising a number of different elements and by means of a suitably programmed computer. In a unit claim enumerating a number of devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc., does not indicate any order. These words may be interpreted as names.

[0142] The above is only a specific embodiment of the present invention or an explanation of a specific embodiment. The protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. The protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A relational self-distillation method, comprising performing a current iteration operation at the i-th iteration in the training process of a student model, wherein the current iteration operation comprises: Get N i sample images and corresponding annotation data, wherein the annotation data is used to indicate the N i The categories corresponding to the sample images are N i The sample images are divided into K i categories, among which N i and K i are all positive integers greater than or equal to 1, i = 1, 2, ..., M, M is a positive integer greater than 1; The N i sample images are input into the student model to obtain image classification information corresponding to the i-th iteration, wherein the image classification information corresponding to the i-th iteration includes i Classification information corresponding to each sample image; When i is greater than or equal to a preset threshold, a distillation operation is performed, wherein the distillation operation includes: For the K i For each category in the categories, determining the current classification information corresponding to the category based on the classification information corresponding to all sample images included in the category; For each category pair in at least one category pair, the distance between the current classification information corresponding to the two categories in the category pair is calculated to obtain the current intra-class / inter-class distance information of the category pair, wherein each category in each category pair in the at least one category pair is the K i one of the categories; Acquire historical intra-class / inter-class distance information of each category pair in the at least one category pair, wherein the historical intra-class / inter-class distance information is obtained based on image classification information respectively corresponding to previous iterations, wherein the previous iterations include one or more iterations before the i-th iteration; and The student model is distilled by matching current intra-class / inter-class distance information with historical intra-class / inter-class distance information for each same class pair in the at least one class pair.

2. The method of claim 1, wherein: In the i After a sample image is input into the student model to obtain image classification information corresponding to the i-th iteration, the current iteration operation further includes: Acquire library storage classification information currently stored in the information library, the library storage classification information including historical classification information corresponding to a plurality of preset categories one by one, the plurality of preset categories including all categories of the at least one category pair; combining the image classification information corresponding to the i-th iteration with the acquired library storage classification information to obtain new library storage classification information; Replace the library storage classification information currently stored in the information library with the new library storage classification information; The obtaining of historical intra-class / inter-class distance information of each category pair in the at least one category pair includes: For each category pair in the at least one category pair, the distance between the historical classification information corresponding to the two categories in the category pair is calculated to obtain the historical intra-class / inter-class distance information of the category pair.

3. The method of claim 2, wherein: The library storage classification information includes C historical average features corresponding to C preset categories one by one, the historical average feature is the historical classification information, the K i The categories are subsets of the C preset categories, and the C preset categories are all categories to which all sample images used in iterations from the 1st to the Mth belong.

4. The method of claim 3, wherein: The image classification information corresponding to the i-th iteration includes N output by the intermediate network layer of the student model i intermediate features, the N i The intermediate features and the N i The sample images correspond one to one, and the intermediate feature corresponding to any sample image is the classification information corresponding to the sample image. For each category pair in at least one category pair, for the K i For each category in the categories, the current classification information corresponding to the category is determined based on the classification information corresponding to all sample images included in the category, including: For the K i For each category in the categories, average processing is performed on the intermediate features corresponding to all sample images included in the category to obtain a current average feature corresponding to the category, and the current average feature is the current classification information.

5. The method of claim 4, wherein: The dimension of each intermediate feature, each current average feature, and each historical average feature is equal to d. The library storage classification information is represented by a historical feature matrix of size C×d. The C rows in the historical feature matrix correspond one-to-one to the C historical average features, where: Before calculating the distance between the current classification information corresponding to the two categories in the category pair for each category pair in the at least one category pair to obtain the current intra-class / inter-class distance information of the category pair, the distillation operation further includes: Based on K i The current average features are used to construct a current feature matrix of size C×d, wherein the C rows in the current feature matrix correspond to the C preset categories one by one, and in the current feature matrix, the K rows correspond to the K preset categories one by one. i The rows corresponding to each category take the corresponding current average features, and the elements in the remaining rows are all set to 0; The step of calculating, for each category pair in at least one category pair, the distance between current classification information corresponding to two categories in the category pair to obtain current intra-class / inter-class distance information of the category pair includes: Calculating current intra-class / inter-class distance information of the at least one class pair using the current feature matrix; The step of calculating, for each category pair in the at least one category pair, the distance between the historical classification information corresponding to the two categories in the category pair to obtain the historical intra-category / inter-category distance information of the category pair comprises: The historical feature matrix is ​​used to calculate historical intra-class / inter-class distance information of the at least one class pair.

6. The method of claim 5, wherein: The calculating the current intra-class / inter-class distance information of the at least one class pair by using the current feature matrix comprises: Calculating the product of the current feature matrix and the transposed matrix of the current feature matrix to obtain a first product; Dividing the first product by the modulus of the current feature matrix to obtain a first distance matrix; Obtaining current intra-class / inter-class distance information of the at least one class pair based on the first distance matrix; The calculating the historical intra-class / inter-class distance information of each category pair in the at least one category pair by using the historical feature matrix comprises: Calculating the product of the historical feature matrix and the transposed matrix of the historical feature matrix to obtain a second product; Dividing the second product by the modulus of the historical feature matrix to obtain a second distance matrix; The historical intra-class / inter-class distance information of the at least one class pair is obtained based on the second distance matrix.

7. The method of claim 2, wherein: The combining the image classification information corresponding to the i-th iteration with the acquired library storage classification information to obtain new library storage classification information comprises: The image classification information corresponding to the i-th iteration is superimposed on the acquired library storage classification information by using an exponential sliding average method to obtain the new library storage classification information.

8. The method of claim 2, wherein: In the case of i=1, all elements in the acquired library storage classification information are set to 0.

9. The method according to claim 1 or 2, wherein: The image classification information corresponding to the i-th iteration includes N output by the intermediate network layer of the student model i intermediate features, the N i The intermediate features and the N i The sample images correspond one to one, and the intermediate feature corresponding to any sample image is the classification information corresponding to the sample image. For each category pair in at least one category pair, for the K i For each category in the categories, the current classification information corresponding to the category is determined based on the classification information corresponding to all sample images included in the category, including: For the K i For each category in the categories, average processing is performed on the intermediate features corresponding to all sample images included in the category to obtain a current average feature corresponding to the category, and the current average feature is the current classification information.

10. The method according to claim 1 or 2, wherein: The distilling of the student model by matching the current intra-class / inter-class distance information of each same class pair in the at least one class pair with the historical intra-class / inter-class distance information comprises: Calculate a distance loss value based on current intra-class / inter-class distance information of each same class pair in the at least one class pair and the historical intra-class / inter-class distance information; The student model is distilled based on at least the distance loss value.

11. The method of claim 10, wherein: The total number of categories to which all sample images used in the 1st to the Mth iteration belong is C categories, and the K i The categories are subsets of the C categories, the current intra-class / inter-class distance information of the at least one category pair is represented by a first distance matrix of size C×C, and the historical intra-class / inter-class distance information of the at least one category pair is represented by a second distance matrix of size C×C. In the first distance matrix, the element M1 i′j′ It is used to represent the current intra-class / inter-class distance information between the i'th class and the j'th class in the C classes. In the second distance matrix, the element M2 i′j′ It is used to represent the historical intra-class / inter-class distance information between the i'th class and the j'th class in the C classes, i'=1, 2...C, j'=1, 2...C, The calculating of the distance loss value based on the current intra-class / inter-class distance information of each same class pair in the at least one class pair and the historical intra-class / inter-class distance information comprises: Generate a mask matrix of size C×C, where in the mask matrix, element M3 i′j′ The value of the i'th category and the j'th category in the C categories belong to the K i When there are 1 categories, the element M i′j′ The value of in either the i'th category or the j'th category does not belong to the K i When there are multiple categories, take 0; Calculating a mean square error loss value between the first distance matrix and the second distance matrix; The mean square error loss value is multiplied by the mask matrix to obtain the distance loss value.

12. The method of claim 10, wherein: The distilling the student model at least based on the distance loss value comprises: Calculate the additional loss value; Adding the distance loss value to the additional loss value to obtain a distillation loss value; The student model is distilled based on the distillation loss value.

13. The method of claim 12, wherein: The image classification information corresponding to the i-th iteration includes the image classification result output by the last network layer of the student model, and the image classification result includes i N sample images correspond one to one i classification results, the calculation of the additional loss value includes: Based on the N i The cross entropy loss value is calculated based on the classification results and the first labeled data, and the additional loss value includes the cross entropy loss value.

14. A relational self-distillation device, comprising: The current iteration operation module is used to perform the current iteration operation in the i-th iteration of the training process of the student model, and the current iteration operation module includes: The first acquisition submodule is used to obtain N i sample images and corresponding annotation data, wherein the annotation data is used to indicate the N i The categories corresponding to the sample images are N i The sample images are divided into K i categories, among which N i and K i are all positive integers greater than or equal to 1, i = 1, 2, ..., M, M is a positive integer greater than 1; The input submodule is used to convert the N i sample images are input into the student model to obtain image classification information corresponding to the i-th iteration, wherein the image classification information corresponding to the i-th iteration includes i Classification information corresponding to each sample image; The information determination submodule is used to determine the K i For each category in the categories, determining the current classification information corresponding to the category based on the classification information corresponding to all sample images included in the category; a calculation submodule, configured to calculate, for each category pair in at least one category pair, the distance between the current classification information corresponding to the two categories in the category pair when i is greater than or equal to a preset threshold, so as to obtain the current intra-class / inter-class distance information of the category pair, wherein each category in each category pair in the at least one category pair is the K i one of the categories; A second acquisition submodule is configured to acquire historical intra-class / inter-class distance information of each category pair in the at least one category pair when i is greater than or equal to a preset threshold, wherein the historical intra-class / inter-class distance information is obtained based on image classification information respectively corresponding to previous iterations, wherein the previous iterations include one or more iterations before the i-th iteration; A distillation submodule is used to distill the student model by matching the current intra-class / inter-class distance information of each same category pair in the at least one category pair with the historical intra-class / inter-class distance information when i is greater than or equal to a preset threshold.

15. A relational self-distillation system, comprising a processor and a memory, wherein: The memory stores computer program instructions, which are used by the processor to execute the relational self-distillation method according to any one of claims 1 to 13 when executed.

16. A storage medium having program instructions stored thereon, wherein the program instructions are used to execute the relational self-distillation method according to any one of claims 1 to 13 when run.

Citation Information

Patent Citations

  • Model distillation implementation method, device and system, computer equipment and storage medium

    CN110232411A

  • Image classification method and device based on model distillation and electronic equipment

    CN111950638A

  • Image big data-oriented class increment classification method, system and device and medium

    CN112990280A

  • Unification of models having respective target classes with distillation

    US20210034985A1