Small sample image recognition method based on local feature reweighting and category adaptation

By introducing local feature reweighting of inter-class relationships and local feature category adaptation modules in small sample image recognition, the problem of neglecting inter-class information and the influence of category-irrelevant features in the existing technology is solved, and the accuracy of small sample image recognition is improved. sex and performance.

CN118365903BActive Publication Date: 2024-09-27OCEAN UNIV OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410788370.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-19
Publication Date
2024-09-27
Estimated Expiration
2044-06-19

AI Technical Summary

Technical Problem

When dealing with small samples and low data, existing small sample image recognition methods ignore inter-class relationship information and category-independent local features for similarity measurement, resulting in the loss of discriminative local information and affecting the accuracy of similarity measurement.

Method used

The local feature reweighting module and local feature category adaptation module based on inter-class relationships are used to reweight and adaptive feature fusion through the attention mechanism and Transformer encoder block to reduce the interference of discriminant irrelevant features and category irrelevant features similar between classes. Effects on similarity measures.

Benefits of technology

It improves the performance of small sample image recognition, enhances the accuracy of similarity measurement and the ability to distinguish local features, and reduces the impact of category-independent features on the recognition results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118365903B
    Figure CN118365903B
Patent Text Reader

Abstract

The present invention belongs to the field of image processing, and discloses a small sample image recognition method based on local feature reweighting and category adaptation, including step S1, constructing a small sample recognition task: sampling a small sample image recognition task from a training set, each task includes two parts: a support set and a query set, step S2, feature extraction, obtaining category features, step S3, local feature reweighting based on inter-class relationships: reweighting the local features of the sample using the inter-class relationships, step S4, local feature category adaptation, obtaining adaptive features, step 5: dense feature similarity measurement: calculating the similarity scores between the M local features of the query set sample after adaptation and the M local features of the support set sample, and the category with the highest similarity score with the query set image is the category of the query set image. The present invention improves the performance of small sample image recognition based on local feature measurement.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of image processing, and relates to deep learning and small sample image recognition technology, and in particular to a small sample image recognition method based on local feature reweighting and category adaptation. Background Art

[0002] Thanks to large-scale data sets and powerful computing resources, artificial intelligence algorithms such as deep learning have achieved remarkable results in image recognition fields such as face recognition, autonomous driving, and robotics. Deep learning relies on a large amount of labeled data, and in practical applications, data acquisition often faces many challenges. This includes personal privacy issues, such as face data, and issues with rare objects, such as identifying rare and protected animals. In addition, data labeling work usually requires a lot of manpower and material resources, which hinders the further development of deep learning technology in some image recognition fields. In contrast, humans can quickly recognize new objects with a small number of samples. Inspired by the ability of humans to learn quickly, researchers hope that after learning a large amount of data in a certain category, machine learning models only need a small number of samples to quickly learn new categories. Therefore, the problem of small sample image recognition has gradually become a current research hotspot.

[0003] Among them, the metric learning-based method is one of the most common and effective methods to solve the problem of small sample image recognition. Its basic idea is to learn a feature embedding space so that the samples of the same category have a high similarity in this feature embedding space, and the samples of different categories have a low similarity, so as to perform small sample image recognition tasks. Traditional metric learning-based methods use image-level global semantic features to represent images, but in the case of small samples and low data, these deep global features will lose a lot of discriminative local information, affecting the accuracy of similarity measurement. Therefore, existing work often uses a set of local features to represent images, and then uses various methods to find similar parts of two sets of local features for feature alignment, and then performs similarity measurement. Although these methods have achieved good performance, there are also some problems. These methods often focus on finding better feature alignment methods for query set images and support set images, ignoring the inter-class information in the support set samples, and the alignment of some category-independent local features will also affect the similarity measurement. Summary of the invention

[0004] In view of the shortcomings of the prior art, the present invention provides a small sample image recognition method based on local feature reweighting and category adaptation. (1) First, in view of the problem that the prior method ignores the inter-class relationship information, a local feature reweighting module based on inter-class relationship is proposed. This module considers the inter-class relationship information of the sample and reweights the local features of the sample to reduce the interference of the local features that are irrelevant to the discrimination of similar classes. (2) In view of the problem that the local features irrelevant to the category affect the similarity measurement, a local feature category adaptation module is proposed. By adaptively correlating the local features of the sample with the category features, the influence of the local features irrelevant to the category on the similarity measurement is reduced.

