Small sample image classification method, device and medium

By combining a meta-learning model with width learning and attention mechanism, the problem of traditional metric failure in small sample image classification is solved, higher classification accuracy and efficiency are achieved, the feature expression and adaptability of the model are enhanced, and it has good interpretability.

CN120510459BActive Publication Date: 2025-09-19INSPUR SOFTWARE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511006555.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-07-22
Publication Date
2025-09-19
Estimated Expiration
2045-07-22

AI Technical Summary

Technical Problem

Existing small sample image classification technology has a problem that the intra-class variance is greater than the inter-class variance, which leads to the failure of traditional metrics and makes it difficult to define effective distance metrics or similarity functions, affecting classification accuracy and efficiency.

Method used

A meta-learning model based on width learning and attention mechanism is adopted. By increasing the number of hidden layer neurons, directly connecting input features to multiple hidden layers, multi-head attention mechanism modules and meta-learning framework, the feature importance and parameters are dynamically adjusted, and the initial parameters of the model are optimized to adapt to new tasks.

Benefits of technology

It improves the accuracy and efficiency of small sample image classification, enhances the feature expression ability and adaptability of the model, enables it to quickly adapt to new tasks, reduces the demand for task data volume, and improves the generalization ability and interpretability of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120510459B_ABST
    Figure CN120510459B_ABST
Patent Text Reader

Abstract

The present invention discloses a small sample image classification method, device and medium, which belongs to the field of image classification technology. The technical problem to be solved by the present invention is how to improve the accuracy and efficiency of small sample image classification. The technical solution is: image acquisition and preprocessing; constructing and updating a meta-learning model based on width learning and attention mechanism; wherein, the meta-learning model based on width learning and attention mechanism includes an input layer, a width learning module, a multi-head attention mechanism module, an output layer and a meta-learning framework; the width learning module improves the expressive power of the meta-learning model based on width learning and attention mechanism by increasing the connection between the input layer and the hidden layer; the multi-head attention mechanism module enables the meta-learning model based on width learning and attention mechanism to dynamically adjust the importance of small sample image features; the meta-learning framework updates the initialization parameters of the meta-learning model through inner and outer loops to obtain an updated meta-learning model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image classification, and in particular to a small sample image classification method, device and medium. Background Art

[0002] Few-Shot Image Classification (FSL) is a key task in computer vision, aiming to achieve efficient classification using a very small number of labeled samples (e.g., only 1-5 images per class). Current techniques for few-shot image classification struggle because the intra-class variance in small sample data can be greater than the inter-class variance, rendering traditional metrics (such as Euclidean distance) ineffective. Furthermore, distance metrics in high-dimensional feature spaces can be susceptible to the curse of dimensionality, making it difficult to define effective distance metrics or similarity functions for few-shot classification.

[0003] Therefore, how to improve the accuracy and efficiency of small sample image classification is a technical problem that needs to be solved urgently. Summary of the Invention

[0004] The technical task of the present invention is to provide a small sample image classification method, device and medium to solve the problem of how to improve the accuracy and efficiency of small sample image classification.

[0005] The technical task of the present invention is achieved in the following manner: a small sample image classification method, the method is as follows:

[0006] Image acquisition and preprocessing: 32×32 pixel RGB images were collected from the CIFAR10 dataset. The pixel values ​​of the 32×32 pixel RGB images were normalized from [0, 255] to [0, 1] using the mean and standard deviation. This was followed by standardization to obtain a small sample image dataset containing small sample image features. The small sample image dataset was then divided into a support set, a query set, and a test set for training, validation, and testing of the meta-learning framework.

[0007] Construct and update a meta-learning model based on width learning and attention mechanism; wherein, the meta-learning model based on width learning and attention mechanism includes an input layer, a width learning module, a multi-head attention mechanism module, an output layer and a meta-learning framework; the input layer inputs small sample image features and passes them to the width learning module; the width learning module improves the expressive power of the meta-learning model based on width learning and attention mechanism by increasing the connection between the input layer and the hidden layer; the multi-head attention mechanism module calculates the similarity between the input small sample image features and weights the features according to the similarity, so that the meta-learning model based on width learning and attention mechanism can dynamically adjust the importance of small sample image features; the output layer outputs the processed small sample image features; the meta-learning framework updates the initialization parameters of the meta-learning model based on width learning and attention mechanism through inner and outer loops to obtain an updated meta-learning model based on width learning and attention mechanism;

