Small sample image classification method and device
By processing image data through adaptive feature enhancement and data augmentation modules, and combining them with feature smoothing modules to normalize feature distribution, the problems of poor generalization ability and random feature distribution in small sample image classification are solved, and higher classification accuracy is achieved.
Patent Information
- Application Number
- CN202410591620.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-13
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2044-05-13
AI Technical Summary
Existing few-sample image classification methods require a large amount of base class data during the training phase. The scarcity of new class data leads to poor generalization ability, and the random and irregular distribution of features results in low classification accuracy.
An adaptive average pooling layer is replaced with an adaptive feature enhancement module, and zero-mask occlusion is performed in conjunction with a data augmentation module. A feature smoothing module is added to standardize feature distribution, and a classification model is constructed.
It improves feature utilization, prevents overfitting, enhances the discriminative power of features, and improves classification accuracy.
Smart Images

Figure CN118351382B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image classification technology, and in particular to a method and apparatus for classifying small sample images. Background Technology
[0002] Deep learning models often rely on large-scale data to learn better feature representations, but in many scenarios, obtaining large-scale data is extremely difficult; for example, acquiring large-scale image data is quite challenging in medicine. When the amount of data is small, deep learning models often suffer from overfitting and poor generalization ability. One way to address this problem is few-shot learning.
[0003] Most existing few-shot image classification methods are based on ResNet12 as the backbone network, while some use Conv4-64 or ResNet18. The difference lies in the number of network layers, but the goal is the same: to obtain the best weights through pre-training and then better generalize to new tasks (new classes) during the testing phase. Existing techniques mainly improve the algorithm, such as using attention mechanisms to focus on feature information in the image. Some have also proposed different distance metrics to reduce the distance between the query set features and the support set features. However, such techniques cannot fundamentally solve the problem of scarce few-shot data. The few-shot domain faces two main problems: First, during the model training phase, a large amount of base class data is often needed to obtain a good feature extractor, but the amount of data for new classes is scarce, resulting in poor generalization ability of the trained feature extractor to new classes and a tendency to overfit. Secondly, after feature extraction, the features of different categories are randomly distributed in the feature embedding space, and there is no regularity. This results in high randomness when matching the query set and the support set, which easily leads to incorrect matching and low classification accuracy. Summary of the Invention
[0004] The purpose of this invention is to provide a method and apparatus for classifying small sample images to solve the above-mentioned problems, thereby improving the classification accuracy of small sample images.
[0005] The first aspect of this application provides a few-sample image classification method, the method comprising: pre-training a feature extraction network using base class data to obtain pre-trained weights; selecting the optimal pre-trained weights and applying them to a classification model; and inputting the image to be classified in the actual task into the classification model for classification.
[0006] Furthermore, the feature extraction network includes a feature extraction module and a data augmentation module; the feature extraction module includes four consecutive residual blocks and an adaptive feature augmentation module, which consists of adaptive average pooling and soft pooling; a learnable parameter β is used to assign and fuse the importance of the output information of adaptive average pooling and soft pooling; the data augmentation module is used to perform zero-mask occlusion processing on the input image to obtain enhanced data, and the enhanced data is used as input to the feature extraction module for feature extraction.
[0007] Furthermore, the classification model is constructed by adding a feature smoothing module and a classifier to the feature extraction network; the feature smoothing module consists of feature shrinkage and feature normalization; the feature shrinkage is used to shorten the distance between samples of the same type according to the structural properties of the input data and separate samples of different categories; the feature normalization constrains the shrunken features, optimizes the feature distance in the shrunken subspace, and makes the distribution of samples in the shrunken subspace tend to be stable.
[0008] A second aspect of this application provides a few-sample image classification device, including a pre-training module and a classification module. The pre-training module is used to pre-train a constructed feature extraction network using base class data to obtain pre-training weights; and selects the optimal pre-training weights to apply to a classification model. The classification module is used to input images that need to be classified in a real-world task into the classification model to classify the images that need to be classified in the real-world task.
[0009] The feature extraction network includes a feature extraction module and a data augmentation module. The feature extraction module includes four consecutive residual blocks and an adaptive feature augmentation module, which consists of adaptive average pooling and soft pooling. A learnable parameter β is used to assign and fuse the importance of the output information of adaptive average pooling and soft pooling. The data augmentation module is used to perform zero-mask occlusion processing on the input image to obtain enhanced data, which is then used as input to the feature extraction module for feature extraction.
[0010] The classification model is constructed by adding a feature smoothing module and a classifier to the feature extraction network. The feature smoothing module consists of feature shrinkage and feature normalization. Feature shrinkage is used to shorten the distance between samples of the same type and separate samples of different categories based on the structural properties of the input data. Feature normalization constrains the shrunken features, optimizes the feature distance in the shrunken subspace, and makes the distribution of samples in the shrunken subspace tend to be stable.
[0011] A third aspect of this application provides an electronic device, comprising: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to execute the steps of the few-sample image classification method described above.
[0012] A fourth aspect of this application provides a computer-readable storage medium having computer program instructions stored thereon, which, when executed by a processor, implement the steps of the small sample image classification method described above.
[0013] The fifth aspect of this application provides a computer program product containing instructions that, when run on a computer, cause the computer to perform the steps of the small sample image classification method described above.
[0014] The beneficial effects of this invention are as follows: This invention provides a method and apparatus for small-sample image classification. It pre-trains a feature extraction network using base class data to obtain pre-trained weights; selects the optimal pre-trained weights for application to the classification model; and inputs the images to be classified in the actual task into the classification model for classification. In this invention, an adaptive feature enhancement module (AFE) replaces the adaptive average pooling layer in the original model as the feature extraction module. The adaptive feature enhancement module can reasonably utilize the local and global information of the feature map, preventing information loss, retaining important classification information, and obtaining strong representational power of the features; thereby effectively improving the utilization rate of features and preventing overfitting of the model. Furthermore, a data augmentation module performs zero-mask occlusion processing on the input image data, enhancing the representation of the data by occluding some pixels in the sample. This processing does not generate noise or introduce additional interference and can be regarded as a simple and effective regularization technique to improve model performance. Furthermore, this invention further adds a feature smoothing module (FSM) and a classifier to the feature extraction network to construct a classification model. The feature smoothing module is used to normalize the distribution of features, aiming to aggregate samples of the same category together, while highly separating samples of different categories, improving the discriminative power of sample features, and thus improving the classification accuracy of the classifier. Attached Figure Description
[0015] Figure 1 The diagram shown is a structural block diagram of the existing ResNet12 model.
[0016] Figure 2 What is shown is Figure 1 Structural diagram of the residual block.
[0017] Figure 3 The diagram shown is a structural diagram of the improved ResNet12 model of this invention.
[0018] Figure 4 The diagram shown is a structural schematic of the adaptive feature enhancement module of the present invention.
[0019] Figure 5 The diagram shown is a flowchart of the data enhancement module processing procedure according to the present invention.
[0020] Figure 6 The diagram shown is a flowchart of the pre-training method of the present invention.
[0021] Figure 7 The diagram shows the flowchart of the testing phase of the classification model constructed in this invention.
[0022] Figure 8 The diagram shown is a schematic diagram of the feature smoothing module of the present invention.
[0023] Figure 9 The figure shown is a t-SNE visualization analysis of the performance of the Feature Smoothing Module (FSM) on the CIFAR-FS dataset, based on the present invention.
[0024] Figure 10 The diagram shows a random 16x16 area mask, two random 8x8 area masks, and a class activation map without any enhancement strategy, all set up in a 5-way 1-shot configuration.
[0025] Figure 11 This is an overall flowchart of a small sample image classification method provided by the present invention.
[0026] Figure 12 This is a schematic diagram of an electronic device provided by the present invention. Detailed Implementation
[0027] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0028] In existing technologies, the main problems faced in the small sample size domain include two aspects. First, during the model training phase, a large amount of base class data is often required to obtain a good feature extractor, but the amount of data for new classes is scarce. This results in poor generalization ability of the trained feature extractor for new classes, easily leading to overfitting. Second, after feature extraction, the features of different classes are randomly distributed in the embedding space without any regularity. This results in high randomness when matching the query set and support set, easily leading to incorrect matching and low classification accuracy.
[0029] Concept Explanation: Few-shot learning refers to the ability of a machine to learn effectively even with a small number of training classes. Few-shot learning aims to enable the machine to quickly learn new classes (NewClass) with only a few samples after learning a large number of base classes. When there is only one training sample per class, it is called One-shot Learning; when there are multiple training samples per class, it is called Few-shot Learning. The experimental evaluation metric for few-shot image classification methods is often called the N-way K-shot task. The N-way K-shot task involves selecting N classes of image samples from a dataset with known ground truth values (in this invention, the CIFAR-FS dataset is used), selecting K samples from each class to form an N*K support set; selecting Q unclassified images as a query set; and correctly classifying the images in the query set based on the existing support set, where the query set and support set form the new class (NewClass); and using the remaining samples from the dataset with known ground truth values as base classes (BaseClass).
[0030] To address the above problems, this invention provides a method and apparatus for small-sample image classification, the main contents of which are as follows:
[0031] First, a few-shot learning dataset is constructed, which contains base class data and new class data. Then, support sets and query sets are further selected from the new class data.
[0032] Secondly, this invention replaces the adaptive average pooling layer in the original ResNet12 model with an adaptive feature enhancement module (AFE) as the feature extraction module (using f). φ (This is represented as follows), and a data augmentation module is added before the feature extraction module to build the feature extraction network; the data augmentation module can perform zero-mask occlusion processing on the sample data to obtain augmented data; the base class data is used to pre-train the constructed feature extraction network and obtain the model's pre-trained weights, which are used for small sample testing of the classification model.
[0033] Subsequently, a feature smoothing module (FSM) and a classifier are further added to the pre-trained feature extraction network to construct a classification model. This classification model can achieve small-sample image classification, and compared with existing technologies, the classification model provided by this invention has higher classification accuracy. The classification model is tested using support sets and query sets, and its effectiveness is effectively verified.
[0034] The present invention will now describe in detail the contents of each of the above parts.
[0035] In one specific embodiment of this invention, the process of constructing a few-shot learning dataset is as follows: The initial few-shot dataset used is the CIFAR-FS dataset, which contains 100 categories, with 600 images per category, and each image has a resolution of 32×32. The CIFAR-FS dataset is further divided into a base class dataset and a new class dataset, with no overlap between the categories of the base class dataset and the new class dataset. The base class dataset includes 80 categories, and the new class dataset includes 20 categories. A support set and a query set are further selected from the new class dataset. In this invention, the feature extraction network constructed using the base class dataset is used for pre-training. The classification model constructed using the new class dataset is used for performance testing.
[0036] During the testing phase, the evaluation metric for few-shot image classification is usually referred to as the N-way K-shot task, where each N-way K-shot task {ξ=<S,Q> Random sampling is performed from the new class dataset. The support set is included. Includes N categories, each containing K samples; query set The system includes N identical categories, each containing M samples. In this invention, N is less than or equal to 20; specifically, 5 categories are randomly selected. K+M is less than or equal to the number of images in a single category, and K and M images do not overlap. In this invention, M is 15, and K is 1 or 5. This invention constructs two types of tasks for testing: 5-way 1-shot and 5-way 5-shot. When using the 5-way 1-shot task, one sample is selected from the support set, and 15 samples are selected from the query set. When using the 5-way 5-shot task, 5 samples are selected from the support set, and 15 samples are selected from the query set. A total of 100 rounds of few-shot learning training are performed in this invention.
[0037] like Figure 1 The diagram shows the structural block of the existing ResNet12 model. The existing ResNet12 model consists of four consecutive residual blocks, followed by an adaptive average pooling layer used to generate feature embeddings. Figure 2 The diagram shows the structure of the residual block. Each residual block has three convolutional layers with a kernel size of 3×3.
[0038] This invention improves the existing ResNet12 model as follows: An adaptive feature enhancement module replaces the adaptive average pooling layer in the ResNet12 model to generate feature embeddings and enhance feature representation; for example... Figure 3 The diagram shown is the structure of the improved ResNet12 model. For ease of description, this invention names it the feature extraction module (using f). φ express).
[0039] like Figure 4 The diagram shows the structure of the adaptive feature enhancement module of this invention, which consists of adaptive average pooling and soft pooling. Adaptive average pooling has a strong ability to perceive global information in image data. This pooling method retains key information by adaptively calculating the average value. Specifically, adaptive average pooling can adaptively adjust the size of the pooling region. It divides the input feature map into multiple regions, the size of which is determined by the size of the input feature map, and then calculates the average value of the features within each region.
[0040] While adaptive average pooling can mitigate the risk of information loss associated with traditional average pooling, its ability to perceive local information remains weak, easily leading to the loss of local information in the feature map. To address this, this invention introduces soft pooling. Soft pooling, through a nonlinear transformation, alters the spatial distribution of features, helping the model extract more discriminative feature representations. Simultaneously, by weighting all positions in the feature map, it effectively preserves local detail features.
[0041] Soft pooling uses a weighted average based on a probability distribution to preserve more detailed information. Specifically, soft pooling is differentiable and computes activations in the neural network using the natural exponent (e) to ensure that large activations have a greater impact on the output. It also uses a smoothed maximum approximation to process activations within the kernel region (R), where each activation... Each has a weight w i Weight w i yes The natural index is the ratio of the natural index of the active power to the sum of the natural indices of all active powers in its neighborhood. This can be formally expressed as Equation 1:
[0042]
[0043] The obtained weight w i A nonlinear transformation is performed along with the corresponding activation values to change the spatial distribution of features, helping the model extract more discriminative feature representations. Simultaneously, all positions in the feature map are weighted using a weighted method, and the output of soft pooling is formally represented as shown in Formula 2 below:
[0044]
[0045] To balance the extraction of global and local information, this invention introduces a learnable parameter β to assign values to the importance of the output information of adaptive average pooling and soft pooling. Parameter β is automatically updated as the model performs gradient updates during training, enabling the model to adaptively select and focus on global and local information, thereby improving the discriminative power of features. This can be formally expressed as the following formula 3:
[0046]
[0047] In Formula 3, β∈[0,1] is used to balance the fusion operation, F ASP F represents the total output. AAP F represents the output of adaptive average pooling. SP This represents the output of soft pooling.
[0048] The adaptive feature enhancement module proposed in this invention can rationally utilize local and global information from feature maps, preventing information loss, retaining important classification and discrimination information, and obtaining strong representational power of features. This effectively improves feature utilization and prevents model overfitting.
[0049] The data augmentation module proposed in this invention employs the Cutout algorithm to perform zero-mask occlusion processing on the input image data. Specifically, it randomly selects multiple pixels in the image as center points according to a predetermined number and places zero masks around them. This zero-mask approach simulates the occlusion of objects in a real-world image. Figure 5 The diagram shows a flowchart of the data augmentation module processing procedure of the present invention. In this example, the number of zero masks is set to 2. One zero mask covers an 8*8 pixel area. The range of this area can also be set. After data augmentation processing, two random pixels in the image turn gray.
[0050] The data augmentation strategy using the Cutout algorithm is performed at the pixel level, enhancing the data representation by occluding a portion of the pixels in the sample. This process does not generate noise or introduce additional interference, and can be considered a simple and effective regularization technique to improve model performance.
[0051] The principle of the Cutout algorithm is as follows:
[0052] Assume the original image is I, with size (m, n), where m and n represent the pixel values of the image's length and width, respectively. Figure 5 As shown in (a), to better understand the algorithm principle of this study, this invention first defines a matrix M representing image I. Matrix M can be defined using the following formula 4:
[0053]
[0054] In Formula 4, i and j represent the row and column indices of the matrix, respectively. If i and j are located between [1, m] and [1, n], respectively, then the image matrix M is padded with 1s, as shown below. Figure 5 As shown in (b), if it is not within this range, it is filled with 0, indicating no filling.
[0055] After defining the image as matrix M, pixel-level operations are performed on the image I. Specifically, this invention first defines two zero-containing matrices, A1 and A2, as follows: Figure 5 As shown in (c), the original image matrix M is multiplied sequentially by A1 and A2 to obtain the padded matrix, as follows. Figure 5 As shown in (d), the matrix multiplication operation can be represented by the following formula 5:
[0056] M′=M·A1·A2 (Formula 5)
[0057] In Formula 5, · represents matrix multiplication, and A1 and A2 represent matrices containing zero masks. In the optimal solution of this invention, two identical regions are selected for masking, that is, A1 and A2 contain zero mask regions of the same area.
[0058] Convert the enhanced image I′ back to its original form, such as Figure 5 As shown in (e), the image after filling is represented. The gray part corresponds to 0 in the matrix, indicating that zero filling has been performed, while the other parts correspond to 1 in the matrix, indicating that zero filling has not been performed.
[0059] Furthermore, this invention explores in detail the impact of different mask numbers and individual mask areas on classification performance, as detailed in the experimental content below.
[0060] Using the above method, this invention constructs a feature extraction network; the constructed feature extraction network is pre-trained using base class data to obtain pre-trained weights, which are then used for small-sample testing of the classification model.
[0061] like Figure 6 The diagram shown is a flowchart of the pre-training method of this invention. The pre-training method is as follows: Base class data is input into the feature extraction network. The base class data first undergoes zero-mask occlusion processing by a data augmentation module to output augmented data. This invention uses a cross-entropy loss function on the augmented base class data to optimize the feature extraction module f. φ Pre-training is performed, and the weights are saved every 10 training rounds. A total of 100 training rounds are conducted until the model reaches convergence. Through pre-training, the best pre-trained weights can be obtained for testing.
[0062] This invention applies the best pre-trained weights obtained to the testing phase for classifying new categories. During this process, it was found that the feature distribution of different new categories in the feature embedding space after feature extraction is random and irregular. This results in high randomness when matching the query set and support set, easily leading to incorrect matching and low classification accuracy. Specifically, due to the differences between categories, the neural network captures these differences during feature extraction and maps them to different regions of the embedding space, resulting in a loose distribution of sample features across different categories. Secondly, even samples of the same category may have different representations in the embedding space due to their different backgrounds and environments. Furthermore, due to the non-linear mapping characteristics of neural networks, they consider higher-level semantic information, not just low-level visual features, when extracting features. This can lead to similar samples being spaced apart in the embedding space, forming a relatively random distribution.
[0063] Therefore, this invention further adds a Feature Smoothing Module (FSM) and a classifier to the above-mentioned feature extraction network to construct a classification model. The structure of the classification model constructed by this invention is as follows: Figure 7 As shown, the feature smoothing module in the classification model is used to normalize the distribution of features, aiming to aggregate samples of the same category together while highly separating samples of different categories, thereby improving the discriminative power of sample features and thus improving the classification accuracy of the classifier.
[0064] In this invention, the Feature Smoothing Module (FSM) consists of two parts: feature shrinkage and feature normalization.
[0065] like Figure 8 The diagram illustrates the principle of a feature smoothing module in a 5-way 5-shot setup. Feature shrinkage aims to reduce the distance between similar samples and separate samples from different categories based on the structural properties of the input data. This invention treats the features of a single sample in the embedding space as node representations in a graph neural network, i.e., f i,j Where i,j∈N represent sample features from the same category, in order to reduce the offset between nodes of the same category, this invention calculates the centralization weight between nodes, that is, decentralizes each node, which can be formally expressed as the following formula 6:
[0066]
[0067] in, f i and f j The centering parameter between them is a learnable weight parameter that is determined by the structural properties of the input data.
[0068] To make sample features more discriminative, this invention uses a learnable parameter matrix W. i Shrink the features of similar samples into the same subspace E k(k=1,2,3....) Internally, this operation can be formally represented as Equation 7 below:
[0069]
[0070] In Formula 7, k represents the number of categories in the embedding space.
[0071] To avoid the negative effects of excessive feature shrinkage and to improve the discriminative power between sample features, this invention uses L2 feature normalization to constrain the shrunken features, optimizing the feature distance in the shrunken subspace and stabilizing the distribution of samples within it. This operation can be formally represented as Equation 8 below:
[0072]
[0073] In formula 8 in, and Represents the normalized features. for and The inner product of f represents the feature f i and f j The similarity between them.
[0074] like Figure 7 The diagram shows the flowchart of the testing phase of the classification model constructed in this invention. To verify the classification effect of the classification model of this invention on small sample images, this invention uses a support set and a query set to test the classification model. The testing method is as follows.
[0075] Experimental setup
[0076] The experimental platform for this invention was a Windows 10 computer with an NVIDIA GeForce GTX 1080Ti GPU, and all code was run in PyTorch version 1.10.1. This invention uses the SGD optimizer to optimize the model, with a momentum of 0.9 and weight decay of 5e-4. Simultaneously, the initial learning rate was set to 0.05, and the learning rate was decayed in increments of 0.1. During the testing phase, this invention trained a logistic regression classifier.
[0077] The testing method is as follows (refer to...) Figure 7 (Understanding): Specifically, the enhanced support set image data and query set image data are fed into the trained feature extraction network f. φ At this point, the feature extraction network fφ Obtained by loading the best pre-trained weights, via f φ Obtain the feature vectors of the support set and query set, and then obtain the feature maps of the support set and query set in the embedding space. For example... Figure 8 (a) illustrates the possible distribution of support set features and query set features in the embedding space. To make the boundaries between category features more distinct, this invention employs feature shrinkage and feature normalization to normalize feature representations, shrinking intra-class distances and expanding inter-class distances. The effect after processing by the FSM module is shown below. Figure 8 As shown in (b). Finally, the feature vector after passing through the FSM module is fed into the LR classifier for final classification and to obtain the classification accuracy of the N-way K-shot task.
[0078] Comparative testing was conducted using support sets and query sets to test the ResNet12 model.
[0079] Experimental Results and Analysis
[0080] The classification accuracy of the classification model of this invention was tested and achieved 74.77% and 88.25% in 5-way 1-shot and 5-way 5-shot settings, respectively. As shown in Table 1 below, this invention demonstrates the accuracy of some existing few-sample image classification methods based on the ResNet12 model, among which APP2S, GLFA, and SENet are state-of-the-art methods. Compared with these methods, the method of this invention achieves the best classification accuracy in both 5-way 1-shot and 5-way 5-shot settings. By comparing with other methods, the superiority of the method of this invention can be highlighted.
[0081] Table 1
[0082]
[0083] In Comparative Experiment 1, this invention further investigated the impact of specific parameter settings (mask quantity and mask size) in the data augmentation module on classification performance. The experimental details are as follows:
[0084] First, this invention tested the effect of different mask sizes (4*4, 8*8, 16*16, 24*24) on model performance when the number of masks was 1, and compared it with the optimal solution of this invention with 2 masks and a mask size of 8*8. The experimental results are shown in Table 2.
[0085] Table 2. Experimental results of randomly shading different areas.
[0086]
[0087]
[0088] Experiments show that when the number of masks is 1, a mask size of 16*16 performs best, and the optimal solution in the embodiments of this invention is even better. It improves performance by approximately 0.75% and 0.79% in 1-shot and 5-shot settings, respectively.
[0089] Furthermore, this invention investigated masking schemes for randomly occluding two 4*4 and 8*8 regions, three 4*4 and 8*8 regions, and four 4*4 regions. The experimental results are shown in Table 3 below.
[0090] Table 3. Experimental results with random occlusion at multiple locations
[0091]
[0092] As shown in the table, the data augmentation effect is best when two 8x8 regions are randomly occluded. As the number of occluded regions increases, the model's performance declines, and the more occluded regions, the worse the performance. This may be because as the number of occluded regions increases, some important features are covered, making it difficult for the model to learn effective features. Occluding two or three 4x4 regions does not significantly improve the performance. This may be because the occluded areas are too small, essentially introducing noise that does not enhance the data representation, thus failing to improve model performance.
[0093] Comparative Experiment 2: To further verify the impact of the Adaptive Feature Enhancement (AFE) module of this invention on the quality of generated features, this invention uses adaptive average pooling, soft pooling, and AFE as the last layer of the feature extractor to generate feature embeddings. Experiments were conducted on the CIFAR-FS dataset, and the experimental results are shown in Table 4.
[0094] Table 4. Impact of generated feature quality on model performance, where AAP: Adaptive Average Pooling; SP: Soft Pooling; AFE: Adaptive Feature Enhancement Module.
[0095]
[0096] As shown in Table 4, the model with the AFE module exhibits the best performance, outperforming adaptive average pooling and soft pooling in both 1-shot and 5-shot settings. This is because the AFE module can fully consider both global and local information in the image, enhance the representational power of effective features, effectively preserve important classification information, and adaptively improve the quality of feature embedding.
[0097] Comparative Experiment 3: Visual Experimental Analysis of Feature Smoothing Module.
[0098] This invention presents a t-SNE visualization analysis of the performance of the Feature Smoothing Module (FSM) on the CIFAR-FS dataset. The invention randomly selects features from 2000 images across five categories in the CIFAR-FS dataset for t-SNE visualization, and the visualization results are shown below. Figure 9 As shown in the figure, when the FSM module is not used for feature smoothing, the class boundaries are blurred, and the clusters are relatively scattered, making it difficult to obtain good clustering results. Figure 9 As shown in (b). When using the FSM module for feature smoothing, the boundaries between classes are clear, and the feature distribution within each class is relatively compact, as shown in [example]. Figure 9 As shown in (a), the experimental results demonstrate that the FSM module is effective and can improve the classification performance of small sample images.
[0099] Comparative Experiment 4: Model Visualization Analysis.
[0100] To further demonstrate that data augmentation strategies can improve classification performance for few-sample image classification, this invention uses Grad-CAM to visualize the output feature map of the last layer of the model. Figure 10 This diagram illustrates class activation maps under a 5-way 1-shot setup, showing a random 16x16 region mask, two random 8x8 region masks, and no augmentation strategy. In the categories of pickup trucks and tanks, without augmentation, the model only focuses on partial location information, easily leading to misclassification. With data augmentation, the model extracts more feature information, especially with the two random 8x8 region masks, resulting in more comprehensive information acquisition. Visualizing the results demonstrates that data augmentation allows the model to learn more information and acquire richer feature representations. Compared to a random 16x16 region mask, two random 8x8 region masks allow the model to focus on the object of interest more comprehensively, learning more contextual information.
[0101] like Figure 11 The diagram shows the overall flowchart of a few-shot image classification method provided by the present invention. In summary, the present invention provides a few-shot image classification method, which includes the following steps: first, pre-training the constructed feature extraction network using base class data to obtain pre-trained weights; selecting the optimal pre-trained weights and applying them to the classification model; inputting the images to be classified in the actual task into the classification model, and classifying the images to be classified in the actual task; the feature extraction network and classification model constructed in the present invention are described in detail above and will not be repeated here.
[0102] Corresponding to the above method embodiments, this application embodiment also provides a few-sample image classification device, including a pre-training module and a classification module. The pre-training module is used to pre-train the constructed feature extraction network using base class data to obtain pre-training weights; and select the optimal pre-training weights to apply to the classification model. The classification module is used to input the images that need to be classified in the actual task into the classification model to classify the images that need to be classified in the actual task.
[0103] This invention also provides an electronic device, such as... Figure 12 As shown, it includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus.
[0104] Memory is used to store computer programs.
[0105] When the processor executes the program stored in memory, it performs the following steps: pre-trains the constructed feature extraction network using base class data to obtain pre-trained weights; selects the optimal pre-trained weights and applies them to the classification model; inputs the images that need to be classified in the actual task into the classification model and classifies the images that need to be classified in the actual task.
[0106] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0107] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0108] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0109] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0110] In another embodiment provided in this application, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the steps of any of the above-described few-sample image classification methods.
[0111] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute any of the small sample image classification methods described above.
[0112] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).
[0113] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0114] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the apparatus embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0115] The above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention are included within the scope of protection of the present invention.
Claims
1. A few-sample image classification method, characterized in that, The method includes: pre-training a feature extraction network using base class data to obtain pre-trained weights; selecting the optimal pre-trained weights and applying them to a classification model; and inputting the image to be classified in the actual task into the classification model for classification. The feature extraction network includes a feature extraction module and a data augmentation module; the feature extraction module includes four consecutive residual blocks and an adaptive feature augmentation module, which consists of adaptive average pooling and soft pooling; learnable parameters are used. The importance of the output information from adaptive average pooling and soft pooling is assigned and fused; the data augmentation module is used to perform zero-mask occlusion processing on the input image to obtain enhanced data, and the enhanced data is used as input to the feature extraction module for feature extraction; The classification model is constructed by adding a feature smoothing module and a classifier to the feature extraction network. The feature smoothing module consists of feature shrinkage and feature normalization. Feature shrinkage is used to shorten the distance between samples of the same type and separate samples of different categories based on the structural properties of the input data. Feature normalization constrains the shrunken features, optimizes the feature distance in the shrunken subspace, and makes the distribution of samples in the shrunken subspace tend to be stable.
2. A small sample image classification device, characterized in that, It includes a pre-training module and a classification module. The pre-training module is used to pre-train the constructed feature extraction network using base class data to obtain pre-training weights; and selects the optimal pre-training weights to apply to the classification model. The classification module is used to input the images that need to be classified in the actual task into the classification model and classify the images that need to be classified in the actual task. The feature extraction network includes a feature extraction module and a data augmentation module; The feature extraction module includes four consecutive residual blocks and an adaptive feature enhancement module, which consists of adaptive average pooling and soft pooling; it employs learnable parameters. The importance of the output information from adaptive average pooling and soft pooling is assigned and fused. The data augmentation module is used to perform zero-mask occlusion processing on the input image to obtain enhanced data, and the enhanced data is used to input the feature extraction module for feature extraction; The classification model is constructed by adding a feature smoothing module and a classifier to the feature extraction network; the feature smoothing module consists of feature shrinkage and feature normalization; the feature shrinkage is used to shorten the distance between samples of the same type and separate samples of different categories according to the structural properties of the input data. The feature normalization constrains the shrunken features, optimizes the feature distance in the shrunken subspace, and makes the distribution of samples in the shrunken subspace tend to be stable.
3. An electronic device, characterized in that, include: processor; Memory used to store processor-executable instructions; The processor is configured to execute the steps of the few-sample image classification method of claim 1.
4. A computer-readable storage medium having computer program instructions stored thereon, characterized in that, When the program instructions are executed by the processor, they implement the steps of the few-sample image classification method described in claim 1.
5. A computer program product containing instructions, characterized in that, When it is run on a computer, it causes the computer to perform the steps of the few-sample image classification method of claim 1.
Citation Information
Patent Citations
Small sample image classification method
CN115830401A