[0005] In order to solve the above technical problems, the technical solution adopted by the present invention is:

[0006] The small sample image recognition method based on local feature reweighting and category adaptation includes the following steps:

[0007] Step S1: Construct a small sample recognition task:

[0008] A small sample image recognition task is sampled from the training set. Each task consists of two parts: a support set and a query set. N categories are randomly selected from the training set, and then K samples are randomly selected from the N categories, a total of N×K samples, to form the support set; then q samples are randomly selected from the remaining samples, a total of N×q samples, to form the query set. Among them, the support set is labeled, and the query set is unlabeled. In each training process, the model is required to use N×K samples to learn how to distinguish these N categories;

[0009] Step S2: feature extraction:

[0010] For each image x in task T, its global semantic feature is obtained through the feature extraction network: , and the M local features are ; For each of the N classes in task T, add the global semantic features of its K images and then take the average as the category feature , for use in subsequent steps;

[0011] Step S3: Reweighting of local features based on inter-class relationships:

[0012] The local feature reweighting module uses the inter-class relationship to reweight the local features of the sample. For each sample in the support set, its M local features and the category features of another N-1 classes are sent to the local feature reweighting module; the local feature reweighting module finds the local features in the current sample that are similar to other categories through the attention mechanism and assigns small weights to obtain M reweighted local features. ;

[0013] Step S4: local feature category adaptation:

[0014] For the support set samples, the M local features after the support set samples are reweighted and the category characteristics of this category Send it to the local feature category adaptive module; for the query set samples, send its global features and local features together to the local feature category adaptive module to obtain M adaptive features;

[0015] Step 5: Dense feature similarity measurement:

[0016] The similarities between the M local features of the adaptive query set samples and the M local features of the support set samples are calculated to obtain an M×M similarity matrix and a similarity score.

[0017] Furthermore, the feature extraction network uses the visual self-attention model ViT and is pre-trained in a self-supervised manner.

[0018] Furthermore, the specific operation of the re-weighting in step S3 is as follows:

[0019] First, calculate N-1 category features and M local feature attention vectors A of the query set samples, whose dimension is 1×M, A i Represents the attention score of the category feature and the i-th local feature of the sample,

[0020] Then the N-1 attention vectors A are inverted and added together and sent to a projection head to obtain the total weight vector ;

[0021] Finally, the total weight vector Multiply it with the M local features of the query set sample for weighting as follows:

[0022] ;

[0023] represents the reweighted i-th local feature, where ; Represents the weight vector The ith value of .

[0024] Furthermore, in step 4, the local feature category adaptation module consists of two layers of Transformer encoder blocks.

[0025] For the support set samples, the relationship between the category features and the local features is first learned through the attention mechanism and projected to obtain the category adaptation coefficient vector R; then, the category adaptation coefficient vector R is multiplied by the category feature Then, the local features output by the local feature category adaptive module are added to obtain M adaptive features. , as shown below:

[0026]

[0027] represents the i-th local feature after adaptive correlation fusion, is the i-th value of the category adaptation coefficient vector R, indicating the category characteristics of this category And the adaptation coefficient of the i-th local feature of the sample represents the i-th local feature output by the local feature category adaptation module;

[0028] For the query set samples, the global features and local features are sent to the local feature category adaptation module to obtain M adaptive features. , as shown below:

[0029]

[0030] in, represents the i-th local feature after the query set sample category is adapted, is the i-th value of the category adaptation coefficient vector R, representing the global characteristics of the query set sample And the adaptation coefficient of the i-th local feature of the sample, Represents the i-th local feature output by the local feature category adaptation module of the query set sample.

[0031] Furthermore, in step 5, the similarity matrix is ​​as follows:

[0032] ;

[0033] in, represents the ath local feature of the support set image, represents the bth local feature of the query set image, Indicates the similarity between the two. represents the cosine similarity; then, the similarity matrix is ​​flattened and directly input into an MLP multi-layer perceptron to output the similarity score.

