A small-shot learning method with dynamic randomness enhancement based on smaller loss
By adopting a small-sample learning method with enhanced dynamic randomness in the neural network, combined with pre-training and fine-tuned ternary network training, the problem of insufficient information in data samples is solved and the classification and generalization capabilities of the model are improved.
Patent Information
- Application Number
- CN202111429857.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-29
- Publication Date
- 2024-10-01
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
When the neural network model faces insufficient inherent information in data samples, it cannot fully learn the inherent distribution differences contained in the data set, resulting in a decline in the model's classification ability during prediction.
A small-sample learning method based on dynamic randomness enhancement with smaller loss is used. By selecting an appropriate base enhancement method to form an enhancement strategy, data enhancement is performed, and the ternary network is trained using pre-training + fine-tuning, combined with momentum update. and stochastic gradient descent to update network parameters and dynamically adjust the enhancement strategy to reduce losses.
It effectively alleviates the problem that the parameter distribution of the model is close to 0 when the sample is small, enhances the generalization ability of the model, and explores the best sample enhancement method through the dynamic random data enhancement method to improve the classification performance of the model.
Smart Images

Figure CN114429570B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of small sample learning in deep learning, and in particular to a small sample learning method based on dynamic randomness enhancement with smaller loss. Background Art
[0002] Through various experiences and knowledge in life, we find that each category has a similar distribution, and different categories do have differences. For example, in the classification of cat and dog pictures, from the perspective of geometric distribution, the samples belonging to the cat category generally have similar textures. The texture and other geometric features in the samples belonging to the cat category constitute the appearance distribution of the cat. The convolutional neural network can extract the texture features in the image through operations such as convolution. The neural network model will learn to maximize the difference between the distribution of cats and dogs through gradient descent or other methods. When the sample data is sufficient, the distribution of cats and dogs in the sample is very close to the real distribution in nature. Therefore, when taking pictures of cats and dogs in nature for prediction, their distribution is likely to fall into the distribution learned by the model. When the data samples are small, the distribution of cats and dogs learned by the neural network model is far from the real distribution of cats and dogs in nature. Therefore, when predicting, the distribution of cats and dogs in the test set pictures is different from the distribution learned by the model, which will cause the model classification to decline. Therefore, we hope that the information distribution contained in the samples in the data set is as rich as possible.
[0003] In 1948, Shannon extended the concept of entropy in statistical physics to the process of channel communication, thus creating the discipline of "information theory". The "entropy" defined by Shannon is also called "Shannon entropy" or "information entropy", that is, p represents the probability of occurrence of a sample. For samples with equal probability distribution, the larger the number of samples, the larger the entropy value, which is generally more beneficial to model training. Therefore, for a long-tail data set, its entropy value will be smaller than the entropy of a data set with uniform distribution of each category, resulting in a slightly weaker classification ability of the model. The maximum entropy principle is a criterion for learning probability models. The maximum entropy principle holds that when learning a probability model, the model with the largest entropy among all possible probability model distributions is the best model. In information theory and probability statistics, entropy is a measure of uncertainty of a random variable. It can be proved that the larger the entropy, the greater the uncertainty of the random variable. When the probabilities in entropy and conditional entropy are obtained by data estimation (especially maximum likelihood estimation), the corresponding entropy and conditional entropy become empirical entropy and empirical conditional entropy respectively.
[0004] The problem with small sample learning is that first, when the number of samples decreases, the randomness of sample features decreases, that is, entropy decreases. In this case, the empirical risk minimization replaced by the expected risk will have a large estimation bias due to the small number of samples, and the final model accuracy will have certain problems. Therefore, a large data set with strong randomness (large information entropy) is an important factor in ensuring a good classification model. Secondly, when the ternary network model accepts three extremely similar pictures in the same category, the SGD stochastic gradient descent will make the distribution of the three-way network parameters extremely similar; and when the ternary network model accepts pictures in different categories, for example, the feature vectors h1 and h2 extracted by fθ1 and fθ2 need to be 0 when calculating the similarity. Since the number of categories in small sample learning is often greater than the number of samples in the same category, the SGD stochastic gradient descent will make the distribution of the two-way network parameters fθ1 and fθ2 close to 0, making it difficult to train. Therefore, by updating the parameter fθ2 with momentum, it can be similar to but not the same as the distribution of fθ1 and fθ3, which can effectively avoid the distribution of model parameters close to 0. Therefore, in order to enable the neural network model to fully learn the features in the dataset, a small sample learning method based on dynamic randomness enhancement with smaller loss is proposed.
[0005] Patent CN112949717A discloses a data enhancement method, training method, device and electronic device. This method adds data features to the original sample data and inputs it into the autoencoder model to output new sample data, thereby enhancing the original training set, thereby increasing the sample size and sample information of the original sample data, thereby solving the problem of insufficient sample size and facilitating training of a neural network model that meets the requirements. The key to this data enhancement method is that it is difficult for a single autoencoder model to dynamically adjust the autoencoder model to enhance these data sets when faced with many different data sets.
[0006] Patent CN112651892A establishes a data enhancement strategy search space, sets N data transformation operations, and each image transformation operation is performed with a probability value P, and then input into the deep learning neural network model for further training. This method does not dynamically adjust the set values of N and P according to the training results of the neural network model, so the amount of calculation is relatively small, and the resource consumption is also small, which solves the problem of insufficient samples to a certain extent. Since the N and P values have been set before training, the samples added to the data set are executed according to a certain rule, lacking the randomness generated by network training, and it is impossible to judge whether the samples generated by this rule just conform to the distribution of this category in nature. Summary of the invention
[0007] The purpose of the present invention is to solve the problem that when a neural network model is faced with insufficient intrinsic information in a data sample, the model cannot fully learn the intrinsic distribution differences contained in the data set. A small sample learning method based on dynamic randomness enhancement with smaller loss is provided.
[0008] The object of the present invention is achieved in that:
[0009] A small sample learning method based on dynamic randomness enhancement with smaller loss, comprising the following steps:
[0010] Step 1: Select some appropriate base enhancement methods bi, combine these enhancement methods into an enhancement strategy Φ, set the same initial probability p for each base enhancement method and the usage ratio ui of each base enhancement method, where p, ui∈(0,1);
[0011] Step 2: Divide the dataset D into training samples Dtrain and test samples Dtest. Dtrain contains the support set and the query set. Select two base augmentation methods b with the highest probability from Φ. i With b j , with probability p i 、p j , the Supportset in the labeled Dtrain is augmented to obtain the augmented data set (AugmentSet), hereinafter referred to as A-set. In each iteration, C categories are selected from the training categories, and K samples are selected from C to form C-way K-shot learning;
[0012] Step 3: The training method is pre-trained + fine-tuned. The ternary network is used to receive images from the Support set, Query set, and A-set respectively, and feature vectors h1, h2, and h3 are obtained after extracting features. If these images have the same category, the label yi is set to 1, otherwise it is set to 0;
[0013] Step 4: Calculate the cosine values of feature vectors h1 and h2, h2 and h3 respectively, and record the difference between their cosine values and the absolute value of the label yi as loss. The average loss of h1 and h2 of a batch is recorded as l1, and the average loss of h2 and h3 is recorded as l2;
[0014] Step 5: Let l1-l2=d, d is the loss difference, α is the scaling factor of the loss difference, P r A correction factor representing the probability and usage ratio of the basis enhancement method;
[0015] Step 6: The network that extracts the feature vector h2 uses momentum to update the network parameters fθ2. The network with the smaller loss in the other two networks is updated using stochastic gradient descent (SGD), and the other network directly copies the parameters updated by SGD.
[0016] Furthermore, the step 1 is specifically as follows: image enhancement methods such as flipping, cropping, translation, and scaling in geometric transformations are selected as base enhancement methods, and the initial probability and usage ratio of each base enhancement method are set to 0.5. In order to avoid complete equality and increase randomness, random enhancement noise is added before applying the enhanced sample, where the usage ratio as the probability needs to be multiplied by the batch size to determine the number of enhanced images.
[0017] Furthermore, the step 2 is specifically as follows: the labeled samples in the data set are used as the samples Dtrain for model training, the Support set is randomly enhanced using the random basis enhancement method described in the previous paragraph to obtain A-Set, and then the training samples are randomly shuffled. In each iteration, a total of C*K samples are selected from the training samples and combined with the images in the Query Set and A-set into small sets, and then these sets are combined into a Batch.
[0018] Furthermore, the step 3 is specifically as follows: using ResNet or its variant trained on ImageNet as a pre-training model, cloning ResNet and dividing it into two paths, ResNet_Q and ResNet_A, to form a ternary network. The images in A-set and Support set in Dtrain are continuously combined with Query set to form small sets. If they are of the same type, the label yi is 1, such as {image1Support, image2Query, image3A-set, 1}, otherwise the fourth item is 0. Because A-set is enhanced by Support set, they are the same type of images in a set. It is only necessary to determine whether they are of the same type as the images in Query set.
[0019] Furthermore, step 4 is specifically as follows: first, perform L2 regularization on the feature vector, then calculate the cosine values of the feature vectors h1 and h2, and h2 and h3 respectively, and record the difference between the respective cosine values and the absolute value of the label yi as loss. The loss of h1 and h2 of a batch is averaged as l1, and the loss of h2 and h3 is averaged as l2.
[0020] Furthermore, the step 5 is specifically as follows: let l1-l2=d, Adjust the scaling factor α so that -p max<tanh(αd)<p max , where p max is the maximum value of the current probability of a base enhancement method in the enhancement strategy Φ. r The probability p of the two largest base enhancement methods in the enhancement strategy Φ i With p j Make corrections and also use the ratio u i with u j Make corrections.
[0021] Furthermore, step 6 is specifically as follows: compare the size of l1 and l2 in a batch, and select the network model with smaller loss as the training model for the next batch. Therefore, SGD stochastic gradient descent is used to update the parameters of the ResNet or ResNet_A network with smaller loss. As the epoch increases, different learning rates lr are set to try to find the best loss value L; the ResNet_Q network uses momentum to update the network parameters.
[0022] Compared with the prior art, the present invention has the following beneficial effects:
[0023] (1) The invention adopts the Pre-trained + Fine-tune model training method. By training the network on the basis of a large sample, the randomness is extremely strong and the information entropy contained is extremely large, so that the deep neural network model can learn sufficient general features and generalize. Only corresponding fine-tuning is needed to obtain a model with better results.
[0024] (2) The present invention uses momentum update to make the parameter fθ2 of the ternary network model similar to but not identical to fθ1 and fθ3, which can effectively alleviate the problem that the model parameters are largely zero when processing small samples.
[0025] (3) The present invention adds enhanced samples A-set through a dynamic random data enhancement method, thereby adding randomness to the data set. However, these random features do not all conform to the real feature distribution in nature, which will interfere with model training. Therefore, the present invention selects a ResNet or ResNet_A model with smaller loss to explore the probability of the best sample enhancement method and the proportion of sample usage as much as possible. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 It is a training set partition diagram of the present invention;
[0027] Figure 2 is a model training graph of the present invention;
[0028] Figure 3 This is a training flow chart of the present invention. DETAILED DESCRIPTION
[0029] The present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments.
[0030] See also Figure 1-3 As shown, an embodiment of the present application provides a small sample learning method based on dynamic randomness enhancement with smaller loss, which is specifically implemented according to the following steps.
[0031] Step 1: Select some appropriate base enhancement methods bi, combine these enhancement methods into an enhancement strategy dictionary Φ, set the same initial probability p for each base enhancement method and the usage ratio ui of each base enhancement method, where p, ui∈(0,1);
[0032] Specifically:
[0033] Select appropriate base enhancement methods bi and combine them into an enhancement strategy dictionary Φ. The initial probability and usage ratio of each base enhancement method are set to 0.5. Here, we take the cropping, scaling and Mix-up base enhancement methods as examples, so we have
[0034] Φ = ["'The first item is the enhancement method, the second item is the probability of selecting this method to enhance the sample, and the third item is the proportion of samples in a Batch to be enhanced'"
[0035] ('crop',p=0.5,u=0.5),
[0036] ('scale',p=0.5,u=0.5),
[0037] ˙˙˙˙˙˙
[0038] ('mix-up',p=0.5,u=0.5)]
[0039] Before enhancing the sample, in order to increase the randomness of the base enhancement method, we choose to add normal distribution random noise, (p,u) = (p,u) + Noise normal-distribution In order to make the description clearer and simpler, different types of basis enhancement methods are put into one enhancement strategy Φ. In practical applications, different types of basis enhancement methods should be classified into different enhancement strategies Φi.
[0040] Step 2: Divide the dataset D into training samples Dtrain and test samples Dtest, and select two base enhancement methods p with the highest probability from Φ i With p j, the training data (Support Set) in the labeled Dtrain is augmented to obtain the Augment Set. In each iteration, C categories are selected from the training categories, and K samples are selected from C to form C-wayK-shot learning;
[0041] Specifically:
[0042] After passing through the normal distribution random noise, sort by the probability of each basis augmentation method, select the two basis augmentation methods with the largest p, and perform data augmentation on the Support Set in Dtrain to obtain A-Set. Set the epoch size, and you can also set the epoch cutoff value according to the specific loss value. Randomly shuffle the training samples. In each iteration, select C categories from the training categories, and then select K samples from C. A total of C*K samples are selected to combine with the images in the Query set and A-set into a Batch.
[0043] Step 3: The training method is Pre-trained+Fine-tune. The ternary network is used to receive images from the Support set, Query set, and A-set respectively, and feature vectors h1, h2, and h3 are obtained after extracting features. If these images have the same category, the label yi is set to 1, otherwise it is set to 0;
[0044] Specifically:
[0045] Use ResNet or its variants trained on ImageNet as the pre-trained image classification model, clone ResNet into three paths to form a ternary network, and clone ResNet_Q and ResNet_A to extract features from the Query set and A-set images respectively. The images in A-set and Query set in Dtrain are continuously combined with Support set to form small sets. If they are of the same type, the label is 1, for example (image1Support, image2Query, image3A-set, 1), otherwise the fourth item is 0. Because A-set is enhanced by Support set, they are the same type of images. You only need to determine whether they are of the same type as the images in the query set.
[0046] Step 4: Calculate the cosine values of feature vectors h1 and h2, and h2 and h3 respectively, and record the difference between their cosine values and the absolute value of the label yi as loss. The average loss of h1 and h2 of the entire batch is recorded as l1, and the average loss of h2 and h3 is recorded as l2.
[0047] Specifically:
[0048] During training, two base enhancement methods are generally selected for each enhancement, with probabilities p and i With p j , which is more conducive to model learning from experience. Of course, multiple base enhancement methods can be set for each enhancement. Perform L2 regularization on the feature vectors h1, h2, and h3 extracted by the ternary network, calculate the cosine values of the feature vectors h1 and h2, and h2 and h3 respectively, and record the difference between the respective cosine values and the absolute value of the label yi as loss. The average loss of h1 and h2 in a batch is recorded as l1, and the average loss of h2 and h3 is recorded as l2. For example Then calculate
[0049] Step 5: Let l1-l2=d. d is the loss difference, α is the scaling factor of the loss difference, P r The correction factor representing the probability and usage ratio of the basis enhancement method;
[0050] Specifically:
[0051] Let l1-l2=d, Since the image distribution may vary greatly in actual classification scenarios, before applying the enhancement method, you can first check the specific loss size of several batches, and then generate a list α = [α1, α i ,······,α n ], so that -p max <tanh(αd)<p max ,in This can avoid the dynamic probability changes of the basis enhancement method being too drastic. max is the maximum probability of a base enhancement method in the enhancement strategy Φ. d is the loss difference, α is the scaling factor of the loss difference, P r The probability and usage ratio correction factor of the base enhancement method are represented here. In order to make the patent more concise and easy to use, only P is used. r The basis augmentation method uses probability p i With p j And usage ratio u i with u j To make corrections, of course, P r As the base number, construct a new usage ratio correction factor to correct the usage ratio in different proportions. In order to ensure the effectiveness of the base augmentation method training, the probability and usage ratio of the base augmentation method are dynamically corrected every v epochs. If the sample base number is large enough, the interval unit epoch can be replaced by Batch.
[0052] Proof P r And an idea to enhance the convergence of strategy Φ:
[0053] In v epochs, assuming that some base enhancement methods bi are effective in improving the classification ability of the model, then the model training loss l1 without effective enhancement method processing will be greater than the model training loss l2 with effective enhancement method processing, so at the beginning, the correction factor However, by selecting a model with a smaller training loss, the training model of the next Batch will inherit this capability, and l1-l2 will be further reduced, so the correction factor P r will also decrease until convergence. On the contrary, due to the correction factor P r is negative, p i,j =p i,j +P r , then the probability of the base enhancement method will decrease, and the next time when choosing according to the probability size, the invalid enhancement method will be eliminated. Therefore, the probability and usage ratio of the random enhancement strategy Φ will converge with the increase of epochs. Note that the validity condition of this proof is that in v epochs, a base enhancement method bi is effective in improving the classification ability of the model. Due to the wide variety of real classification scenarios, there will definitely be local batches that are difficult to meet the conditions, resulting in the correction factor P r The oscillation also causes the enhancement strategy Φ to fail to converge, which requires P r Add a regular term to suppress its violent oscillation.
[0054] Step 6: The network that extracts the feature vector h2 uses momentum to update the network parameters fθ1. The network with the smaller loss in the other two networks is updated using stochastic gradient descent (SGD), and the other network directly copies the parameters updated by SGD.
[0055] Specifically:
[0056] Compare the size of l1 and l2 in a batch, and select the network model with smaller loss as the training model for the next batch. Use SGD stochastic gradient descent to update the ResNet or ResNet_A network parameters fθ1 or fθ3 with smaller loss. As the epoch increases, set different learning rates lr to try to find the best loss value L; ResNet_Q network uses momentum to update the network parameters of this path, specifically f θ2 =mf θ2 +(1-m)f θ1 or θ2 =mf θ2 +(1-m)f θ3Where m is the momentum coefficient (Momentum), and its general value is (0.9, 0.999).
[0057] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the various parameter values in the embodiments of the present invention can be arbitrarily replaced and matched. Without departing from the principles of the present application, any modifications, equivalent substitutions, embellishments, etc. made should be included in the protection scope of the present invention.
Claims
1. A small sample learning method based on dynamic randomness enhancement with smaller loss, characterized by: The following steps are involved: Step 1: Select some appropriate base enhancement methods bi, combine these enhancement methods into an enhancement strategy Φ, set the same initial probability p for each base enhancement method and the usage ratio ui of each base enhancement method, where p, ui∈(0,1); Step 2: Divide the dataset D into training samples Dtrain and test samples Dtest, where Dtrain contains the support set and the query set; select two basis augmentation methods b with the highest probability from Φ i With b j , with probability p i 、p j , the Supportset in the labeled Dtrain is augmented to obtain an augmented data set (AugmentSet), hereinafter referred to as A-set; in each iteration, C categories are selected from the training categories, and then K samples are selected from C to form C-way K-shot learning; Step 3: The training method adopts pre-training (Pre-trained) + fine-tuning (Fine-tune). Use the ternary network to receive pictures from the Support set, Query set and A-set respectively, extract features and obtain feature vectors h1, h2 and h3; if these pictures have the same category, set the label yi to 1, otherwise it is 0; Step 4: Calculate the cosine values of feature vectors h1 and h2, h2 and h3 respectively, and record the difference between their cosine values and the absolute value of the label yi as loss; take the average loss of h1 and h2 of a batch as l1, and the average loss of h2 and h3 as l2; Step 5: Let l1-l2=d, d is the loss difference, α is the scaling factor of the loss difference, P r A correction factor representing the probability and usage ratio of the basis enhancement method; Step 6: The network that extracts the feature vector h2 uses momentum to update the network parameters fθ2. The network with the smaller loss in the other two networks is updated using stochastic gradient descent (SGD), and the other network directly copies the parameters updated by SGD.
2. The small sample learning method based on dynamic randomness enhancement with smaller loss according to claim 1 is characterized in that: The step 1 is specifically as follows: selecting flipping, cropping, translation, and scaling image enhancement methods in geometric transformation as base enhancement methods, and setting the initial probability and usage ratio of each base enhancement method to 0.
5. In order to avoid complete equality and increase randomness, random enhancement noise is added before applying the enhanced sample, and the usage ratio as the probability needs to be multiplied by the batch size to determine the number of enhanced images.
3. The small sample learning method based on dynamic randomness enhancement with smaller loss according to claim 2 is characterized by: The step 2 is specifically as follows: the samples annotated in the data set are used as the samples Dtrain for model training, the support set is randomly enhanced by the base enhancement method to obtain A-Set, and the training samples are randomly shuffled. In each iteration, C*K samples are selected from the training samples and combined with the pictures in the query set and A-set into small sets, and these sets are then combined into a batch.
4. The small sample learning method based on dynamic randomness enhancement with smaller loss according to claim 1 is characterized by: The step 3 is specifically as follows: using ResNet or its variant trained on ImageNet as a pre-training model, cloning ResNet and dividing it into two paths, ResNet_Q and ResNet_A, to form a ternary network; continuously combining the images in A-set and Support set in Dtrain with the Query set to form small sets, if they are of the same type, the label yi is 1, such as {image1Support, image2Query, image3A-set, 1}, otherwise the fourth item is 0; because A-set is enhanced by Support set, they are the same type of images in a set, and it is only necessary to determine whether they are of the same type as the images in Queryset.
5. The small sample learning method based on dynamic randomness enhancement with smaller loss according to claim 1 is characterized by: The step 4 is specifically as follows: first, perform L2 regularization on the feature vector, then calculate the cosine values of the feature vectors h1 and h2, and h2 and h3 respectively, and record the difference between each cosine value and the absolute value of the label yi as loss; take the average loss of h1 and h2 of a batch as l1, and take the average loss of h2 and h3 as l2.
6. The small sample learning method based on dynamic randomness enhancement with smaller loss according to claim 1 is characterized by: The step 5 is specifically as follows: let l1-l2=d, Adjust the scaling factor α so that -p max <tanh(αd)<p max , where p max is the maximum value of the current probability of a base enhancement method in the enhancement strategy Φ; use P r The probability p of the two largest base enhancement methods in the enhancement strategy Φ i With p j Make corrections and also use the ratio u i with u j Make corrections.
7. The small sample learning method based on dynamic randomness enhancement with smaller loss according to claim 1 is characterized by: The step 6 is specifically as follows: compare the sizes of l1 and l2 in a Batch, and select the network model with a smaller loss as the training model for the next Batch; therefore, use SGD stochastic gradient descent to update the parameters of the ResNet or ResNet_A network with a smaller loss; as the epoch increases, set different learning rates lr to try to find the best loss value L; the ResNet_Q network uses momentum to update the network parameters of this path.
