A single-class image recognition method based on multi-hyper-sphere space division
By using a multi-hypersphere spatial partitioning and threshold radius judgment method, the problem of low accuracy in single-class image recognition on small sample datasets is solved, achieving efficient single-class image recognition, which is suitable for single-class image recognition tasks on small sample datasets.
Patent Information
- Application Number
- CN202310455204.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-25
- Publication Date
- 2025-11-07
- Estimated Expiration
- 2043-04-25
AI Technical Summary
Existing single-class image recognition methods have poor accuracy on small sample datasets and do not consider the distribution shape of positive samples in the feature space, resulting in unsatisfactory recognition results.
A multi-hypersphere spatial partitioning method is adopted, and the samples are mapped to the latent space through a feature extraction network. A threshold radius is introduced to determine whether the test sample is within the multi-hypersphere. A loss function is designed in combination with meta-learning method to optimize the feature extraction network and the radius.
It improves the prediction accuracy for unlearned samples, balances the prediction of positive and negative samples, and enhances recognition efficiency, making it suitable for single-class image recognition tasks with small sample datasets.
Smart Images

Figure CN116310593B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to a single-class image recognition method based on multi-hyper-sphere space division, and belongs to the technical field of image recognition and machine learning. BACKGROUND
[0002] At present, when performing image recognition tasks by using machine learning algorithms, most algorithms can only divide a test image sample into pre-learned categories, but cannot determine whether the test sample is a category that has not been learned.
[0003] Single-class image classification problem refers to learning a data set containing only target class samples, and then determining whether a sample that has not been learned belongs to the category during testing. The image sample used for testing may belong to the target category or other categories. Samples belonging to the target category are called positive samples, and samples not belonging to the category are called negative samples. In the case of only giving positive samples during training, many problems such as anomaly detection and face recognition belong to the single-class classification category. Single-class image recognition technology has wide application in the fields of medicine and industry.
[0004] With the continuous development of deep neural networks, convolutional neural networks and other technologies, the single-class image recognition method based on deep learning has greatly improved the effect on large data sets compared with traditional methods. However, the existing methods still perform poorly on small sample data sets. In recent years, researchers have gradually proposed single-class classification algorithms based on small samples. For example, A. Kruspe proposed combining the negative sample class center assumption method with the prototype network. First, the feature is extracted by a deep network, and the coordinate origin is used as the class center of the negative sample in the feature space. Then, the mean of each positive sample in the feature space is calculated as the class center of the positive sample. Finally, the distance between the test sample and the two class centers is calculated to predict the category of the test sample. G. Dahia et al. proposed using a hyper-sphere as the positive sample space in the feature space, and then learning the feature extraction by meta-learning. This method finds the smallest hyper-sphere that can include all positive samples as the positive sample space. For a test sample, if the deep network mapped by meta-learning is in the hyper-sphere, the sample is a positive sample, otherwise it is predicted as a negative sample.
[0005] However, the existing single-class image recognition methods do not consider whether the distribution shape of the positive samples in the feature space is reasonable. The existing technology only considers representing positive samples and negative samples by class centers, where the distribution of positive samples in the feature space is a hyper-sphere or a certain side region of a hyperplane, and does not study more complex space division. SUMMARY
[0006] The present application aims at the defects and deficiencies existing in the prior art, and creatively proposes a single-class image recognition method based on multi-super sphere space division, in order to effectively solve the technical problems such as accuracy rate for single-class image recognition.
[0007] The innovation points of the present application include: first, mapping the sample to a latent space through a feature extraction network, and then classifying and recognizing the test image sample according to the similarity of the training sample and the test sample in the space.
[0008] The key point of the present application is: how to determine whether the test sample is close enough to the nearest training sample without other class samples. For this purpose, the present application proposes that the feature of a test sample obtained after being calculated by the feature extraction network is within a certain range of the nearest training set positive sample, and then the model predicts the test sample as a positive sample. The threshold radius is introduced to determine whether the test sample is close enough to the nearest neighbor training sample. Therefore, the representation of the target class in the feature space is a space formed by the superposition of multiple super sphere regions, and the threshold value is used as the radius of each super sphere. If the feature of a test sample is within the space range formed by the multiple super spheres, it is predicted as a positive sample; otherwise, it is predicted as a negative sample.
[0009] In order to achieve the ideal technical effect when the above method is used for single-class image recognition, the present application further proposes a meta-learning method of feature extraction network and radius based on the above single-class image recognition method and a design method of loss function. The meta-learning needs to learn an additional data set unrelated to the target task, which is called meta-training set. The data set used for testing the classification effect is called meta-test set.
[0010] Advantages
[0011] Compared with the prior art, the method of the present application has the following advantages:
[0012] 1. The prediction accuracy of the test image sample (sample not appearing in learning) is obviously improved.
[0013] 2. The prediction of positive samples and negative samples in the test image sample is more balanced.
[0014] 3. After learning the feature extraction network and the radius, a new single-class image recognition task can be recognized without optimizing the deep network, thereby greatly improving the execution efficiency. BRIEF DESCRIPTION OF DRAWINGS
[0015] Figure 1 is a positive sample representation method based on multi-super sphere distribution in the method of the present application.
[0016] Figure 2is a flow chart of the training method of the feature extraction network weight and radius in the method of the present application.
[0017] Figure 3 is a flow chart of the method of the present application for identifying test samples. DETAILED DESCRIPTION
[0018] The method of the present application will be described in detail below in combination with the drawings and examples.
[0019] The method of the present application adopts the following technical solutions.
[0020] A single-class image recognition method based on multi-super sphere space division, comprising the following steps:
[0021] Step 1: unify the format of all image data, so that the length, width and number of channels remain consistent.
[0022] Step 2: initialize the parameters θ and radius r of the feature extraction network.
[0023] Step 3: randomly form a single-class image recognition task in the meta-training set. Each single-class image recognition task contains a training set D train and a test set D test , wherein the data of the training set are from one class.
[0024] Step 4: input the training samples and test samples into the feature extraction network to obtain the features.
[0025] Specifically, the feature extraction network f θ is expressed as: f θ : R n → R m , θ is the parameter of the network, R n represents that the input of the data is a vector with a dimension of n, and R m represents that the output of the network is a vector with a dimension of m.
[0026] For a sample x, the feature obtained after calculation by the feature extraction network is denoted as f θ (x).
[0027] Step 5: calculate the similarity distance of each training sample and the test sample.
[0028] Specifically, the Euclidean distance can be used to calculate the similarity distance d of two samples in the feature space:
[0029]
[0030] wherein a1 and a2 are two vectors with a dimension of m, and a (i)denotes the i-th item of vector a, m denotes the dimension.
[0031] Calculate the similarity distance d(f q (x θ ), f θ (x q )) between the test sample x q and each training sample x train . train .
[0032] Step 6: Select the similarity distance of the test sample to its nearest neighbor training sample, that is, the smallest similarity distance d q :
[0033]
[0034] where D train denotes the training set.
[0035] Step 7: Calculate the loss.
[0036] Specifically, the loss function L is as follows:
[0037] L(x q ) = max(0, Y x (r - d q )) (3)
[0038] where r is the radius, L(x q ) is the final loss; Y = -1 indicates that x q is a positive sample, and Y = 1 indicates that x q is a negative sample.
[0039] Step 8: Optimize the parameters θ of the feature extraction network and the radius r according to the loss L(x q ).
[0040] Step 9: Repeat steps 3 to 8 until the training is complete. At this point, the training process is completed, as shown in Figure 2 .
[0041] Step 10: Initialize the target single-class image recognition task.
[0042] Step 11: Input the training samples and test samples into the feature extraction network to obtain the features.
[0043] Step 12: Calculate the similarity distance d(f θ (x), f θ (x q )) between the test sample and each training sample according to formula 1.
[0044] Step 13: Select the minimum distance d in the similarity distance according to formula 2 q .
[0045] Step 14: Compare the minimum distance d q with the radius r. If the distance is less than or equal to the radius, the test data is divided into positive samples; if the distance is greater than the radius, the test data is divided into negative samples.
[0046] Specifically, the predicted label of the test data is calculated according to the following formula:
[0047]
[0048]
[0049] wherein, is the predicted result of sample x q , 0 represents a positive sample, and 1 represents a negative sample.
[0050] Up to now, the prediction of sample x q is completed.
[0051] Step 15: Output the predicted label of the test image sample to complete the recognition of the image. Up to now, the recognition of the test sample in a single-class image recognition task is completed, as shown in Figure 3 .
[0052] The above steps 1-9 are the training (meta-learning) part, and steps 10-15 are the part for recognizing a single-class image recognition task.
[0053] The core idea of the present application is that for a training set D train in a single-class image recognition task, each training sample x t forms a hypersphere The representation of the hypersphere formed by a training sample x t is: For a training set D train containing multiple training samples, the space N pos of positive samples is the union of these hyperspheres, represented as: The multi-hypersphere representation method is shown in Figure 1 .
[0054] Embodiment
[0055] This embodiment describes the specific implementation process of using the method described in the present application to perform 5-shot single-class image recognition test on the classic dataset miniImagenet.
[0056] The embodiment is divided into feature extraction network and radius learning, and the two links are tested on a single-class image recognition task.
[0057] First, the miniImagenet dataset selected in the embodiment is divided into three parts: meta-training set, meta-validation set, and meta-test set. Among them, the meta-training set is used to train the feature extraction network and the radius, the meta-validation set is used to verify the training effect, and the meta-test set is used to finally test the effect of the method.
[0058] The training, verification, and meta-test links all involve sampling of single-class image recognition tasks. Among them, during training, single-class image recognition task samples for learning of the feature extraction network and the radius are randomly sampled from the meta-training set; during testing and verification, single-class image recognition task samples for testing classification effect are sampled from the meta-test set and the meta-validation set, respectively.
[0059] The steps of sampling single-class image recognition task samples in a set are as follows:
[0060] Step A: Randomly select a class in the dataset as the target class.
[0061] Step B: Randomly select 5 different samples in the target class data of the dataset to form a training set.
[0062] Step C: Randomly select n samples different from the 5 samples in the training set in the target class data of the dataset.
[0063] Step D: Select n samples different from the target class in the dataset, and together with the samples selected in step C as a test set.
[0064] In the embodiment, n = 20, i.e. a single-class image recognition task test set contains 20 positive samples and 20 negative samples. The feature extraction network used in the embodiment selects Conv-4, which contains 4 convolutional layers, each containing 64 3*3 convolutional kernels. The optimizer of the feature extraction network selects Adam with a learning rate of 0.001; the optimizer of the radius selects SGD with a learning rate of 5. The embodiment is implemented using Python language, and the deep learning framework uses pytorch1.8.1.
[0065] In the embodiment, the specific implementation steps of training the feature extraction network and the radius are as follows:
[0066] Step 1: Initialize the parameters θ of the feature extraction network and the radius r.
[0067] Step 2: Uniform the format of the samples in the meta-training set, meta-validation set, and meta-test set, where the length is 84, the width is 84, and the number of channels is 3.
[0068] Step 3: Randomly form a single-class image recognition task in the meta-training set according to the method described above.
[0069] Step 4: Input the training samples and test samples of the task into the feature extraction network to obtain the features.
[0070] Step 5: Calculate the similarity distance between the test sample and each training sample.
[0071] Step 6: Select the smallest distance d q .
[0072] Step 7: Calculate the loss L(x q ) according to formula 3.
[0073] Step 8: Optimize the parameters θ and radius r of the feature extraction network according to the loss L(x q ).
[0074] Step 9: Repeat steps 3-8 for 100 times, i.e. perform 100 times of meta-training task learning, and save the network model parameters and radius.
[0075] Step 10: Randomly form a single-class classification task in the meta-validation set.
[0076] Step 11: Input the training samples and test samples into the feature extraction network to obtain the features f θ (x).
[0077] Step 12: Calculate the similarity distance d(f θ (x), f θ (x q )) between the test sample and each training sample.
[0078] Step 13: According to formula 1, obtain the similarity distance d q of the test sample to its nearest neighbor training sample.
[0079] Step 14: Compare the minimum distance d q with the radius r. If the distance is less than or equal to the radius, the test data is classified as positive sample; if the distance is greater than the radius, the test data is classified as negative sample.
[0080] Step 15: Repeat steps 10-15 for 500 times, and take the average value to obtain the result of the meta-validation set.
[0081] Step 16: Repeat steps 3-15 for 2000 times.
[0082] Step 17: Select the network model parameters and radius with the best performance of the validation set.
[0083] Further, the specific implementation steps of the single-class image recognition task test on the test set data are as follows:
[0084] Step 1: According to the method, randomly form a single-class classification task in the meta test set.
[0085] Step 2: Input the training samples and test samples into the feature extraction network to obtain the features.
[0086] Step 3: Calculate the similarity distance d(f θ (x),f θ (x q )) of the test sample and each training sample respectively.
[0087] Step 4: According to formula 1, obtain the similarity distance d q of the test sample to its nearest neighbor training sample.
[0088] Step 5: Compare the minimum distance d q with the radius r. If the distance is less than or equal to the radius, the test data is divided into positive samples; if the distance is greater than the radius, the test data is divided into negative samples.
[0089] Step 6: Repeat steps 1-5 10,000 times to obtain the performance of the test set, and the final accuracy is 74.19%. Among them, the accuracy of the positive samples is 77.46%, and the accuracy of the negative samples is 70.92%.
[0090] It should be noted that the above is one of the preferred embodiments of the present application, and the present application is not limited to the content disclosed in the embodiment. Without departing from the principles of the present application, several improvements can also be made, which should also be considered as falling within the scope of protection of the present application.
Claims
1. A single-class image recognition method based on multi-hyper-sphere space partitioning, characterized in that, Comprising the following steps: Step 1: unify the format of all image data, keep the length, width and the number of channels consistent; Step 2: initialize the parameters θ and radius r of the feature extraction network; Step 3: In the meta-training set, a single-class image recognition task is randomly formed; each single-class image recognition task contains a training set D train and a test set D test , wherein the data of the training set are from one category; Step 4: input the training samples and test samples into the feature extraction network to obtain the features; Feature extraction network f θ is denoted as: f θ : R n → R m , θ are parameters of the network, R n denotes that the input of the data is a vector of dimension n, R m denotes that the output of the network is a vector of dimension m; For a sample x, the feature f obtained after computing through the feature extraction network is denoted as f θ (i); Step 5: calculate the similarity distance of the test sample and each training sample respectively; Calculate the test sample x respectively q The similarity distance d(f) with each training sample θ (x), f θ (x q ), where x q Let x represent the test sample and x represent the training set D. train A sample, x∈D train ; Step 6: Select the test sample distance to its nearest neighbor training sample, i.e., the smallest similarity distance d q : wherein D train denotes the training set; Step 7: calculate the loss; The loss function L is as follows: L(x q ) = max(0, Y x (r - d q )) (3) where r is the radius, L(x q ) is the final loss; Y = -1 indicates that x q is a positive sample, and Y = 1 indicates that x q is a negative sample; Step 8: The parameters θ of the feature extraction network and the radius r are optimized according to the loss L(x q ) Step 9: repeat steps 3 to 8 until the training is completed; Step 10: initialize the target single-class image recognition task; Step 11: input the training samples and test samples into the feature extraction network to obtain the features; Step 12: Calculate the similarity distance d(f θ (x), f θ (x q )) between the test sample and each training sample respectively. Step 13: Select the smallest distance d in the similarity distances q ; Step 14: compare the minimum distance d q with the radius r; if the distance is less than or equal to the radius, then the test data is classified as a positive sample; if the distance is greater than the radius, then the test data is classified as a negative sample; Step 15: outputting the predicted label for the test image sample The recognition of the image is completed.
2. The single category image recognition method based on multi-hyper-sphere space division of claim 1, wherein, In step 5, the Euclidean distance is used to calculate the similarity distance d of two samples in the feature space: where a1, a2are two m-dimensional vectors, a (i) denotes the i-th item of vector a, m denotes the dimension.
3. The single category image recognition method based on multi-hyper-sphere space division of claim 1, wherein, In step 14, the predicted label of the test data is calculated according to the following formula: wherein, is the prediction result for the sample x q 0 indicates a positive sample and 1 indicates a negative sample.
Citation Information
Patent Citations
A method of kinship identification based on angle loss neural network
CN109344759A
Infrared image recognition method based on transfer learning and storage medium
CN112215296A