[0008] The test set is input into the updated meta-learning model based on width learning and attention mechanism, the output results of the meta-learning model based on width learning and attention mechanism are analyzed and the curve is drawn to obtain the classification accuracy of the small image.

[0009] As a preferred method, the width learning module increases the width in the following manner:

[0010] Increasing the width of the hidden layer: Improving the expressive power of the meta-learning model based on width learning and attention mechanism by increasing the number of neurons in the hidden layer;

[0011] Adding additional input connections: Connecting input features directly to multiple hidden layers enables meta-learning models based on width learning and attention mechanisms to better utilize input features;

[0012] In a neural network, the number of neurons in the hidden layer determines the width of the corresponding network layer. Increasing the number of neurons in the hidden layer improves the expressive power of the meta-learning model based on width learning and attention mechanisms, enabling the meta-learning model based on width learning and attention mechanisms to capture more complex feature relationships. Directly connecting input features to multiple hidden layers serves the following purposes:

[0013] Defining additional connections: In a neural network, in addition to the normal forward propagation path, adding direct connections from the input layer to multiple hidden layers;

[0014] Modify the forward pass: During the forward pass, combine the input features with the output of the hidden layer (e.g., by addition or concatenation).

[0015] Preferably, the width learning module includes a first hidden layer and a second hidden layer, the first hidden layer includes a first fully connected layer and a first ReLU activation function; the first hidden layer includes a second fully connected layer and a second ReLU activation function;

[0016] Among them, the first fully connected layer maps the input features to the hidden layer and outputs features of dimension hidden_dim * 2 (increased width);

[0017] The first layer ReLU activation function is used to enhance nonlinear expression capabilities;

[0018] The width of the second fully connected layer remains unchanged, and the output dimension is still hidden_dim * 2;

[0019] The second layer ReLU activation function is used to further enhance the nonlinear expression ability.

[0020] Preferably, the meta-learning framework is implemented using the Model-Agnostic Meta-Learning (MAML) algorithm. The Model-Agnostic Meta-Learning algorithm optimizes the initial parameters of the meta-learning model based on width learning and attention mechanism by training on multiple few-shot tasks, so that the meta-learning model based on width learning and attention mechanism can quickly adapt to new tasks.

[0021] Preferably, the inner loop is used to implement fast parameter updates of the meta-learning model based on width learning and attention mechanism through the support set; specifically as follows:

[0022] Initialize fast parameters: copy the current parameters of the meta-learning model based on width learning and attention mechanism into fast parameters fast_weights; the fast parameters fast_weights include the parameters of the width learning module and the parameters of the multi-head attention mechanism module; the parameters of the width learning module include the weights and biases of the network layer; the parameters of the multi-head attention mechanism module include the weights and biases of the query, key, value and output;

[0023] Multiple rapid updates: perform several rapid parameter updates on the support set;

[0024] After multiple rapid updates, the meta-learning model based on width learning and attention mechanism completes rapid adaptation on the support set; at this time, the fast parameter fast_weights has been optimized according to the task characteristics of the support set; in the inner loop, the parameters of the width learning module (such as fc1.weight and fc1.bias) are dynamically adjusted through rapid parameter updates, so that the meta-learning model based on width learning and attention mechanism can dynamically adjust the width of the hidden layer according to the task characteristics of the support set, so that the meta-learning model based on width learning and attention mechanism can better adapt to the current task; at the same time, the parameters of the multi-head attention mechanism module are dynamically adjusted through rapid parameter updates, so that the meta-learning model based on width learning and attention mechanism can dynamically adjust the importance of features according to the task characteristics of the support set, so that the meta-learning model based on width learning and attention mechanism can focus more on features that are more helpful to the task.

[0025] Preferably, when performing multiple rapid updates, each update is as follows:

[0026] Replace parameters: Replace the parameters of the meta-learning model based on width learning and attention mechanism with the fast parameter fast_weights;

[0027] Forward propagation: Use the support set data support_x for forward propagation and calculate the predicted value support_pred

[0028] Calculate loss: Use the cross entropy loss function to calculate the loss support_loss on the support set;

[0029] Calculate gradients: Calculate the gradient of loss through automatic differentiation;

[0030] Update fast parameters: Update fast parameters fast_weights according to the meta learning rate meta_lr.

[0031] Preferably, the outer loop is used to optimize the initial parameters of the meta-learning model based on width learning and attention mechanism, so that the meta-learning model based on width learning and attention mechanism performs better on multiple tasks; specifically as follows:

[0032] Replace parameters: Replace the parameters of the meta-learning model based on width learning and attention mechanism with the fast parameters fast_weights after inner loop optimization;

