Network training method, visual retrieval method and device
Through knowledge distillation technology and whitening processing, the knowledge of multiple teacher networks is distilled into the student network, which solves the deficiencies in computational efficiency of deep neural networks, realizes an efficient visual retrieval model, and improves performance and computational efficiency.
Patent Information
- Application Number
- CN202310379400.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-31
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2043-03-31
AI Technical Summary
Visual retrieval methods based on deep neural networks have shortcomings in computational efficiency, especially in large-scale retrieval scenarios where more compact and efficient retrieval models are needed.
Through knowledge distillation technology, the knowledge of multiple pre-trained teacher networks is distilled into a small student network. The relationship-based distillation method is used to use the similarity between samples as knowledge transfer between teachers and students, and to the teacher network The output feature vectors are whitened to unify the output distribution and achieve the fusion of multi-teacher networks.
It achieves the reduction of computing cost without loss of performance, improves computing efficiency, and improves performance through stable and effective multi-teacher network fusion.
Smart Images

Figure CN118734932A_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of this specification relate to the field of artificial intelligence technology, and in particular, to a network training method, a visual retrieval method, and a device. Background Art
[0002] The goal of visual retrieval is to search for the data that is most relevant to a given query from candidate data. Visual retrieval includes image retrieval, video retrieval, etc., and has a wide range of application scenarios, including instance matching, fine-grained recognition, product recommendations, etc.
[0003] Retrieval methods based on deep neural networks (DNNs) have become the mainstream approach for visual retrieval in recent years. Although DNNs have brought significant performance improvements in visual retrieval, their computational efficiency remains an important issue. Summary of the Invention
[0004] In view of this, one or more embodiments of this specification provide a network training method, a visual retrieval method, and an apparatus.
[0005] To achieve the above objectives, one or more embodiments of this specification provide the following technical solutions:
[0006] According to a first aspect of one or more embodiments of this specification, a network training method is proposed, including:
[0007] Inputting multiple sample image pairs into multiple pre-trained teacher networks and into a student network, each sample image pair being a positive sample pair, including a first sample image and a second sample image;
[0008] Performing whitening processing on the feature vectors of each first sample image and the feature vectors of each second sample image output by each teacher network, and obtaining a first similarity matrix based on the feature vectors after the whitening processing;
[0009] fusing the first similarity matrices of the multiple teacher networks to obtain a fused similarity matrix;
[0010] The network parameters of the student network are adjusted according to the distillation loss between the fused similarity matrix and a second similarity matrix, wherein the second similarity matrix is obtained according to the feature vectors of each first sample image and the feature vector of the second sample image output by the student network.
[0011] In some embodiments, the whitening process of the feature vectors of each first sample image and each second sample image output by each teacher network includes:
[0012] Performing linear transformations on the eigenvectors of the first sample image and the second sample image respectively so that the covariance matrix of the transformed eigenvectors is a unit matrix, wherein the parameters of the linear transformation are determined by the results of running a set training set on the teacher network.
[0013] In some embodiments, the method further comprises:
[0014] Obtaining a zero-mean vector by averaging the mean of feature vectors obtained by extracting features from all training samples in the set training set using the teacher network;
[0015] Using the zero-mean vector to perform zero-mean conversion on the feature matrices corresponding to all training samples;
[0016] Get the eigenvector matrix of the covariance matrix of the zero-mean eigenmatrix;
[0017] The parameters for performing the linear transformation are obtained according to the zero mean vector and the eigenvector matrix.
[0018] In some embodiments, performing linear transformation on the feature vector of the first sample image and the feature vector of the second sample image respectively includes:
[0019] subtracting the zero-mean vector from a feature vector of an image to be processed to obtain a zero-mean feature vector, wherein the image to be processed includes a first sample image and a second sample image;
[0020] The whitened eigenvector is obtained according to the multiplication result of the eigenvector matrix and the zero-mean eigenvector.
[0021] In some embodiments, obtaining a first similarity matrix according to the whitened eigenvectors includes:
[0022] Obtaining a feature matrix according to the whitened feature vector;
[0023] The first similarity matrix is obtained according to a multiplication result of a transposed matrix of the feature matrix and the feature matrix.
[0024] In some embodiments, the method further comprises:
[0025] Performing a full connection operation on the feature vector of the first sample image output by the student network to obtain a first feature matrix;
[0026] Performing a full connection operation on the feature vector of the second sample image output by the student network to obtain a second feature matrix;
[0027] The second similarity matrix is obtained according to the first feature matrix and the second feature matrix.
[0028] In some embodiments, fusing the first similarity matrices of the plurality of teacher networks to obtain a fused similarity matrix includes:
[0029] For the elements on the diagonal of the fused similarity matrix, obtaining the element value according to the maximum value of the corresponding elements in the plurality of first similarity matrices;
[0030] For the off-diagonal elements of the fusion similarity matrix, the element values are obtained according to any of the following methods:
[0031] Obtained according to the minimum value of corresponding elements in multiple first similarity matrices;
[0032] Obtained according to the average value of corresponding elements in a plurality of first similarity matrices;
[0033] The method is obtained according to a corresponding element value of a specified first similarity matrix among the multiple first similarity matrices.
[0034] In some embodiments, the method further comprises:
[0035] Each row of the similarity matrix to be processed is processed using a Gaussian kernel function to obtain a probability distribution matrix, and the similarity matrix to be processed is updated using the probability distribution matrix, where the similarity matrix to be processed includes a first similarity matrix and a second similarity matrix.
[0036] In some embodiments, adjusting the network parameters of the student network according to the distillation loss between the fused similarity matrix and the second similarity matrix includes:
[0037] The distillation loss between the fused similarity matrix and the second similarity matrix is calculated according to the KL divergence loss function.
[0038] According to a second aspect of one or more embodiments of this specification, a visual retrieval method is proposed, comprising: inputting an image to be retrieved into a visual retrieval network to obtain first feature information of the image to be retrieved, wherein the visual retrieval network is a student network trained according to the above embodiment;
[0039] The first feature information is compared with the second feature information of the images in the image library, and the images whose similarity meets the requirements are used as retrieval results, wherein the second feature information is obtained by extracting features from the images in the image library using the visual retrieval network.
[0040] According to a third aspect of one or more embodiments of this specification, a network training device is provided, comprising:
[0041] An input unit, configured to input a plurality of sample image pairs into a plurality of pre-trained teacher networks and into a student network, wherein each sample image pair is a positive sample pair, including a first sample image and a second sample image;
[0042] a whitening unit, configured to perform whitening processing on the eigenvectors of each first sample image and each second sample image output by each teacher network, and obtain a first similarity matrix according to the eigenvectors after the whitening processing;
[0043] a fusion unit, configured to fuse the first similarity matrices of the plurality of teacher networks to obtain a fused similarity matrix;
[0044] An adjustment unit is used to adjust the network parameters of the student network according to the distillation loss between the fused similarity matrix and the second similarity matrix, wherein the second similarity matrix is obtained according to the feature vectors of each first sample image and the feature vector of the second sample image output by the student network.
[0045] In some embodiments, the whitening unit is specifically configured to:
[0046] Performing linear transformations on the eigenvectors of the first sample image and the second sample image respectively so that the covariance matrix of the transformed eigenvectors is a unit matrix, wherein the parameters of the linear transformation are determined by the results of running a set training set on the teacher network.
[0047] In some embodiments, the apparatus further includes a parameter acquisition unit configured to:
[0048] Obtaining a zero-mean vector by averaging the mean of feature vectors obtained by extracting features from all training samples in the set training set using the teacher network;
[0049] Using the zero-mean vector to perform zero-mean conversion on the feature matrices corresponding to all training samples;
[0050] Get the eigenvector matrix of the covariance matrix of the zero-mean eigenmatrix;
[0051] The parameters for performing the linear transformation are obtained according to the zero mean vector and the eigenvector matrix.
[0052] In some embodiments, when the whitening unit is used to perform linear transformation on the feature vector of the first sample image and the feature vector of the second sample image, the whitening unit is specifically used to:
[0053] subtracting the zero-mean vector from a feature vector of an image to be processed to obtain a zero-mean feature vector, wherein the image to be processed includes a first sample image and a second sample image;
[0054] The whitened eigenvector is obtained according to the multiplication result of the eigenvector matrix and the zero-mean eigenvector.
[0055] In some embodiments, when the whitening unit is used to obtain the first similarity matrix according to the whitened eigenvector, it is specifically used to:
[0056] Obtaining a feature matrix according to the whitened feature vector;
[0057] The first similarity matrix is obtained according to a multiplication result of a transposed matrix of the feature matrix and the feature matrix.
[0058] In some embodiments, the apparatus further comprises a determining unit configured to:
[0059] Performing a full connection operation on the feature vector of the first sample image output by the student network to obtain a first feature matrix;
[0060] Performing a full connection operation on the feature vector of the second sample image output by the student network to obtain a second feature matrix;
[0061] The second similarity matrix is obtained according to the first feature matrix and the second feature matrix.
[0062] In some embodiments, the fusion unit is specifically configured to:
[0063] For the elements on the diagonal of the fused similarity matrix, obtaining the element value according to the maximum value of the corresponding elements in the plurality of first similarity matrices;
[0064] For the off-diagonal elements of the fusion similarity matrix, the element values are obtained according to any of the following methods:
[0065] Obtained according to the minimum value of corresponding elements in multiple first similarity matrices;
[0066] Obtained according to the average value of corresponding elements in a plurality of first similarity matrices;
[0067] The method is obtained according to a corresponding element value of a specified first similarity matrix among the multiple first similarity matrices.
[0068] In some embodiments, the apparatus further comprises an updating unit configured to:
[0069] Each row of the similarity matrix to be processed is processed using a Gaussian kernel function to obtain a probability distribution matrix, and the similarity matrix to be processed is updated using the probability distribution matrix, where the similarity matrix to be processed includes a first similarity matrix and a second similarity matrix.
[0070] In some embodiments, the adjustment unit is specifically configured to:
[0071] The distillation loss between the fused similarity matrix and the second similarity matrix is calculated according to the KL divergence loss function.
[0072] According to a fourth aspect of one or more embodiments of this specification, a visual retrieval device is provided, including:
[0073] An input unit, configured to input an image to be retrieved into a visual retrieval network to obtain first feature information of the image to be retrieved, wherein the visual retrieval network is a student network trained in the above embodiment;
[0074] A retrieval unit is used to compare the first feature information with the second feature information of the images in the image library, and take the images whose similarity meets the requirements as retrieval results, wherein the second feature information is obtained by extracting features from the images in the image library using the visual retrieval network.
[0075] According to a fifth aspect of one or more embodiments of this specification, an electronic device is provided, including:
[0076] processor;
[0077] a memory for storing processor-executable instructions;
[0078] The processor implements the method proposed in the above embodiment by running the executable instructions.
[0079] According to a sixth aspect of one or more embodiments of this specification, a computer-readable storage medium is proposed, on which computer instructions are stored. When the instructions are executed by a processor, the steps of the method proposed in the above embodiment are implemented.
[0080] In an embodiment of the present specification, features are extracted from multiple sample image pairs using multiple pre-trained teacher networks, and the feature vectors of the first sample image and the second sample image output by each teacher network are whitened, and a first similarity matrix is obtained based on the whitened feature matrix; the first similarity matrices of the multiple teacher networks are fused to obtain a fused similarity matrix; features are extracted from the multiple sample image pairs using a student network, and a second similarity matrix is obtained based on the feature vectors of the first sample image and the second sample image output by the student network; then, the network parameters of the student network are adjusted based on the distillation loss between the fused similarity matrix and the second similarity matrix. By performing whitening-based similarity normalization on the output of the teacher network, the output distributions of the multiple teacher networks can be unified, making the similarities of the multiple teacher networks comparable, and achieving stable and effective multi-teacher network fusion, so that the multiple teacher networks can be distilled into the student network, achieving improved performance and computational efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0081] Figure 1 This is a flowchart of a network training method provided by an exemplary embodiment.
[0082] Figure 2 It is a schematic diagram of a network training method provided by an exemplary embodiment.
[0083] Figure 3A and Figure 3B These are schematic diagrams of the similarity distribution of multiple neural network outputs before and after whitening.
[0084] Figure 4 This is a flowchart of a method for whitening a feature matrix provided by an exemplary embodiment.
[0085] Figure 5 It is a schematic diagram of another network training method provided by an exemplary embodiment.
[0086] Figure 6 It is a flowchart of a visual retrieval method provided by an exemplary embodiment.
[0087] Figure 7 It is a block diagram of a network training device provided by an exemplary embodiment.
[0088] Figure 8 It is a block diagram of a visual retrieval device provided by an exemplary embodiment.
[0089] Figure 9 It is a structural diagram of a device provided by an exemplary embodiment. DETAILED DESCRIPTION
[0090] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The implementations described in the following exemplary embodiments are not intended to represent all implementations consistent with one or more embodiments of this specification. Rather, they are merely examples of apparatuses and methods consistent with certain aspects of one or more embodiments of this specification, as detailed in the appended claims.
[0091] It should be noted that in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the method may include more or fewer steps than those described in this specification. In addition, a single step described in this specification may be broken down into multiple steps for description in other embodiments, and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0092] The goal of visual retrieval is to search for the data that is most relevant to a given query from candidate data. Visual retrieval includes image retrieval, video retrieval, etc., and has a wide range of application scenarios, including instance matching, fine-grained recognition, product recommendations, etc.
[0093] Retrieval methods based on deep neural networks (DNNs) have become the mainstream approach for visual retrieval in recent years. Although DNNs have brought significant performance improvements to visual retrieval, the computational efficiency of pre-trained models in related technologies is low. For practical large-scale retrieval scenarios, more compact and efficient retrieval models are needed.
[0094] In light of this, the embodiments of this specification propose a network training method that combines multiple heavy pre-trained visual retrieval networks into a more optimized and efficient lightweight visual retrieval network. Specifically, through knowledge distillation technology, the knowledge of multiple large models (teacher networks) is distilled into a small model (student network), reducing computational cost without sacrificing performance.
[0095] Because visual retrieval is a ranking problem and focuses on the relationships between samples, this embodiment uses a relationship-based distillation method, leveraging the inter-sample relationships as the knowledge transferred between the teacher and the student. The following describes this network training method using image retrieval as an example. Those skilled in the art will appreciate that this method is also applicable to other types of visual retrieval.
[0096] Figure 1 1 is a flowchart of a network training method provided by an exemplary embodiment, the method comprising:
[0097] Step 101: Input multiple sample image pairs into multiple pre-trained teacher networks and into a student network.
[0098] Each sample image pair is a positive sample pair, including a first sample image and a second sample image.
[0099] Figure 2 1 is a schematic diagram of a plurality of sample image pairs provided by an exemplary embodiment. The diagram includes N sample image pairs, and each sample image pair includes a first sample image and a second sample image.
[0100] If the first sample image and the second sample image in a sample image pair meet the set requirements, such as the similarity is greater than or equal to the set threshold, they are obtained from the same image and contain overlapping parts, contain the same target object, etc., then the first sample image and the second sample image can be considered to be similar and can be called a positive sample pair; conversely, if the similarity between the first sample image and the second sample image in a sample image pair does not meet the set requirements, then the two can be considered to be unrelated and can be called a negative sample pair.
[0101] by Figure 2 Take the input image in the landmark image retrieval scenario shown as an example, Figure 2 If the first sample image and the second sample image in each sample image pair in contain the same building, then each sample image pair is considered to be a positive sample pair.
[0102] In the embodiments of this specification, each of the multiple teacher networks is a pre-trained visual retrieval network; the student network is a visual retrieval network to be trained. The visual retrieval network is primarily used to extract features from the input image, compare the extracted features with the features of each image in the image library, and generate visual retrieval results based on similarity ranking.
[0103] Step 102: Whiten the feature vectors of each first sample image and each second sample image output by each teacher network, and obtain a first similarity matrix based on the feature vectors after the whitening process.
[0104] In the embodiments of this specification, the multiple teacher networks may have different network structures, or may be trained using different training methods or different training sets. In this case, the similarity distributions output by the multiple teacher networks may be significantly different.
[0105] Figure 3AThe similarity (cosine similarity) distribution graphs of the outputs of five pre-trained visual retrieval networks are shown. The horizontal axis represents the similarity value, and the vertical axis represents the frequency of similarity. Among them, of the two curves with similar peaks on the left, the one on the left is the similarity distribution curve output by the GeM (Generalized-Mean) network, and the one on the right is the similarity distribution curve output by the SOLAR (Second-Order Loss and Attention for image Retrieval) network. The curve with a relatively lower peak is the similarity distribution curve output by the DELG (Deep Local and Global features) network, the curve with the lowest peak is the similarity distribution curve output by the DOLG (Deep Orthogonal Local and Global features) network, and the curve with the highest peak on the right is the similarity distribution curve output by the AP (Average Precision)-GeM network. Figure 3A It can be seen that the similarity distributions of the various teacher networks are significantly different. If this distribution difference is ignored and a multi-teacher selection strategy such as averaging or weighted sum is adopted, the fusion result is likely to be biased towards the distribution of a particular teacher network.
[0106] In the embodiments of this specification, a method of whitening the output features of each teacher network is proposed to eliminate the similarity distribution differences among multiple teacher networks.
[0107] Specifically, each pre-trained teacher network is used to extract features from each first sample image in the multiple sample image pairs to obtain a feature vector for the first sample image, and then whiten the feature vector. Simultaneously, features are extracted from each second sample image in the multiple sample image pairs to obtain a feature vector for the second sample image, and then whiten the feature vector. Next, a first similarity matrix corresponding to the teacher network is obtained based on the whitened feature vectors corresponding to the first sample images and the whitened feature vectors corresponding to the second sample images.
[0108] Whitening the eigenvector is to perform a linear transformation on the eigenvector, transforming the eigenvector with a known covariance matrix into an eigenvector with a covariance matrix of the identity matrix, thereby converting the eigenvector into multiple uncorrelated white noise distributions, and the similarities calculated under the white noise distribution can be consistently aligned. Figure 3B , after whitening treatment, Figure 3AThe five similarity curves in are basically overlapped, with no obvious differences. Therefore, the process of whitening the feature vectors output by multiple teacher networks can also be regarded as the process of standardizing the similarities of the outputs of multiple teacher networks.
[0109] Step 103: Fusing the first similarity matrices of the multiple teacher networks to obtain a fused similarity matrix.
[0110] After the whitening process in step 102, the first similarities of multiple teacher networks are comparable. Therefore, the fusion similarity matrix of multiple teacher networks can be obtained by taking the average of the first similarities output by all teacher networks, thereby realizing the fusion of multiple teacher networks.
[0111] Step 104: Adjust the network parameters of the student network according to the distillation loss between the fused similarity matrix and the second similarity matrix.
[0112] In the embodiments of this specification, a student network to be trained can be used to perform feature extraction on multiple sample image pairs. Specifically, feature extraction is performed on each first sample image to obtain a feature vector of the first sample image; feature extraction is performed on each second sample image to obtain a feature vector of the second sample image; and a second similarity matrix is obtained based on the feature vectors of the first sample images and the feature vectors of the second sample images.
[0113] In one example, a full connection operation can be performed on the feature vector of the first sample image output by the student network to obtain a first feature matrix; a full connection operation can be performed on the feature vector of the second sample image output by the student network to obtain a second feature matrix; and the second similarity matrix can be obtained based on the first feature matrix and the second feature matrix.
[0114] After obtaining the second similarity matrix, the distillation loss between the fusion similarity matrix corresponding to multiple teacher networks and the second similarity matrix is calculated, that is, the difference between the similarity distribution output by multiple teacher networks and the similarity distribution output by the student network is obtained. By minimizing the difference, the network parameters of the student network are adjusted to achieve training of the student network.
[0115] In an embodiment of the present specification, features are extracted from multiple sample image pairs using multiple pre-trained teacher networks, and the feature vectors of the first sample image and the feature vectors of the second sample image output by each teacher network are whitened, and a first similarity matrix is obtained based on the whitened feature vectors; the first similarity matrices of the multiple teacher networks are fused to obtain a fused similarity matrix; features are extracted from the multiple sample image pairs using a student network, and a second similarity matrix is obtained based on the feature vectors of the first sample image and the feature vectors corresponding to the second sample image output by the student network; then, the network parameters of the student network are adjusted based on the distillation loss between the fused similarity matrix and the second similarity matrix. By performing whitening-based similarity normalization on the output of the teacher network, the output distributions of the multiple teacher networks can be unified, making the similarities of the multiple teacher networks comparable, and achieving stable and effective multi-teacher network fusion, so that the multiple teacher networks can be distilled into the student network, achieving improved performance and computational efficiency.
[0116] In the embodiments of this specification, the parameters for the linear transformation (whitening process) performed on the feature vectors of the first sample image and the second sample image are determined by running the results of the teacher network on the set training set. The process of obtaining the parameters for the whitening process can be performed after training the teacher network and before distilling the student network.
[0117] See also Figure 4 , the parameters for whitening processing can be obtained through the following steps.
[0118] Step 401: Obtain a zero-mean vector by extracting the average value of the feature vectors obtained by extracting features of all training samples in the set training set according to the teacher network.
[0119] Assume that the training set is represented as B is the number of training samples. For each teacher network k, the zero-mean vector b k It can be expressed as:
[0120]
[0121] Among them, B is the number of training samples, x i represents the training sample, ψ k (·) represents the feature vector extracted by the teacher network k.
[0122] Step 402: Use the zero-mean vector to perform zero-mean conversion on the feature matrices corresponding to all training samples.
[0123] Specifically, the zero-mean feature vector is obtained by subtracting the feature vector of each training sample from the zero-mean feature vector. And according to the corresponding Get the zero-mean feature matrix corresponding to all training samples. It can be expressed as:
[0124]
[0125] Among them, ψ k (·) represents the feature vector extracted by the teacher network k, b k represents a zero-mean vector.
[0126] Step 403: Obtain an eigenvector matrix of the covariance matrix of the zero-mean eigenmatrix.
[0127] Each element of the covariance matrix ∑ represents the covariance between different components of the eigenvector matrix, and the eigenvector matrix satisfies The eigenvector matrix Wk can be calculated using this formula.
[0128] Step 404: Obtain the parameters for performing the linear transformation according to the zero-mean vector and the eigenvector matrix.
[0129] The zero-mean vector b obtained according to steps 401 to 403 k and the eigenvector matrix W k , which can be used to whiten the equally processed feature vectors to obtain the whitened results.
[0130] The whitening process in step 102 can be implemented by the following steps.
[0131] First, the zero-mean vector obtained in step 402 is subtracted from the feature vector of the first sample image to obtain a zero-mean feature vector corresponding to the first sample image; and the zero-mean vector is subtracted from the feature vector of the second sample image to obtain a zero-mean feature vector corresponding to the second sample image.
[0132] Next, the whitened eigenvector corresponding to the first sample image is obtained based on the multiplication result of the zero-mean eigenvector corresponding to the first sample image and the eigenvector matrix obtained in step 403; the whitened eigenvector corresponding to the second sample image is obtained based on the multiplication result of the zero-mean eigenvector corresponding to the second sample image and the eigenvector matrix.
[0133] The following describes in detail the process of whitening during the training of the student network.
[0134] The sample image pairs input to the pre-trained teacher networks are (x1, y1), (x2, y2), ..., (x N ,y N ), where x iRepresents the first sample image, y i represents the second sample image, i=1, 2, ..., N, where N is the number of sample image pairs.
[0135] In the embodiments of this specification, both the teacher network and the student network can be regarded as encoders from the input space to the feature space. Assume that the teacher network can be represented as ψ k : Where m is the size of the input space, n is the size of the feature space, and K is the number of teacher networks. k Each sample image pair is subjected to feature extraction to obtain the feature vector ψ of the first sample image k (x i ), i = 1, 2, ..., N, and the feature vector ψ of the second sample image k (y i ), i = 1, 2, ..., N. Correspondingly, the feature matrix corresponding to the first sample image in the N sample image pairs is The feature matrix corresponding to the second sample image Among them, ψ k (·) is an n-dimensional column vector.
[0136] For each teacher network k, the process of whitening the feature vectors of the first sample image and the second sample image can be expressed by the following linear transformation formula:
[0137]
[0138] Among them, W k is the eigenvector matrix of the covariance matrix ∑ of the zero-mean eigenmatrix, b k is a zero-mean vector, W k and b k Refer to steps 401 to 404 for the method of obtaining ψ k (·) represents the features extracted by the teacher network k for the input sample image pair, b k Represents zero mean.
[0139] Correspondingly, after whitening, the feature matrix corresponding to the first sample image in the N sample image pairs can be expressed as The feature matrix corresponding to the second sample image can be expressed as
[0140] In the embodiment of this specification, cosine similarity can be used to measure the relationship between images. After obtaining the feature matrix after whitening, the first similarity matrix can be obtained by multiplying the transposed matrix of the feature matrix with the feature matrix itself. For the teacher network k, the first similarity matrix can be expressed by the following formula, for example:
[0141]
[0142] The i-th row of the first similarity matrix represents the similarity value between any image j and image i. represents the feature matrix of the first sample image after whitening processing, Represents the feature matrix of the second sample image after whitening.
[0143] In some embodiments, the similarity matrix can be further converted into a probability matrix, including converting a first similarity matrix output by the teacher network into a probability matrix, and converting a second similarity matrix output by the student network into a probability matrix.
[0144] Specifically, each row of the similarity matrix to be processed can be normalized using a Gaussian kernel function, and the normalization result can be used to update the similarity matrix to be processed. This process can be expressed, for example, by the following formula:
[0145]
[0146] Where s(i, j) is the image x i and image y i The similarity between them is τ, which is a temperature factor and can be set according to the actual task.
[0147] After the similarity matrix is converted into a probability matrix, the distillation loss between the fused similarity matrix and the second similarity matrix can be calculated according to the Kullback-Lerbler (KL) divergence loss function. The loss function can be expressed, for example, by the following formula:
[0148]
[0149] Where N is the number of sample image pairs, and are the similarity matrices of the teacher network and the student network represented by probability matrices respectively.
[0150] The distillation loss is calculated according to the KL divergence loss function, which takes into account the asymmetry of the difference between the two probability distributions and can improve the training effect.
[0151] The following describes the process of handling the student network.
[0152] Assume that the student network can be expressed as Where m is the size of the input space and n is the size of the feature space. Perform feature extraction on N sample image pairs to obtain the feature matrix corresponding to the first sample image And the feature matrix corresponding to the second sample image in, is an n-dimensional column vector representing the features extracted by the student network.
[0153] Accordingly, the second similarity matrix of the student network can be expressed by the following formula, for example:
[0154] S=(П x ) T П y , S∈R N×N (7)
[0155] Among them, the i-th row of the second similarity matrix represents the similarity value between any image j and image i, П x Represents the feature matrix corresponding to the first sample image, П y Represents the feature matrix corresponding to the first sample image.
[0156] During student network training, multiple sample image pairs are sequentially input to the multiple teacher networks and the student network during each training iteration. The network parameters of the student network are adjusted based on the distillation loss between the fused similarity matrices corresponding to the multiple teacher networks and the second similarity matrix corresponding to the student network. After the current iterative training is completed, the next batch of multiple sample image pairs is input for the next iterative training. The multiple sample image pairs input for each iteration include at least partially different sample image pairs. When a predetermined termination condition is met, such as when the distillation loss value drops to a certain threshold or when a predetermined number of iterations is reached, the student network training is completed.
[0157] In this embodiment, the input sample image pairs are all positive sample pairs. The diagonal elements of the first similarity matrix corresponding to each teacher network represent the similarity between the positive sample pairs, which can be used to evaluate the alignment of the teacher network with samples within the class. The off-diagonal area describes the structure of the corresponding feature space and can reflect the arrangement of the sample images in space.
[0158] The first similarity matrices corresponding to the K teacher networks are fused and can be expressed using the following formula:
[0159]
[0160] in, represents the fusion function, represents the first similarity matrix of the k-th teacher network.
[0161] In some embodiments, the first similarity matrices of multiple teacher networks may be fused using any of the following fusion strategies:
[0162] 1. For elements on the diagonal, the maximum value of the corresponding elements in the multiple first similarity matrices is taken as the element value; for elements on the non-diagonal, the minimum value of the corresponding elements in the multiple first similarity matrices is taken as the element value.
[0163] In this strategy, we prefer a more compact intra-class distribution and push all negative samples as far as possible to achieve a more uniform distribution.
[0164] 2. For elements on the diagonal, the maximum value of the corresponding elements in the multiple first similarity matrices is taken as the element value; for elements on the non-diagonal, the average value of the corresponding elements in the multiple first similarity matrices is taken as the element value.
[0165] In this strategy, a more compact within-class distribution is favored, and the average of multiple distributions is considered.
[0166] 3. For the elements on the diagonal, the maximum value of the corresponding elements in multiple similarity matrices is taken as the element value; for the elements on the non-diagonal, the corresponding element value in the specified first similarity matrix in multiple first similarity matrices is taken.
[0167] In this strategy, a more compact intra-class distribution is preferred, the average distribution of multiple distributions is considered, and learning from a fixed teacher network is adopted.
[0168] According to the fusion strategy proposed in the embodiments of this specification, better fusion effects can be achieved based on the actual training conditions of multiple teacher networks.
[0169] Figure 5 FIG. 1 is a schematic diagram of another network training method provided by an exemplary embodiment. Figure 5 As shown, N sample image pairs are input into K pre-trained multiple teacher networks T k , k=1, 2, ..., K, and a student network S to be trained, the N sample image pairs are all positive sample pairs, and the first sample image and the second sample image in each positive sample pair contain the same building.
[0170] The following describes the processing process of the teacher network T1 as an example:
[0171] Teacher network T1 performs feature extraction on N sample image pairs to obtain feature vectors of each first sample image. The feature matrices corresponding to the N first sample images in the N sample image pairs are shown as 501. Furthermore, the teacher network T1 obtains feature vectors of each second sample image. The feature matrices corresponding to the N second sample images in the N sample image pairs are shown as 502. Feature matrices 501 and 502 are whitened to obtain feature matrices 503 and 504 after whitening. A first similarity matrix 505 is obtained based on feature matrices 503 and 504. For example, the first similarity matrix 505 can be obtained by multiplying the transposed matrix of feature matrix 503 by feature matrix 504. The first similarity matrix 505 can be updated to a probability matrix.
[0172] The other teacher networks can adopt the same processing process as T1 to obtain the corresponding first similarity matrix; and the first similarity matrices corresponding to multiple teacher networks are fused to obtain a fused similarity matrix 506.
[0173] The student network S similarly extracts features from the N sample image pairs to obtain feature vectors for each first sample image. The feature matrices corresponding to the N first sample images in the N sample image pairs are shown in 511. Feature vectors for each second sample image are also obtained. The feature matrices corresponding to the N second sample images in the N sample image pairs are shown in 512. Fully connected operations are performed on feature matrices 511 and 512, respectively, to obtain feature matrices 513 and 514. A second similarity matrix 505 is obtained based on feature matrices 513 and 514. For example, a second similarity matrix 515 can be obtained by multiplying the transposed matrix of feature matrix 513 by feature matrix 514. This second similarity matrix 515 can be updated to a probability matrix.
[0174] According to the distillation loss between the fusion similarity matrix 506 and the second similarity matrix 515 , the network parameters of the student network S are adjusted to achieve training of the student network S.
[0175] Figure 6 FIG. 1 is a flowchart of a visual retrieval method provided by an exemplary embodiment. The method includes the following steps:
[0176] Step 601: Input the image to be retrieved into a visual retrieval network to obtain first feature information of the image to be retrieved. The visual retrieval network is trained according to the above embodiment.
[0177] Step 602: Compare the first feature information with the second feature information of the images in the image library, and use the images whose similarity meets the requirements as retrieval results, wherein the second feature information is obtained by extracting features from the images in the image library using the visual retrieval network.
[0178] See also Figure 7 , Figure 7 1 is a block diagram of a network training device provided by an exemplary embodiment, the device comprising:
[0179] An input unit 701 is configured to input a plurality of sample image pairs into a plurality of pre-trained teacher networks and into a student network, wherein each sample image pair is a positive sample pair and includes a first sample image and a second sample image;
[0180] a whitening unit 702 for performing whitening processing on the feature vectors of each first sample image and each second sample image output by each teacher network, and obtaining a first similarity matrix based on the feature vectors after the whitening processing;
[0181] A fusion unit 703 is configured to fuse the first similarity matrices of the plurality of teacher networks to obtain a fused similarity matrix;
[0182] An adjustment unit 704 is configured to adjust the network parameters of the student network according to the distillation loss between the fused similarity matrix and the second similarity matrix, wherein the second similarity matrix is obtained based on the feature vectors of each first sample image and the feature vectors of the second sample image output by the student network.
[0183] In some embodiments, the whitening unit is specifically configured to:
[0184] Performing linear transformations on the eigenvectors of the first sample image and the second sample image respectively so that the covariance matrix of the transformed eigenvectors is a unit matrix, wherein the parameters of the linear transformation are determined by the results of running a set training set on the teacher network.
[0185] In some embodiments, the apparatus further includes a parameter acquisition unit configured to:
[0186] Obtaining a zero-mean vector by averaging the mean of feature vectors obtained by extracting features from all training samples in the set training set using the teacher network;
[0187] Using the zero-mean vector to perform zero-mean conversion on the feature matrices corresponding to all training samples;
[0188] Get the eigenvector matrix of the covariance matrix of the zero-mean eigenmatrix;
[0189] The parameters for performing the linear transformation are obtained according to the zero mean vector and the eigenvector matrix.
[0190] In some embodiments, when the whitening unit is used to perform linear transformation on the feature vector of the first sample image and the feature vector of the second sample image, the whitening unit is specifically used to:
[0191] subtracting the zero-mean vector from a feature vector of an image to be processed to obtain a zero-mean feature vector, wherein the image to be processed includes a first sample image and a second sample image;
[0192] The whitened eigenvector is obtained according to the multiplication result of the eigenvector matrix and the zero-mean eigenvector.
[0193] In some embodiments, when the whitening unit is used to obtain the first similarity matrix according to the whitened eigenvector, it is specifically used to:
[0194] Obtaining a feature matrix according to the whitened feature vector;
[0195] The first similarity matrix is obtained according to a multiplication result of a transposed matrix of the feature matrix and the feature matrix.
[0196] In some embodiments, the apparatus further comprises a determining unit configured to:
[0197] Performing a full connection operation on the feature vector of the first sample image output by the student network to obtain a first feature matrix;
[0198] Performing a full connection operation on the feature vector of the second sample image output by the student network to obtain a second feature matrix;
[0199] The second similarity matrix is obtained according to the first feature matrix and the second feature matrix.
[0200] In some embodiments, the fusion unit is specifically configured to:
[0201] For the elements on the diagonal of the fused similarity matrix, obtaining the element value according to the maximum value of the corresponding elements in the plurality of first similarity matrices;
[0202] For the off-diagonal elements of the fusion similarity matrix, the element values are obtained according to any of the following methods:
[0203] Obtained according to the minimum value of corresponding elements in multiple first similarity matrices;
[0204] Obtained according to the average value of corresponding elements in a plurality of first similarity matrices;
[0205] The method is obtained according to a corresponding element value of a specified first similarity matrix among the multiple first similarity matrices.
[0206] In some embodiments, the apparatus further comprises an updating unit configured to:
[0207] Each row of the similarity matrix to be processed is processed using a Gaussian kernel function to obtain a probability distribution matrix, and the similarity matrix to be processed is updated using the probability distribution matrix, where the similarity matrix to be processed includes a first similarity matrix and a second similarity matrix.
[0208] In some embodiments, the adjustment unit is specifically configured to:
[0209] The distillation loss between the fused similarity matrix and the second similarity matrix is calculated according to the KL divergence loss function.
[0210] Figure 8 This is a block diagram of a visual retrieval device provided by an exemplary embodiment. The device includes:
[0211] An input unit 801 is used to input an image to be retrieved into a visual retrieval network to obtain first feature information of the image to be retrieved. The visual retrieval network is a student network trained in the above embodiment.
[0212] The retrieval unit 802 is used to compare the first feature information with the second feature information of the image in the image library, and take the image whose similarity meets the requirements as the retrieval result, wherein the second feature information is obtained by using the visual retrieval network to extract features from the image in the image library.
[0213] Figure 9 This is a schematic structural diagram of a device provided by an exemplary embodiment. Figure 9 At the hardware level, the device includes a processor 902, an internal bus 904, a network interface 906, a memory 908, and a non-volatile memory 910. Of course, it may also include hardware required for other tasks. One or more embodiments of this specification can be implemented based on software, such as the processor 902 reading the corresponding computer program from the non-volatile memory 910 into the memory 908 and then running it. Of course, in addition to software implementation, one or more embodiments of this specification do not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0214] The systems, devices, modules, or units described in the above embodiments may be implemented by computer chips or entities, or by products having certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email transceiver, game console, tablet computer, wearable device, or any combination of these devices.
[0215] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0216] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0217] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information using any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices, or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.
[0218] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0219] The foregoing description of this specification describes specific embodiments. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0220] The terms used in one or more embodiments of this specification are for the purpose of describing specific embodiments only and are not intended to limit one or more embodiments of this specification. The singular forms "a," "an," "the," and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0221] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when..." or "when..." or "in response to determining."
[0222] The above description is merely a preferred embodiment of one or more embodiments of this specification and is not intended to limit one or more embodiments of this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of this specification shall be included in the scope of protection of one or more embodiments of this specification.
Claims
1. A network training method, comprising: Inputting a plurality of sample image pairs into a plurality of pre-trained teacher networks and into a student network, each sample image pair being a positive sample pair, including a first sample image and a second sample image; Performing whitening processing on the feature vectors of each first sample image and the feature vectors of each second sample image output by each teacher network, and obtaining a first similarity matrix according to the feature vectors after the whitening processing; fusing the first similarity matrices of the plurality of teacher networks to obtain a fused similarity matrix; The network parameters of the student network are adjusted according to the distillation loss between the fused similarity matrix and the second similarity matrix, wherein the second similarity matrix is obtained according to the feature vectors of each first sample image and the feature vectors of the second sample image output by the student network.
2. The method according to claim 1, wherein the step of whitening the feature vectors of each first sample image and each second sample image output by each teacher network comprises: Linear transformation is performed on the feature vector of the first sample image and the feature vector of the second sample image respectively, so that the covariance matrix of the transformed feature vector is a unit matrix, wherein the parameters of the linear transformation are determined by the result of running a set training set on the teacher network.
3. The method according to claim 2, further comprising: Obtain a zero-mean vector by extracting features from all training samples in the set training set according to the teacher network and obtaining an average mean of feature vectors; Using the zero-mean vector to perform zero-mean conversion on the feature matrices corresponding to all training samples; Get the eigenvector matrix of the covariance matrix of the zero-mean eigenmatrix; The parameters for performing the linear transformation are obtained according to the zero mean vector and the eigenvector matrix.
4. The method according to claim 3, wherein the linear transformation of the feature vector of the first sample image and the feature vector of the second sample image comprises: Subtracting the zero mean vector from the feature vector of the image to be processed to obtain a zero mean feature vector, wherein the image to be processed includes a first sample image and a second sample image; The whitened eigenvector is obtained according to the multiplication result of the eigenvector matrix and the zero-mean eigenvector.
5. The method according to any one of claims 1 to 4, wherein obtaining a first similarity matrix according to the whitened feature vectors comprises: Obtaining a feature matrix according to the whitened feature vector; The first similarity matrix is obtained according to the multiplication result of the transposed matrix of the feature matrix and the feature matrix.
6. The method according to any one of claims 1 to 4, further comprising: Performing a full connection operation on the feature vector of the first sample image output by the student network to obtain a first feature matrix; Performing a full connection operation on the feature vector of the second sample image output by the student network to obtain a second feature matrix; The second similarity matrix is obtained according to the first feature matrix and the second feature matrix.
7. According to the method according to any one of claims 1 to 4, the step of fusing the first similarity matrices of the plurality of teacher networks to obtain a fused similarity matrix comprises: For the elements on the diagonal of the fused similarity matrix, obtaining the element value according to the maximum value of the corresponding elements in the plurality of first similarity matrices; For the elements on the off-diagonal line of the fused similarity matrix, the element value is obtained according to any of the following methods: Obtained according to the minimum value of corresponding elements in a plurality of first similarity matrices; Obtained according to the average value of corresponding elements in a plurality of first similarity matrices; The method is obtained according to a corresponding element value of a specified first similarity matrix among the plurality of first similarity matrices.
8. The method according to any one of claims 1 to 4, further comprising: Each row of the similarity matrix to be processed is processed using a Gaussian kernel function to obtain a probability distribution matrix, and the similarity matrix to be processed is updated using the probability distribution matrix, wherein the similarity matrix to be processed includes a first similarity matrix and a second similarity matrix.
9. The method according to claim 8, wherein adjusting the network parameters of the student network according to the distillation loss between the fused similarity matrix and the second similarity matrix comprises: The distillation loss between the fused similarity matrix and the second similarity matrix is calculated according to the KL divergence loss function.
10. A visual retrieval method, comprising: Inputting the image to be retrieved into a visual retrieval network to obtain first feature information of the image to be retrieved, wherein the visual retrieval network is a student network trained according to any one of claims 1 to 9; The first feature information is compared with the second feature information of the image in the image library, and the image whose similarity meets the requirement is taken as the retrieval result, wherein the second feature information is obtained by extracting features of the image in the image library using the visual retrieval network.
11. A network training device, comprising: An input unit, used to input a plurality of sample image pairs into a plurality of pre-trained teacher networks and into a student network, each sample image pair being a positive sample pair, including a first sample image and a second sample image; A whitening unit, used for performing whitening processing on the feature vectors of each first sample image and the feature vectors of each second sample image output by each teacher network, and obtaining a first similarity matrix according to the feature vectors after the whitening processing; A fusion unit, used for fusing the first similarity matrices of the plurality of teacher networks to obtain a fused similarity matrix; An adjustment unit is used to adjust the network parameters of the student network according to the distillation loss between the fused similarity matrix and the second similarity matrix, wherein the second similarity matrix is obtained according to the feature vectors of each first sample image and the feature vectors of the second sample image output by the student network.
12. A visual retrieval device, comprising: An input unit, used for inputting the image to be retrieved into a visual retrieval network to obtain first feature information of the image to be retrieved, wherein the visual retrieval network is a student network trained according to any one of claims 1 to 9; A retrieval unit is used to compare the first feature information with the second feature information of the image in the image library, and take the image whose similarity meets the requirements as the retrieval result, wherein the second feature information is obtained by extracting features from the image in the image library using the visual retrieval network.
13. An electronic device comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 9 or claim 10 by running the executable instructions.
14. A computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 9 or claim 10.
Citation Information
Patent Citations
Edge equipment knowledge-oriented distillation method and device
CN115618945A
Neural network compression via weak supervision
US20180260695A1
Cited By
Lightweight radiation source signal identification method and system
CN122412857A
