Few-sample classification method based on image-text pre-training model
Through a four-branch architecture few-sample classification network, combined with multi-modal feature extraction and optimal transportation modules, the problem of low performance of visual-language multi-modal few-sample classification algorithms in the existing technology is solved, and higher classification accuracy is achieved. and generalization, verifying the effectiveness of the algorithm on Caltech01, DTD, and EuroSAT data sets.
Patent Information
- Application Number
- CN202410891628.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-04
- Publication Date
- 2024-10-08
- Estimated Expiration
- 2044-07-04
AI Technical Summary
It is difficult for existing few-shot classification algorithms to simultaneously consider multiple learnable visual and textual cues in visual-linguistic multi-modal technology, resulting in low model classification performance and failure to fully utilize the generalization of pre-trained zero-shot CLIP models. ability.
A few-sample classification network using a four-branch architecture, through a multi-modal feature extraction module, a primitive-level and prompt-level optimal transportation module, a similarity calculation module, and a combination of cross-entropy loss, non-equilibrium consistency loss and prototype distance loss function, Extract and match image-text features to achieve optimal transportation of image patches with reweighting and cascade regularization.
It improves the accuracy and generalization of few-sample classification tasks, and enhances the classification performance of the model through prototype distance and cross-matching mechanisms. The experimental results outperform advanced algorithms on Caltech01, DTD, and EuroSAT data sets.
Smart Images