[0033] Query set verification: Use query set data query_x and query_y for forward propagation and calculate the predicted value query_pred;

[0034] Calculate the query set loss: Use the cross entropy loss function to calculate the loss query_loss on the query set;

[0035] Backpropagation and parameter update: Backpropagate the query set loss query_loss, calculate the gradient, and use the optimizer to update the initial parameters of the meta-learning model based on width learning and attention mechanism;

[0036] After the optimization of the outer loop, the initial parameters of the meta-learning model based on width learning and attention mechanism are updated. By optimizing the initial parameters of the meta-learning model based on width learning and attention mechanism, the meta-learning model based on width learning and attention mechanism can converge quickly on multiple tasks, including not only the parameters of the width learning module and the multi-head attention mechanism module, but also the initial parameters of the entire meta-learning model based on width learning and attention mechanism.

[0037] Preferably, the forward propagation of the width learning module is expressed as follows:

[0038] ;

[0039] ;

[0040] ;

[0041] in, Represents the input feature vector, the dimension is input_dim; Represents the output of the first hidden layer, with a dimension of hidden_dim * 2; Represents the output of the second hidden layer, with a dimension of hidden_dim * 2; It is the final output of the meta-learning model based on width learning and attention mechanism, with dimension output_dim; and are the weights and biases of the first hidden layer respectively; and are the weights and biases of the second hidden layer respectively; and are the weights and biases of the meta-learning framework respectively;

[0042] The multi-head attention mechanism module is represented as follows:

[0043] ;

[0044] in, Represent the query (Query), key (Key) and value (Value) matrices respectively; represents the dimension of the key vector; softmax represents the normalization function, so that each element of the output is between 0 and 1, and the sum is 1; the multi-head attention mechanism module is used to enhance the importance adjustment of features, and the formula is as follows:

[0045] ;

[0046] ;

[0047] ;

[0048] ;

[0049] in, , , Represent the weight matrices of the multi-head attention mechanism modules respectively; , , Represent the bias vector of the multi-head attention mechanism module; the output of the multi-head attention mechanism module Used for output layer calculation.

[0050] An electronic device comprising: a memory and at least one processor;

[0051] Wherein, the memory stores a computer program;

[0052] The at least one processor executes the computer program stored in the memory, so that the at least one processor performs the small sample image classification method as described above.

[0053] A computer-readable storage medium stores a computer program, wherein the computer program can be executed by a processor to implement the small sample image classification method as described above.

[0054] The small sample image classification method, device, and medium of the present invention have the following advantages:

[0055] (1) By combining width learning and attention mechanism, the model can more effectively process input features, thereby improving feature expression capabilities;

[0056] (2) The width learning module of the present invention can capture more complex feature relationships by increasing the connection between the input layer and the hidden layer, enhancing the ability to express input data and enabling it to capture more complex feature relationships; at the same time, it ensures that the width of the hidden layer is dynamically adjusted through rapid parameter updates in the inner loop, so that it can better adapt to the current task;

[0057] (3) The attention mechanism module of the present invention dynamically weights the input features, enabling the model to focus more on features that are more helpful for the task, thereby improving the relevance and importance of the features;

[0058] (4) The meta-learning framework of the present invention enables the model to quickly adapt to new tasks, reduces the demand for task data, and enhances the model's adaptability and generalization ability. By training on multiple few-shot tasks, the model's initial parameters are optimized, enabling it to achieve good performance on new tasks with only a few iterations. Joint training on multiple related tasks learns common features and generation strategies, resulting in better generalization ability on new tasks.

[0059] (5) In multi-task learning, the complexity of the task may be reflected in the diversity of input features, the complexity of output targets, and the correlation between tasks. The combination of the width learning module and the multi-head attention mechanism module can better handle these complexities. In specific implementation methods, the width learning module provides more powerful feature extraction capabilities, enabling the model to handle more complex input features; the multi-head attention mechanism module can dynamically adjust the importance of features, allowing the model to better adapt to the needs of different tasks; for example, in some tasks, certain features may contribute more to the output, and the attention mechanism can automatically identify and enhance the role of these features, thereby improving the model's adaptability to complex tasks;

[0060] (6) An important advantage of the multi-head attention mechanism module of the present invention is its interpretability. By analyzing the attention weights, one can intuitively understand which features or input components play a key role in the model's decision-making. The multi-head attention mechanism module can provide this interpretability, allowing researchers or developers to better understand the model's behavior.

