Zero sample image classification method and system based on prompt guidance
Through the prompt-guided zero-shot image classification method, the cross-modal fusion of semantic and visual information is used to solve the problems of traditional models in the lack of annotated data and unseen category classification, and achieve high accuracy in zero-shot scenarios. Image classification.
Patent Information
- Application Number
- CN202410857514.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2044-06-28
AI Technical Summary
In the field of image classification, traditional artificial intelligence models are difficult to effectively classify when they lack annotated data or encounter unseen categories. Especially in scenarios where annotated data is sparse, it is difficult for existing technologies to achieve high-precision classification.
A zero-shot image classification method based on cue guidance is used to enhance the visual representation through global semantic representation, instance cue representation and instance visual representation, and project it into the semantic attribute space. It combines semantic attribute consistency loss, cue attribute consistency loss, Cross-entropy loss and debiasing loss optimize the classification model to achieve automatic classification of images.
In scenarios where there are no trainable image samples, textual semantic cues and attribute vectors are used for automatic image classification, ensuring reliable cross-modal communication of instance-level semantic information and visual information, improving the accuracy of image classification, and in situations where annotation data is sparse. Performs well in scenes.
Smart Images

Figure CN118691899A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision artificial intelligence technology, and in particular to a zero-sample image classification method and system based on prompt guidance. Background Art
[0002] At present, the end-to-end model technology of artificial intelligence from image feature extraction to classification has been quite mature in the field of computer vision and image processing, and can achieve high classification accuracy with the support of a large number of labeled samples. In particular, the currently widely used large-scale pre-trained image models based on CNN, such as ResNet and VGG, trained on the imageNet dataset, have provided a new paradigm for image classification: using them as the backbone network and fine-tuning downstream tasks. Although these models can perform tasks well in daily scenarios, in some specific scenarios, such as the high cost of manually annotated data, the imbalance of the number of samples of different categories following the long-tail distribution, the scarcity of annotated data in low-resource fields, and the need for professional knowledge in extreme scenarios, traditional artificial intelligence models often cannot play a role. In addition, the trained model can only classify the categories seen during the training process, and cannot classify some unseen categories. These problems have brought a series of challenges to the field of image classification.
[0003] In order to meet this challenge, image classification work for zero-shot learning has been widely studied and continuously developed. Zero-shot learning mainly simulates the cognitive process of the human brain, simulates the knowledge transfer from visible classes to invisible classes to learn transferable related knowledge from visible classes, and applies it to the classification of invisible classes. Research work on zero-shot image classification based on semantic cues is mainly divided into two categories, one is the zero-shot classification model based on generation, and the other is the zero-shot classification model based on embedding. The generation-based model aims to generate corresponding image features for the invisible class through semantic cues and simplify it to a fully supervised classification problem. The embedding-based model hopes to find a mapping relationship to map semantic attributes to visual space, or to map visual features to semantic space, or to find a common space to map semantic attributes and visual features to the common space together. Its ultimate goal is to learn the connection between semantic and visual features in the same vector space and complete the classification task in this space. Summary of the invention
[0004] The main purpose of the present invention is to overcome the shortcomings and deficiencies of the prior art and to provide a prompt-guided zero-sample image classification method and system, which can fully utilize text semantic cues and attribute vectors for automatic image classification in scenarios where there are no trainable image samples, thereby ensuring reliable cross-modal communication of instance-level semantic information and instance-level visual information and improving the accuracy of image classification.
[0005] According to one aspect of the present invention, the present invention provides a zero-shot image classification method based on prompt guidance, the method comprising the following steps:
[0006] The enhanced visual representation is calculated based on the global semantic representation, the instance hint representation and the instance visual representation; the enhanced visual representation integrating the semantic information is projected into the semantic attribute space, and the similarity scores of the attributes of all categories are calculated;
[0007] Calculate the total loss of classification model optimization according to semantic attribute consistency loss, hint attribute consistency loss, cross entropy loss and debiasing loss, take the total loss as the optimization target, and optimize the parameters of the classification model;
[0008] According to the optimized classification model, the similarity score between the given image and the attributes of the invisible category is calculated, and the predicted label corresponding to the image is output to achieve the classification of zero-sample images.
[0009] Preferably, the step of calculating the enhanced visual representation according to the global semantic representation, the instance hint representation and the instance visual representation comprises:
[0010] Obtain instance images of visible classes, attribute vectors corresponding to visible classes, and global semantic descriptions of shared attributes from the dataset, and obtain corresponding textual instance prompts through the attribute vectors;
[0011] The global semantic description and the instance prompt corresponding to the instance image are input into the text encoder to obtain the global semantic representation and the instance prompt representation; the instance image is input into the first L-1 layers of the visual encoder to obtain the instance visual representation;
[0012] The global semantic representation and the instance visual representation are fed into the visual instance guided global semantic enhancement decoder in the semantic visual cross-modal fusion module to obtain the enhanced global semantic representation;
[0013] The enhanced global semantic representation and the instance hint representation are input into the hint instance guided local enhancement semantic enhancement decoder in the semantic visual cross-modal fusion module to obtain the locally enhanced local enhancement semantic representation;
[0014] The instance visual representation and the local enhanced semantic representation are input into the local enhanced semantics-guided visual decoder in the semantic-visual cross-modal fusion module to obtain the enhanced visual representation.
[0015] Inputting the enhanced visual representation into the last encoding layer of the visual encoder for encoding to obtain an encoding result;
[0016] The encoding result of the enhanced visual representation, the global semantic representation and the instance prompt representation are fused and paired to obtain the enhanced visual representation.
[0017] Preferably, projecting the enhanced visual representation integrated with semantic information into the semantic attribute space and calculating the similarity scores of attributes of all categories comprises:
[0018] Use cosine similarity to evaluate the similarity score between the given image and the attribute vector of each class:
[0019]
[0020] in, is the candidate label for the classification task, Z is the set of attribute vectors that need to be classified, τ is the scaling factor, x is the instance image, To enhance the visual representation, W p is a fully connected layer, and GAP is a one-dimensional global average pooling function.
[0021] Preferably, the total loss of optimizing the classification model is calculated according to the semantic attribute consistency loss, the prompt attribute consistency loss, the cross entropy loss and the debiasing loss, including:
[0022]
[0023] Among them, L sa is the semantic attribute consistency loss, L pac To indicate the attribute consistency loss, L cls is the cross entropy loss, L deb is the debiasing loss, L is the total optimization loss; Attention_score S,V , are the attention scores in the global semantic decoder guided by the visual instance and the local semantic decoder guided by the cue instance, respectively. GMP represents the one-dimensional global maximum pooling function, and z c is the attribute vector of the class, represents the square of the vector's second norm, α S , α U are the means of the predicted similarity scores for the visible and invisible classes, β S , β U are the variances of the predicted similarity scores of the visible and unseen classes, respectively, and λ c , cls and λ deb is the weighting coefficient.
[0024] Preferably, the similarity score between the given image and the attribute of the invisible category is calculated according to the optimized classification model, and the predicted label corresponding to the output image includes:
[0025] Compute scores for unseen classes:
[0026]
[0027] Output the predicted label of the category with the highest similarity score
[0028]
[0029] Among them, γ is the calibration coefficient used to balance the scores of visible and invisible classes during training, and f i (·) is an indicator function if If Y U Represents the label set of the unseen class; Y is the label set that needs to be predicted.
[0030] According to another aspect of the present invention, the present invention also provides a prompt-guided zero-sample image classification system, the system comprising:
[0031] A calculation module is used to calculate an enhanced visual representation based on the global semantic representation, the instance hint representation and the instance visual representation; the enhanced visual representation integrating the semantic information is projected into the semantic attribute space, and the similarity scores with the attributes of all categories are calculated;
[0032] An optimization module, used to calculate the total loss of classification model optimization according to the semantic attribute consistency loss, the prompt attribute consistency loss, the cross entropy loss and the debiasing loss, and optimize the parameters of the classification model by taking the total loss as the optimization target;
[0033] The classification module is used to calculate the similarity score between the given image and the attributes of the invisible category according to the optimized classification model, output the predicted label corresponding to the image, and realize the classification of zero-sample images.
[0034] Preferably, the calculation module calculates the enhanced visual representation according to the global semantic representation, the instance hint representation and the instance visual representation, and comprises:
[0035] Obtain instance images of visible classes, attribute vectors corresponding to visible classes, and global semantic descriptions of shared attributes from the dataset, and obtain corresponding textual instance prompts through the attribute vectors;
[0036] The global semantic description and the instance prompt corresponding to the instance image are input into the text encoder to obtain the global semantic representation and the instance prompt representation; the instance image is input into the first L-1 layers of the visual encoder to obtain the instance visual representation;
[0037] The global semantic representation and the instance visual representation are fed into the visual instance guided global semantic enhancement decoder in the semantic visual cross-modal fusion module to obtain the enhanced global semantic representation;
[0038] The enhanced global semantic representation and the instance hint representation are input into the hint instance guided local enhancement semantic enhancement decoder in the semantic visual cross-modal fusion module to obtain the locally enhanced local enhancement semantic representation;
[0039] The instance visual representation and the local enhanced semantic representation are input into the local enhanced semantics-guided visual decoder in the semantic-visual cross-modal fusion module to obtain the enhanced visual representation.
[0040] Inputting the enhanced visual representation into the last encoding layer of the visual encoder for encoding to obtain an encoding result;
[0041] The encoding result of the enhanced visual representation, the global semantic representation and the instance prompt representation are fused and paired to obtain the enhanced visual representation.
[0042] Preferably, the calculation module projects the enhanced visual representation integrated with semantic information into the semantic attribute space, and calculates the similarity scores of attributes of all categories, including:
[0043] Use cosine similarity to evaluate the similarity score between the given image and the attribute vector of each class:
[0044]
[0045] in, is the candidate label for the classification task, Z is the set of attribute vectors that need to be classified, τ is the scaling factor, x is the instance image, To enhance the visual representation, W p is a fully connected layer, and GAP is a one-dimensional global average pooling function.
[0046] Preferably, the optimization module calculates the total loss of the classification model optimization according to the semantic attribute consistency loss, the prompt attribute consistency loss, the cross entropy loss and the debiasing loss, including:
[0047]
[0048]
[0049] Among them, L sac is the semantic attribute consistency loss, L pac To indicate the attribute consistency loss, L cls is the cross entropy loss, L deb is the debiasing loss, L is the total optimization loss; Attention_score S,V , are the attention scores in the global semantic decoder guided by the visual instance and the local semantic decoder guided by the cue instance, respectively. GMP represents the one-dimensional global maximum pooling function, and z cis the attribute vector of the class, represents the square of the vector's second norm, α S , α U are the means of the predicted similarity scores for the visible and invisible classes, β S , β U are the variances of the predicted similarity scores of the visible and unseen classes, respectively, and λ c , cls and λ deb is the weighting coefficient.
[0050] Preferably, the classification module calculates the similarity score between the given image and the attributes of the invisible category according to the optimized classification model, and the predicted label corresponding to the output image includes:
[0051] Compute scores for unseen classes:
[0052]
[0053] Output the predicted label of the category with the highest similarity score
[0054]
[0055] Among them, γ is the calibration coefficient used to balance the scores of visible and invisible classes during training, and f i (·) is an indicator function if If Y U Represents the label set of the unseen class; Y is the label set that needs to be predicted.
[0056] Beneficial effects: The present invention introduces instance-level textual prompts, which makes up for the lack of instance-level semantic information in the zero-shot image classification task under semantic prompts, and provides more instance-level semantic information for the classification task. The present invention uses the local enhanced semantic decoder guided by the prompt instance to bring about the alignment of global semantics and instance semantic information in the semantic space, ensuring the transfer of the semantic space of visible class knowledge. The present invention uses the prompt-guided semantic visual cross-modal fusion module to complete the task of instance-level semantic information and instance-level visual information interacting with the help of global semantic information, ensuring reliable cross-modal communication of instance-level semantic information and instance-level visual information, and helping to align fine-grained visual information with fine-grained semantic information. The present invention fully completes the fusion of semantic vision, realizes the transfer of semantic and visual knowledge from visible classes to invisible classes, and achieves excellent results on three public datasets of zero-shot image classification, and has good practicality in some scenarios where labeled data is scarce.
[0057] The features and advantages of the present invention will become clear through reference to the following drawings and detailed description of specific embodiments of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] Figure 1 It is a flow chart of the prompt-guided zero-shot image classification method;
[0059] Figure 2 Schematic diagram of the model of the method of the present invention.
[0060] Figure 3 Architecture diagram for the visual instance-guided global semantic decoder and the cue instance-guided local enhanced semantic decoder.
[0061] Figure 4 Architecture diagram of the visual decoder guided by semantics for local enhancement.
[0062] Figure 5 Schematic diagram of a prompt-guided zero-shot image classification system. DETAILED DESCRIPTION
[0063] The following is a clear and complete description of the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0064] Example 1
[0065] Figure 1 This is a flowchart of the prompt-guided zero-shot image classification method. Figure 1 As shown, this embodiment provides a zero-sample image classification method based on prompt guidance, and the method includes the following steps:
[0066] An enhanced visual representation is calculated based on the global semantic representation, the instance hint representation and the instance visual representation; the enhanced visual representation that incorporates the semantic information is projected into the semantic attribute space, and the similarity scores with the attributes of all categories are calculated;
[0067] Calculate the total loss of classification model optimization according to semantic attribute consistency loss, hint attribute consistency loss, cross entropy loss and debiasing loss, take the total loss as the optimization target, and optimize the parameters of the classification model;
[0068] According to the optimized classification model, the similarity score between the given image and the attributes of the invisible category is calculated, and the predicted label corresponding to the image is output to achieve the classification of zero-sample images.
[0069] This method can fully utilize text semantic cues and attribute vectors for automatic image classification in scenarios without trainable image samples, ensuring reliable cross-modal communication of instance-level semantic information and instance-level visual information, and improving the accuracy of image classification.
[0070] Preferably, the step of calculating the enhanced visual representation according to the global semantic representation, the instance hint representation and the instance visual representation comprises:
[0071] Obtain instance images of visible classes, attribute vectors corresponding to visible classes, and global semantic descriptions of shared attributes from the dataset, and obtain corresponding textual instance prompts through the attribute vectors;
[0072] The global semantic description and the instance prompt corresponding to the instance image are input into the text encoder to obtain the global semantic representation and the instance prompt representation; the instance image is input into the first L-1 layers of the visual encoder to obtain the instance visual representation;
[0073] The global semantic representation and the instance visual representation are fed into the visual instance guided global semantic enhancement decoder in the semantic visual cross-modal fusion module to obtain the enhanced global semantic representation;
[0074] The enhanced global semantic representation and the instance hint representation are input into the hint instance guided local enhancement semantic enhancement decoder in the semantic visual cross-modal fusion module to obtain the locally enhanced local enhancement semantic representation;
[0075] The instance visual representation and the local enhanced semantic representation are input into the local enhanced semantics-guided visual decoder in the semantic-visual cross-modal fusion module to obtain the enhanced visual representation.
[0076] Inputting the enhanced visual representation into the last encoding layer of the visual encoder for encoding to obtain an encoding result;
[0077] The encoding result of the enhanced visual representation, the global semantic representation and the instance prompt representation are fused and paired to obtain the enhanced visual representation.
[0078] Specifically, see Figure 2 , Figure 3 and Figure 4 , this step may include the following steps S1-S7.
[0079] The zero-shot image classification task hopes to obtain s ={x s ,y s )|x∈X s , y∈Y s} Learn transferable knowledge and apply it to unseen classes D u ={{u,y u )|x∈Xu , y∈Y u}}, where x represents the image to be classified, y represents the label and belongs to a category c, where c∈C, C=C s UC u At the same time, the visible class and the invisible class do not intersect, that is, C s ∩C u =Φ. For each category c, there is a d a Dimensional attribute vector Correspondingly, each dimension a of zc i They all represent the probability of the attributes of this category appearing. a The attributes in D s and D u As a bridge for knowledge transfer, the semantic information of the category is shared between c In addition to this attribute vector expression, you can also use textual semantic descriptions to express it, using To represent all semantic descriptions of the corresponding category, where t i Represents attribute a i The corresponding text description. For the traditional zero-shot task, the label to be predicted is y∈Y u , and for the generalized zero-shot task, the label to be predicted is y∈Y u U Y S The specific steps are as follows:
[0080] S1: First, obtain the input instance image x and the corresponding attribute vector from the dataset where z c Each dimension a i Both represent the probability of occurrence of the attributes of this category and the global semantic attribute description To represent all semantic descriptions of the corresponding category, where t i Represents attribute a i The corresponding text description, these attributes are shared between the visible and invisible classes. Then, through the attribute z of each class c Calculate the binary attribute vector, and use the binary attribute vector to obtain the attribute hint T of each category P That is, if the attribute vector in binary format is 1 in a certain dimension, then the category is considered to contain this attribute. At the same time, according to the attribute feature grouping of the data set, the attribute vector in binary format is converted into a semantic attribute prompt through a unified prompt format. For example, the kth instance prompt of the data set CUB is shown in 1:
[0081]
[0082] Among them, the attribute features of the same data set can be classified into different feature groups. If there are multiple attributes in the same group of features, they are separated by commas.
[0083] S2: Then, the text encoder is used to transform the global semantics T and attribute hints T obtained in step 1 into P Send it to the text encoder to obtain the global semantic representation and instance hints As shown in formula 2 and formula 3:
[0084] S = text_encoder(T) (2)
[0085] P = text_encoder(T P ) (3)
[0086] Where b represents the training batch size, d represents the output feature dimension of the text encoder, and l represents the length of the prompt sentence. a is the number of global semantic attributes. In particular, we want to use the global semantic representation as a fixed reference, so the parameters of the text encoder when generating the global semantic representation S are frozen. Similarly, the instance image x is fed into the 0th to L-1th layers of the visual encoder ViT to obtain the visual instance representation As shown in formula 4:
[0087] V=ViT 0∶L-1 (x) (4)
[0088] Where x is the input instance image, L represents the total number of layers of the Transformer structure of the visual encoder pre-training model ViT, and p 2 Represents the number of small image blocks into which the image is segmented, that is, the input image will be segmented into p×p small image blocks, and c represents the feature dimension of the visual representation output by ViT.
[0089] S3: Send the global semantic representation S and visual instance representation V in step 2 to the global semantic enhancement decoder guided by the visual instance. The specific structure is shown in Figure 2 In (a), the decoder is used to pair and fuse global semantics with instance visual features to adjust the global semantics to an enhanced global semantic representation centered on the visual instance. The decoder uses an R-layer loop to achieve progressive fusion and activation. Each layer first passes through the semantic-visual instance attention module to represent the i-th dimension attribute of the global semantics S i The jth image patch V with the instance visual feature jMatching is performed, and relevant semantic and visual features are integrated layer by layer to achieve the effect of localizing global semantic representation. Then, through the semantic self-correlation activation module, important semantic features are further activated through semantic self-correlation connections to achieve the effect of removing irrelevant semantics. The specific module definitions are as follows:
[0090] Semantic-Visual Instance Attention Module: In order to localize the global semantic features shared by the visible and invisible classes and adapt them to different instance visual features, a semantic-visual instance attention module is used to calculate the i-th dimension attribute semantic representation S of the global semantics i The jth image patch V with the instance visual feature j The attention score is shown in 5:
[0091]
[0092] in, and is the linear transformation matrix, responsible for converting the input into the query and key in the attention mechanism. LN represents the layer normalization function. The i-th dimension attribute representing the global semantics is represented by S i The jth image patch V of the visual instance j The higher the score, the better the image block V j The more it can express this semantic attribute S i The attention score is calculated for each dimension of the global semantics and each image block of the visual instance, and finally a localized attention score dominated by the visual instance is obtained. In order to ensure the correct pairing of global semantics and visual instances, the present invention uses the semantic attribute consistency loss L sac To optimize the semantic-visual attention module, as shown in formula 6:
[0093]
[0094] Among them, GMP represents one-dimensional global maximum pooling, zc is the attribute vector of this class, represents the square of the vector 2 norm. Subsequently, we use the attention score and the visual instance to calculate the global semantic representation centered on the visual instance For example, in formula 7:
[0095]
[0096] in, It is a linear transformation matrix used to calculate the value in the attention mechanism, using residual connection to add the adjusted global semantic representation to the global semantic representation before adjustment.
[0097] Global semantic autocorrelation activation module: Since there is a connection between global semantic features and features, a global semantic autocorrelation activation module is used to enable global semantic features to interact with each other and further reduce the impact of irrelevant features on global semantic representation. This embodiment first calculates the autocorrelation attention score Relevant_score between semantic attributes S , as shown in formula 8:
[0098]
[0099] Among them, GAP is the one-dimensional global average pooling function, σ represents the GELU activation function, and is the linear weight matrix of the fully connected layer, where g represents the number of feature groups, that is, the number of feature groups to which different features in the prompt belong. Subsequently, the autocorrelation attention score is combined with the global semantic representation centered on the visual instance. Multiply them together and make residual connections to get the global semantic representation after attribute interaction. As shown in formula 9:
[0100]
[0101] Finally, the MLP layer is used to activate important semantic features, eliminate the influence of irrelevant features, and perform residual connections to finally obtain an enhanced global semantic representation. As shown in formula 10:
[0102]
[0103] Here, MLP stands for a simple multi-layer perceptron neural network.
[0104] S4: The enhanced global semantic representation in step 2 The hint instance representation P is fed into the hint instance guided local enhanced semantic decoder, see Figure 2 (b) in the figure. The decoder consists of an enhanced global semantics-cue instance attention module and a local enhanced semantic autocorrelation activation module. The overall structure is similar to the global semantic decoder guided by visual instances. The function of this decoder is to pair and fuse the enhanced global semantics with instance cues, use instance-level cue representations to activate the enhanced global semantic representations that incorporate visual instance features, and further activate instance-related semantic attribute features in the enhanced global semantics to further refine the semantic representation. The encoder uses an R-layer loop to achieve fusion. Each layer first uses the enhanced global semantics-cue instance attention module to enhance the i-th dimension attribute of the global semantics. The jth prompt word P with the instance prompt jMatching is performed, and the relevant enhanced semantic attributes and feature words of instance prompts are paired and fused layer by layer, so as to compress the detailed semantic information of the prompts into the various semantic attributes of the enhanced global semantics. The local enhanced semantic autocorrelation activation module is then used to further explore the relationship between the local enhanced semantic attributes, so as to achieve the effect of refining the local enhanced semantic representation. The specific module definitions are as follows:
[0105] Enhanced global semantics-cue instance attention module: In order to use the specific cue word activation in the cue instance to enhance the global semantic representation, the enhanced global semantics-cue instance attention module is used to calculate the i-th dimension attribute of the enhanced global semantics The jth prompt word P with the instance prompt j The attention score is shown in formula 11:
[0106]
[0107] in, and is the linear transformation matrix responsible for transforming the input into the query and key in the attention mechanism, Represents the i-th dimension attribute that enhances the global semantics The jth prompt word representation P of the prompt instance j The higher the score, the higher the correlation between the dimension attribute and the prompt word. The attention score is calculated for each feature group of the instance prompt and each dimension of the enhanced global semantics, and finally the instance prompt attention score guided by the enhanced global semantics is obtained. In order to ensure the correct pairing of global semantics with visual instances, the cue attribute consistency loss L is used. pac To optimize the semantic-visual attention module, as shown in formula 12:
[0108]
[0109] Subsequently, the fused local enhanced semantic representation is calculated using the attention score and the enhanced global semantic representation. For example, in formula 13:
[0110]
[0111] in, is a linear transformation matrix used to calculate the value in the attention mechanism, using residual connections to add the fused local enhanced semantic representation and enhanced global semantic representation. The local enhanced semantic representation after incorporating the prompt instance further refines the semantic representation, and the semantic information expressed is more localized.
[0112] Local enhanced semantic autocorrelation activation module: Same as the global semantic autocorrelation activation module, the local enhanced semantic autocorrelation activation module is used to complete the interaction between the features in the local enhanced semantic representation, and further compress and fuse the local enhanced semantic representation. We first calculate the autocorrelation attention score between the features. As shown in formula 14:
[0113]
[0114] in, and is the linear weight matrix of the fully connected layer. Subsequently, the autocorrelation attention score is combined with the local enhanced semantic representation Multiply them together and make residual connections to get the global semantic representation after the interaction of feature groups. As shown in formula 15:
[0115]
[0116] Finally, the MLP layer is used to activate important features, eliminate the influence of irrelevant features, and perform residual connections to obtain the final local enhanced semantic representation. As shown in formula 16:
[0117]
[0118] S5: The local enhanced semantic representation obtained in step 4 The instance visual representation V obtained in step 2 is fed into the cue instance guided local enhanced semantic decoder, see Figure 3 The decoder consists of a visual-local enhanced semantic attention module and a visual autocorrelation activation module. The decoder uses the localized local enhanced semantic representation to activate the instance visual representation, achieves cross-domain fusion with precise matching, and obtains the instance-level semantic-visual fusion feature representation. In order to make the local enhanced semantic representation of the semantic space and the visual instance representation of the visual space to perform cross-domain interactive fusion, the visual-local enhanced semantic attention score is used. To build an instance visual representation of the i-th image block V i and local enhanced semantic representation of the jth attribute feature The specific calculation is shown in 17:
[0119]
[0120] in, and is the linear transformation matrix responsible for transforming the input into the query and key in the attention mechanism, Represents the instance visual representation of the i-th image patch V iand local enhanced semantic representation of the jth attribute feature The higher the score, the higher the correlation between the semantic feature and the image block. The attention score is calculated for each image block of the instance visual representation and each feature of the local enhanced semantic representation, and finally the visual instance attention score based on the local enhanced semantics is obtained.
[0121] Subsequently, according to The key semantic information matching the image is extracted from the local enhanced semantic representation to enhance the instance visual features, as shown in Formula 18:
[0122]
[0123] in, It is a linear transformation matrix used to calculate the value in the attention mechanism. It uses residual connection to add the visual representation after integrating the local enhanced semantic information and the original visual representation. The fused instance visual representation integrates the matching refined semantic information and achieves fine-grained semantic-visual interaction. Since the prompt instance provides localized refined semantic information, the local enhanced semantic information is more accurately associated with the image block.
[0124] Visual autocorrelation activation module: Similarly, the fused visual features still need to explore the relationship between image blocks, and use the image block fusion activation module to integrate and refine the features between image blocks. The calculation process is defined as shown in formulas 19-22:
[0125]
[0126] Where T represents the matrix transpose operation, is a fully connected layer, after which the image block features are expanded to high dimensions and then Do the filtering and finally the fully connected layer Project back to the original dimension and make a residual connection to obtain enhanced visual features Finally, an MLP layer and residual connection are used to reactivate the enhanced visual features.
[0127] S6: The enhanced visual features obtained in step 5 Send it to the last layer of the visual encoder ViT and get As shown in formula 23:
[0128]
[0129] S7: Repeat S3 to S5, S and P are sent to the hint-guided semantic visual cross-modal fusion module for secondary fusion pairing, and finally a discriminable enhanced visual representation is obtained.
[0130] Preferably, projecting the enhanced visual representation integrated with semantic information into the semantic attribute space and calculating the similarity scores of attributes of all categories comprises:
[0131] Use cosine similarity to evaluate the similarity score between the given image x and the attribute vector of each class:
[0132]
[0133] in, is the candidate label for the classification task, Z is the set of attribute vectors that need to be classified, τ is the scaling factor, x is the instance image, To enhance the visual representation, W p is a fully connected layer, and GAP is a one-dimensional global average pooling function.
[0134] Specifically, after two cue-guided fusions of semantic-visual cross-modal fusion modules, an enhanced visual representation that integrates semantic-visual information is obtained. This example uses a fully connected layer The enhanced visual representation obtained in step 7 Projection to attribute vector z c The space where the class is located is used, and a cosine similarity is used to evaluate the similarity score with the attribute vector of each class, as shown in Formula 24:
[0135]
[0136] in, is the candidate label of the classification task, Z is the set of attribute vectors of the categories to be classified, when the task is traditional zero-sample classification, Z = {z c |c∈C U}, when the task is generalized zero-shot classification, Z = {z c |c∈C U ∪ C S}. U Represents the invisible class, C S represents the visible class. τ is the scaling factor.
[0137] Preferably, the total loss of optimizing the classification model is calculated according to the semantic attribute consistency loss, the prompt attribute consistency loss, the cross entropy loss and the debiasing loss, including:
[0138]
[0139] Among them, Lsac is the semantic attribute consistency loss, L pac To indicate the attribute consistency loss, L cls is the cross entropy loss, L deb is the debiasing loss, L is the total optimization loss; Attention_score S,V , are the attention scores in the global semantic decoder guided by the visual instance and the local semantic decoder guided by the cue instance, respectively. GMP represents the one-dimensional global maximum pooling function, and z c is the attribute vector of the class, represents the square of the vector's second norm, α S , α U are the mean scores of the visible and invisible classes, β S , β U are the variances of the visible and unseen classes, respectively, c , cls and λ deb is the weighting coefficient.
[0140] Specifically, using the calculated correlation score Calculate the cross entropy loss L cls To supervise the training of this classification task, as shown in Equation 25:
[0141]
[0142] Among them, y refers to the true label of the classification, Y s Represents the set of visible class labels, and then calculates the debiasing loss L deb To reduce the deviation between the visible class and the invisible class, as shown in Equation 26:
[0143]
[0144] Among them, α S , α U are the mean scores of the visible and invisible classes, β S , β U are the variances of the visible class and the unseen class, respectively. Through this loss, the distribution of the visible class and the unseen class is made consistent as much as possible to ensure that the model does not overfit the visible class.
[0145] Finally, L sac , L pac , L cls L deb The weighted summation gives the total optimization loss L of the model, as shown in Formula 27:
[0146]
[0147] Among them, λc , cls and λ deb is the weighting coefficient. Finally, the total loss L is used as the optimization target to optimize the model parameters.
[0148] Preferably, the similarity score between the given image and the attribute of the invisible category is calculated according to the optimized classification model, and the predicted label corresponding to the output image includes:
[0149] Compute scores for unseen classes:
[0150]
[0151] Output the predicted label of the category with the highest similarity score
[0152]
[0153] Among them, γ is the calibration coefficient used to balance the scores of visible and invisible classes during training, and f i (·) is an indicator function if If Y U Represents the label set of the unseen class; Y is the label set that needs to be predicted.
[0154] Specifically, since the model can only classify visible classes during model training, the model will inevitably tend to generate higher scores for visible classes, resulting in poor generalization performance. Therefore, calibration stacking is used to assign certain scores to unseen classes, such as Equation 28:
[0155]
[0156] Among them, γ is the calibration coefficient used to balance the scores of visible and invisible classes during training. i (·) is an indicator function if If Y is true, the function value is 0, otherwise it is 1. U is the set of unseen class labels.
[0157] Finally, use the trained model to obtain the relevant scores And use the relevant score to calculate the label y corresponding to the instance image x, as shown in Formula 29:
[0158]
[0159] Where Y is the set of labels that need to be predicted.
[0160] This embodiment introduces instance-level textual prompts, which makes up for the lack of instance-level semantic information in the zero-shot image classification task under semantic prompts, and provides more instance-level semantic information for the classification task. The present invention uses a local enhanced semantic decoder guided by prompt instances to bring about the alignment of global semantics and instance semantic information in the semantic space, ensuring the transfer of the semantic space of visible class knowledge. The present invention uses a prompt-guided semantic visual cross-modal fusion module to complete the task of instance-level semantic information and instance-level visual information interacting with the help of global semantic information, ensuring reliable cross-modal communication of instance-level semantic information and instance-level visual information, and helping to align fine-grained visual information with fine-grained semantic information. The present invention fully completes the fusion of semantic vision, realizes the transfer of semantic and visual knowledge from visible classes to invisible classes, and achieves excellent results on three public data sets for zero-shot image classification, and has good practicality in some scenarios where labeled data is scarce.
[0161] Example 2
[0162] Figure 5 This is a schematic diagram of a prompt-guided zero-shot image classification system. Figure 5 As shown, this embodiment provides a zero-sample image classification system based on prompt guidance, and the system includes:
[0163] The calculation module 501 is used to calculate the enhanced visual representation according to the global semantic representation, the instance hint representation and the instance visual representation; project the enhanced visual representation integrating the semantic information into the semantic attribute space, and calculate the similarity scores with the attributes of all categories;
[0164] An optimization module 502 is used to calculate the total loss of classification model optimization according to the semantic attribute consistency loss, the prompt attribute consistency loss, the cross entropy loss and the debiasing loss, and optimize the parameters of the classification model by taking the total loss as the optimization target;
[0165] The classification module 503 is used to calculate the similarity score between the given image and the attributes of the invisible category according to the optimized classification model, output the predicted label corresponding to the image, and realize the classification of the zero-sample image.
[0166] Preferably, the calculation module 501 calculates the enhanced visual representation according to the global semantic representation, the instance hint representation and the instance visual representation, including:
[0167] Obtain instance images of visible classes, attribute vectors corresponding to visible classes, and global semantic descriptions of shared attributes from the dataset, and obtain corresponding textual instance prompts through the attribute vectors;
[0168] The global semantic description and the instance prompt corresponding to the instance image are input into the text encoder to obtain the global semantic representation and the instance prompt representation; the instance image is input into the first L-1 layers of the visual encoder to obtain the instance visual representation;
[0169] The global semantic representation and the instance visual representation are fed into the visual instance guided global semantic enhancement decoder in the semantic visual cross-modal fusion module to obtain the enhanced global semantic representation;
[0170] The enhanced global semantic representation and the instance hint representation are input into the hint instance guided local enhancement semantic enhancement decoder in the semantic visual cross-modal fusion module to obtain the locally enhanced local enhancement semantic representation;
[0171] The instance visual representation and the local enhanced semantic representation are input into the local enhanced semantics-guided visual decoder in the semantic-visual cross-modal fusion module to obtain the enhanced visual representation.
[0172] Inputting the enhanced visual representation into the last encoding layer of the visual encoder for encoding to obtain an encoding result;
[0173] The encoding result of the enhanced visual representation, the global semantic representation and the instance prompt representation are fused and paired to obtain the enhanced visual representation.
[0174] Preferably, the calculation module 501 projects the enhanced visual representation integrated with semantic information into the semantic attribute space, and calculates the similarity scores of attributes of all categories, including:
[0175] Use cosine similarity to evaluate the similarity score of the attribute vectors of each class:
[0176]
[0177] in, is the candidate label for the classification task, Z is the set of attribute vectors that need to be classified, τ is the scaling factor, x is the instance image, To enhance the visual representation, W p is a fully connected layer, and GAP is a one-dimensional global average pooling function.
[0178] Preferably, the optimization module 502 calculates the total loss of the classification model optimization according to the semantic attribute consistency loss, the prompt attribute consistency loss, the cross entropy loss and the debiasing loss, including:
[0179]
[0180] Among them, L sac is the semantic attribute consistency loss, L pac To indicate the attribute consistency loss, L clsis the cross entropy loss, L deb is the debiasing loss, L is the total optimization loss; Attention_score S,V , are the attention scores in the global semantic decoder guided by the visual instance and the local semantic decoder guided by the cue instance, respectively. GMP represents the one-dimensional global maximum pooling function, and z c is the attribute vector of the class, represents the square of the vector's second norm, α S , α U are the mean scores of the visible and invisible classes, β S , β U are the variances of the visible and unseen classes, respectively, c , cls and λ deb is the weighting coefficient.
[0181] Preferably, the classification module 503 calculates the similarity score between the given image and the attributes of the invisible category according to the optimized classification model, and the predicted label corresponding to the output image includes:
[0182] Compute scores for unseen classes:
[0183]
[0184] Output the predicted label of the category with the highest similarity score
[0185]
[0186] Among them, γ is the calibration coefficient used to balance the scores of visible and invisible classes during training, and f i (·) is an indicator function if If Y U Represents the label set of the unseen class; Y is the label set that needs to be predicted.
[0187] The specific implementation process of the functions realized by each module in this embodiment 2 is the same as the implementation process in embodiment 1, and will not be repeated here.
[0188] The above description is only a preferred embodiment of the present invention, and does not limit the patent scope of the present invention. All equivalent structural changes made by using the contents of the present invention specification and drawings under the concept of the present invention, or directly / indirectly applied in other related technical fields are included in the patent protection scope of the present invention.
Claims
1. A zero-shot image classification method based on prompt guidance, characterized in that: The method comprises the following steps: An enhanced visual representation is calculated based on the global semantic representation, the instance hint representation and the instance visual representation; the enhanced visual representation that incorporates the semantic information is projected into the semantic attribute space, and the similarity scores with the attributes of all categories are calculated; Calculate the total loss of classification model optimization according to semantic attribute consistency loss, hint attribute consistency loss, cross entropy loss and debiasing loss, take the total loss as the optimization target, and optimize the parameters of the classification model; According to the optimized classification model, the similarity score between the given image and the attributes of the invisible category is calculated, and the predicted label corresponding to the image is output to achieve the classification of zero-sample images.
2. The method according to claim 1, characterized in that The enhanced visual representation calculated according to the global semantic representation, the instance hint representation and the instance visual representation comprises: Obtain instance images of visible classes, attribute vectors corresponding to visible classes, and global semantic descriptions of shared attributes from the dataset, and obtain corresponding textual instance prompts through the attribute vectors; The global semantic description and the instance prompt corresponding to the instance image are input into the text encoder to obtain the global semantic representation and the instance prompt representation; the instance image is input into the first L-1 layers of the visual encoder to obtain the instance visual representation; The global semantic representation and the instance visual representation are fed into the visual instance guided global semantic enhancement decoder in the semantic visual cross-modal fusion module to obtain the enhanced global semantic representation; The enhanced global semantic representation and the instance hint representation are input into the hint instance guided local enhancement semantic enhancement decoder in the semantic visual cross-modal fusion module to obtain the locally enhanced local enhancement semantic representation; The instance visual representation and the local enhanced semantic representation are input into the local enhanced semantics-guided visual decoder in the semantic-visual cross-modal fusion module to obtain the enhanced visual representation. Inputting the enhanced visual representation into the last encoding layer of the visual encoder for encoding to obtain an encoding result; The encoding result of the enhanced visual representation, the global semantic representation and the instance prompt representation are fused and paired to obtain the enhanced visual representation.
3. The method according to claim 2, characterized in that The enhanced visual representation integrated with semantic information is projected into the semantic attribute space, and the similarity scores with attributes of all categories are calculated, including: Use cosine similarity to evaluate the similarity score between the given image and the attribute vector of each class: in, is the candidate label for the classification task, Z is the set of attribute vectors that need to be classified, τ is the scaling factor, x is the instance image, To enhance the visual representation, W p is a fully connected layer, and GAP is a one-dimensional global average pooling function.
4. The method according to claim 3, characterized in that The total loss of the classification model optimization calculated according to the semantic attribute consistency loss, the prompt attribute consistency loss, the cross entropy loss and the debiasing loss includes: Among them, L sac is the semantic attribute consistency loss, L pac To indicate the attribute consistency loss, L cls is the cross entropy loss, L deb is the debiasing loss, L is the total optimization loss; Attention_score S,V , are the attention scores in the global semantic decoder guided by the visual instance and the local semantic decoder guided by the cue instance, respectively. GMP represents the one-dimensional global maximum pooling function, and z c is the attribute vector of the class, represents the square of the vector's second norm, α S , α U are the means of the predicted similarity scores for the visible and invisible classes, respectively, and β S , β U are the variances of the predicted similarity scores of the visible and unseen classes, respectively, and λ c , cls and λ deb is the weighting coefficient.
5. The method according to claim 4, characterized in that The similarity score between the given image and the attribute of the invisible category is calculated according to the optimized classification model, and the predicted label corresponding to the output image includes: Compute scores for unseen classes: Output the predicted label of the category with the highest similarity score Among them, γ is the calibration coefficient used to balance the scores of visible and invisible classes during training, and f i (·) is an indicator function if If Y U Represents the label set of the unseen class; Y is the label set that needs to be predicted.
6. A prompt-guided zero-shot image classification system, characterized in that: The system comprises: A calculation module is used to calculate an enhanced visual representation based on the global semantic representation, the instance hint representation and the instance visual representation; the enhanced visual representation integrating the semantic information is projected into the semantic attribute space, and the similarity scores with the attributes of all categories are calculated; An optimization module, used to calculate the total loss of classification model optimization according to the semantic attribute consistency loss, the prompt attribute consistency loss, the cross entropy loss and the debiasing loss, and optimize the parameters of the classification model by taking the total loss as the optimization target; The classification module is used to calculate the similarity score between the given image and the attributes of the invisible category according to the optimized classification model, output the predicted label corresponding to the image, and realize the classification of zero-sample images.
7. The system according to claim 6, characterized in that The computing module calculates the enhanced visual representation according to the global semantic representation, the instance hint representation and the instance visual representation, and comprises: Obtain instance images of visible classes, attribute vectors corresponding to visible classes, and global semantic descriptions of shared attributes from the dataset, and obtain corresponding textual instance prompts through the attribute vectors; The global semantic description and the instance prompt corresponding to the instance image are input into the text encoder to obtain the global semantic representation and the instance prompt representation; the instance image is input into the first L-1 layers of the visual encoder to obtain the instance visual representation; The global semantic representation and the instance visual representation are fed into the visual instance guided global semantic enhancement decoder in the semantic visual cross-modal fusion module to obtain the enhanced global semantic representation; The enhanced global semantic representation and the instance hint representation are input into the hint instance guided local enhancement semantic enhancement decoder in the semantic visual cross-modal fusion module to obtain the locally enhanced local enhancement semantic representation; The instance visual representation and the local enhanced semantic representation are input into the local enhanced semantics-guided visual decoder in the semantic-visual cross-modal fusion module to obtain the enhanced visual representation. Inputting the enhanced visual representation into the last encoding layer of the visual encoder for encoding to obtain an encoding result; The encoding result of the enhanced visual representation, the global semantic representation and the instance prompt representation are fused and paired to obtain the enhanced visual representation.
8. The system according to claim 7, characterized in that The calculation module projects the enhanced visual representation integrated with semantic information into the semantic attribute space, and calculates the similarity scores of attributes of all categories, including: Use cosine similarity to evaluate the similarity score between the image and the attribute vector of each class: in, is the candidate label for the classification task, Z is the set of attribute vectors that need to be classified, τ is the scaling factor, x is the instance image, To enhance the visual representation, W p is a fully connected layer, and GAP is a one-dimensional global average pooling function.
9. The system according to claim 8, characterized in that The optimization module calculates the total loss of the classification model optimization according to the semantic attribute consistency loss, the prompt attribute consistency loss, the cross entropy loss and the debiasing loss, including: Among them, L sac is the semantic attribute consistency loss, L pa To indicate the attribute consistency loss, L cls is the cross entropy loss, L deb is the debiasing loss, L is the total optimization loss; Attention_score S,V , are the attention scores in the global semantic decoder guided by the visual instance and the local semantic decoder guided by the cue instance, respectively. GMP represents the one-dimensional global maximum pooling function, and z c is the attribute vector of the class, represents the square of the vector's second norm, α S , α U are the means of the predicted similarity scores for the visible and invisible classes, β S , β U are the variances of the predicted similarity scores of the visible and unseen classes, respectively, and λ c , cls and λ deb is the weighting coefficient.
10. The system according to claim 9, characterized in that The classification module calculates the similarity score between the given image and the attributes of the invisible category according to the optimized classification model, and the predicted label corresponding to the output image includes: Compute scores for unseen classes: Output the predicted label of the category with the highest similarity score Among them, γ is the calibration coefficient used to balance the scores of visible and invisible classes during training, and f i (·) is an indicator function if If Y U Represents the label set of the unseen class; Y is the label set that needs to be predicted.
Citation Information
Patent Citations
Cross-modal comparison zero sample learning method fusing knowledge graph
CN115631365A
Generalized zero sample image classification method based on fused visual information
CN116797821A
Generalized zero sample learning method based on progressive semantics-vision interadaptation
CN116994027A
Zero sample image recognition method based on CLIP
CN117197568A
Zero sample sketch retrieval model training and image retrieval method
CN117708361A
Cited By
A Prompt-Guided Zero-Shot Image Classification Method and System
CN118691899B
Image multi-classification model generation method and device, equipment and storage medium
CN119204144A
A method, device, equipment and storage medium for generating multi-classification model of image
CN119204144B
Multi-label image classification method for multi-layer prompt information
CN119445216A
Multi-label Image Classification Method for Multi-layer Prompt Information
CN119445216B