[0034] Further, in step S5, there are K labeled images in the nth support set category. After obtaining the similarity scores between the eth query image and all support images, the similarity score of the eth query image belonging to the nth support set category is obtained, as shown below:

[0035] ;

[0036] in, represents the similarity score between the e-th query image and the f-th support image in the n-th support set category; then, the probability that the e-th query image belongs to the n-th support set category is calculated , as shown below:

[0037] .

[0038] Furthermore, the loss function L formula is as follows:

[0039] ;

[0040] Where Q is the total number of query images, represents the label of the e-th query set image, is an indicator function that is equal to 1 if its argument is true and 0 otherwise.

[0041] Compared with the prior art, the present invention has the following advantages:

[0042] (1) The present invention proposes a local feature reweighting module based on inter-class relations, which uses the inter-class information of samples to reweight the local features of samples to reduce the interference of local features that are irrelevant to the discrimination of similar inter-class features;

[0043] (2) The present invention proposes a local feature category adaptive module, which adaptively fuses the sample local features and category features to reduce the impact of category-irrelevant local features on the similarity measurement, thereby improving the performance of small sample image recognition based on local feature measurement. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.

[0045] Figure 1 It is a flow chart of the present invention. DETAILED DESCRIPTION

[0046] The present invention will be further described below in conjunction with the accompanying drawings and specific embodiments.

[0047] Combination Figure 1 As shown, the small sample image recognition method based on local feature reweighting and category adaptation includes the following steps:

[0048] Step S1: construct a small sample recognition task.

[0049] Sample a small sample image recognition task from the training set (for example, you can sample an N-wayK-shot paradigm task from the training set). Each task consists of two parts: a support set and a query set. Randomly select N categories from the training set, then randomly select K samples from the N categories, a total of N×K samples, to form the support set; then randomly select q samples from the remaining samples, a total of N×q samples, to form the query set. Among them, the support set is labeled, and the query set is unlabeled. In each training process, the model is required to use N×K samples to learn how to distinguish these N categories.

[0050] Step S2: feature extraction.

[0051] For each image x in task T, its global semantic feature is obtained through the feature extraction network: , and the M local features are ; For each of the N classes in task T, add the global semantic features of its K images and then take the average as the category feature , for use in subsequent steps.

[0052] Among them, the feature extraction network uses the visual self-attention model ViT (Vision Transformer). In order to alleviate the negative impact of using image-level annotations for supervised pre-training and retain as much information of the sample image as possible, a self-supervised method is used for pre-training to improve the generalization ability of the model.

[0053] Step S3: re-weighting local features based on inter-class relationships.

[0054] The local feature reweighting module uses the inter-class relationship to reweight the local features of the sample to reduce the interference of similar local features that are irrelevant to the discrimination between classes. For each sample in the support set, its M local features and the category features of another N-1 classes are sent to the local feature reweighting module; the local feature reweighting module uses the attention mechanism to find the local features in the current sample that are similar to other categories and assign small weights to reduce the interference of similar local features between classes on the similarity measurement, and obtain M reweighted local features. .

[0055] The specific operation of step S3 re-weighting is as follows:

[0056] First, calculate N-1 category features and M local feature attention vectors A of the query set samples, whose dimension is 1×M, A i Represents the attention score of the category feature and the i-th local feature of the sample,

[0057] Then the N-1 attention vectors A are inverted and added together and sent to a projection head to obtain the total weight vector ;

[0058] Finally, the total weight vector Multiply it with the M local features of the query set sample for weighting as follows:

[0059] ;

[0060] Represents the reweighted local features, among which ; Represents the weight vector No. value.

[0061] Step S4: local feature category adaptation.

[0062] For the support set samples, first, the M local features of the support set samples are reweighted and the category characteristics of this category It is sent to the local feature category adaptation module, which consists of two layers of Transformer encoder blocks. The relationship between category features and local features is learned through the attention mechanism and projected to obtain the category adaptation coefficient vector R. The Transformer encoder block is a commonly used structure and will not be described here.

[0063] Then, multiply the category adaptation coefficient vector R by the category feature Then, the local features output by the local feature category adaptive module are added to obtain M adaptive features. , as shown below:

[0064]

[0065] represents the i-th local feature after adaptive correlation fusion, is the i-th value of the category adaptation coefficient vector R, indicating the category characteristics of this category And the adaptation coefficient of the i-th local feature of the sample Represents the i-th local feature output by the local feature category adaptation module.

[0066] For the query set samples, the global features and local features are sent to the local feature category adaptation module to obtain M adaptive features. , as shown below:

[0067]

[0068] in, represents the i-th local feature after the query set sample category is adapted, is the i-th value of the category adaptation coefficient vector R, representing the global characteristics of the query set sample And the adaptation coefficient of the i-th local feature of the sample, Represents the i-th local feature output by the local feature category adaptation module of the query set sample.

[0069] Step 5: Dense feature similarity measurement.

[0070] Calculate the similarity between the M local features of the adaptive query set samples and the M local features of the support set samples, and obtain an M×M similarity matrix, as shown below:

[0071] ;

[0072] in, represents the ath local feature of the support set image, represents the bth local feature of the query set image, Indicates the similarity between the two. represents the cosine similarity; then, the similarity matrix is ​​flattened and directly input into an MLP multi-layer perceptron to output the similarity score.

[0073] There are K labeled images in the nth support set category. After obtaining the similarity scores between the eth query image and all support images, the similarity score of the eth query image belonging to the nth support set category is obtained as follows:

[0074] ;

[0075] in, represents the similarity score between the e-th query image and the f-th support image in the n-th support set category; then, the probability that the e-th query image belongs to the n-th support set category is calculated , as shown below:

[0076] .

[0077] Furthermore, the loss function L formula is as follows:

[0078] ;

[0079] Where Q is the total number of query images, represents the label of the e-th query set image, is an indicator function that is equal to 1 if its argument is true and 0 otherwise.

[0080] Based on the model trained in the above steps, a small sample task is sampled from the test set for recognition. First, N classes are randomly selected from the test set, and then K images are selected from each class to form a support set, and q images are selected to form a query set. The query set images are recognized based on the support set images.

[0081] For the support set image, firstly, feature extraction is performed in step S2 to obtain the local features and category features of the image. Next, the local features of the sample are re-weighted using the trained local feature reweighting module to reduce the interference of similar local features between classes on the similarity measurement. Then, the local features are category-adapted using the trained local feature category adaptation module to obtain its adaptive features.

[0082] For the query set images, the trained local feature category adaptation module is also used to perform category adaptation on the local features to obtain their adaptive features.

[0083] Finally, dense feature similarity measurement is performed through step 5 to calculate the similarity scores between the query set image and all support set images. The category with the highest similarity score with the query set image is the category of the query set image.

[0084] In summary, the existing methods based on local feature measurement mainly align features by finding similar local features between samples and then measure similarity. Although these methods have achieved good results, there are also some problems. These methods often only focus on the feature alignment method between the local features of the two images, ignoring the inter-class information of the samples, which is also important for improving the accuracy of similarity measurement. In addition, the local features of feature alignment are not always beneficial to similarity measurement, such as those local features that are not related to the category.

[0085] In this regard, the present invention designs a small sample image recognition method based on local feature reweighting and category adaptation. The method proposes a local feature reweighting module based on inter-class relations, and uses the inter-class information of the sample to reweight the local features of the sample to reduce the interference of local features that are irrelevant to the discrimination of similar inter-classes; and proposes a local feature category adaptation module, which reduces the influence of local features irrelevant to the category on the similarity measurement by adaptively fusing the local features of the sample and the category features, thereby improving the performance of small sample image recognition based on local feature measurement.

[0086] Of course, the above description is not a limitation of the present invention, and the present invention is not limited to the above examples. Any changes, modifications, additions or substitutions made by ordinary technicians in this technical field within the essential scope of the present invention should fall within the protection scope of the present invention.

Claims