[0061] (7) The width learning module of the present invention increases the width of the model, enabling the model to learn richer feature representations. The feature representations can be analyzed through visualization and other means, thereby further enhancing the interpretability of the model. For example, by analyzing the activation values ​​of the hidden layer, it is possible to understand how the model maps input features to outputs.

[0062] (8) The meta-learning framework of the present invention can reduce the training time of the model on each task by quickly adapting to multiple tasks. The meta-learning framework enables the model to adapt to new tasks in a short time by quickly updating parameters on the support set, thereby improving computational efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0063] The present invention will be further described below with reference to the accompanying drawings.

[0064] Attachment Figure 1This is a flowchart of the small sample image classification method;

[0065] Attachment Figure 2 The error curve diagram of the present invention and the common neural network in the regression task is compared;

[0066] Attachment Figure 3 The figure is a graph showing the accuracy of the present invention compared with that of a common neural network in regression tasks;

[0067] Attachment Figure 4 The error curve diagram of the present invention and the common meta-learning method in the classification task is compared;

[0068] Attachment Figure 5 The figure shows the accuracy curve comparing the present invention and the common meta-learning method in classification tasks. DETAILED DESCRIPTION

[0069] The small sample image classification method, device and medium of the present invention are described in detail below with reference to the accompanying drawings and specific embodiments.

[0070] Example 1: As shown in the attached Figure 1 As shown, this embodiment provides a small sample image classification method, which is specifically as follows:

[0071] S1. Image acquisition and preprocessing: 32×32 pixel RGB images are collected from the CIFAR10 dataset. The pixel values ​​of the 32×32 pixel RGB images are normalized from [0, 255] to [0, 1] using the mean and standard deviation, and then standardized to obtain a small sample image dataset that includes small sample image features. The small sample image dataset is divided into a support set, a query set, and a test set for training, validation, and testing of the meta-learning framework.

[0072] CIFAR10 is a commonly used image classification dataset containing 10 categories, each with 6,000 32×32 pixel RGB images, for a total of 60,000 images. Of these, 50,000 images are used for training and 10,000 for testing. To highlight the small sample size, this example randomly selects 64 samples per batch.

[0073] For meta-learning, the images of each category are divided into a support set and a query set. 32 samples from each category are selected as the support set, and the remaining 32 are used as the query set. To ensure the randomness of the division, the index of each category is randomly shuffled.

[0074] S2. Construct and update a meta-learning model based on width learning and attention mechanism; wherein, the meta-learning model based on width learning and attention mechanism includes an input layer, a width learning module, a multi-head attention mechanism module, an output layer and a meta-learning framework; the input layer inputs small sample image features and passes them to the width learning module; the width learning module improves the expressive power of the meta-learning model based on width learning and attention mechanism by increasing the connection between the input layer and the hidden layer; the multi-head attention mechanism module calculates the similarity between the input small sample image features and weights the features according to the similarity, so that the meta-learning model based on width learning and attention mechanism can dynamically adjust the importance of small sample image features; the output layer outputs the processed small sample image features; the meta-learning framework updates the initialization parameters of the meta-learning model based on width learning and attention mechanism through inner and outer loops to obtain an updated meta-learning model based on width learning and attention mechanism;

[0075] S3. Input the test set into the updated meta-learning model based on width learning and attention mechanism, analyze the output results of the meta-learning model based on width learning and attention mechanism and draw a curve to obtain the classification accuracy of the small image.

[0076] The width learning module in step S2 of this embodiment increases the width in the following manner:

[0077] Increasing the width of the hidden layer: Improving the expressive power of the meta-learning model based on width learning and attention mechanism by increasing the number of neurons in the hidden layer;

[0078] Adding additional input connections: Connecting input features directly to multiple hidden layers enables meta-learning models based on width learning and attention mechanisms to better utilize input features;

[0079] In a neural network, the number of neurons in the hidden layer determines the width of the corresponding network layer. Increasing the number of neurons in the hidden layer improves the expressive power of the meta-learning model based on width learning and attention mechanisms, enabling the meta-learning model based on width learning and attention mechanisms to capture more complex feature relationships. Directly connecting input features to multiple hidden layers serves the following purposes:

[0080] ① Define additional connections: In the neural network, in addition to the normal forward propagation path, add direct connections from the input layer to multiple hidden layers;

[0081] ② Modify the forward propagation: During the forward propagation process, the input features are merged with the output of the hidden layer (for example, by addition or splicing).

[0082] The width learning module in step S2 of this embodiment includes a first hidden layer and a second hidden layer, the first hidden layer includes a first fully connected layer and a first ReLU activation function; the first hidden layer includes a second fully connected layer and a second ReLU activation function;

