Few-shot image classification method based on Mahalanobis distance loss feature attention network
By using the Mahalanobis distance loss feature attention network in small sample image classification and giving features different weights, the problem of insufficient adaptability of the backbone model to new task features is solved and the classification performance is improved.
Patent Information
- Application Number
- CN202211460720.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-17
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2042-11-17
AI Technical Summary
In small sample learning, the backbone model is difficult to adapt to the feature distribution of new tasks, and existing methods fail to fully utilize the feature distribution information of labeled samples in new tasks, resulting in insufficient classification performance.
The feature attention network based on Mahalanobis distance loss is used to assign different weights to features through the feature attention network to reduce the intra-class distance and expand the inter-class distance, thereby improving classification performance.
Through the Mahalanobis distance loss feature attention network, the backbone model can better adapt to new task features and improve the accuracy of small sample image classification.
Smart Images

Figure CN115880524B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision technology, and in particular to a small sample image classification method based on a Mahalanobis distance loss feature attention network. Background Art
[0002] In recent years, deep learning has made great progress in many other tasks including image classification, object detection and segmentation. However, the advanced performance of deep learning models depends heavily on the size of the network. If the network is trained with samples that are much smaller than the number of parameters, it will lead to catastrophic overfitting. However, in many cases, it is expensive to collect enough data for effective model training. Therefore, data scarcity greatly limits the applicability of current visual systems to effectively learn new visual concepts. In contrast, the human visual system can recognize new classes with very little labeled data. Learning to generalize new classes using a small amount of labeled data is of great significance to the development of deep learning, general artificial intelligence and other fields.
[0003] In small sample learning, since there are very few labeled samples for the new task, and the training domain is usually different from the new task domain, the distribution of the backbone features obtained through training is difficult to adapt to the new task. Therefore, many methods have been proposed to adapt the features extracted from the backbone to the new task. For example, the PT (Power Transform) model scales the features to the same scale so that the large variance features do not dominate, reducing the impact of the difference between the training domain and the new task domain; the CNAPS (Conditional Neural Adaptive Processes) model uses affine transformation in the backbone network to make the feature vectors obtained by the backbone more adaptable to the new domain. However, the above methods either directly reduce the large variance features and do not utilize the feature distribution information of the labeled samples in the new task, or the simple affine transformation is difficult to have a sufficient impact on the features extracted by the network. Therefore, how to make full use of the training set to adapt the backbone network to the new task is still a technical problem that urgently needs to be solved in this field. Summary of the invention
[0004] To this end, the technical problem to be solved by the present invention is to overcome the technical defects existing in the prior art. It provides a small sample image classification method based on the Mahalanobis distance loss feature attention network, which makes up for the shortcoming that the backbone model has insufficient knowledge of the importance of new task features. Before using the Mahalanobis distance classification, different weights are assigned to the features through the feature attention network, so that the intra-class distance is reduced and the intra-class distance is expanded, thereby improving the classification performance.
[0005] In order to solve the above technical problems, the present invention provides a small sample image classification method based on Mahalanobis distance loss feature attention network, comprising the following steps:
[0006] Performing feature extraction on a small sample image data set with labels to obtain a training set, wherein the training set includes feature vectors of the samples and their corresponding categories;
[0007] Input the samples in the training set into the feature attention network for training to obtain a trained feature attention network, and average the feature vectors in the training set after passing through the trained feature attention network to obtain the representation of the class;
[0008] Feature extraction is performed on a small sample image dataset without labels to obtain a test set. The samples in the test set are input into a trained feature attention network to obtain a new feature vector. The Mahalanobis distance between the new feature vector and the class representation is calculated, where the class corresponding to the minimum Mahalanobis distance represents the classification prediction for the sample.
[0009] In one embodiment of the present invention, feature extraction is performed on a small sample image dataset with labels to obtain a training set, including:
[0010] Input the labeled small sample image dataset into the pre-trained backbone model to obtain the training set Where N τ represents the number of training sets, X i Represents the feature vector of the i-th image, y i Indicates the category corresponding to the feature vector, wherein the backbone model is a classification network with the last classification head removed.
[0011] In one embodiment of the present invention, the feature attention network includes d convolution kernels of size 1×1, each convolution kernel corresponds to the weight of a corresponding feature, and the output of the feature attention network has the same dimension as its input.
[0012] In one embodiment of the present invention, the loss function for training the feature attention network is:
[0013]
[0014] In the formula, intraSim represents the intra-class similarity, and interSim represents the inter-class similarity.
[0015] In one embodiment of the present invention, the intra-class similarity intraSim and the inter-class similarity interSim are defined as follows:
[0016]
[0017]
[0018] In the formula, class represents r crepresents the average vector obtained by training the feature attention network of the c-th type input in the training set, o c,i represents the i-th vector of the c-th category output by the feature attention network, o t,i represents the i-th vector of the t-th category output by the feature attention network, Indicates that rc and o are obtained through Mahalanobis distance t,i The similarity.
[0019] In one embodiment of the present invention, the Mahalanobis distance function maha( t,i ,r c ) is as follows:
[0020]
[0021] In the formula, Represents the c-th type of mixed covariance matrix of the training set, which is expressed by the c-th type of covariance matrix of the training set The covariance matrix Σ with the training set τ Jointly decide that:
[0022]
[0023] In the formula, the weight E is an identity matrix, the covariance as well as
[0024] In addition, the present invention also provides a small sample image classification system based on Mahalanobis distance loss feature attention network, comprising:
[0025] A data preprocessing module, which is used to extract features from a small sample image data set with labels to obtain a training set, wherein the training set includes a feature vector of the sample and its corresponding category;
[0026] A feature attention network training module, wherein the feature attention network training module is used to input the samples in the training set into the feature attention network for training to obtain a trained feature attention network, and the feature vectors in the training set are averaged after passing through the trained feature attention network to obtain a class representation;
[0027] A classification prediction module is used to extract features from a small sample image data set without labels to obtain a test set, input the samples in the test set into a trained feature attention network to obtain a new feature vector, and calculate the Mahalanobis distance between the new feature vector and the class representation, where the class corresponding to the minimum Mahalanobis distance represents the classification prediction for the sample.
[0028] In one embodiment of the present invention, in the feature attention network training module, the loss function for training the feature attention network is:
[0029]
[0030] In the formula, intraSim represents the intra-class similarity, and interSim represents the inter-class similarity.
[0031] In one embodiment of the present invention, the intra-class similarity intraSim and the inter-class similarity interSim are defined as follows:
[0032]
[0033]
[0034] In the formula, class represents r c represents the average vector obtained by training the feature attention network of the c-th type input in the training set, o c,i represents the i-th vector of the c-th category output by the feature attention network, o t,i represents the i-th vector of the t-th category output by the feature attention network, Indicates that rc and o are obtained through Mahalanobis distance t,i The similarity.
[0035] In one embodiment of the present invention, the Mahalanobis distance function maha( t,i ,r c ) is as follows:
[0036]
[0037] In the formula, Represents the c-th type of mixed covariance matrix of the training set, which is expressed by the c-th type of covariance matrix of the training set The covariance matrix Σ with the training set τ Jointly decide that:
[0038]
[0039] In the formula, the weight E is an identity matrix, the covariance as well as
[0040] The above technical solution of the present invention has the following advantages compared with the prior art:
[0041] The present invention discloses a small sample image classification method based on a Mahalanobis distance loss feature attention network, which makes up for the shortcoming of the backbone model's insufficient knowledge of the importance of new task features. Before using the Mahalanobis distance classification, different weights are assigned to features through a feature attention network, so that the intra-class distance is reduced and the intra-class distance is expanded, thereby improving the classification performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to make the content of the present invention more clearly understood, the present invention is further described in detail below according to specific embodiments of the present invention in conjunction with the accompanying drawings, wherein
[0043] Figure 1 It is a flowchart of a small sample image classification method based on a Mahalanobis distance loss feature attention network proposed in the present invention.
[0044] Figure 2 It is a structural schematic diagram of a small sample image classification system based on a Mahalanobis distance loss feature attention network proposed in the present invention.
[0045] Among them, the figure numerals are explained: 10, data preprocessing module; 20, feature attention network training module; 30, classification prediction module. DETAILED DESCRIPTION
[0046] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention.
[0047] Reference Figure 1 As shown, a small sample image classification method based on a Mahalanobis distance loss feature attention network of the present invention comprises the following steps:
[0048] S1: extracting features from a small sample image dataset with labels to obtain a training set, wherein the training set includes feature vectors of the samples and their corresponding categories;
[0049] S2: Input the samples in the training set into the feature attention network for training to obtain a trained feature attention network, and average the feature vectors in the training set after passing through the trained feature attention network to obtain the representation of the class;
[0050] S3: Perform feature extraction on a small sample image dataset without labels to obtain a test set, input the samples in the test set into the trained feature attention network to obtain a new feature vector, and calculate the Mahalanobis distance between the new feature vector and the class representation, where the class corresponding to the smallest Mahalanobis distance represents the classification prediction of the sample.
[0051] In step S1, feature extraction is performed on the labeled small sample image dataset to obtain a training set, including inputting the labeled small sample image dataset into a pre-trained backbone model to obtain a training set. Where N τ represents the number of training sets, X i Represents the feature vector of the i-th image, y i Indicates the category corresponding to the feature vector, wherein the backbone model is a classification network with the last classification head removed.
[0052] In step S2, the feature attention network includes d convolution kernels of size 1×1, each convolution kernel corresponds to the weight of the corresponding feature, and the output of the feature attention network has the same dimension as its input. The loss function for training the feature attention network is:
[0053]
[0054] In the formula, intraSim represents the intra-class similarity, and interSim represents the inter-class similarity.
[0055] The definitions of the intra-class similarity intraSim and the inter-class similarity interSim mentioned above are as follows:
[0056]
[0057]
[0058] In the formula, class represents r c represents the average vector obtained by training the feature attention network of the c-th type input in the training set, o c,i represents the i-th vector of the c-th category output by the feature attention network, o t,i represents the i-th vector of the t-th category output by the feature attention network, Indicates that r is obtained through Mahalanobis distance c With o t,i The similarity of. The Mahalanobis distance function maha(o t,i ,r c ) is as follows:
[0059]
[0060] In the formula, Represents the c-th type of mixed covariance matrix of the training set, which is expressed by the c-th type of covariance matrix of the training set The covariance matrix Σ with the training set τ Jointly decide that:
[0061]
[0062] In the formula, the weight E is an identity matrix, the covariance as well as
[0063] The following is a detailed explanation of a small sample image classification method based on a Mahalanobis distance loss feature attention network proposed in an embodiment of the present invention through a specific application scenario.
[0064] The present invention is carried out on the public dataset CIFAR-FS for small sample image classification. The CIFAR-FS dataset contains a total of 100 categories of images, each category consists of 600 images, with a high average inter-class similarity and a lower resolution of 32×32, which is a sufficient challenge for small sample classification methods. In the example, the first 60 categories of data in the CIFAR-FS dataset are used as pre-trained backbone models, and WideResNet is used here as the backbone model. The present invention uses the last 40 categories of the CIFAR-FS dataset as new tasks for learning, and uses a 5-way5-shot method for experiments. The specific implementation steps are as follows:
[0065] S1: First, input the training images of the last 40 categories of the CIFAR-FS dataset into the pre-trained backbone model to obtain the training set Where N τ is the number of training sets, that is, N τ =|D τ |=5×5=25,X i is the feature vector of the i-th image, assuming its dimension is d=600, y i is the category corresponding to the feature vector.
[0066] S2: The feature attention network consists of 600 convolution kernels of size 1×1, and each convolution kernel corresponds to the weight of the corresponding feature. The output of the feature attention network has the same dimension as its input. To train the feature attention network, the loss function is defined as follows:
[0067]
[0068] Among them, intraSim represents the similarity within a class, and interSim represents the similarity between classes. The above loss function hopes to obtain greater similarity within a class and smaller similarity between classes through learning. The definitions of intraSim and interSim are as follows:
[0069]
[0070]
[0071] The class represents rc represents the average vector obtained by training the feature attention network of the c-th type input in the training set, o c,i represents the i-th vector of the c-th category output by the feature attention network, o t,i represents the i-th vector of the t-th category output by the feature attention network, Indicates that r is obtained through Mahalanobis distance c With o t,i The similarity of the Mahalanobis distance function maha(o t,i ,r c ) is as follows:
[0072]
[0073] in Represents the c-th type of mixed covariance matrix of the training set, which is expressed by the c-th type of covariance matrix of the training set The covariance matrix Σ with the training set τ Joint decision, i.e.
[0074]
[0075] The weight E is an identity matrix, the covariance as well as
[0076] The training of the feature attention network stops after 15 rounds, and a new feature vector set can be obtained. And the class representation of each type c ,c=1,L,5.
[0077] S3: Input a test image of the last 40 categories of CIFAR-FS into the pre-trained backbone model to extract its feature vector X; then input the feature vector into the trained feature attention network to obtain a new feature vector o, and then find the new feature vector o and the class representation r c The Mahalanobis distance between them, where the class corresponding to the smallest distance is the model's prediction for the sample.
[0078] The effect of the present invention can be verified by the following experiments:
[0079] The present method is compared with PT, CNAPS and Simple CNAPS based on CNAPS using Mahalanobis distance metric on the same data set. From the results in Table 1, it can be seen that the method proposed in the present invention achieves better performance in classification accuracy (ACC) than PT and other methods.
[0080] Table 1
[0081] CNAPS Simple CNAPS PT The present invention ACC 61.57 74.36 90.68 96.59
[0082] The following is an introduction to a small sample image classification system based on a Mahalanobis distance loss feature attention network disclosed in an embodiment of the present invention. The small sample image classification system based on a Mahalanobis distance loss feature attention network described below and the small sample image classification method based on a Mahalanobis distance loss feature attention network described above can be referenced to each other.
[0083] Reference Figure 2 As shown, the embodiment of the present invention also provides a small sample image classification system based on Mahalanobis distance loss feature attention network, including:
[0084] A data preprocessing module 10, wherein the data preprocessing module 10 is used to extract features from a small sample image data set with labels to obtain a training set, wherein the training set includes a feature vector of the sample and its corresponding category;
[0085] A feature attention network training module 20, wherein the feature attention network training module 20 is used to input the samples in the training set into the feature attention network for training, thereby obtaining a trained feature attention network, and averaging the feature vectors in the training set after passing through the trained feature attention network to obtain a class representation;
[0086] The classification prediction module 30 is used to extract features from a small sample image data set without labels to obtain a test set, input the samples in the test set into a trained feature attention network to obtain a new feature vector, and calculate the Mahalanobis distance between the new feature vector and the class representation, wherein the class corresponding to the smallest Mahalanobis distance represents the classification prediction for the sample.
[0087] In one embodiment of the present invention, in the feature attention network training module 20, the loss function for training the feature attention network is:
[0088]
[0089] In the formula, intraSim represents the intra-class similarity, and interSim represents the inter-class similarity.
[0090] In one embodiment of the present invention, the intra-class similarity intraSim and the inter-class similarity interSim are defined as follows:
[0091]
[0092]
[0093] In the formula, class represents r crepresents the average vector obtained by training the feature attention network of the c-th type input in the training set, o c,i represents the i-th vector of the c-th category output by the feature attention network, o t,i represents the i-th vector of the t-th category output by the feature attention network, Indicates that r is obtained through Mahalanobis distance c With o t,i The similarity.
[0094] In one embodiment of the present invention, the Mahalanobis distance function maha( t,i ,r c ) is as follows:
[0095]
[0096] In the formula, Represents the c-th type of mixed covariance matrix of the training set, which is expressed by the c-th type of covariance matrix of the training set The covariance matrix Σ with the training set τ Jointly decide that:
[0097]
[0098] In the formula, the weight E is an identity matrix, the covariance as well as
[0099] The small sample image classification system based on the Mahalanobis distance loss feature attention network of this embodiment is used to implement the aforementioned small sample image classification method based on the Mahalanobis distance loss feature attention network. Therefore, the specific implementation method of the system can be seen in the embodiment part of the small sample image classification method based on the Mahalanobis distance loss feature attention network in the previous text. Therefore, its specific implementation method can refer to the description of the corresponding embodiments of each part, which will not be elaborated here.
[0100] In addition, since the small sample image classification system based on the Mahalanobis distance loss feature attention network of this embodiment is used to implement the aforementioned small sample image classification method based on the Mahalanobis distance loss feature attention network, its function corresponds to that of the above method and will not be repeated here.
[0101] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0102] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0103] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0104] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0105] Obviously, the above embodiments are merely examples for clear explanation and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived from these are still within the protection scope of the invention.
Claims
1. A small sample image classification method based on Mahalanobis distance loss feature attention network, characterized by: The following steps are involved: Performing feature extraction on a small sample image data set with labels to obtain a training set, wherein the training set includes feature vectors of the samples and their corresponding categories; Input the samples in the training set into the feature attention network for training to obtain a trained feature attention network, and average the feature vectors in the training set after passing through the trained feature attention network to obtain the representation of the class; Perform feature extraction on a small sample image dataset without labels to obtain a test set, input the samples in the test set into a trained feature attention network to obtain a new feature vector, and calculate the Mahalanobis distance between the new feature vector and the class representation, where the class corresponding to the minimum Mahalanobis distance represents the classification prediction of the sample; The loss function for training the feature attention network is: In the formula, intraSim represents the intra-class similarity, and interSim represents the inter-class similarity; The definitions of the intra-class similarity intraSim and the inter-class similarity interSim are as follows: In the formula, class represents r c represents the average vector obtained by training the feature attention network of the c-th category in the training set, o c,i represents the i-th vector of the c-th category output by the feature attention network, o t,i represents the i-th vector of the t-th category output by the feature attention network, Indicates that r is obtained through Mahalanobis distance c With o t,i similarity; Mahalanobis distance function maha(o t,i ,r c ) is as follows: In the formula, Represents the c-th type of mixed covariance matrix of the training set, which is expressed by the c-th type of covariance matrix of the training set The covariance matrix Σ with the training set τ Jointly decide that: In the formula, the weight E is an identity matrix, the covariance as well as 2. The small sample image classification method based on Mahalanobis distance loss feature attention network according to claim 1 is characterized in that: Perform feature extraction on the labeled small sample image dataset to obtain a training set, including: Input the labeled small sample image dataset into the pre-trained backbone model to obtain the training set Where N τ represents the number of training sets, X i Represents the feature vector of the i-th image, y i Indicates the category corresponding to the feature vector, wherein the backbone model is a classification network with the last classification head removed.
3. The small sample image classification method based on Mahalanobis distance loss feature attention network according to claim 1 is characterized in that: The feature attention network includes d convolution kernels of size 1×1, each convolution kernel corresponds to the weight of the corresponding feature, and the output of the feature attention network has the same dimension as its input.
4. A small sample image classification system based on Mahalanobis distance loss feature attention network, characterized by: include: A data preprocessing module, which is used to extract features from a small sample image data set with labels to obtain a training set, wherein the training set includes a feature vector of the sample and its corresponding category; A feature attention network training module, wherein the feature attention network training module is used to input the samples in the training set into the feature attention network for training to obtain a trained feature attention network, and the feature vectors in the training set are averaged after passing through the trained feature attention network to obtain a class representation; A classification prediction module is used to extract features from a small sample image data set without labels to obtain a test set, input the samples in the test set into a trained feature attention network to obtain a new feature vector, and calculate the Mahalanobis distance between the new feature vector and the class representation, wherein the class corresponding to the minimum Mahalanobis distance represents the classification prediction of the sample; In the feature attention network training module, the loss function for training the feature attention network is: In the formula, intraSim represents the intra-class similarity, and interSim represents the inter-class similarity; The definitions of the intra-class similarity intraSim and the inter-class similarity interSim are as follows: In the formula, class represents r c represents the average vector obtained by training the feature attention network of the c-th category in the training set, o c,i represents the i-th vector of the c-th category output by the feature attention network, o t,i represents the i-th vector of the t-th category output by the feature attention network, Indicates that r is obtained through Mahalanobis distance c With o t,i similarity; Mahalanobis distance function maha(o t,i ,r c ) is as follows: In the formula, Represents the c-th type of mixed covariance matrix of the training set, which is expressed by the c-th type of covariance matrix of the training set The covariance matrix Σ with the training set τ Jointly decide that: In the formula, the weight E is an identity matrix, the covariance as well as
Citation Information
Patent Citations
Small sample and zero sample image classification method based on metric learning and meta-learning
CN109961089A
Image classification method
CN112836629A
Method and apparatus for training model for image classification
CN114118196A
Small sample image classification method based on memory enhanced prototype network
CN114444600A
Improved face recognition system and method based on mahalanobis distance
CN114821722A
