Small sample image classification method and device based on global and local content matching
By combining global and local features in small sample image classification, a robust classifier is constructed, which solves the problem of recognition performance degradation caused by ignoring local content in the existing technology, improves the robustness and efficiency of the classifier, and reduces the computational cost. Storage costs.
Patent Information
- Application Number
- CN202411034782.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-07-31
AI Technical Summary
Existing small-sample image classification methods ignore local content expression when fitting global features to image content, resulting in reduced recognition performance when training samples are insufficient, and the introduction of huge training parameters increases computing and storage costs.
By obtaining global and local features of natural image sample sets, selectively combining discriminative local features, fusion constructs local representations, and matching with global features to form a robust classifier, and use cross-entropy loss and gradient descent algorithms to train the classifier , combining local and global content for image classification.
The robustness and efficiency of the image classifier are improved. By paying attention to the local details and global structure of the image, the content is analyzed from multiple angles, the perception of samples from different fields of view is enhanced, and the computing and storage costs are reduced.
Smart Images

Figure CN118570557A
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of image classification, and more specifically to a method and device for classifying small sample images based on global and local content matching. Background Art
[0002] In recent years, convolutional neural networks (CNNs) have demonstrated outstanding performance in various visual tasks. However, such data-driven methods require a large amount of labeled training data to ensure their performance. However, the process of collecting and labeling data is time-consuming and expensive. In contrast, humans only need a small number of samples to quickly recognize new objects because they have accumulated a large amount of prior knowledge. The Few-Shot Learning (FSL) task aims to mimic the human ability to quickly recognize new objects.
[0003] At present, the mainstream FSL method pre-trains the model on a large number of basic category samples and uses the pre-trained model to extract the visual features of new category samples. It aims to obtain visual features with strong generalization through pre-training and use the extracted new category visual features to realize the recognition of new categories. However, the visual features of a small number of new category samples are not enough to represent their data distribution, which easily leads to overfitting problems.
[0004] Recently, with the development of visual-language models such as contrastive visual-language pre-training (CLIP), several methods aim to adapt CLIP to FSL and have achieved significant improvements. Among them, few-shot tasks are designed to solve classification tasks with limited training samples and categories. However, these methods only use global features to fit the content of the image, thereby ignoring the expression of the local content of the image, and the recognition performance of such models will be impaired when the training samples are insufficient. To alleviate these problems, one is to extract different parts of the image (such as foreground or background), and the other is to design a global-local interaction architecture to help the model capture more content from the image. However, these methods introduce huge training parameters and therefore require large-scale computational and storage costs. Summary of the invention
[0005] In this embodiment, a small sample image classification method and device based on global and local content matching are provided to solve the problem in the related art that the content of the image is fitted with global features, while the expression of the local content of the image is ignored. When the training samples are insufficient, the recognition performance of such models will be impaired.
[0006] In a first aspect, an embodiment of the present invention provides a small sample image classification method based on global and local content matching, the small sample image classification method comprising: Acquire a natural image sample set, extract image features from the natural image sample set to obtain global features and local features, and convert a text description corresponding to the image into a high-dimensional feature vector; Selectively combining discriminative local features and constructing a local representation using the local feature fusion; Matching the local representation with the global feature to construct a robust classifier; The robust classifier is trained, and the trained robust classifier is used to perform image classification.
[0007] In an optional embodiment, obtaining a natural image sample set, extracting image features from the natural image sample set to obtain global features and local features, and converting a text description corresponding to the image into a high-dimensional feature vector includes: Acquire a natural image sample set, where the natural image sample set is used for pre-training; Using the visual encoder of the CLIP model to extract features from the images in the natural image sample set, to obtain global features and local features; The text encoder of the CLIP model is used to convert the text description corresponding to the image into a high-dimensional feature vector.
[0008] In an optional embodiment, selectively combining discriminative local features and constructing a local representation by fusing the local features includes: The classification scores of local features are calculated using the CLIP model; Calculate the KL divergence between the classification score and the text label, select local features according to the KL divergence, and fuse the selected local features by averaging; The average value of the selected local features is taken as the local representation.
[0009] In an optional embodiment, selectively combining discriminative local features and fusing the local features to construct a local representation further comprises: Remove the last pooling layer of the visual encoder of the CLIP model.
[0010] In an optional embodiment, matching the local representation with the global feature to construct a robust classifier includes: Constructing a local classifier and a global classifier according to the local representation and the global feature respectively; The local classifier and the global classifier are fused to obtain a robust classifier.
[0011] In an optional embodiment, constructing a local classifier and a global classifier according to the local representation and the global feature respectively includes: The logits of the cache module described in Tip-Adapter are fused with the CLIP model to obtain local and global classifiers.
[0012] In an optional embodiment, training the robust classifier and using the trained robust classifier to perform image classification includes: Acquire a support set, wherein the support set includes support samples, and extract global features and local features of the support samples; Use global features to train the classifier, use cross entropy loss and support feature labels to train the classifier, and get the training loss function; The robust classifier is trained using a gradient descent algorithm, and a loss function is calculated, and parameters of each part are updated according to the loss function; When the number of training iterations reaches a preset number, a trained robust classifier is obtained, and the trained robust classifier is used to perform image classification.
[0013] Compared with the prior art, the small sample image classification method based on global and local content matching of the present invention has the following beneficial effects: By focusing on the local content of the image and designing a local structure by selectively combining the local content to build a robust local representation, this helps the classifier focus on the details of the image; by jointly fine-tuning the global classifier and the local classifier to match the global content and the local content, and then analyzing the image content from different angles to obtain a better match, it helps the model perceive the content of samples under different fields of view and improves the efficiency of the classifier; finally, the two classifiers are combined to focus on both local details and global structures, and the image content is analyzed from multiple angles to achieve sample recognition.
[0014] In a second aspect, an embodiment of the present invention provides a small sample image classification device based on global and local content matching, comprising: A feature extraction module is used to obtain a natural image sample set, extract image features from the natural image sample set to obtain global features and local features, and convert a text description corresponding to the image into a high-dimensional feature vector; A local representation construction module, for selectively combining discriminative local features and constructing a local representation by fusing the local features; A classifier construction module, used for matching the local representation with the global feature to construct a robust classifier; The training module is used to train the robust classifier and use the trained robust classifier to perform image classification.
[0015] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the small sample image classification method based on global and local content matching as described in the first aspect is implemented.
[0016] In a fourth aspect, an embodiment of the present invention provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the small sample image classification method based on global and local content matching as described in the first aspect.
[0017] Compared with the prior art, the beneficial effects of the small sample image classification device, electronic device and storage medium based on global and local content matching of the present invention are the same as the small sample image classification method based on global and local content matching described in the first aspect, so they will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0019] Figure 1 Flow chart of a small sample image classification method based on global and local content matching in an embodiment of the present invention; Figure 2 is a classification principle diagram of a robust classifier in an embodiment of the present invention; Figure 3 It is a structural block diagram of a small sample image classification device based on global and local content matching in an embodiment of the present invention; Figure 4 4 is a structural block diagram of an electronic device in an embodiment of the present invention. DETAILED DESCRIPTION
[0020] 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.
[0021] 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.
[0022] In an embodiment of the present invention, a small sample image classification method based on global and local content matching is provided. Figure 1 is a flow chart of the small sample image classification method based on global and local content matching of the present invention. Figure 1 As shown, the process includes the following steps: S100, obtaining a natural image sample set, extracting image features from the natural image sample set to obtain global features and local features, and converting a text description corresponding to the image into a high-dimensional feature vector; It should be noted that the natural image sample set includes a plurality of image samples. In this embodiment, the visual encoder of the CLIP model is used to extract features from the natural image samples.
[0023] Specifically, a natural image sample set is obtained, image features in the natural image sample set are extracted, global features and local features are obtained, and the text description corresponding to the image is converted into a high-dimensional feature vector, including: Obtain a natural image sample set, which is used for pre-training; for example, the training samples of the N-way-K-shot task come from the support set , the test samples come from the test set , an N-way-K-shot task identifies N categories, each category has K support samples.
[0024] Combination Figure 2 As shown in Figure 1, the CLIP model visual encoder is used to extract features from images in the natural image sample set to obtain global features and local features. It should be noted that the CLIP model includes a visual encoder and a text encoder For example, given C hand-crafted prompts T (e.g., word embeddings “a photo of a{class}”, {class} is the class name), where C is the number of classes, the CLIP model first represents them as features, denoted as . Then the classification logits can be calculated as , which is the extracted feature of the test sample, is the temperature coefficient learned in the pre-training phase, represents the cosine similarity, Aims to classify input samples into C different categories.
[0025] Text encoder using CLIP model The text description corresponding to the image is converted into a high-dimensional feature vector. Each dimension corresponds to a specific semantics or feature. The high-dimensional feature vector captures the semantic information of the text description, so that different text descriptions have different representations in the feature space.
[0026] S200, selectively combining discriminative local features and constructing local representations using local feature fusion; It should be noted that discriminative local features refer to local features with top-K dis values, which contain information that can classify the content corresponding to the local features into the correct category, and are called discriminative. By selectively combining discriminative local features and constructing local representations using local feature fusion, the local representations contain enough local details, which can help the classifier focus on the details of the image.
[0027] Specifically, selectively combining discriminative local features and constructing local representations using local feature fusion include: The classification score S of the local features is calculated using the CLIP model; Calculate the KL divergence between the classification score and the text label, select local features based on the KL divergence, and fuse the selected local features by averaging; The average value of the selected local features is taken as the local representation.
[0028] Selectively combining discriminative local features and constructing local representations using local feature fusion also includes: Visual encoder without CLIP model The last pooling layer.
[0029] For example, the last pooling layer of the visual encoder of the CLIP model is removed to extract local features. Given a label The training samples are extracted by: , , in, is the visual encoder of the CLIP model with the last pooling layer removed. Convert the input tags to vector, so, The global features and local features are respectively denoted as and , where the global feature Local features , m is the number of local features.
[0030] Using the pre-trained CLIP model to calculate the classification score S of the local features, it can be formalized as: , for function, .
[0031] Calculate the KL divergence between the classification score S and the one-hot label , to select local features, which can be formalized as: , Therefore, the local features with the top-K dis values are selected, and the selected local features are recorded as .
[0032] The selected local features are fused by selecting the average value of local features, which can be formalized as: ; The local representation of the structure is , and global features that present global content In contrast, local representation It contains more detailed local information, which makes it easier to build a robust local classifier.
[0033] S300, matching the local representation with the global features to construct a robust classifier; Specifically, matching local representations with global features and building a robust classifier include: Construct local classifiers and global classifiers according to local representations and global features respectively; The local classifier and the global classifier are fused to obtain a robust classifier.
[0034] Further, constructing a local classifier and a global classifier according to the local representation and the global features respectively includes; The logits of the cache module described in Tip-Adapter are fused with the CLIP model to obtain local and global classifiers.
[0035] For example, the test features of the extracted test samples are As input , in order to reduce computational and storage costs, only the global features of the test sample are used. Specifically, given the global features of the training sample and the constructed local representation , design classifiers for the local part and the global part respectively. Using the cache module described in Tip-Adapter, the classification logic calculation of the local cache module is: ; in, is a hyperparameter of the local cache module.
[0036] The local classifier is written by fusing the logits of the cache module with the pre-trained CLIP model, which can be written as: ; in, is a hyperparameter that controls the fusion process, It represents a local classifier.
[0037] The global cache module and global classifier are calculated as: ; ; in and is a hyperparameter of the global classifier, which has similar effects as described for the local classifier, Represents the global classifier.
[0038] In order to further match the local classifier and the global classifier, the final classifier is defined as the fusion of the two classifiers, which can be formalized as: ; in, It is a hyperparameter that controls the fusion ratio. The global classifier and the local classifier are fine-tuned simultaneously to obtain the final classifier, which can focus on contents at different scales.
[0039] S400, training a robust classifier (GLCM-Adapter), and using the trained robust classifier to perform image classification.
[0040] Specifically, training a robust classifier and using the trained robust classifier to classify an image includes: Get the support set, which includes support samples, and extract the global and local features of the support samples; it should be noted that the support set is the above N-way-K-shot support sample set; Extract local features and global features of samples in the support set, and the global features and local features are recorded as and ,in , m is the number of local features; In order to maintain the correspondence between the training phase and the inference phase, the global features are used to train the classifier, where the global features of the support samples are represented as , and the label is represented as ,in , ; Furthermore, the local representation and global features are set to be adjustable, and a linear classifier is applied on the CLIP model texture features, which can be formalized as: , where W and b are learnable parameters; Use global features to train the classifier, use cross entropy loss and support feature labels to train the classifier, and get the training loss function; The final classifier is trained using cross entropy (CE) loss and support feature label pairs. The training loss can be formalized as follows: ; Use the gradient descent algorithm to train a robust classifier and calculate the loss function L , according to the loss function L Update the parameters of each part; It should be noted that all parameters were optimized using 20 epochs.
[0041] When the number of training iterations reaches a preset number, a trained robust classifier is obtained, and the trained robust classifier is used to classify images. The trained robust classifier can be used to predict the category of new image samples.
[0042] By focusing on the local content of the image and designing a local structure by selectively combining the local content to build a robust local representation, this helps the classifier focus on the details of the image; by jointly fine-tuning the global classifier and the local classifier to match the global content and the local content, and then analyzing the image content from different angles to obtain a better match, it helps the model perceive the content of samples under different fields of view and improves the efficiency of the classifier; finally, the two classifiers are combined to focus on both local details and global structures, and the image content is analyzed from multiple angles to achieve sample recognition.
[0043] The embodiment of the present invention also provides a small sample image classification device based on global and local content matching, which is used to implement the above method embodiment, and will not be repeated hereafter. The terms "module", "unit", "subunit", etc. used below can implement a combination of software and / or hardware of predetermined functions. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware or a combination of software and hardware is also possible and conceivable.
[0044] like Figure 3 As shown, Figure 3 : is a structural block diagram of a small sample image classification device based on global and local content matching in the present invention, the device comprises: A feature extraction module is used to obtain a natural image sample set, extract image features from the natural image sample set to obtain global features and local features, and convert a text description corresponding to the image into a high-dimensional feature vector; A local representation construction module, for selectively combining discriminative local features and constructing a local representation by fusing the local features; A classifier construction module, used for matching the local representation with the global feature to construct a robust classifier; The training module is used to train the robust classifier and use the trained robust classifier to perform image classification.
[0045] This device builds a robust local representation by focusing on the local content of the image and designing a local structure by selectively combining the local content, which helps the classifier to focus on the details of the image; by jointly fine-tuning the global classifier and the local classifier to match the global content and the local content, and then analyzing the image content from different angles to obtain a better match, while helping the model to perceive the content of samples under different fields of view and improve the efficiency of the classifier; finally, the two classifiers are combined to focus on local details and global structures at the same time, and the image content is analyzed from multiple angles, thereby realizing sample recognition.
[0046] Figure 4 A structural block diagram of an electronic device provided by an embodiment of the present invention, such as Figure 4 As shown, the electronic device may include: a processor 610, a communication interface 620, a memory 630 and a communication bus 640, wherein the processor 610, the communication interface 620 and the memory 630 communicate with each other through the communication bus 640. The processor 610 may call the logic instructions in the memory 630 to execute the following method: Acquire a natural image sample set, extract image features from the natural image sample set to obtain global features and local features, and convert a text description corresponding to the image into a high-dimensional feature vector; Selectively combining discriminative local features and constructing a local representation using the local feature fusion; Matching the local representation with the global feature to construct a robust classifier; The robust classifier is trained, and the trained robust classifier is used to perform image classification.
[0047] In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including 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 method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0048] An embodiment of the present invention further provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the method provided in each of the above embodiments is implemented, for example, including: Acquire a natural image sample set, extract image features from the natural image sample set to obtain global features and local features, and convert a text description corresponding to the image into a high-dimensional feature vector; Selectively combining discriminative local features and constructing a local representation using the local feature fusion; Matching the local representation with the global feature to construct a robust classifier; The robust classifier is trained, and the trained robust classifier is used to perform image classification.
[0049] 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 of each embodiment or some parts of the embodiment.
[0050] 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 based on global and local content matching, characterized in that: The small sample image classification method comprises: Acquire a natural image sample set, extract image features from the natural image sample set to obtain global features and local features, and convert a text description corresponding to the image into a high-dimensional feature vector; Selectively combining discriminative local features and constructing a local representation using the local feature fusion; Matching the local representation with the global feature to construct a robust classifier; The robust classifier is trained, and the trained robust classifier is used to perform image classification.
2. The small sample image classification method based on global and local content matching according to claim 1 is characterized in that: Acquiring a natural image sample set, extracting image features from the natural image sample set to obtain global features and local features, and converting a text description corresponding to the image into a high-dimensional feature vector includes: Acquire a natural image sample set, where the natural image sample set is used for pre-training; Using the visual encoder of the CLIP model to extract features from the images in the natural image sample set, to obtain global features and local features; The text encoder of the CLIP model is used to convert the text description corresponding to the image into a high-dimensional feature vector.
3. The small sample image classification method based on global and local content matching according to claim 2 is characterized in that: Selectively combining discriminative local features and constructing a local representation using the local feature fusion includes: The classification scores of local features are calculated using the CLIP model; Calculate the KL divergence between the classification score and the text label, select local features according to the KL divergence, and fuse the selected local features by averaging; The average value of the selected local features is taken as the local representation.
4. The small sample image classification method based on global and local content matching according to claim 3 is characterized in that: Selectively combining discriminative local features and constructing a local representation using the local feature fusion further includes: Remove the last pooling layer of the visual encoder of the CLIP model.
5. The small sample image classification method based on global and local content matching according to claim 1, characterized in that: Matching the local representation with the global feature to construct a robust classifier includes: Constructing a local classifier and a global classifier according to the local representation and the global feature respectively; The local classifier and the global classifier are fused to obtain a robust classifier.
6. The small sample image classification method based on global and local content matching according to claim 5, characterized in that: Constructing a local classifier and a global classifier according to the local representation and the global feature respectively comprises: The logits of the cache module described in Tip-Adapter are fused with the CLIP model to obtain local and global classifiers.
7. The small sample image classification method based on global and local content matching according to claim 1, characterized in that: Training the robust classifier and using the trained robust classifier to perform image classification includes: Acquire a support set, wherein the support set includes support samples, and extract global features and local features of the support samples; Use global features to train the classifier, use cross entropy loss and support feature labels to train the classifier, and get the training loss function; The robust classifier is trained using a gradient descent algorithm, and a loss function is calculated, and parameters of each part are updated according to the loss function; When the number of training iterations reaches a preset number, a trained robust classifier is obtained, and the trained robust classifier is used to perform image classification.
8. A small sample image classification device based on global and local content matching, characterized in that: include: A feature extraction module is used to obtain a natural image sample set, extract image features from the natural image sample set to obtain global features and local features, and convert a text description corresponding to the image into a high-dimensional feature vector; A local representation construction module, for selectively combining discriminative local features and constructing a local representation by fusing the local features; A classifier construction module, used for matching the local representation with the global feature to construct a robust classifier; The training module is used to train the robust classifier and use the trained robust classifier to perform image classification.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the small sample image classification method based on global and local content matching is implemented as described in any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the small sample image classification method based on global and local content matching are implemented as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Brain-inspired global-local dual-channel image classification method and system
CN115439696A
Cross-domain small sample image classification method based on global-local knowledge distillation
CN115953630A
Small sample open set identification method based on global-local energy collaborative representation
CN116563603A
Zero sample image recognition method based on CLIP
CN117197568A
Small sample classification method, system, medium and equipment
CN118397351A
Cited By
Image classification method and device, equipment and medium
CN121074917A