[0083] Among them, the first fully connected layer maps the input features to the hidden layer and outputs features of dimension hidden_dim * 2 (increased width);

[0084] The first layer ReLU activation function is used to enhance nonlinear expression capabilities;

[0085] The width of the second fully connected layer remains unchanged, and the output dimension is still hidden_dim * 2;

[0086] The second layer ReLU activation function is used to further enhance the nonlinear expression ability.

[0087] The multi-head attention mechanism module in step S2 of this embodiment captures feature relationships in different subspaces by splitting the input features into multiple "heads," calculating attention weights for each, and then concatenating these results. Integrating the attention mechanism module into the width learning module enables the model to dynamically weight features.

[0088] The meta-learning framework in step S2 of this embodiment is implemented using the Model-Agnostic Meta-Learning (MAML) algorithm. The Model-Agnostic Meta-Learning algorithm optimizes the initial parameters of the meta-learning model based on width learning and attention mechanism by training on multiple few-shot tasks, so that the meta-learning model based on width learning and attention mechanism can quickly adapt to new tasks.

[0089] The inner loop in step S2 of this embodiment is used to implement fast parameter updates of the meta-learning model based on width learning and attention mechanism through the support set; specifically, as follows:

[0090] (1) Initialize fast parameters: copy the current parameters of the meta-learning model based on width learning and attention mechanism into fast parameters fast_weights; the fast parameters fast_weights include the parameters of the width learning module and the parameters of the multi-head attention mechanism module; the parameters of the width learning module include the weights and biases of the network layer; the parameters of the multi-head attention mechanism module include the weights and biases of the query, key, value and output;

[0091] (2) Multiple rapid updates: 5 rapid parameter updates are performed on the support set;

[0092] (3) After multiple rapid updates, the meta-learning model based on width learning and attention mechanism completes rapid adaptation on the support set; at this time, the fast parameter fast_weights has been optimized according to the task characteristics of the support set; in the inner loop, the parameters of the width learning module (such as fc1.weight and fc1.bias) are dynamically adjusted through rapid parameter updates, so that the meta-learning model based on width learning and attention mechanism can dynamically adjust the width of the hidden layer according to the task characteristics of the support set, so that the meta-learning model based on width learning and attention mechanism can better adapt to the current task; at the same time, the parameters of the multi-head attention mechanism module are dynamically adjusted through rapid parameter updates, so that the meta-learning model based on width learning and attention mechanism can dynamically adjust the importance of features according to the task characteristics of the support set, so that the meta-learning model based on width learning and attention mechanism can focus more on features that are more helpful to the task.

[0093] In the multiple rapid updates in step (2) of this embodiment, each update is as follows:

[0094] ① Replace parameters: Replace the parameters of the meta-learning model based on width learning and attention mechanism with the fast parameter fast_weights;

[0095] ②Forward propagation: Use the support set data support_x for forward propagation and calculate the predicted value support_pred

[0096] ③Calculate loss: Use the cross entropy loss function to calculate the loss support_loss on the support set;

[0097] ④Calculate gradient: Calculate the gradient of loss through automatic differentiation;

[0098] ⑤Update fast parameters: Update fast parameters fast_weights according to the meta learning rate meta_lr.

[0099] The outer loop in step S2 of this embodiment is used to optimize the initial parameters of the meta-learning model based on width learning and attention mechanism, so that the meta-learning model based on width learning and attention mechanism performs better on multiple tasks; specifically, as follows:

[0100] (1) Replace parameters: Replace the parameters of the meta-learning model based on width learning and attention mechanism with the fast parameters fast_weights after inner loop optimization;

[0101] (2) Query set verification: Use query set data query_x and query_y for forward propagation and calculate the predicted value query_pred;

[0102] (3) Calculate the query set loss: Use the cross entropy loss function to calculate the loss query_loss on the query set;

[0103] (4) Backpropagation and parameter update: Backpropagate the query set loss query_loss, calculate the gradient, and use the optimizer to update the initial parameters of the meta-learning model based on width learning and attention mechanism;

[0104] (5) After the optimization of the outer loop, the initial parameters of the meta-learning model based on width learning and attention mechanism are updated. By optimizing the initial parameters of the meta-learning model based on width learning and attention mechanism, the meta-learning model based on width learning and attention mechanism can converge quickly on multiple tasks, including not only the parameters of the width learning module and the multi-head attention mechanism module, but also the initial parameters of the entire meta-learning model based on width learning and attention mechanism.