1. A small sample image recognition method based on local feature reweighting and category adaptation, characterized in that: The following steps are involved: Step S1: Construct a small sample recognition task: A small sample image recognition task is sampled from the training set. Each task consists of two parts: a support set and a query set. N categories are randomly selected from the training set, and then K samples are randomly selected from the N categories, a total of N×K samples, to form the support set; then q samples are randomly selected from the remaining samples, a total of N×q samples, to form the query set. Among them, the support set is labeled, and the query set is unlabeled. In each training process, the model is required to use N×K samples to learn how to distinguish these N categories; Step S2: feature extraction: For each image x in task T, its global semantic feature is obtained through the feature extraction network as f cls (x), and M local features are f(x); for each of the N classes in task T, the global semantic features of its K images are added and then averaged as the category feature f p (x) for use in subsequent steps; Step S3: Reweighting of local features based on inter-class relationships: The local feature reweighting module uses the inter-class relationship to reweight the local features of the sample. For each sample in the support set, its M local features and the category features of another N-1 classes are sent to the local feature reweighting module; the local feature reweighting module finds the local features in the current sample that are similar to other categories through the attention mechanism and assigns small weights to obtain M reweighted local features. The specific operation of step S3 re-weighting is as follows: First, calculate N-1 category features and M local feature attention vectors A of the query set samples, whose dimension is 1×M, A i Represents the attention score of the category feature and the i-th local feature of the sample, Then the N-1 attention vectors A are inverted and added together and sent to a projection head to obtain the total weight vector Finally, the total weight vector Multiply it with the M local features of the query set sample for weighting as follows: represents the reweighted i-th local feature, where i∈[1,M]; Represents the weight vector The i-th value of ; Step S4: local feature category adaptation: For the support set samples, the M local features after the support set samples are reweighted and the category feature f of this category p (x) sending it to the local feature category adaptive module; for the query set samples, sending its global features and local features together to the local feature category adaptive module to obtain M adaptive features; In step S4, the local feature category adaptation module consists of two layers of Transformer encoder blocks. For the support set samples, the relationship between the category features and the local features is first learned through the attention mechanism and projected to obtain the category adaptation coefficient vector R; then, the category adaptation coefficient vector R is multiplied by the category feature f p (x), and then add the local features output by the local feature category adaptation module to obtain M adaptive features As shown below: represents the i-th local feature after adaptive correlation fusion, R i is the i-th value of the category adaptation coefficient vector R, indicating the category feature f p (x) and the adaptation coefficient of the i-th local feature of the sample, represents the i-th local feature output by the local feature category adaptation module; For the query set samples, the global features and local features are sent to the local feature category adaptation module to obtain M adaptive features. As shown below: in, represents the i-th local feature after the query set sample category is adapted, R i is the i-th value of the category adaptation coefficient vector R, representing the global characteristics of the query set sample And the adaptation coefficient of the i-th local feature of the sample, Represents the i-th local feature output by the local feature category adaptation module of the query set sample; Step 5: Dense feature similarity measurement: The similarities between the M local features of the adaptive query set samples and the M local features of the support set samples are calculated to obtain an M×M similarity matrix and a similarity score.

2. The small sample image recognition method based on local feature reweighting and category adaptation according to claim 1 is characterized in that: The feature extraction network uses the visual self-attention model ViT and is pre-trained in a self-supervised manner.

3. The small sample image recognition method based on local feature reweighting and category adaptation according to claim 1 is characterized in that: In step 5, the similarity matrix is ​​as follows: in, represents the ath local feature of the support set image, represents the bth local feature of the query set image, S ab represents the similarity between the two, and d(·,·) represents the cosine similarity; then, the similarity matrix is ​​flattened and directly input into an MLP multi-layer perceptron to output the similarity score.

4. The small sample image recognition method based on local feature reweighting and category adaptation according to claim 1 is characterized in that: In step S5, there are K labeled images in the nth support set category. After obtaining the similarity scores between the eth query image and all support images, the similarity score of the eth query image belonging to the nth support set category is obtained as follows: Among them, S nef represents the similarity score between the e-th query image and the f-th support image in the n-th support set category; then, the probability p that the e-th query image belongs to the n-th support set category is calculated ne , as shown below:

5. The small sample image recognition method based on local feature reweighting and category adaptation according to claim 4 is characterized in that: The loss function L formula is as follows: Where Q is the total number of query images, represents the label of the e-th query set image, and I(·) is an indicator function that is equal to 1 if its argument is True and 0 otherwise.