Figure CN118747313A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision technology, and in particular to a few-sample classification method based on an image-text pre-training model. Background Art
[0002] Few-shot classification is an important technology in the field of machine learning. Its goal is to design a classification model with efficient learning and accurate prediction capabilities using only a small number of samples. Early few-shot classification algorithms mainly studied the extraction and utilization of visual features. However, when the visual features have large differences, it is difficult for the few-shot classification algorithm based on a single visual modality to accurately identify objects of the same category. Therefore, this will bring great challenges to the few-shot object classification task. In addition, with the development of vision-language multimodal technology, the application scenarios of few-shot object classification have been further expanded. At present, few-shot classification has been widely used in many fields, such as: robot manipulation, surface defect detection, remote sensing image understanding, etc. Therefore, it is of great significance to study the few-shot classification algorithm based on vision-language multimodality. With the development of deep learning and model fine-tuning technology, few-shot classification algorithms have also made significant progress. Many works extract multimodal features through pre-trained vision-language models, and distinguish and judge whether the semantic information represented by different features is the same through contrastive learning. In this process, the network is used to learn a multimodal high-dimensional embedding space so that positive image-text pairs have higher similarity and negative image-text pairs have lower similarity, thereby completing the matching and alignment of multimodal features.
[0003] The document "International Journal of Computer Vision, 2337-2348, 2022" models contextual cues through a set of learnable text vectors that can be optimized by minimizing the cross-entropy classification loss. However, this method only uses a single text vector to adapt to downstream tasks and cannot simultaneously consider multiple learnable visual and textual cues, resulting in low classification performance of the model. The document "Neural Information Processing Systems, 52792-52810, 2023" uses primitive-level and cue-level optimal transport methods to simultaneously learn multiple visual and textual cues, and achieves multimodal feature alignment through a cross-entropy loss function. However, this method only focuses on the few-sample information contained in the trained cues, which makes the model only consider the ability to fit downstream tasks, without considering the generalization ability of the pre-trained zero-sample CLIP model, resulting in unsatisfactory performance of the model. Summary of the invention
[0004] The purpose of this invention is to propose a few-sample classification method based on an image-text pre-training model to improve the accuracy and generalization of few-sample classification tasks.
[0005] The technical solution of the present invention is as follows: a few-sample classification method based on an image-text pre-training model, establishing a few-sample classification network for classification;
[0006] The few-sample classification network is a four-branch architecture; the first branch is a zero-sample text branch, the second branch is a few-sample image branch, the third branch is a few-sample text branch, and the fourth branch is a zero-sample image branch; the zero-sample text branch takes unlearnable text as input, and outputs unlearnable primitive-level text features and unlearnable prompt-level text features; the zero-sample image branch takes an unlearnable image as input, and outputs unlearnable primitive-level image features and their prototypes, as well as unlearnable prompt-level image features and their prototypes; the few-sample image branch takes a learnable image as input, and outputs a learnable primitive-level image feature and a learnable prompt level image features; the few-shot text branch takes learnable text as input and outputs learnable primitive-level text features and learnable prompt-level text features; the zero-shot text branch and the zero-shot image branch are respectively composed of a multimodal feature extraction module, a prompt-level optimal transport module and a similarity calculation module; the few-shot text branch and the few-shot image branch are respectively composed of a multimodal feature extraction module, a primitive-level optimal transport module, a prompt-level optimal transport module and a similarity calculation module; the optimization process of the few-shot classification network is completed through three loss functions, namely, the cross-entropy loss function, the unbalanced consistency loss function and the prompt-level prototype distance loss function.
[0007] The few-sample image branch extracts image features through the following formula:
[0008]
[0009] Where z represents the learnable cue-level image features, f represents the CLIP image encoder in the few-shot image branch, and They represent the image patch vector in the learnable primitive-level image feature and the visual primitive vector in the learnable primitive-level image feature respectively; e, v represent the input learnable primitive-level image feature; <cls>Represents learnable category primitives;
[0010] Learnable text vector t and fixed text vector corresponding to the kth category The input text features are formed, and the output text features are obtained by the following formula:
[0011]
[0012] Among them, h k represents learnable prompt-level text features, and represents the learnable primitive-level text features; g represents the CLIP text encoder in the few-shot text branch, <eos>Represents the ending primitive of input text.
[0013] Given an object category, the CLIP image encoder with a zero-shot image branch computes non-learnable primitive-level image features.
[0014]
[0015] is a non-learnable hint-level image feature;
[0016] Non-learnable primitive-level image feature prototypes e The calculation method is as follows:
[0017]
[0018] in, represents the training samples of the selected k categories; N is the number of image samples in the few-shot classification dataset; the Euclidean distance is used To measure the non-learnable primitive-level image feature prototypes s e With learnable primitive-level image patch vectors The differences between them are as follows:
[0019]
[0020] Distance to non-learnable primitive-level image feature prototype center s e Closer learnable primitive-level image patches have smaller intra-class differences; Euclidean distance and learnable primitive-level image patch weights Inversely proportional; the following Gaussian function is used to implement this mapping process:
[0021]
[0022] Where σ is the standard deviation of the Gaussian function; according to the learnable primitive-level image patch weights The re-weighted learnable primitive-level image patch is represented as follows:
[0023]
[0024] The learnable primitive-level image features and learnable primitive-level text features Modeled as two empirical distributions as follows:
[0025]
[0026] in, Represents r j The corresponding Dirac function value is, Indicates l The corresponding Dirac function value;
[0027] Define the primitive level cost matrix as in The optimal transport distance between the learnable primitive-level image feature r and the learnable primitive-level text feature s is expressed as follows:
[0028]
[0029] Among them, ε>0 is a hyperparameter; T t represents the optimal transportation matrix between R and S.
[0030] Using two empirical distributions, P and Q, to simulate learnable hint-level image features z and learnable hint-level text features h, we obtain a hint-level optimal transportation strategy with cross alignment:
[0031]
[0032] Among them, z m represents the mth learnable hint-level image feature; h n represents the nth learnable prompt-level text feature; feature Indicates z m The corresponding Dirac function value, Indicates h n The corresponding Dirac function value;
[0033] Computing non-learnable primitive-level text features from the CLIP text encoder with zero-shot text branch and non-learnable hint-level text features
[0034]
[0035] Non-learnable hint-level image features and non-learnable hint-level text features The corresponding distribution and It is expressed as follows:
[0036]
[0037] in, represents the mth non-learnable hint-level image feature, represents the nth non-learnable prompt-level text feature; express The corresponding Dirac function value, express The corresponding Dirac function value;
[0038] The prompt-level optimal transport distance is expressed as follows:
[0039]
[0040] Among them, T p represents the optimal transportation matrix between P and Q; C p ∈R M×N is the cost matrix between P and Q, defined as follows:
[0041]
[0042] The optimal transport distance for prompt-level crossover is defined as follows:
[0043]
[0044] The cost matrix in equations (15) and (16) is defined as follows:
[0045]
[0046]
[0047] The class prediction probability with the optimal transportation matrix is expressed as follows:
[0048]
[0049] The unbalanced consistency loss with prototype distance uses the cross entropy loss as the base loss function:
[0050]
[0051] Among them, y x,k is the label of image x of category k;
[0052] By imposing an imbalanced consistency loss and To maintain the consistency between the learnable prompt features and the non-learnable prompt features, the formula is defined as follows:
[0053]
[0054]
[0055] in, represents the consistency loss that includes non-learnable hint-level image features, represents the consistency loss that includes non-learnable hint-level text features; Represents KL divergence; uses training samples from a few-shot dataset Compute non-learnable hint-level image feature prototypes s p :
[0056]
[0057] in is a non-learnable hint-level image feature; prototype loss is used to supervise the learnable hint-level image feature z and the non-learnable hint-level image feature prototype s p Distance between:
[0058]
[0059] Where k represents the category label of image x; combined with unbalanced consistency loss and And prototype loss Unbalanced consistency loss based on prototype distance It is expressed as follows:
[0060]
[0061] The overall loss function is as follows:
[0062]
[0063] Beneficial effects of the present invention: In view of the problems such as low accuracy in the few-sample classification algorithm, the present invention proposes a few-sample classification method based on an image-text pre-training model to solve the few-sample classification tasks in different scenarios. First, for the optimal transport at the primitive level, we propose an image block reweighting mechanism based on the prototype distance. We convert the Euclidean distance between the prototype and the image block into the weight of each image block, thereby assigning different weights to the image blocks. For the prompt-level stage, we propose a cascade regularized optimal transport module. This module not only considers the optimal transport between the few-sample image-text features, but also considers the cross-matching between the zero-sample and few-sample CLIP multimodal features. Finally, we propose a prototype-based unbalanced logarithmic-level loss function to supervise the network. The loss function is divided into a prototype distance metric and a logarithmic-level consistency. The prototype part calculates the loss according to the distance between the prompt-level prototype and the image feature embedding. The logarithmic-level constraint makes the few-sample logarithmic distribution close to the zero-sample logarithmic distribution. Finally, tests were carried out on the Caltech01, DTD, and EuroSAT datasets. The experimental results show that the performance of the network model proposed in this paper is better than the most advanced algorithm, verifying the effectiveness of the algorithm. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] Figure 1 Flowchart of the few-shot classification method based on the image-text pre-training model. DETAILED DESCRIPTION
[0065] Figure 1 It is the main flow chart of the technical solution of the present invention. Figure 1 As shown, the few-sample classification method based on the image-text pre-training model proposed in the present invention includes the following steps:
[0066] Step 1, training data: the present invention constructs relevant training sets with RGB images in the data sets Caltech101, EuroSAT, and DTD, and provides input images for the network;
[0067] Step 2, model training: The network framework proposed in the present invention is composed of a four-branch architecture, the first branch is a zero-sample text branch, the second branch is a few-sample image branch, the third branch is a few-sample text branch, and the fourth branch is a zero-sample image branch. Each branch consists of three forward stages, namely, multimodal feature extraction, optimal transportation planning, and similarity calculation; in the multimodal feature extraction stage, it is implemented by a text encoder or an image encoder; the few-sample image and its language description are respectively input into each branch of the few-sample classification network, and after image-text feature extraction, the transportation matrix is calculated by optimal transportation planning; in the few-sample text branch and the few-sample image branch, the optimal transportation module is composed of primitive-level optimal transportation and prompt-level optimal transportation; the optimization process of the few-sample classification network is completed through three loss functions, namely, the cross entropy loss function, the unbalanced logarithmic consistency loss function, and the prompt-level prototype distance loss function. Next, we will introduce these in detail.
[0068] a. Primitive-level optimal transportation based on image patch prototype distance
[0069] Given multiple images of an object category, different image embeddings can be obtained from the pre-trained CLIP image encoder. In this case, intra-class differences will appear between image patch embeddings. To better align text and image embeddings for prompt-level optimal transport, more attention should be paid to image patch embeddings with small intra-class differences. Therefore, we propose a primitive-level reweighting mechanism for image patches.
[0070] Given an object category, different image embeddings can be obtained from the pre-trained CLIP image encoder. Non-learnable primitive-level image feature prototypes e As shown below:
[0071]
[0072] in, represents the training samples of the selected k categories. N is the number of image samples in the few-shot classification dataset. The CLIP image encoder representing the zero-shot image branch computes non-learnable primitive-level image features:
[0073]
[0074] Then, use the Euclidean distance To measure the non-learnable primitive-level image feature prototypes s e With learnable primitive-level image patch vectors The differences between them are as follows:
[0075]
[0076] Distance to non-learnable primitive-level image feature prototype center s e The intra-class differences of closer blocks are smaller, and more weight needs to be assigned to these blocks in the optimization process. Inversely proportional to the block weight value. The following Gaussian function is used to implement this mapping process:
[0077]
[0078] Where σ is the standard deviation of the Gaussian function. The reweighted image patch can be represented as follows:
[0079]
[0080] To link multimodal cues to optimal transportation, learnable primitive-level image features are needed. and learnable primitive-level text features As shown below:
[0081]
[0082] in, It is a combination of image patches of length J = a + o and learnable image primitives. is a combination of learnable and original text primitives of length L = b + l.
[0083] In addition, the primitive level cost matrix is defined as in The optimal transport distance between the learnable primitive-level image feature r and the learnable primitive-level text feature s is expressed as follows:
[0084]
[0085] Where ε>0 is a hyperparameter. The primitive-level transport matrix T t represents the correlation between the jth visual primitive and the lth text primitive.
[0086] b. Tip-level optimal transport with cross-matching
[0087] In order to enable the network to maintain the generalization performance of the pre-trained CLIP model while fitting the downstream classification task, we simultaneously consider and cross-match zero-shot image-text features and few-shot image-text features in the prompt-level optimal transport stage.
[0088] The cue-level optimal transportation policy with cross-matching uses two empirical distributions, P and Q, to model visual-language learnable cues:
[0089]
[0090] Among them, z m represents the mth learnable hint-level image feature; h n represents the nth learnable hint-level text feature; at the same time, z m and h n are all feature embeddings in a shared space of dimension d. To cross-align the learnable embeddings and the zero-shot features, we compute the zero-shot features from the pre-trained CLIP model using formula (5) and the following formula:
[0091]
[0092] Similar to formula (11), the distribution of zero-sample features and It is expressed as follows:
[0093]
[0094] in, represents the mth non-learnable hint-level image feature, represents the nth non-learnable prompt-level text feature. The prompt-level optimal transport distance is expressed as follows:
[0095]
[0096] Among them C p ∈R M×N is the cue-level cost matrix between the visual cue set and the textual cue set. T p ∈R M×N is the prompt level transportation matrix. The prompt level cost matrix is defined as follows:
[0097]
[0098] The optimal transport distance for prompt-level crossover is defined as follows:
[0099]
[0100] The cost matrix in equations (16) and (17) is defined as follows:
[0101]
[0102] The class prediction probability with optimal transportation planning is expressed as follows:
[0103]
[0104] c. Unbalanced consistency loss with prototype distance
[0105] To train the proposed few-shot classification network model based on the image-text pre-trained model, we adopt a set of hybrid loss functions, including the cross entropy loss function and unbalanced consistency loss with prototype distance The overall loss function is as follows:
[0106]
[0107] First, the cross entropy loss is used as the basic loss function:
[0108]
[0109] Among them, y x,k is the label of image x of category k. By applying an unbalanced log-level consistency loss and To maintain the consistency between the learnable prompt features and the non-learnable prompt features, the formula is defined as follows:
[0110]
[0111] in, represents the consistency loss that includes non-learnable hint-level image features, represents the consistency loss that includes non-learnable hint-level text features; represents the KL divergence. For hint-level alignment, different image feature embeddings should be close to the corresponding prototypes. Therefore, using the training samples in the few-shot dataset Compute non-learnable hint-level image feature prototypes s p :
[0112]
[0113] in is a non-learnable hint-level image feature; in order to cluster image embeddings into the same class, each image feature embedding should be close to its hint-level prototype. Therefore, a prototype loss is used to supervise the learnable hint-level image feature z and the non-learnable hint-level image feature prototype s p Distance between:
[0114]
[0115] Where k represents the category label of image x. Combined with unbalanced log-level consistency loss and And prototype loss Unbalanced consistency loss based on prototype distance It is expressed as follows:
[0116]
[0117] Step 3, Few-shot classification: In the test phase, we first construct the category labels of the classification task into corresponding description texts according to the learnable prompt template. Then, the description text is fed into the text encoder of the CLIP network to obtain the corresponding text features. After that, the image to be predicted is fed into the image encoder of the CLIP network to obtain the corresponding image features. Then, the cosine similarity of the image features and text features is calculated, and multiplied with the prompt-level optimal transport matrix, and the category corresponding to the text with the largest product result is selected as the classification result.
[0118] In order to verify the effectiveness of the algorithm in terms of few-sample classification accuracy, the present invention is tested on Caltech101, DTD, and EuroSAT datasets. According to the experimental results, the few-sample classification results of the algorithm proposed in the present invention are 96.3%, 73.7%, and 92.7% respectively in the cases of indoor and outdoor natural scenes, surface texture scenes, and satellite image scenes.< / eos> < / cls>
Claims
1. A few-sample classification method based on an image-text pre-training model, characterized in that: Establish a few-shot classification network for classification; The few-sample classification network is a four-branch architecture; the first branch is a zero-sample text branch, the second branch is a few-sample image branch, the third branch is a few-sample text branch, and the fourth branch is a zero-sample image branch; The zero-shot text branch takes unlearnable text as input and outputs unlearnable primitive-level text features and unlearnable hint-level text features; The zero-shot image branch takes the non-learnable image as input and outputs the non-learnable primitive-level image features and their prototypes, as well as the non-learnable hint-level image features and their prototypes; The few-shot image branch takes a learnable image as input and outputs learnable primitive-level image features and learnable hint-level image features; The few-shot text branch takes learnable text as input and outputs learnable primitive-level text features and learnable hint-level text features; The zero-shot text branch and the zero-shot image branch are composed of a multimodal feature extraction module, a prompt-level optimal transportation module and a similarity calculation module, respectively; the few-shot text branch and the few-shot image branch are composed of a multimodal feature extraction module, a primitive-level optimal transportation module, a prompt-level optimal transportation module and a similarity calculation module, respectively; the optimization process of the few-shot classification network is completed through three loss functions, namely, the cross-entropy loss function, the unbalanced consistency loss function and the prompt-level prototype distance loss function.
2. The few-sample classification method based on the image-text pre-training model according to claim 1, characterized in that: The few-sample image branch extracts image features through the following formula: Where z represents the learnable cue-level image features, f represents the CLIP image encoder in the few-shot image branch, and They represent the image patch vector in the learnable primitive-level image feature and the visual primitive vector in the learnable primitive-level image feature respectively; e, v represent the input learnable primitive-level image feature; <cls> Represents learnable category primitives;< / cls> Learnable text vector t and fixed text vector corresponding to the kth category The input text features are formed, and the output text features are obtained by the following formula: Among them, h k represents learnable prompt-level text features, and represents the learnable primitive-level text features; g represents the CLIP text encoder in the few-shot text branch, <eos> Represents the ending primitive of input text.< / eos> 3. The few-sample classification method based on the image-text pre-training model according to claim 1 or 2, characterized in that: Given an object category, the CLIP image encoder with a zero-shot image branch computes non-learnable primitive-level image features. is a non-learnable hint-level image feature; Non-learnable primitive-level image feature prototypes e The calculation method is as follows: in, represents the training samples of the selected k categories; N is the number of image samples in the few-shot classification dataset; the Euclidean distance is used To measure the non-learnable primitive-level image feature prototypes s e With learnable primitive-level image patch vectors The differences between them are as follows: Distance to non-learnable primitive-level image feature prototype center s e Closer learnable primitive-level image patches have smaller intra-class differences; Euclidean distance and learnable primitive-level image patch weights Inversely proportional; the following Gaussian function is used to implement this mapping process: Where σ is the standard deviation of the Gaussian function; according to the learnable primitive-level image patch weights The re-weighted learnable primitive-level image patch is represented as follows:
4. The few-sample classification method based on the image-text pre-training model according to claim 3 is characterized in that: The learnable primitive-level image features and learnable primitive-level text features Modeled as two empirical distributions as follows: in, Represents r j The corresponding Dirac function value is, Indicates l The corresponding Dirac function value; Define the primitive level cost matrix as in The optimal transport distance between the learnable primitive-level image feature r and the learnable primitive-level text feature s is expressed as follows: Among them, ε>0 is a hyperparameter; T t represents the optimal transportation matrix between R and S.
5. The few-sample classification method based on the image-text pre-training model according to claim 3 is characterized in that: Using two empirical distributions, P and Q, to simulate learnable hint-level image features z and learnable hint-level text features h, we obtain a hint-level optimal transportation strategy with cross alignment: Among them, z m represents the mth learnable hint-level image feature; h n represents the nth learnable prompt-level text feature; feature Indicates z m The corresponding Dirac function value, Indicates h n The corresponding Dirac function value; Compute the non-learnable primitive-level text features w and the non-learnable hint-level text features h from the CLIP text encoder of the zero-shot text branch: [-,w,h]=g(<cls>,w,<eos>) (11) Non-learnable hint-level image features and the distribution corresponding to the non-learnable hint-level text feature h and It is expressed as follows: in, represents the mth non-learnable hint-level image feature, represents the nth non-learnable prompt-level text feature; express The corresponding Dirac function value, express The corresponding Dirac function value; The prompt-level optimal transport distance is expressed as follows: Among them, T p represents the optimal transportation matrix between P and Q; C p ∈R M×N is the cost matrix between P and Q, defined as follows: The optimal transport distance for prompt-level crossover is defined as follows: The cost matrix in equations (15) and (16) is defined as follows: The class prediction probability with the optimal transportation matrix is expressed as follows:
6. The few-sample classification method based on the image-text pre-training model according to claim 4 or 5, characterized in that: The unbalanced consistency loss with prototype distance uses the cross entropy loss as the base loss function: Among them, y x,k is the label of image x of category k; By imposing an imbalanced consistency loss and To maintain the consistency between the learnable prompt features and the non-learnable prompt features, the formula is defined as follows: in, represents the consistency loss that includes non-learnable hint-level image features, represents the consistency loss that includes non-learnable hint-level text features; Represents KL divergence; uses training samples from a few-shot dataset Compute non-learnable hint-level image feature prototypes s p : in is a non-learnable hint-level image feature; prototype loss is used to supervise the learnable hint-level image feature z and the non-learnable hint-level image feature prototype s p Distance between: Where k represents the category label of image x; combined with unbalanced consistency loss and And prototype loss Unbalanced consistency loss based on prototype distance It is expressed as follows: The overall loss function is as follows:
Citation Information
Patent Citations
Zero-sample image classification method based on double-discrimination generative adversarial network text reconstruction
CN110443293A
Few-sample image classification system and method using semantic information
CN117496259A
Visual language model image feature extraction method based on attention prompt
CN117876698A
Small sample visual classification method and device based on retrieval enhancement mechanism and visual cue learning
CN117953282A
Method and apparatus for vision-language understanding
EP4343624A1
Cited By
Cross-domain few-sample remote sensing target classification method based on discriminant text prompt learning
CN121033550A