[0105] The forward propagation of the width learning module in step S2 of this embodiment is expressed as follows:

[0106] ;

[0107] ;

[0108] ;

[0109] in, Represents the input feature vector, the dimension is input_dim; Represents the output of the first hidden layer, with a dimension of hidden_dim * 2; Represents the output of the second hidden layer, with a dimension of hidden_dim * 2; It is the final output of the meta-learning model based on width learning and attention mechanism, with dimension output_dim; and are the weights and biases of the first hidden layer respectively; and are the weights and biases of the second hidden layer respectively; and are the weights and biases of the meta-learning framework respectively.

[0110] The multi-head attention mechanism module in step S2 of this embodiment is represented as follows:

[0111] ;

[0112] in, Represent the query (Query), key (Key) and value (Value) matrices respectively; represents the dimension of the key vector; softmax represents the normalization function, so that each element of the output is between 0 and 1, and the sum is 1; the multi-head attention mechanism module is used to enhance the importance adjustment of features, and the formula is as follows:

[0113] ;

[0114] ;

[0115] ;

[0116] ;

[0117] in, , , Represent the weight matrices of the multi-head attention mechanism modules respectively; , , Represent the bias vector of the multi-head attention mechanism module; the output of the multi-head attention mechanism module Used for output layer calculation.

[0118] In step S3 of this embodiment, the test set is input into the updated meta-learning model based on width learning and attention mechanism, the output results of the meta-learning model based on width learning and attention mechanism are analyzed and a curve is drawn to obtain the classification accuracy of the small image as follows:

[0119] S301. Draw curves: Draw loss curves and accuracy curves to analyze the performance changes of the model during training.

[0120] S302. Comparative performance: Compare with the ordinary MLP model and the ordinary meta-learning model to verify the advantages of the meta-learning model that combines width learning and attention mechanism in terms of generalization ability, convergence speed, and adaptability to complex tasks.

[0121] Through the above training process, the meta-learning model combining width learning and attention mechanisms can effectively learn richer feature representations and dynamically adjust feature importance, thereby achieving stronger performance in multi-task learning. Key steps include fast parameter updates and query set validation, which together ensure that the model can quickly adapt to new tasks while maintaining good generalization capabilities.

[0122] In this embodiment, the error decreases rapidly in the initial stage of iteration, the accuracy increases rapidly, and it maintains the lead until the end of iteration. Figure 2 As shown in the attached figure, the error of the ordinary neural network on the regression task is 0.2022. Figure 3As shown in the attached figure, the accuracy of the ordinary neural network on the regression task is 0.9032. Figure 4 As shown in the attached figure, the error of the ordinary meta-learning method on the classification task is 0.1658. Figure 5 As shown, the conventional meta-learning method achieves an accuracy of 0.9209 on the classification task, while the error of this embodiment is 0.0035 and the accuracy is 0.9995. Furthermore, after multiple rounds of training, this embodiment achieves smaller errors, higher accuracy, and stronger anti-interference capabilities. This demonstrates the clear superiority of this embodiment.

[0123] Embodiment 2: An embodiment of the present invention further provides an electronic device, comprising: a memory and a processor;

[0124] wherein the memory stores computer-executable instructions;

[0125] The processor executes the computer-executable instructions stored in the memory, so that the processor executes the small sample image classification method in any embodiment of the present invention.

[0126] The processor may be a central processing unit (CPU), other general-purpose processors, 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, discrete hardware components, etc. The processor may be a microprocessor or any conventional processor, etc.

[0127] The memory can be used to store computer programs and / or modules. The processor implements various functions of the electronic device by running or executing the computer programs and / or modules stored in the memory and accessing the data stored in the memory. The memory can mainly include a program storage area and a data storage area. The program storage area can store the operating system and at least one application required for the function; the data storage area can store data generated based on the use of the terminal. In addition, the memory can also include high-speed random access memory and non-volatile memory, such as a hard disk, internal memory, a plug-in hard disk, a smart card (SMC), a secure digital (SD) card, a flash memory card, at least one disk storage device, a flash memory device, or other volatile solid-state memory devices.

[0128] Embodiment 3: This embodiment further provides a computer-readable storage medium storing a plurality of instructions. The instructions are loaded by a processor, causing the processor to execute the small sample image classification method according to any embodiment of the present invention. Specifically, a system or device equipped with a storage medium can be provided. The storage medium stores software program code that implements the functions of any of the above embodiments, and the computer (or CPU or MPU) of the system or device can read and execute the program code stored in the storage medium.

