Small sample image classification method, device, electronic device and storage medium
By constructing the subspace of image features and text features and performing projection alignment, the problem of feature mode differences of the CLIP model in small sample scenarios is solved, and the accuracy and performance of image classification are improved.
Patent Information
- Application Number
- CN202410931847.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-12
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2044-07-12
AI Technical Summary
The CLIP model suffers from modal differences between image features and text features in small sample scenarios, resulting in limited classification performance and difficulty in ensuring feature consistency and accuracy.
Using the image feature map as an intermediate bridge, the image feature subspace and text feature subspace are constructed, and singular value decomposition is used to obtain the projection matrix. The image features and text features are projected and aligned to eliminate modal differences and improve classification accuracy.
It effectively eliminates the difference between image and text features, improves the accuracy of the CLIP model in small sample image classification, and improves classification performance without increasing training parameters.
Smart Images

Figure CN118470446B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of image processing technology, and specifically relates to a small sample image classification method, device, electronic equipment and storage medium. Background Art
[0002] In recent years, visual language pre-training models have shown excellent performance in various visual tasks. For example, the CLIP (Contrastive Language-Image Pretraining) model uses a contrastive loss function to perform pre-training on 400 million paired image-text data pairs and has strong zero-sample classification capabilities. Specifically, when a test sample is given, the CLIP model uses an image encoder to convert the test sample into image features, then calculates the similarity with text labels of all categories, and finally predicts the classification result based on the maximum similarity score.
[0003] At present, some research works are exploring the generalization ability of the CLIP model in the case of small samples. This type of method directly uses the image features and text features extracted by the CLIP model to adapt to specific tasks. Although it avoids the introduction of additional training parameters, it also ensures computational efficiency. However, they ignore the modal differences of the features extracted by the CLIP model, which limits the performance in small sample scenarios. Specifically, due to the different intrinsic expressions of images and texts, they have inherent differences at the original feature level.
[0004] Difference in information type: Images contain pixel-level visual information, such as color, shape, texture, etc., while text is language information composed of vocabulary and grammatical structure. The information carrier forms of the two are very different.
[0005] Difference in expression complexity: Images may be very intuitive but also imply complex high-level abstract concepts, while text directly expresses clearer concepts and logic through word sequences.
[0006] Semantic mapping difficulty: Although CLIP attempts to build a multimodal shared semantic space, in practice, it is a challenge to ensure that the rich semantics within each modality can be accurately mapped to the common space and maintain consistency.
[0007] Therefore, how to ensure the consistency of image features and text features extracted by the CLIP model has become an urgent problem to be solved in small sample learning of the CLIP model. Summary of the invention
[0008] The present invention aims to solve the deficiencies of the above-mentioned prior art and proposes a small sample image classification method, device, electronic device and storage medium to maximize the exploration of data distribution under the condition of limited information, thereby improving the accuracy of small sample image classification.
[0009] In order to achieve the above-mentioned purpose, the present invention adopts the following technical scheme:
[0010] In a first aspect, the present invention provides a small sample image classification method, the image classification method comprising the following steps:
[0011] Acquire a small sample data set, where the small sample data set includes image samples and text labels corresponding to the image samples;
[0012] Extracting features from the image samples to obtain image features and an image feature map;
[0013] Determining an image feature subspace according to the image feature and the image feature map;
[0014] Determining the projected image features according to the image feature subspace;
[0015] Performing feature extraction on the text label to obtain text features;
[0016] Determining a text feature subspace according to the text feature and the image feature map corresponding to the text feature;
[0017] Determining the projected text features according to the text feature subspace;
[0018] Get the image to be classified;
[0019] The image to be classified is classified according to the projected image features and the projected text features.
[0020] In some of the embodiments, determining the image feature subspace according to the image feature and the image feature map includes:
[0021] Calculating a first similarity between the image feature and the image feature map;
[0022] Determine a first region feature in the image feature map according to the first similarity;
[0023] The first region feature and the image feature are concatenated.
[0024] In some of the embodiments, determining the projected image features according to the image feature subspace includes:
[0025] Perform singular value decomposition on the image feature subspace, and determine the image subspace projection matrix according to the singular value decomposition result;
[0026] The image features are projected according to the image subspace projection matrix.
[0027] In some embodiments, determining a text feature subspace according to the text feature and the image feature map corresponding to the text feature includes:
[0028] Calculating the second similarity between the text feature and the image feature map of the same category respectively;
[0029] Determine a second region feature of the image feature map of the same category according to the second similarity;
[0030] The second region feature and the text feature are concatenated.
[0031] In some embodiments, determining the projected text features according to the text feature subspace includes:
[0032] Performing singular value decomposition on each of the text feature subspaces, and determining a text subspace projection matrix according to the singular value decomposition result;
[0033] The text features are projected according to the text subspace projection matrix.
[0034] In some embodiments, classifying the image to be classified according to the projected image feature and the projected text feature includes:
[0035] Extracting features of the image to be classified to obtain features of the image to be classified;
[0036] Calculating the similarity between the features of the image to be classified and the features of the projected image;
[0037] Calculating the similarity between the image feature to be classified and the projected text feature;
[0038] The calculated similarities are linearly weighted, and the category with the greatest similarity is taken as the final classification result.
[0039] Compared with the prior art, the present invention mines the image feature map of the image sample as an intermediate bridge, uses subspace projection to align the image features and text features extracted by the CLIP model, effectively eliminates the difference between the image modality features and the text modality features, and improves the accuracy of the CLIP model in small sample image classification; and the present invention belongs to a feature alignment method without training parameters, and aligns the image features and text features by projection without increasing the parameter amount, thereby improving the classification accuracy.
[0040] In a second aspect, the present invention provides a small sample image classification device, comprising:
[0041] An input module, used to obtain a small sample data set, the small sample data set including image samples and text labels corresponding to the image samples, and to obtain images to be classified;
[0042] A feature extraction module is used to extract features from the image sample to obtain image features and image feature maps, and to extract features from the text label to obtain text features.
[0043] A subspace construction module, for determining an image feature subspace according to the image feature and the image feature map, and for determining a text feature subspace according to the text feature and the image feature map corresponding to the text feature.
[0044] A spatial alignment module, used for determining the projected image features according to the image feature subspace, and for determining the projected text features according to the text feature subspace;
[0045] A classification module is used to classify the image to be classified according to the projected image features and the projected text features.
[0046] In a third aspect, the present invention provides an electronic processing device, comprising a memory and a processor, wherein the memory stores at least one computer executable instruction, and the processor is configured to run the computer executable instruction, and when the computer executable instruction is executed by the processor, the small sample image classification method described in the first aspect is implemented.
[0047] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the small sample image classification method described in the first aspect is implemented.
[0048] Compared with the prior art, the beneficial effects of the small sample image classification device, electronic device and storage medium of the present invention are the same as the beneficial effects of the above-mentioned small sample image classification method, so they are not repeated here.
[0049] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 A flowchart of a small sample image classification method in an embodiment of the present invention;
[0051] Figure 2A model structure diagram of a small sample image classification method in an embodiment provided by the present invention;
[0052] Figure 3 A structural block diagram of a small sample image classification device in an embodiment of the present invention;
[0053] Figure 4 An electronic device diagram in an embodiment of the present invention; DETAILED DESCRIPTION
[0054] In order to more clearly understand the purpose, technical solutions and advantages of the present application, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments.
[0055] Unless otherwise defined, the technical terms or scientific terms involved in this application shall have the general meaning understood by people with general skills in the technical field to which this application belongs. The words "one", "a", "the", "these" and the like in this application do not indicate a quantitative limitation, and they may be singular or plural. The terms "include", "comprise", "have" and any variants thereof involved in this application are intended to cover non-exclusive inclusions; for example, a process, method and system, product or device comprising a series of steps or modules (units) is not limited to the listed steps or modules (units), but may include unlisted steps or modules (units), or may include other steps or modules (units) inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there may be three relationships, for example, "A and / or B" may mean: A exists alone, A and B exist at the same time, and B exists alone. Generally, the character " / " indicates that the objects associated with each other are in an "or" relationship. The terms "first", "second", "third", etc. in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.
[0056] First, the prior art and related concepts involved in the embodiments of the present invention are described:
[0057] CLIP model: A pre-trained neural network model in a multimodal domain. CLIP is able to understand image content and match it with natural language descriptions.
[0058] Image feature: a numerical vector or feature vector with representative meaning extracted from an image.
[0059] Image feature map: It is the output of a certain layer of the network, expressed as a two-dimensional matrix (for a single channel) or a three-dimensional tensor (when considering multiple channels), in which each element (pixel) represents the response intensity of the original image in a specific area and under a specific filter. The feature map shows the result of the input image after being processed by different filters, which can be understood as a mapping of different features of the image (such as edges and textures of different scales and directions).
[0060] Reference Figure 1 to Figure 2 This embodiment discloses a small sample image classification method, which includes the following steps:
[0061] S1, image feature subspace construction: obtain a small sample data set, which includes image samples and text labels corresponding to the image samples; the small sample data set is relative to other image and text models that require a large amount of pre-training data sets; that is, relative to existing models that require a large amount of training, the small sample data set described in the present invention is a condition that gives the pre-trained model limited information to maximize the exploration of data distribution.
[0062] After obtaining the small sample data set, feature extraction is performed on the image samples to obtain image features and an image feature map;
[0063] An image feature subspace is determined based on the image features and the image feature map. A specific method for determining the image feature subspace is: calculating a first similarity between the image features and the image feature map, determining a first region feature in the image feature map based on the first similarity, and concatenating the first region feature and the image features.
[0064] Exemplarily, in this embodiment, the specific steps of step S1 are:
[0065] The image encoder of the pre-trained CLIP model is used to extract image features and image feature maps of image samples in the small sample dataset;
[0066] The image features are expressed as:
[0067] The image feature map is represented as: ,
[0068] Wherein, d is the feature dimension, h and w are the height and width of the image feature map, respectively, b is the basic data set, and m,i represents the i-th sample in the m-th category in the basic data set. In this embodiment, the basic data set is the small sample data set.
[0069] For example, refer to Figure 2The image samples in the small sample data set may be training picture samples of foxes, cardinals, etc.; of course, they may also be training picture samples of red foxes, sparrows, etc.
[0070] Further, calculating a first similarity between the image feature and the image feature map;
[0071] The first similarity is expressed as: ;
[0072] Among them, is the jth sample in the i-th category in the few-shot training set, is the image feature The image feature map (i.e., the image feature map extracted by the image encoder of the pre-trained CLIP model), is the first similarity, indicating the image feature and image feature map The degree of similarity between them.
[0073] Furthermore, from the image feature map Select the first region feature corresponding to the first Q high similarity score;
[0074] The first region feature is expressed as: ;
[0075] Concatenate the first region feature and all global image features to obtain an image feature subspace;
[0076] The image feature subspace is expressed as: .
[0077] The following is a further explanation of the above concepts or formulas in this embodiment: Image features The meaning is: a vector , which is a one-dimensional array, d represents the feature dimension. Therefore, the entire vector Belongs to the real number space This vector is the image feature of the image sample after feature extraction , the image features It is extracted by the image encoder of the pre-trained CLIP model.
[0078] Image feature map The meaning is: a three-dimensional array (tensor) , which has three dimensions: height h, width w, and depth d. The values in each dimension are real numbers, so the entire tensor belongs to the real number space R. This tensor is the image feature map of the image sample , the image feature map It is extracted by the image encoder of the pre-trained CLIP model.
[0079] The formula for the first similarity is: The meaning is that the image features With image feature map Transpose and multiply to get the first similarity score In the inner product operation, if two vectors are more similar, their inner product value will be larger, and vice versa, if two vectors are less similar, their inner product value will be smaller. Therefore, by calculating the image features and image feature map The inner product of .
[0080] The first region feature is expressed as: , which means, is the image feature map Middle of the categories The image feature map of the sample The regional features corresponding to the high similarity scores; It is before The index corresponding to the high similarity score is is the number of selected regions, It is The index of the region. Represents the image feature map Select the index as The regional characteristics of No. Therefore, the meaning of this step is to combine the image features and the previous The regional features corresponding to high similarity scores are combined into a new feature vector, namely the image feature subspace .
[0081] The image classification method further comprises:
[0082] S2, image feature space alignment: determine the projected image features according to the image feature subspace; the specific steps for determining the projected image features are: perform singular value decomposition on the image feature subspace, and determine the image subspace projection matrix according to the singular value decomposition result; project the image features according to the image subspace projection matrix.
[0083] Exemplarily, in this embodiment, the specific steps of step S2 are:
[0084] Image feature subspace Perform singular value decomposition;
[0085] The singular value decomposition is expressed as: ;
[0086] Among them, is the left singular vector, is a diagonal matrix of singular values, For right singular vectors, select the singular vectors corresponding to the large singular values in the right singular vectors to construct the image subspace projection matrix;
[0087] The image subspace projection matrix is expressed as:
[0088] Furthermore, the image subspace projection matrix is used to transform all image features To project: ; Among them, It is the set of all image features, including the feature vectors of all images; It is the feature of the projected image, which contains the feature vectors of all images after projection, that is, the feature of the projected image. .
[0089] The following is a further explanation of the above concepts or formulas in this embodiment. SVD (singular value decomposition) is a linear transformation of the image feature subspace, which can decompose the image feature subspace into three parts: left singular vectors, singular value diagonal matrix and right singular vectors. In this embodiment, is the left singular vector, which is a matrix containing all the basis vectors of the image feature subspace; is the singular value diagonal matrix, which is a diagonal matrix containing the singular values of each basis vector in the image feature subspace; is a right singular vector, which is a matrix containing all basis vectors of the image feature subspace. Therefore, through SVD decomposition, the image subspace projection matrix can be obtained, that is, .in is the matrix of singular vectors corresponding to large singular values in the right singular vectors, is the transpose of this matrix.
[0090] The difference between the left singular vector and the right singular vector is that their coordinate systems are different. The coordinate system of the left singular vector is the original coordinate system of the image feature space, while the coordinate system of the right singular vector is the orthogonal coordinate system of the image feature space. In the orthogonal coordinate system, each basis vector is orthogonal to each other, that is, there is no linear correlation between them. Therefore, in the orthogonal coordinate system, we can construct the projection matrix of the image feature space by selecting basis vectors with large singular values.
[0091] The image classification method further comprises the following steps:
[0092] S3, text feature subspace construction: extract the features of the text label to obtain text features; determine the text feature subspace according to the text features and the image feature map corresponding to the text features; and how to determine the text feature subspace,
[0093] The second similarities of the text feature and the image feature map of the same category are calculated respectively, and the second region feature of the image feature map of the same category is determined according to the second similarity, and the second region feature and the text feature are concatenated.
[0094] Exemplarily, in this embodiment, the specific steps of step S3 are:
[0095] Use the text encoder of the pre-trained CLIP model to extract text features of text labels in the small sample dataset;
[0096] The text features are represented as: ;
[0097] Then, the second similarity between the text feature and the image feature map of the same category is calculated respectively;
[0098] The second similarity is expressed as: ;
[0099] in, is the first i The text label features of categories, Represents the text features and image feature maps of the same category The similarity score between .
[0100] For example, refer to Figure 2 The text labels in the small sample data set are the text labels corresponding to the training image samples. For example, the text labels corresponding to the fox training image samples are: A photo of [fox], and the text labels corresponding to the cardinal training image samples are: A photo of [linnet]. When the training image samples are changed, the corresponding text labels also need to be changed.
[0101] Furthermore, from the image feature map Select the front C The second region features corresponding to the high similarity scores;
[0102] The second region feature is expressed as:
[0103] The selected second region features and text features are concatenated to obtain the i The text feature subspace of categories: .
[0104] It should be noted that the steps of constructing the text feature subspace and aligning the image feature space are not in a serial relationship in logic, that is, they are not in a sequential relationship, but should be synchronous and parallel. It can be understood that when the image feature map is extracted, the second region feature is selected and spliced with the text feature to obtain the text feature subspace.
[0105] Referring to the above description, this step uses the text encoder of the pre-trained CLIP model to extract the text features of the text labels in the small sample data set to obtain a text feature , where each row is the text feature of a category's text label; then calculate the text features separately And the feature map of the same category image The similarity of , which is actually also a matrix representation, in which each row is the second similarity between the text feature of a category and the image feature map.
[0106] Specifically, this step selects the front C The second region features corresponding to the high similarity scores are obtained as the matrix , where each row is an image feature map region of a category; then, the selected second region feature and the text features Splice to get The text feature subspace of categories: .
[0107] The image classification method further comprises the following steps:
[0108] S4, text feature space alignment: determine the projected text features according to the text feature subspace; the specific steps of determining the projected text features are: perform singular value decomposition on each of the text feature subspaces, and determine the text subspace projection matrix according to the singular value decomposition results; project the text features according to the text subspace projection matrix, thereby determining the projected text features.
[0109] Exemplarily, in this embodiment, the specific steps of step S4 are:
[0110] Perform singular value decomposition on each text feature subspace;
[0111] The singular value decomposition is expressed as: ,
[0112] Among them, For the left singular vectors of classes, For the The diagonal matrix of singular values of categories, For the The text subspace projection matrix is constructed by selecting the singular vectors corresponding to the large singular values in the right singular vectors:
[0113] The text subspace projection matrix is expressed as: ;
[0114] Furthermore, the corresponding text features are projected using the text subspace projection matrix: .
[0115] Referring to the description of singular value decomposition of the above image feature subspace, we can know that The text subspace projection matrix of categories Is to choose It is composed of the singular vectors corresponding to the largest singular values in the right singular vectors of the categories.
[0116] in, represents the text features after projection, Represents a splicing operation, Indicates The text features of categories, Represents the projection of the text feature of the i-th category in the text subspace. Through the text subspace projection matrix For the corresponding text features Perform projection to obtain the text features after projection .
[0117] The image classification method further comprises:
[0118] S5, classification test: obtain the image to be classified, wherein the image to be classified includes a test sample in this embodiment. The test sample is a concept relative to the pre-training sample, and the image to be classified can be understood as a test sample image that needs to be classified after the classification test of the test sample.
[0119] Classify the image to be classified according to the projected image features and the projected text features; this step specifically includes:
[0120] Extracting features of the image to be classified to obtain features of the image to be classified;
[0121] Calculating the similarity between the features of the image to be classified and the features of the projected image;
[0122] Calculating the similarity between the image feature to be classified and the projected text feature;
[0123] The calculated similarities are linearly weighted, and the category with the greatest similarity is taken as the final classification result.
[0124] Exemplarily, in this embodiment, the specific steps of step S4 are:
[0125] The test sample (which can be equivalent to the image to be classified in this embodiment) is extracted as image features through the image encoder of the CLIP model, and then two similarities are calculated with the projected image features and the projected text features respectively;
[0126] The two calculated similarities are linearly weighted, and the category with the greatest similarity is taken as the final classification result.
[0127] In the above steps, the image features of the test sample and the image features after projection and the projected text features After calculating the similarity separately, two similarity scores are formed; they can be understood as matrix A and matrix B. Matrix A is the projected image features of the test sample and all categories. The similarity score of the matrix B is the projected text features of the test sample and all categories. The matrix A and the matrix B are linearly weighted to obtain another matrix C, where each row of the matrix C is the weighted similarity score between a test sample and all categories. Finally, the category with the largest weighted similarity score is taken as the prediction result of image classification.
[0128] In summary, the present invention uses the image feature map extracted by the CLIP model as an intermediate bridge, and uses the image feature map to construct the image feature subspace and its image subspace projection matrix and the text feature subspace and its text subspace projection matrix, so that the image features and text features can be projected to eliminate the differences between different modal features.
[0129] And the projected image features and text features are used as classifier weights to classify the test samples, which effectively improves the classification accuracy. Of course, the expression of projected image features and projected text features as classifier weights is that the weight is understood as a matrix, and the two matrices are multiplied with the test samples to calculate the similarity, and then the two similarities are linearly weighted to obtain the final similarity.
[0130] The embodiment of the present invention also provides a small sample image classification device, which is used to implement the above method embodiment, and the description has been made no further. The terms "module", "unit", "subunit", etc. used below can implement a combination of software and / or hardware for a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceivable.
[0131] Figure 3 is a small sample image classification device of the present invention, such as Figure 3 As shown, the device comprises:
[0132] An input module, used to obtain a small sample data set, the small sample data set including image samples and text labels corresponding to the image samples, and to obtain images to be classified;
[0133] A feature extraction module is used to extract features from the image sample to obtain image features and image feature maps, and to extract features from the text label to obtain text features.
[0134] A subspace construction module, for determining an image feature subspace according to the image feature and the image feature map, and for determining a text feature subspace according to the text feature and the image feature map corresponding to the text feature.
[0135] A spatial alignment module, used for determining the projected image features according to the image feature subspace, and for determining the projected text features according to the text feature subspace;
[0136] A classification module, used for classifying the image to be classified according to the projected image features and the projected text features;
[0137] The output module outputs the test sample category.
[0138] In the above-mentioned device, by extracting image features, image feature maps and text features of image samples and text labels, and then using the image feature maps as an intermediate bridge, respective subspaces can be constructed and projected; so that the test samples or images to be classified belonging to few-sample data can respectively calculate the similarity between the projected image features and the projected text features, so that the sample category can be obtained based on the similarity processing.
[0139] It should be noted that the above modules can be functional modules or program modules, that is, they can be implemented by software or hardware. For modules implemented by hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.
[0140] like Figure 4 As shown, an embodiment of the present invention further provides an electronic device, which includes a memory 230 and a processor 210, wherein the memory 230 stores at least one computer executable instruction, and the processor 210 is configured to run the computer executable instruction, and when the computer executable instruction is run by the processor 210, the above-mentioned small sample image classification method is implemented.
[0141] The electronic device may include a processor 210, a communications interface 220, a memory 230, and a communications bus 240, wherein the processor 210, the communications interface 220, and the memory 230 communicate with each other via the communications bus 240. The processor 210 may call the logic instructions in the memory 230 to execute the following method:
[0142] Acquire a small sample data set, where the small sample data set includes image samples and text labels corresponding to the image samples;
[0143] Extracting features from the image samples to obtain image features and an image feature map;
[0144] Determining an image feature subspace according to the image feature and the image feature map;
[0145] Determining the projected image features according to the image feature subspace;
[0146] Performing feature extraction on the text label to obtain text features;
[0147] Determining a text feature subspace according to the text feature and the image feature map corresponding to the text feature;
[0148] Determining the projected text features according to the text feature subspace;
[0149] Get the image to be classified;
[0150] The image to be classified is classified according to the projected image features and the projected text features.
[0151] In addition, the logic instructions in the above-mentioned memory 230 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0152] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, i.e., they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative effort.
[0153] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0154] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A small sample image classification method, characterized in that: The image classification method comprises the following steps: Acquire a small sample data set, where the small sample data set includes image samples and text labels corresponding to the image samples; Extracting features from the image samples to obtain image features and an image feature map; Determining an image feature subspace according to the image feature and the image feature map includes: Calculating a first similarity between the image feature and the image feature map; The first similarity is expressed as: ; Among them, is the jth sample in the i-th category in the few-shot training set, is the image feature The image feature map is the image feature map extracted by the image encoder of the pre-trained CLIP model. is the first similarity, indicating the image feature and image feature map The degree of similarity between It is The index of the region; From the image feature map Select the first region features corresponding to the first Q high similarity scores; The first region feature is expressed as: ; The meaning is, is the image feature map Middle of the categories The image feature map of the sample The regional features corresponding to the high similarity scores; It is before The index corresponding to the high similarity score is is the number of selected regions, Represents the image feature map Select the index as The regional characteristics of No. List; Concatenate the first region feature and all global image features to obtain an image feature subspace; The image feature subspace is expressed as: ; The image features With image feature map Transpose and multiply to get the first similarity ; Determine a first region feature in the image feature map according to the first similarity; splicing the first region feature and the image feature; Determining the projected image features according to the image feature subspace; Performing feature extraction on the text label to obtain text features; Determining a text feature subspace according to the text feature and the image feature map corresponding to the text feature includes: Extracting features from the text labels to obtain text features; determining a text feature subspace based on the text features and the image feature graph corresponding to the text features; Determining the text feature subspace includes: The method further comprises: calculating the second similarity between the text feature and the image feature map of the same category respectively, determining the second region feature of the image feature map of the same category according to the second similarity, and concatenating the second region feature and the text feature; and Use the text encoder of the pre-trained CLIP model to extract text features of text labels in the small sample dataset; The text features are represented as: ; Then, the second similarity between the text feature and the image feature map of the same category is calculated respectively; The second similarity is expressed as: ; in, is the first i The text label features of categories, Represents the text features and image feature maps of the same category The similarity score between From the image feature map Select the front The second region features corresponding to the high similarity scores; The second region feature is expressed as: ; It is before The index corresponding to the high similarity score is is the number of selected regions, Represents the image feature map Select the index as The regional characteristics of No. List; The selected second region features and text features are concatenated to obtain the i The text feature subspace of categories: ; Determining the projected text features according to the text feature subspace; Get the image to be classified; Classifying the image to be classified according to the projected image feature and the projected text feature, including: Extracting features of the image to be classified to obtain features of the image to be classified; Calculating the similarity between the features of the image to be classified and the features of the projected image; Calculating the similarity between the image feature to be classified and the projected text feature; The calculated similarities are linearly weighted, and the category with the greatest similarity is taken as the final classification result.
2. A small sample image classification method according to claim 1, characterized in that: Determining the projected image features according to the image feature subspace includes: Perform singular value decomposition on the image feature subspace, and determine the image subspace projection matrix according to the singular value decomposition result; The image features are projected according to the image subspace projection matrix.
3. The small sample image classification method according to claim 1, characterized in that: Determining the projected text features according to the text feature subspace includes: Performing singular value decomposition on the text feature subspace, and determining the text subspace projection matrix according to the singular value decomposition result; The text features are projected according to the text subspace projection matrix.
4. A small sample image classification device, characterized in that: include: An input module, used to obtain a small sample data set, the small sample data set including image samples and text labels corresponding to the image samples, and to obtain images to be classified; A feature extraction module, used for performing feature extraction on the image sample to obtain image features and an image feature map, and for performing feature extraction on the text label to obtain text features; A subspace construction module, used to determine an image feature subspace according to the image feature and the image feature map, and used to determine a text feature subspace according to the text feature and the image feature map corresponding to the text feature; The image feature subspace construction method comprises: Calculating a first similarity between the image feature and the image feature map; The first similarity is expressed as: ; Among them, is the jth sample in the i-th category in the few-shot training set, is the image feature The image feature map is the image feature map extracted by the image encoder of the pre-trained CLIP model. is the first similarity, indicating the image feature and image feature map The degree of similarity between It is The index of the region; From the image feature map Select the first region features corresponding to the first Q high similarity scores; The first region feature is expressed as: ; The meaning is, is the image feature map Middle of the categories The image feature map of the sample The regional features corresponding to the high similarity scores; It is before The index corresponding to the high similarity score is is the number of selected regions, Represents the image feature map Select the index as The regional characteristics of No. List; Concatenate the first region feature and all global image features to obtain an image feature subspace; The image feature subspace is expressed as: ; The image features With image feature map Transpose and multiply to get the first similarity ; Determine a first region feature in the image feature map according to the first similarity; splicing the first region feature and the image feature; The text feature subspace construction method comprises: Extracting features from the text labels to obtain text features; determining a text feature subspace based on the text features and the image feature graph corresponding to the text features; Determining the text feature subspace includes: The method further comprises: calculating the second similarity between the text feature and the image feature map of the same category respectively, determining the second region feature of the image feature map of the same category according to the second similarity, and concatenating the second region feature and the text feature; and Use the text encoder of the pre-trained CLIP model to extract text features of text labels in the small sample dataset; The text features are represented as: ; Then, the second similarity between the text feature and the image feature map of the same category is calculated respectively; The second similarity is expressed as: ; in, is the first i The text label features of categories, Represents the text features and image feature maps of the same category The similarity score between From the image feature map Select the front The second region features corresponding to the high similarity scores; The second region feature is expressed as: ; It is before The index corresponding to the high similarity score is is the number of selected regions, Represents the image feature map Select the index as The regional characteristics of No. List; The selected second region features and text features are concatenated to obtain the i The text feature subspace of categories: ; A spatial alignment module, used for determining the projected image features according to the image feature subspace, and for determining the projected text features according to the text feature subspace; A classification module, used for classifying the image to be classified according to the projected image features and the projected text features, comprising: Extracting features of the image to be classified to obtain features of the image to be classified; Calculating the similarity between the features of the image to be classified and the features of the projected image; Calculating the similarity between the image feature to be classified and the projected text feature; The calculated similarities are linearly weighted, and the category with the greatest similarity is taken as the final classification result.
5. An electronic device, comprising a memory and a processor, wherein the memory stores at least one computer executable instruction, and the processor is configured to execute the computer executable instruction, wherein: The computer executable instructions are executed by the processor to implement the small sample image classification method according to any one of claims 1 to 3.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the small sample image classification method according to any one of claims 1 to 3 is implemented.
Citation Information
Patent Citations
Image processing method, neural network training method and related equipment
CN113065634A
Small sample image classification method based on dimension self-adaption
CN114299495A
Small sample subclass image classification and identification method
CN115861720A
Image classification method and product based on multi-modal small sample continuous learning
CN116524261A
Text classification method and device and related product
CN116975295A
