Open-world semi-supervised image classification method based on dual spatial contrastive learning
By using dual spatial contrastive learning in open-world semi-supervised image classification, combined with self-supervised learning and graph-guided learning in feature space and prediction space, the problem of insufficient supervisory information and unused complementary attributes is solved, and the representation of unlabeled data is improved. capabilities and labeling accuracy.
Patent Information
- Application Number
- CN202410034242.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-10
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2044-01-10
AI Technical Summary
Existing open-world semi-supervised image classification methods suffer from poor performance due to insufficient utilization of supervisory information in the prediction space and unutilized complementary attributes of dual spaces.
Using a method based on dual spatial contrastive learning, through self-supervised contrastive learning and space-guided contrastive learning of feature space and prediction space, graph structure information is mined to achieve information fusion and efficient utilization between feature space and prediction space.
It improves the representation ability and labeling accuracy of the network model for unlabeled data, alleviates the problem of insufficient supervision information in the prediction space, and improves the fusion efficiency of heterogeneous information.
Smart Images

Figure CN118196548B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image recognition, and in particular to an open-world semi-supervised image classification method based on dual space contrast learning. Background Art
[0002] In recent years, deep learning technology has made great progress in the field of computer vision. However, most deep learning models still require a large amount of high-quality labeled data, which is time-consuming and expensive to obtain. To overcome this limitation, researchers have extensively studied semi-supervised image classification methods, which make full use of a large amount of unlabeled data to reduce the need for manual annotation, and have attracted widespread attention from research and industry.
[0003] Although some progress has been made in the research of semi-supervised image classification methods, their application is still limited by the environment, where the categories of unlabeled samples are pre-defined and unchanged. In real-world scenarios, the category distribution of unlabeled samples usually does not match that of labeled samples. Studying the semi-supervised image classification problem in the open world has important practical significance.
[0004] Under the open set hypothesis, the image dataset consists of a limited number of labeled images with known categories and a large number of unlabeled images with broader categories. The categories that appear in the labeled dataset are called old categories, and the categories that do not exist in the labeled dataset but appear in the unlabeled set are called new categories. The ultimate goal of open-world semi-supervised classification is to not only distinguish known old categories, but also cluster samples in new categories, thereby providing reasonable labeling suggestions for unlabeled samples. Compared with traditional semi-supervised labeling methods, the core difficulty of this method lies in capturing the characteristics of new class samples in the absence of supervision.
[0005] Existing research has successfully applied contrastive learning to open-world semi-supervised learning, such as GCD and OpenCon. These methods integrate the contrastive learning process into semi-supervised learning, which is beneficial for learning separable and semantically unique representations of unlabeled data, thereby facilitating accurate labeling of these data. However, there are still two key issues that have not been resolved, resulting in poor performance:
[0006] 1) Insufficient utilization of the prediction space. Previous studies have focused on learning compact representations in the feature space without further exploring the prediction space. These methods typically use prototype learning to generate classification predictions and update the prototypes based on the k-means clustering criterion. However, this process is one-way, resulting in the optimization in the prediction space being unable to directly affect the feature space through gradient propagation, thus affecting the final result.
[0007] 2) Ignoring the complementary properties of dual spaces. In fact, exploiting the correlation between samples can significantly improve the performance of open-world semi-supervised learning. However, current methods are usually limited to extracting sample correlations in a single space, such as in feature space or prediction space, and we find that the common approach of constructing sample associations in two spaces may lead to heterogeneity. Summary of the invention
[0008] The technical problem to be solved by the present invention is to provide an open-world semi-supervised image classification method based on dual space contrastive learning, introduce self-supervised contrastive learning in feature space and prediction space, and utilize the complementary information in feature space and prediction space to propose spatial guided contrastive learning between feature space and prediction space, mine the graph structure information of one space and let it guide the learning of representation of another space, thereby realizing the fusion and efficient utilization of heterogeneous information, improving the representation ability of the network model for unlabeled data, and thus improving the labeling accuracy of unlabeled data.
[0009] The present invention is achieved through the following technical solutions:
[0010] An open-world semi-supervised image classification method based on dual spatial contrastive learning includes the following steps:
[0011] S1: Organize the image dataset to be labeled, divide the labeled samples in the image dataset to be labeled into the labeled dataset, divide the unlabeled samples in the image dataset to be labeled into the unlabeled dataset, and initialize the network model;
[0012] S2: construct a feature graph according to the correlation of all samples in the image data set to be labeled in the feature space, and construct a prediction graph according to the correlation of all samples in the image data set to be labeled in the prediction space;
[0013] S3: using the labeled data set and the unlabeled data set in step S1 and the feature map and the prediction map in step S2 to perform dual spatial contrast iterative learning training on the initialized network model in step S1, calculate the supervision loss, the feature space self-supervised contrast loss, the prediction space self-supervised contrast loss and the spatial guided contrast loss between the feature space and the prediction space, and perform weighted summation of the supervision loss, the feature space self-supervised contrast loss, the prediction space self-supervised contrast loss and the spatial guided contrast loss between the feature space and the prediction space to obtain the overall loss, and then perform gradient backpropagation on the network model and update the network model parameters according to the overall loss;
[0014] S4: Repeat the iteration steps S2 to S3, and determine whether the set number of iterations has been reached. If the set number of iterations has been reached, the trained network model is obtained and the next step is entered;
[0015] S5: Use the network model trained in step S4 to infer each unlabeled sample in the unlabeled data set in step S1 to obtain the predicted labeling result of each unlabeled sample.
[0016] Furthermore, in step S2, a feature map is constructed as follows:
[0017] S21: Screening of connected sample pairs: for each unlabeled sample in the unlabeled data set, collect the sample with the nearest neighbor feature vector in the feature space, and connect the sample with the nearest neighbor feature vector with the unlabeled sample in the feature map to form a connected sample pair of the unlabeled sample; for each labeled sample in the labeled data set, randomly select a labeled sample with the same label as the labeled sample and connect it with the labeled sample in the feature map to form a connected sample pair of the labeled sample;
[0018] S22: Screening of disconnected sample pairs: All samples in the image data set to be labeled are paired into sample pairs, and then the feature vector cosine similarity between each sample pair is calculated, and the feature vector cosine similarity is compared with a set threshold. If the feature vector cosine similarity is less than the set threshold, the sample pair is a disconnected sample pair in the feature map;
[0019] S23: Define sample pairs other than connected sample pairs of unlabeled samples, connected sample pairs of labeled samples, and disconnected sample pairs as having unknown association in the feature graph.
[0020] Further, in step S2, a prediction graph is constructed as follows:
[0021] S24: Estimate the category of unlabeled samples in the unlabeled data set according to the category corresponding to the maximum value of the prediction vector, and select samples in the unlabeled sample category whose confidence is higher than the confidence setting value and meets the preset proportion coefficient to form a high-quality unlabeled data set, and the remaining unlabeled samples to form a low-quality unlabeled data set;
[0022] S25: For each sample in the high-quality unlabeled dataset, the category corresponding to the maximum value of the prediction vector is defined as the pseudo label of the sample, and the pseudo label of the sample in the low-quality unlabeled dataset is defined as unknown;
[0023] S26: Construct a prediction graph for all samples in the labeled image dataset. For any two samples, if at least one of the samples belongs to a low-quality unlabeled dataset, the relationship between the two samples is defined as unknown in the prediction graph. If both samples belong to a high-quality unlabeled dataset or a labeled dataset, continue to determine whether the pseudo-labels or labels of the two samples are of the same category. If they are of the same category, the two samples are connected in the prediction graph. If they are not of the same category, they are not connected in the prediction graph.
[0024] Optimally, the preset proportionality coefficient in step S24 increases gradually as the number of iterations increases.
[0025] Further, the method for calculating the overall loss in step S3 includes the following steps:
[0026] S31: Sampling the samples in the labeled data set and the unlabeled data set in step S1 in batches, and performing augmentation operations on the image data in the sampled batches to obtain weak augmented images and strong augmented images;
[0027] S32: for the weakly augmented image and the strongly augmented image, a weakly augmented feature vector, a strongly augmented feature vector, a weakly augmented prediction vector and a strongly augmented prediction vector are obtained through a deep backbone network model and a classifier, and the weakly augmented feature vector and the strongly augmented feature vector are sorted into a feature set according to the sampling batches, and the weakly augmented prediction vector and the strongly augmented prediction vector are sorted into a prediction set according to the sampling batches;
[0028] S33: Calculate the supervision loss according to the formula of the supervision objective function;
[0029] S34: Feature space self-supervised contrastive learning: The weakly augmented feature vectors and the strongly augmented feature vectors in the feature set are mapped to weakly augmented projection vectors and strong augmented projection vectors, and the weakly augmented projection vectors and the strong augmented projection vectors form a projection vector set. The projection vectors in the projection vector set are subjected to contrastive learning. The strong augmented projection vectors and the weak augmented projection vectors are regarded as two different representations of the same sample under different augmentations and are substituted into the contrast loss function to obtain the feature space self-supervised contrast loss.
[0030] S35: Prediction space self-supervised contrast learning: The weak augmented prediction vectors in the prediction set are stacked in a row vector manner to form a weak augmented prediction matrix, and the strong augmented prediction vectors in the prediction set are stacked in a row vector manner to form a strong augmented prediction matrix, and then the weak augmented prediction matrix is decomposed into weak augmented prediction column vectors along the column direction, and the strong augmented prediction matrix is decomposed into strong augmented prediction column vectors along the column direction, and the weak augmented prediction column vectors and the strong augmented prediction column vectors are formed into a prediction column vector set, and then the prediction column vectors in the prediction column vector set are contrastively learned, and the strong augmented prediction column vectors and the weak augmented prediction column vectors are regarded as two different representations under different augmentations and substituted into the contrast loss function to obtain the contrast loss of the prediction column vector, and then all the weak augmented prediction vectors and strong augmented prediction vectors in the batch are averaged respectively to obtain the entropy of the weak augmented prediction vector and the entropy of the strong augmented prediction vector, and the two entropy values are added as the entropy loss, and finally the contrast loss of the prediction column vector is subtracted from the entropy loss to obtain the prediction space self-supervised contrast loss;
[0031] S36: Spatial Guided Contrastive Learning: Calculate the total guided contrastive loss from prediction space to feature space by graph-guided contrastive learning from prediction space to feature space, and then calculate the guided contrastive loss from feature space to prediction space by graph-guided contrastive learning from feature space to prediction space;
[0032] S37: Calculate the overall loss by summing up the supervised loss of step S33, the feature space self-supervised contrast loss of step S34, the prediction space self-supervised contrast loss of step S35, the total guided contrast loss from the prediction space to the feature space of step S36, and the total guided contrast loss from the feature space to the prediction space.
[0033] Further, the graph-guided contrastive learning method from the prediction space to the feature space in step S36 is as follows:
[0034] S361: Concentrate the features with The features associated with the weakly augmented feature vector or the strongly augmented feature vector of the sample in the prediction graph are collected into the corresponding positively associated feature set, and the features associated with the first The weakly augmented feature vectors or strongly augmented feature vectors of the samples that do not generate correlation features in the prediction graph are collected into the corresponding negative correlation feature set, and the union of the corresponding positive correlation feature set and the negative correlation feature set is formed into the corresponding positive and negative correlation feature set;
[0035] S362: Calculate the The guided contrast loss of the weakly augmented feature vector of the sample from the prediction space to the feature space is calculated according to formula (2) The guided contrast loss of the strongly augmented feature vector of samples from the prediction space to the feature space is:
[0036] (1);
[0037] (2);
[0038] in: Indicates the feature set The eigenvector corresponding to the weakly augmented samples is: express Guided contrastive loss from prediction space to feature space, represents the total sampling batch value, express The positive correlation feature set of express The positive and negative correlation feature set, Indicates belonging to All feature vectors of the positively correlated feature set, Indicates belonging to All feature vectors of the positive and negative correlation feature set, Indicates the feature set The strongly augmented eigenvector of samples, express Guided contrastive loss from prediction space to feature space, express The positive correlation feature set of express The positive and negative correlation feature set, Indicates belonging to All feature vectors of the positively correlated feature set, Indicates belonging to All feature vectors of the positive and negative correlation feature set;
[0039] S363: Calculate the total guided contrast loss from the prediction space to the feature space according to formula (3) :
[0040] (3).
[0041] Furthermore, the guided contrastive learning method from feature space to prediction space is as follows:
[0042] S364: Focus the prediction on The features associated with the weakly augmented prediction vector or the strongly augmented prediction vector of the sample in the feature map are collected into the corresponding positively associated prediction set, and the prediction set is combined with the first The weakly augmented prediction vectors or strongly augmented prediction vectors of the samples that do not generate associated features in the feature graph are collected into the corresponding negatively associated prediction set, and the union of the corresponding positively associated prediction set and the negatively associated prediction set is formed into the corresponding positively and negatively associated prediction set;
[0043] S365: Calculate the The guided contrast loss of the weakly augmented prediction vector of the sample from the feature space to the prediction space is calculated according to formula (5). The guided contrast loss of the strongly augmented prediction vector of samples from feature space to prediction space is:
[0044] (4);
[0045] (5);
[0046] in: Indicates the prediction set The weakly augmented prediction vector of samples, express Guided contrastive loss from feature space to prediction space, express The positive correlation prediction set, express The positive and negative correlation prediction set, Indicates belonging to All prediction vectors of the positively associated prediction set, Indicates belonging to All prediction vectors of the positive and negative correlation prediction set, Indicates the prediction set The strongly augmented prediction vector of samples, express Guided contrastive loss from feature space to prediction space, express The positive correlation prediction set, express The positive and negative correlation prediction set, Indicates belonging to All prediction vectors of the positively associated prediction set, Indicates belonging to All prediction vectors of the positive and negative correlation prediction set;
[0047] S366: Calculate the total guided contrast loss from feature space to prediction space according to formula (6) :
[0048] (6).
[0049] Furthermore, in step S3, the overall loss is calculated according to formula (7): :
[0050] (7);
[0051] in: represents the supervision loss, represents the feature space self-supervised contrast loss, represents the prediction space self-supervised contrastive loss.
[0052] Beneficial effects of the invention:
[0053] The present invention innovatively constructs an open-world semi-supervised image classification method based on dual-space contrastive learning. The core of the method is to apply a contrastive learning paradigm to the feature space and the prediction space, specifically including intra-space self-supervised contrastive learning of the feature space and the prediction space and graph-guided contrastive learning between the feature space and the prediction space. The intra-space self-supervised contrastive learning uses self-supervised learning methods in both the feature space and the prediction space, which can alleviate the problem of insufficient supervision information in the prediction space; the graph-guided contrastive learning between the feature space and the prediction space mines the graph structure information of one space and allows it to guide the learning of the representation of another space, thereby improving the expression ability of the network model, thereby realizing the fusion and efficient utilization of heterogeneous information in the two spaces, improving the representation ability of the network model for unlabeled data and improving the labeling accuracy of unlabeled data. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 It is a schematic diagram of the process of the present invention. DETAILED DESCRIPTION
[0055] Open-world semi-supervised image classification method based on dual spatial contrast learning, the flowchart is as follows Figure 1 As shown, the specific steps include:
[0056] S1: Organize the image dataset to be labeled, divide the labeled samples in the image dataset to be labeled into the labeled dataset, divide the unlabeled samples in the image dataset to be labeled into the unlabeled dataset, and initialize the network model. Specifically, a deep backbone network model and a classifier can be introduced. The backbone network can use the residual neural network ResNet18, and use the parameters pre-trained by SimCLR to initialize the parameters of the deep backbone network model. The classifier is a normalized linear classifier, which stores the category center vectors of all categories, and the total number of classification categories is set to the total number of categories contained in the dataset to be labeled. Since there are unknown categories in the labeled dataset in the unlabeled dataset, the total number of categories is greater than the number of categories in the labeled dataset, which is generally estimated by experience.
[0057] S2: construct a feature map according to the correlation of all samples in the image data set to be labeled in the feature space, and construct a prediction map according to the correlation of all samples in the image data set to be labeled in the prediction space; when constructing the feature map and the prediction map, the deep backbone network model and classifier in step S1 can be used to first calculate the feature vectors and prediction vectors for all samples in the image data set to be labeled, and then the feature map and the prediction map are constructed according to the correlation between these features and prediction vectors to construct the connection between different samples in the feature space and the prediction space; for the prediction map, a progressive learning mode can be used to compose the map, and for the feature map, the cosine similarity between samples in the feature space can be referred to for composition.
[0058] Specifically, the feature map and prediction map can be constructed as follows:
[0059] Construction of feature map:
[0060] The goal of feature graph mining is to discover the local structural information between feature vectors. In previous studies, a classic graph construction method is to find the nearest neighbor feature vectors in the intrinsic feature space of the batch for the feature vectors of all unlabeled samples in each sampling batch, and define their corresponding samples to be connected in the graph. However, due to the limited search space, the reliability of the edges will be greatly limited. In order to improve the quality of the graph, this paper introduces the nearest neighbor information of the feature vectors in the entire data set, rather than the nearest neighbor information of the feature vectors in each batch. The specific method is as follows:
[0061] S21: Screening of connected sample pairs: for each unlabeled sample in the unlabeled data set, collect the sample with the nearest neighbor feature vector in the feature space, and connect the sample with the nearest neighbor feature vector with the unlabeled sample in the feature map to form a connected sample pair of the unlabeled sample; for each labeled sample in the labeled data set, randomly select a labeled sample with the same label as the labeled sample and connect it with the labeled sample in the feature map to form a connected sample pair of the labeled sample;
[0062] S22: Screening of disconnected sample pairs: All samples in the image data set to be labeled are paired into sample pairs, and then the feature vector cosine similarity between each sample pair is calculated, and the feature vector cosine similarity is compared with the set threshold. If the feature vector cosine similarity is less than the set threshold, the sample pair is a disconnected sample pair in the feature map. The set threshold here can be estimated as a binary threshold using the Otsu threshold estimation method;
[0063] S23: Define sample pairs other than connected sample pairs of unlabeled samples, connected sample pairs of labeled samples, and disconnected sample pairs as having unknown association in the feature graph.
[0064] Construction of prediction graph:
[0065] The prediction graph is a graph that determines whether there is an edge between two samples based on the prediction of the samples. It can effectively capture the global community information of samples classified into the same category. First, a part of high-confidence samples can be screened out. The confidence represents the maximum value in the prediction vector of the sample, which represents the credibility of the prediction vector. Then, the category corresponding to the maximum value of the prediction vector of these samples is recorded as a pseudo-label, and then whether there is an edge between them is determined based on whether the categories of their pseudo-labels are the same.
[0066] The general screening method is to use a fixed threshold to screen the confidence of each sample, that is, the maximum value of the prediction vector. However, related work has shown that in the early stage of training, even samples with high confidence may be assigned incorrect pseudo-labels. In order to improve the accuracy of pseudo-label assignment, a progressive screening paradigm can be used to select pseudo-labels. The specific method of constructing the prediction graph is as follows:
[0067] S24: Estimate the category of unlabeled samples in the unlabeled dataset according to the category corresponding to the maximum value of the prediction vector, and select the samples in the unlabeled sample category whose confidence is higher than the confidence setting value and meets the preset proportional coefficient to form a high-quality unlabeled dataset, and the remaining unlabeled samples form a low-quality unlabeled dataset; specifically, select samples in each sample category, sort them from high to low according to confidence, and then screen out the samples that are within a certain preset proportional coefficient range and whose confidence is higher than the confidence setting value to form a high-quality unlabeled dataset.
[0068] The preset proportional coefficient here gradually increases with the increase in the number of iteration rounds. Specifically, the preset proportional coefficient can start from 0 and can be gradually increased by 0.1 every 20 rounds. The confidence setting value can be set to 0.9.
[0069] S25: For each sample in the high-quality unlabeled dataset, the category corresponding to the maximum value of the prediction vector is defined as the pseudo label of the sample, and the pseudo label of the sample in the low-quality unlabeled dataset is defined as unknown;
[0070] S26: Construct a prediction graph for all samples in the labeled image dataset. For any two samples, if at least one of the samples belongs to a low-quality unlabeled dataset, the relationship between the two samples is defined as unknown in the prediction graph. If both samples belong to a high-quality unlabeled dataset or a labeled dataset, continue to determine whether the pseudo-labels or labels of the two samples are of the same category. If they are of the same category, the two samples are connected in the prediction graph. If they are not of the same category, they are not connected in the prediction graph.
[0071] S3: using the labeled data set and the unlabeled data set in step S1 and the feature map and the prediction map in step S2 to perform dual spatial contrast iterative learning training on the initialized network model in step S1, calculate the supervision loss, the feature space self-supervised contrast loss, the prediction space self-supervised contrast loss and the spatial guided contrast loss between the feature space and the prediction space, and perform weighted summation of the supervision loss, the feature space self-supervised contrast loss, the prediction space self-supervised contrast loss and the spatial guided contrast loss between the feature space and the prediction space to obtain the overall loss, and then perform gradient backpropagation on the network model and update the network model parameters according to the overall loss;
[0072] The specific method for calculating the overall loss includes the following steps:
[0073] S31: Sample the samples in the labeled data set and the unlabeled data set in step S1 in batches, and perform augmentation operations on the image data in the sampled batches to obtain weak augmented images and strong augmented images. The sample sampling batch size of the labeled data set can be 128, and the sample sampling batch size of the unlabeled data set is 384, and the total batch size is 512. Weak augmentation represents a small degree of transformation of the original image, which usually does not change the basic features of the image, while strong augmentation represents a large degree of transformation of the original image, which usually changes some basic features of the image. Weak augmentation can use random cropping and random flipping functions, while strong augmentation can use random cropping, random flipping, random brightness contrast adjustment, random exposure and random equalization functions.
[0074] S32: for the weakly augmented image and the strongly augmented image, a weakly augmented feature vector, a strongly augmented feature vector, a weakly augmented prediction vector and a strongly augmented prediction vector are obtained through a deep backbone network model and a classifier, and the weakly augmented feature vector and the strongly augmented feature vector are sorted into a feature set according to the sampling batches, and the weakly augmented prediction vector and the strongly augmented prediction vector are sorted into a prediction set according to the sampling batches;
[0075] Specifically, the weakly augmented image and the strongly augmented image can first be obtained through the deep backbone network model to obtain the weakly augmented feature vector and the strongly augmented feature vector, and then the weakly augmented prediction vector and the strongly augmented prediction vector are obtained through the classifier. The classifier includes the center vectors of all classification categories. When the classifier is used to calculate the prediction vector, the cosine similarity between the feature vector of the sample and the center vector of each category in the classifier is calculated. The obtained similarity is divided by the temperature coefficient and then passed through a standard flexible maximum transfer function (SoftMax) function to obtain the corresponding sample prediction vector. Each element in the prediction vector corresponds to a classification category, and its meaning represents the probability that this sample belongs to this category. In the example of the present invention, the temperature coefficient can be set to 0.1.
[0076] S33: Calculate the supervised loss according to the formula of the supervised objective function; In semi-supervised image classification, it is crucial to use labeled data. The classic supervised loss function is usually the cross entropy function, which is only applied to labeled data. In open-world semi-supervised image classification, the categories to which images in the labeled dataset belong are collectively referred to as old categories, while images in the unlabeled dataset may belong to new categories that are different from any old classes, collectively referred to as new classes. Since the labeled data only contains known old classes, training using only the cross entropy function may lead to an imbalance between the old and new categories. Therefore, we can use a supervised objective function with an uncertainty adaptive mechanism to alleviate the problem of training imbalance. The supervised objective function introduces an adaptive uncertainty margin mechanism to block the training of old classes to reduce the deviation in the degree of training between old and new classes.
[0077] The formula of the supervision objective function is shown in formula (8):
[0078] (8);
[0079] in: represents the supervision loss, Indicates the total number of classification categories, represents the temperature coefficient, Indicates the sample number, Representative The labels of samples, Indicates The label category number of each sample, Indicates the first The normalized class center vector of the class, Indicates that except for Other label category numbers other than the class, Indicates the first The class center vector of the class, Representative feature set The eigenvector corresponding to the weakly augmented samples is: represents the batch size of labeled samples, Uncertainty, uncertainty It is 1 minus the average confidence of all unlabeled samples. In the early stage of training, due to incomplete training, the confidence is low, so the uncertainty is high. At this time, the uncertainty will hinder the training of old classes. In the later stage of training, the uncertainty will gradually decrease, and the supervision objective function will gradually degenerate into a general cross entropy function.
[0080] S34: Feature space self-supervised contrastive learning: The weakly augmented feature vectors and the strongly augmented feature vectors in the feature set are mapped to weakly augmented projection vectors and strong augmented projection vectors, and the weakly augmented projection vectors and the strong augmented projection vectors form a projection vector set. The projection vectors in the projection vector set are subjected to contrastive learning. The strong augmented projection vectors and the weak augmented projection vectors are regarded as two different representations of the same sample under different augmentations and are substituted into the contrast loss function to obtain the feature space self-supervised contrast loss.
[0081] Specifically, the weakly augmented feature vectors and strongly augmented feature vectors in the feature set can be mapped to weakly augmented projection vectors and strongly augmented projection vectors respectively through an additional two-layer multilayer perceptron (MLP), and the projection vectors can be trained by comparative learning, which can improve the quality of learned features and enhance the discriminability of feature vectors.
[0082] Specifically, we can use formula (9) to calculate The feature space self-supervised contrast loss of the weakly augmented feature vector of the sample is calculated according to formula (10) The feature space self-supervised contrast loss of the strongly augmented feature vector of samples is calculated according to formula (11):
[0083] (9);
[0084] (10);
[0085] (11);
[0086] in: represents the inner product, B represents the total sampling batch size, Indicates The weakly augmented projection vector of samples, No. The strongly augmented projection vector of samples, Represents a set of projection vectors The projection vector of Represents the sequence number of the vector in the projection vector set, Indicates The feature space self-supervised contrastive loss of the weakly augmented feature vector of samples, Indicates The feature space self-supervised contrastive loss of the strongly augmented feature vector of samples, represents the feature space self-supervised contrastive loss.
[0087] S35: Prediction space self-supervised contrast learning: The weak augmented prediction vectors in the prediction set are stacked in a row vector manner to form a weak augmented prediction matrix, and the strong augmented prediction vectors in the prediction set are stacked in a row vector manner to form a strong augmented prediction matrix, and then the weak augmented prediction matrix is decomposed into weak augmented prediction column vectors along the column direction, and the strong augmented prediction matrix is decomposed into strong augmented prediction column vectors along the column direction, and the weak augmented prediction column vectors and the strong augmented prediction column vectors are formed into a prediction column vector set, and then the prediction column vectors in the prediction column vector set are contrastively learned, and the strong augmented prediction column vectors and the weak augmented prediction column vectors are regarded as two different representations under different augmentations and substituted into the contrast loss function to obtain the contrast loss of the prediction column vector, and then all the weak augmented prediction vectors and strong augmented prediction vectors in the batch are averaged respectively to obtain the entropy of the weak augmented prediction vector and the entropy of the strong augmented prediction vector, and the two entropy values are added as the entropy loss, and finally the contrast loss of the prediction column vector is subtracted from the entropy loss to obtain the prediction space self-supervised contrast loss;
[0088] Each weak augmented prediction column vector corresponds to a category and records the probability values of all weak augmented prediction vectors in the batch in that category. Each strong augmented prediction column vector also corresponds to a category and records the probability values of all strong augmented prediction vectors in the batch in that category. Since each sample belongs to only one unique category, the goal we introduced is to maximize the similarity between column vectors of the same category under different augmentations, while minimizing the similarity between column vectors of different categories, so that different categories are far away from each other and produce sharper predictions. The prediction vectors are averaged and then the negative entropy loss is calculated to prevent the promotion of balance between different categories.
[0089] Specifically, we can calculate the The prediction space self-supervised contrast loss of the weakly augmented prediction column vector is calculated according to formula (13) Self-supervised contrastive loss in the prediction space of a strongly augmented prediction column vector:
[0090] The prediction space self-supervised contrast loss is calculated according to formula (14):
[0091] (12);
[0092] (13);
[0093] (14);
[0094] in: Indicates weakly augmented prediction column vector, Indicates A strongly augmented prediction column vector, Represents a set of prediction column vectors The prediction column vector of Represents the sequence number of the vector in the projection vector set, represents entropy loss.
[0095] S36: Spatial Guided Contrastive Learning: Calculate the total guided contrastive loss from prediction space to feature space by graph-guided contrastive learning from prediction space to feature space, and then calculate the guided contrastive loss from feature space to prediction space by graph-guided contrastive learning from feature space to prediction space;
[0096] S37: Calculate the overall loss by summing up the supervised loss of step S33, the feature space self-supervised contrast loss of step S34, the prediction space self-supervised contrast loss of step S35, the total guided contrast loss from the prediction space to the feature space of step S36, and the total guided contrast loss from the feature space to the prediction space.
[0097] Further, the graph-guided contrastive learning method from the prediction space to the feature space in step S36 is as follows:
[0098] S361: Concentrate the features with The features associated with the weakly augmented feature vector or the strongly augmented feature vector of the sample in the prediction graph are collected into the corresponding positively associated feature set, and the features associated with the first The weakly augmented feature vectors or strongly augmented feature vectors of the samples that are not associated in the prediction graph are collected into the corresponding negatively associated feature set, and the union of the corresponding positively associated feature set and the negatively associated feature set is used to form the corresponding positively and negatively associated feature set; since the information provided by the samples with unknown association is not reliable enough, the samples with unknown association in the prediction graph are not included in the prediction graph. The weakly augmented feature vectors or strongly augmented feature vectors of the samples with unknown correlation are processed, which is beneficial to the subsequent learning process.
[0099] S362: Calculate the The guided contrast loss of the weakly augmented feature vector of the sample from the prediction space to the feature space is calculated according to formula (2) The guided contrast loss of the strongly augmented feature vector of samples from the prediction space to the feature space is:
[0100] (1);
[0101] (2);
[0102] in: Indicates the first feature set The eigenvector corresponding to the weakly augmented samples is: express Guided contrastive loss from prediction space to feature space, represents the total sampling batch value, express The positive correlation feature set of express The positive and negative correlation feature set, Indicates belonging to All feature vectors of the positively correlated feature set, Indicates belonging to All feature vectors of the positive and negative correlation feature set, Indicates the feature set The strongly augmented eigenvector of samples, express Guided contrastive loss from prediction space to feature space, express The positive correlation feature set of express The positive and negative correlation feature set, Indicates belonging to All feature vectors of the positively correlated feature set, Indicates belonging to All feature vectors of the positive and negative correlation feature set;
[0103] S363: Calculate the total guided contrast loss from the prediction space to the feature space according to formula (3) :
[0104] (3).
[0105] Graph-guided contrastive learning from prediction space to feature space aims to make full use of the global community graph structure information in the prediction graph. It can pull the features of adjacent samples in the prediction graph together and push the features of non-adjacent samples apart. , Therefore, in the calculation of guided contrast loss from prediction space to feature space, no processing is done on sample pairs whose relationships are defined as unknown in the prediction graph. This is because the relationship between these samples is not clear. Separating them out is to prevent the influx of erroneous information caused by hasty supervision of their relationship, thereby improving the network model’s ability to represent unlabeled data and improving the labeling accuracy of unlabeled data.
[0106] Furthermore, the guided contrastive learning method from feature space to prediction space is as follows:
[0107] S364: Focus the prediction on The features associated with the weakly augmented prediction vector or the strongly augmented prediction vector of the sample in the feature map are collected into the corresponding positively associated prediction set, and the prediction set is combined with the first The weakly augmented prediction vector or the strongly augmented prediction vector of the sample that does not generate correlation in the feature graph is collected into the corresponding negative correlation prediction set, and the union of the corresponding positive correlation prediction set and the negative correlation prediction set is formed into the corresponding positive and negative correlation prediction set; since the information that can be provided by the sample pair with unknown correlation is not reliable enough, therefore, the sample pair with the first correlation in the feature graph is not included in the prediction set. The weakly augmented prediction vector of each sample or the prediction of the strong augmented prediction vector with unknown correlation is processed, which is beneficial to the subsequent learning process.
[0108] S365: Calculate the The guided contrast loss of the weakly augmented prediction vector of the sample from the feature space to the prediction space is calculated according to formula (5). The guided contrast loss of the strongly augmented prediction vector of samples from feature space to prediction space is:
[0109] (4);
[0110] (5);
[0111] in: Indicates the prediction set The weakly augmented prediction vector of samples, express Guided contrastive loss from feature space to prediction space, express The positive correlation prediction set, express The positive and negative correlation prediction set, Indicates belonging to All prediction vectors of the positively associated prediction set, Indicates belonging to All prediction vectors of the positive and negative correlation prediction set, Indicates the prediction set The strongly augmented prediction vector of samples, express Guided contrastive loss from feature space to prediction space, express The positive correlation prediction set, express The positive and negative correlation prediction set, Indicates belonging to All prediction vectors of the positively associated prediction set, Indicates belonging to All prediction vectors of the positive and negative correlation prediction set;
[0112] S366: Calculate the total guided contrast loss from feature space to prediction space according to formula (6) :
[0113] (6).
[0114] Graph-guided contrastive learning from feature space to prediction space aims to exploit the local community graph structure information in the feature graph. , Therefore, in the calculation of guided contrast loss from feature space to prediction space, no processing is done on sample pairs whose relationships are defined as unknown correlation in the feature graph. This is because the relationship between these samples is not clear. Separating them out is to prevent the influx of erroneous information caused by hasty supervision of their relationship, thereby improving the network model’s ability to represent unlabeled data and improving the labeling accuracy of unlabeled data.
[0115] Furthermore, in step S3, the overall loss is calculated according to formula (7): :
[0116] (7);
[0117] in: represents the supervision loss, represents the feature space self-supervised contrast loss, represents the prediction space self-supervised contrastive loss.
[0118] Formula (7) is equivalent to calculating the overall loss When , each loss is multiplied by a weight, , , , The weights of are all 1, and The weight is 2, and the specific weight can be determined based on experience or parameter adjustment results.
[0119] S4: Repeat the iteration steps S2 to S3, and determine whether the set number of iterations has been reached. If the set number of iterations has been reached, the trained network model is obtained and the next step is entered;
[0120] S5: Use the network model trained in step S4 to infer each unlabeled sample in the unlabeled data set in step S1, and obtain the predicted labeling result of each unlabeled sample. Specifically, for each image in the unlabeled image data set, let it pass through the backbone network model to obtain features, then pass through the classifier to obtain the prediction vector, and finally obtain the predicted labeling result of each unlabeled sample according to the category corresponding to the maximum value of the prediction vector.
[0121] The open-world semi-supervised image classification method based on dual spatial contrastive learning provided by the present invention is verified by an example on a public dataset CIFAR100, that is, the dataset CIFAR100 is used as the image dataset to be labeled. CIFAR100 has a total of 100 categories, 50 of which are selected as old categories, and then 50% of the data from the old categories are sampled as the labeled dataset, and the remaining data is used as the unlabeled dataset. After training, three indicators are calculated for the unlabeled data:
[0122] New class accuracy: the clustering accuracy of the network model in the unlabeled dataset for samples whose actual labels are new classes;
[0123] Old class accuracy: the classification accuracy of the network model in the unlabeled dataset for samples whose actual labels are old classes;
[0124] All-category accuracy: The clustering accuracy of the network model for all samples in the unlabeled dataset.
[0125] Here, the categories to which images in the labeled dataset belong are collectively referred to as “old categories”. In an open-world environment, images in the unlabeled dataset may belong to new categories that are different from any old categories. These categories are collectively referred to as “new categories”.
[0126] The experimental results are shown in Table 1. In the comparison method, ORCA represents the uncertainty-based adaptive interval method, OpenCon represents the open world contrastive learning method, and GCD represents the general category mining method.
[0127] Table 1
[0128]
[0129] As can be seen from Table 1, the open-world semi-supervised image classification method based on dual spatial contrastive learning provided by the present invention has an improvement of 5.6%, 5.7% and 6.4% in the accuracy of new classes, old classes and all classes respectively compared with the most advanced method OpenCon.
[0130] In summary, the present invention provides an open-world semi-supervised image classification method based on dual space contrastive learning. Through self-supervised contrastive learning within the feature space and the prediction space and mutual guided contrastive learning between the feature space and the prediction space, the self-supervised contrastive learning within the space uses self-supervised learning methods in both the feature space and the prediction space, which can alleviate the problem of insufficient supervision information in the prediction space in previous work; the guided contrastive learning between spaces mines the graph structure information of one space and allows it to guide the learning of the representation of another space, thereby improving the expressive ability of the model, thereby realizing the fusion and efficient utilization of heterogeneous information in the two spaces, improving the representation ability of the network model for unlabeled data and improving the labeling accuracy of unlabeled data.
[0131] 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 present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. An open-world semi-supervised image classification method based on dual spatial contrastive learning, characterized by: The steps include: S1: Organize the image dataset to be labeled, divide the labeled samples in the image dataset to be labeled into the labeled dataset, divide the unlabeled samples in the image dataset to be labeled into the unlabeled dataset, and initialize the network model; S2: construct a feature graph according to the correlation of all samples in the image data set to be labeled in the feature space, and construct a prediction graph according to the correlation of all samples in the image data set to be labeled in the prediction space; S3: using the labeled data set and the unlabeled data set in step S1 and the feature map and the prediction map in step S2 to perform dual spatial contrast iterative learning training on the initialized network model in step S1, calculate the supervision loss, the feature space self-supervised contrast loss, the prediction space self-supervised contrast loss and the spatial guided contrast loss between the feature space and the prediction space, and perform weighted summation of the supervision loss, the feature space self-supervised contrast loss, the prediction space self-supervised contrast loss and the spatial guided contrast loss between the feature space and the prediction space to obtain the overall loss, and then perform gradient backpropagation on the network model and update the network model parameters according to the overall loss; The method for calculating the overall loss includes the following steps: S31: Sampling the samples in the labeled data set and the unlabeled data set in step S1 in batches, and performing augmentation operations on the image data in the sampled batches to obtain weak augmented images and strong augmented images; S32: for the weakly augmented image and the strongly augmented image, a weakly augmented feature vector, a strongly augmented feature vector, a weakly augmented prediction vector and a strongly augmented prediction vector are obtained through a deep backbone network model and a classifier, and the weakly augmented feature vector and the strongly augmented feature vector are sorted into a feature set according to the sampling batches, and the weakly augmented prediction vector and the strongly augmented prediction vector are sorted into a prediction set according to the sampling batches; S33: Calculate the supervision loss according to the formula of the supervision objective function; S34: Feature space self-supervised contrastive learning: The weakly augmented feature vectors and the strongly augmented feature vectors in the feature set are mapped to weakly augmented projection vectors and strong augmented projection vectors, and the weakly augmented projection vectors and the strong augmented projection vectors form a projection vector set. The projection vectors in the projection vector set are subjected to contrastive learning. The strong augmented projection vectors and the weak augmented projection vectors are regarded as two different representations of the same sample under different augmentations and are substituted into the contrast loss function to obtain the feature space self-supervised contrast loss. S35: Prediction space self-supervised contrast learning: The weak augmented prediction vectors in the prediction set are stacked in a row vector manner to form a weak augmented prediction matrix, and the strong augmented prediction vectors in the prediction set are stacked in a row vector manner to form a strong augmented prediction matrix, and then the weak augmented prediction matrix is decomposed into weak augmented prediction column vectors along the column direction, and the strong augmented prediction matrix is decomposed into strong augmented prediction column vectors along the column direction, and the weak augmented prediction column vectors and the strong augmented prediction column vectors are formed into a prediction column vector set, and then the prediction column vectors in the prediction column vector set are contrastively learned, and the strong augmented prediction column vectors and the weak augmented prediction column vectors are regarded as two different representations under different augmentations and substituted into the contrast loss function to obtain the contrast loss of the prediction column vector, and then all the weak augmented prediction vectors and strong augmented prediction vectors in the batch are averaged respectively to obtain the entropy of the weak augmented prediction vector and the entropy of the strong augmented prediction vector, and the two entropy values are added as the entropy loss, and finally the contrast loss of the prediction column vector is subtracted from the entropy loss to obtain the prediction space self-supervised contrast loss; S36: Spatial Guided Contrastive Learning: Calculate the total guided contrastive loss from prediction space to feature space by graph-guided contrastive learning from prediction space to feature space, and then calculate the guided contrastive loss from feature space to prediction space by graph-guided contrastive learning from feature space to prediction space; S37: Calculate the overall loss by summing the supervision loss of step S33, the feature space self-supervised contrast loss of step S34, the prediction space self-supervised contrast loss of step S35, the total guided contrast loss from the prediction space to the feature space of step S36, and the total guided contrast loss from the feature space to the prediction space; The graph-guided contrastive learning method from prediction space to feature space is as follows: S361: Concentrate the features with The features associated with the weakly augmented feature vector or the strongly augmented feature vector of the sample in the prediction graph are collected into the corresponding positively associated feature set, and the features associated with the first The weakly augmented feature vectors or strongly augmented feature vectors of the samples that do not generate correlation features in the prediction graph are collected into the corresponding negative correlation feature set, and the union of the corresponding positive correlation feature set and the negative correlation feature set is formed into the corresponding positive and negative correlation feature set; S362: Calculate the The guided contrast loss of the weakly augmented feature vector of the sample from the prediction space to the feature space is calculated according to formula (2) The guided contrast loss of the strongly augmented feature vector of samples from the prediction space to the feature space is: (1); (2); in: Represents the feature set The eigenvector corresponding to the weakly augmented samples is: express Guided contrastive loss from prediction space to feature space, represents the total sampling batch value, express The positive correlation feature set of express The positive and negative correlation feature set, Indicates belonging to All feature vectors of the positively correlated feature set, Indicates belonging to All feature vectors of the positive and negative correlation feature set, Indicates the feature set The strongly augmented eigenvector of samples, express Guided contrastive loss from prediction space to feature space, express The positive correlation feature set of express The positive and negative correlation feature set, Indicates belonging to All feature vectors of the positively correlated feature set, Indicates belonging to All feature vectors of the positive and negative correlation feature set; S363: Calculate the total guided contrast loss from the prediction space to the feature space according to formula (3) : (3); The guided contrastive learning method from feature space to prediction space is as follows: S364: Focus the prediction on The features associated with the weakly augmented prediction vector or the strongly augmented prediction vector of the sample in the feature map are collected into the corresponding positively associated prediction set, and the prediction set is combined with the first The weakly augmented prediction vectors or strongly augmented prediction vectors of the samples that do not generate associated features in the feature graph are collected into the corresponding negatively associated prediction set, and the union of the corresponding positively associated prediction set and the negatively associated prediction set is formed into the corresponding positively and negatively associated prediction set; S365: Calculate the The guided contrast loss of the weakly augmented prediction vector of the sample from the feature space to the prediction space is calculated according to formula (5). The guided contrast loss of the strongly augmented prediction vector of samples from feature space to prediction space is: (4); (5); in: Indicates the prediction set The weakly augmented prediction vector of samples, express Guided contrastive loss from feature space to prediction space, express The positive correlation prediction set, express The positive and negative correlation prediction set, Indicates belonging to All prediction vectors of the positively associated prediction set, Indicates belonging to All prediction vectors of the positive and negative correlation prediction set, Indicates the prediction set The strongly augmented prediction vector of samples, express Guided contrastive loss from feature space to prediction space, express The positive correlation prediction set, express The positive and negative correlation prediction set, Indicates belonging to All prediction vectors of the positively associated prediction set, Indicates belonging to All prediction vectors of the positive and negative correlation prediction set; S366: Calculate the total guided contrast loss from feature space to prediction space according to formula (6) : (6); S4: Repeat the iteration steps S2 to S3, and determine whether the set number of iterations has been reached. If the set number of iterations has been reached, the trained network model is obtained and the next step is entered; S5: Use the network model trained in step S4 to infer each unlabeled sample in the unlabeled data set in step S1 to obtain the predicted labeling result of each unlabeled sample.
2. The open-world semi-supervised image classification method based on dual spatial contrastive learning according to claim 1, characterized in that: In step S2, the feature map is constructed as follows: S21: Screening of connected sample pairs: for each unlabeled sample in the unlabeled data set, collect the sample with the nearest neighbor feature vector in the feature space, and connect the sample with the nearest neighbor feature vector with the unlabeled sample in the feature map to form a connected sample pair of the unlabeled sample; for each labeled sample in the labeled data set, randomly select a labeled sample with the same label as the labeled sample and connect it with the labeled sample in the feature map to form a connected sample pair of the labeled sample; S22: Screening of disconnected sample pairs: All samples in the image data set to be labeled are paired into sample pairs, and then the feature vector cosine similarity between each sample pair is calculated, and the feature vector cosine similarity is compared with a set threshold. If the feature vector cosine similarity is less than the set threshold, the sample pair is a disconnected sample pair in the feature map; S23: Define sample pairs other than connected sample pairs of unlabeled samples, connected sample pairs of labeled samples, and disconnected sample pairs as having unknown association in the feature graph.
3. The open-world semi-supervised image classification method based on dual spatial contrastive learning according to claim 2, characterized in that: In step S2, the prediction graph is constructed as follows: S24: Estimate the category of unlabeled samples in the unlabeled data set according to the category corresponding to the maximum value of the prediction vector, and select samples in the unlabeled sample category whose confidence is higher than the confidence setting value and meets the preset proportion coefficient to form a high-quality unlabeled data set, and the remaining unlabeled samples to form a low-quality unlabeled data set; S25: For each sample in the high-quality unlabeled dataset, the category corresponding to the maximum value of the prediction vector is defined as the pseudo label of the sample, and the pseudo label of the sample in the low-quality unlabeled dataset is defined as unknown; S26: Construct a prediction graph for all samples in the labeled image dataset. For any two samples, if at least one of the samples belongs to a low-quality unlabeled dataset, the relationship between the two samples is defined as unknown in the prediction graph. If both samples belong to a high-quality unlabeled dataset or a labeled dataset, continue to determine whether the pseudo-labels or labels of the two samples are of the same category. If they are of the same category, the two samples are connected in the prediction graph. If they are not of the same category, they are not connected in the prediction graph.
4. The open-world semi-supervised image classification method based on dual spatial contrastive learning according to claim 3, characterized in that: The preset proportionality coefficient in step S24 increases gradually as the number of iterations increases.
5. The open-world semi-supervised image classification method based on dual spatial contrastive learning according to claim 1, characterized in that: In step S3, the overall loss is calculated according to formula (7): : (7); in: represents the supervision loss, represents the feature space self-supervised contrast loss, represents the prediction space self-supervised contrastive loss.