[0129] In this case, the program code itself read from the storage medium can realize the function of any one of the above-mentioned embodiments, and thus the program code and the storage medium storing the program code constitute part of the present invention.

[0130] Examples of storage media for providing program code include floppy disks, hard disks, magneto-optical disks, optical disks (e.g., CD-ROMs, CD-Rs, CD-RWs, DVD-ROMs, DVD-RWs, DVD+RWs), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, the program code may be downloaded from a server computer via a communications network.

[0131] In addition, it should be clear that the functions of any of the above embodiments can be achieved not only by executing the program code read by the computer, but also by enabling the operating system operating on the computer to complete part or all of the actual operations based on the instructions of the program code.

[0132] In addition, it can be understood that the program code read from the storage medium is written into the memory provided in the expansion board inserted into the computer or into the memory provided in the expansion unit connected to the computer, and then based on the instructions of the program code, the CPU installed on the expansion board or expansion unit is enabled to perform part or all of the actual operations, thereby realizing the functions of any of the above embodiments.

[0133] 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 above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A small sample image classification method, characterized in that: The method is as follows: Image acquisition and preprocessing: 32×32 pixel RGB images were collected from the CIFAR10 dataset. The pixel values ​​of the 32×32 pixel RGB images were normalized from [0, 255] to [0, 1] using the mean and standard deviation. This was followed by standardization to obtain a small sample image dataset containing small sample image features. The small sample image dataset was then divided into a support set, a query set, and a test set for training, validation, and testing of the meta-learning framework. Construct and update a meta-learning model based on width learning and attention mechanism; wherein, the meta-learning model based on width learning and attention mechanism includes an input layer, a width learning module, a multi-head attention mechanism module, an output layer and a meta-learning framework; the input layer inputs small sample image features and passes them to the width learning module; the width learning module improves the expressive power of the meta-learning model based on width learning and attention mechanism by increasing the connection between the input layer and the hidden layer; the multi-head attention mechanism module calculates the similarity between the input small sample image features and weights the features according to the similarity, so that the meta-learning model based on width learning and attention mechanism can dynamically adjust the importance of small sample image features; the output layer outputs the processed small sample image features; the meta-learning framework updates the initialization parameters of the meta-learning model based on width learning and attention mechanism through inner and outer loops to obtain an updated meta-learning model based on width learning and attention mechanism; Input the test set into the updated meta-learning model based on width learning and attention mechanism, analyze the output results of the meta-learning model based on width learning and attention mechanism and draw a curve to obtain the classification accuracy of the small image; The width learning module increases the width in the following ways: Increasing the width of the hidden layer: Improving the expressive power of the meta-learning model based on width learning and attention mechanism by increasing the number of neurons in the hidden layer; Adding additional input connections: Connecting input features directly to multiple hidden layers enables meta-learning models based on width learning and attention mechanisms to better utilize input features; In a neural network, the number of neurons in the hidden layer determines the width of the corresponding network layer. Increasing the number of neurons in the hidden layer improves the expressive power of the meta-learning model based on width learning and attention mechanisms, enabling the meta-learning model based on width learning and attention mechanisms to capture more complex feature relationships. Directly connecting input features to multiple hidden layers serves the following purposes: Defining additional connections: In a neural network, in addition to the normal forward propagation path, adding direct connections from the input layer to multiple hidden layers; Modify the forward propagation: During the forward propagation process, the input features are merged with the output of the hidden layer; The width learning module includes a first hidden layer and a second hidden layer, wherein the first hidden layer includes a first fully connected layer and a first ReLU activation function; the second hidden layer includes a second fully connected layer and a second ReLU activation function; Among them, the first fully connected layer maps the input features to the hidden layer and outputs features with a dimension of hidden_dim * 2; The first layer ReLU activation function is used to enhance nonlinear expression capabilities; The width of the second fully connected layer remains unchanged, and the output dimension is still hidden_dim * 2; The second layer ReLU activation function is used to further enhance the nonlinear expression ability.

2. The small sample image classification method according to claim 1, characterized in that: The meta-learning framework is implemented using the Model-Agnostic Meta-Learning algorithm. The Model-Agnostic Meta-Learning algorithm optimizes the initial parameters of the meta-learning model based on width learning and attention mechanism by training on multiple few-shot tasks, enabling the meta-learning model based on width learning and attention mechanism to quickly adapt to new tasks.

3. The small sample image classification method according to claim 1, characterized in that: The inner loop is used to achieve fast parameter updates of the meta-learning model based on width learning and attention mechanism through the support set; specifically: Initialize fast parameters: copy the current parameters of the meta-learning model based on width learning and attention mechanism into fast parameters fast_weights; the fast parameters fast_weights include the parameters of the width learning module and the parameters of the multi-head attention mechanism module; the parameters of the width learning module include the weights and biases of the network layer; the parameters of the multi-head attention mechanism module include the weights and biases of the query, key, value and output; Multiple rapid updates: perform several rapid parameter updates on the support set; After multiple rapid updates, the meta-learning model based on width learning and attention mechanism completes rapid adaptation on the support set; at this time, the fast parameter fast_weights has been optimized according to the task characteristics of the support set; in the inner loop, the parameters of the width learning module are dynamically adjusted through rapid parameter updates, so that the meta-learning model based on width learning and attention mechanism can dynamically adjust the width of the hidden layer according to the task characteristics of the support set, so that the meta-learning model based on width learning and attention mechanism can better adapt to the current task; at the same time, the parameters of the multi-head attention mechanism module are dynamically adjusted through rapid parameter updates, so that the meta-learning model based on width learning and attention mechanism can dynamically adjust the importance of features according to the task characteristics of the support set, so that the meta-learning model based on width learning and attention mechanism can focus more on features that are more helpful to the task.

4. The small sample image classification method according to claim 3, characterized in that: When multiple quick updates are performed, the details of each update are as follows: Replace parameters: Replace the parameters of the meta-learning model based on width learning and attention mechanism with the fast parameter fast_weights; Forward propagation: Use the support set data support_x for forward propagation and calculate the predicted value support_pred; Calculate loss: Use the cross entropy loss function to calculate the loss support_loss on the support set; Calculate gradients: Calculate the gradient of loss through automatic differentiation; Update fast parameters: Update fast parameters fast_weights according to the meta learning rate meta_lr.

5. The small sample image classification method according to claim 1, characterized in that: The outer loop is used to optimize the initial parameters of the meta-learning model based on width learning and attention mechanism, so that the meta-learning model based on width learning and attention mechanism performs better on multiple tasks; the details are as follows: Replace parameters: Replace the parameters of the meta-learning model based on width learning and attention mechanism with the fast parameters fast_weights after inner loop optimization; Query set verification: Use query set data query_x and query_y for forward propagation and calculate the predicted value query_pred; Calculate the query set loss: Use the cross entropy loss function to calculate the loss query_loss on the query set; Backpropagation and parameter update: Backpropagate the query set loss query_loss, calculate the gradient, and use the optimizer to update the initial parameters of the meta-learning model based on width learning and attention mechanism; After the optimization of the outer loop, the initial parameters of the meta-learning model based on width learning and attention mechanism are updated. By optimizing the initial parameters of the meta-learning model based on width learning and attention mechanism, the meta-learning model based on width learning and attention mechanism can converge quickly on multiple tasks, including not only the parameters of the width learning module and the multi-head attention mechanism module, but also the initial parameters of the entire meta-learning model based on width learning and attention mechanism.

6. The small sample image classification method according to claim 1, characterized in that: The forward propagation of the width learning module is expressed as follows: ; ; ; in, Indicates the input feature vector, the dimension is input_dim; Represents the output of the first hidden layer, with a dimension of hidden_dim * 2; Represents the output of the second hidden layer, with a dimension of hidden_dim * 2; It is the final output of the meta-learning model based on width learning and attention mechanism, with dimension output_dim; and are the weights and biases of the first hidden layer respectively; and are the weights and biases of the second hidden layer respectively; and are the weights and biases of the meta-learning framework respectively; The multi-head attention mechanism module is represented as follows: ; in, Represent the query, key, and value matrices respectively; represents the dimension of the key vector; softmax represents the normalization function so that each element of the output is between 0 and 1 and the sum is 1; the multi-head attention mechanism module is used to enhance the importance adjustment of features, and the formula is as follows: ; ; ; ; in, , , Represent the weight matrices of the multi-head attention mechanism modules respectively; , , Represent the bias vector of the multi-head attention mechanism module; the output of the multi-head attention mechanism module Used for output layer calculation.

7. An electronic device, characterized in that: include: memory and at least one processor; Wherein, the memory stores a computer program; The at least one processor executes the computer program stored in the memory, so that the at least one processor performs the small sample image classification method according to any one of claims 1 to 6.

8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which can be executed by a processor to implement the small sample image classification method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Fabric defect image classification method based on deep learning

    CN119048802A

  • Method of and system for joint data augmentation and classification learning

    US20210241041A1