Semi-supervised learning method and device, electronic equipment and storage medium
By employing a semi-supervised learning method that combines adaptive pseudo-label compression and neighborhood consistency enhancement, the problems of pseudo-label selection mechanism and training stability are solved, thereby improving the robustness and generalization ability of the model and achieving more efficient information utilization and training stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-19
- Publication Date
- 2026-03-27
AI Technical Summary
Existing semi-supervised learning methods have shortcomings in pseudo-label selection mechanisms, pseudo-label robustness, and training stability. Fixed thresholds are difficult to adapt to model changes, resulting in insufficient information utilization and unstable training processes.
An adaptive pseudo-label compression mechanism and neighborhood consistency enhancement technique are adopted. Soft pseudo-labels are generated through K-nearest neighbor graphs. Combined with the main classification head and the auxiliary classification head, multiple loss functions are calculated to optimize the neural network parameters and improve the robustness and training stability of pseudo-labels.
It improves the stability and generalization ability of the model, effectively utilizes information from medium confidence samples, reduces gradient oscillations, and enhances classification accuracy and overall generalization performance.
Smart Images

Figure CN121745202A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of semi-supervised learning technology, and in particular to semi-supervised learning methods, apparatus, electronic devices, and storage media. Background Technology
[0002] Semi-supervised learning (SSL) is a machine learning technique that utilizes both a small number of labeled samples and a large number of unlabeled samples during training. This method significantly improves the generalization performance of models while reducing the cost of manual annotation, and therefore has been widely used in fields such as image classification, speech recognition, and medical image analysis.
[0003] In existing technologies, pseudo-labeling is one of the mainstream directions in semi-supervised learning. A representative work is the paper "FixMatch: Simplifying Semi-Supervised Learning with Consistency and Confidence" published by Kihyuk Sohn et al. at the 2020 NeurIPS conference. The main technical process of this method includes the following steps:
[0004] (1) Apply weak and strong enhancement to the unlabeled samples respectively to generate two enhanced views;
[0005] (2) Use the model to predict the weakly enhanced samples and obtain the class probability distribution;
[0006] (3) When the maximum confidence of the prediction result exceeds a fixed threshold (usually 0.95), the category is used as a pseudo-label; otherwise, the sample is discarded.
[0007] (4) Use the retained pseudo-labels as the supervision signals for the corresponding strongly enhanced samples and calculate the unsupervised loss;
[0008] (5) Combine unsupervised loss with supervised loss of labeled samples to jointly optimize model parameters.
[0009] This method ensures the reliability of pseudo-labels through a high-confidence screening mechanism, but it still has the following problems:
[0010] ① A fixed global threshold is difficult to adapt to the dynamic changes of the model under different categories, different training stages or different feature regions, resulting in the discarding of some samples with medium confidence but potential learning value, and insufficient utilization of information;
[0011] ② There is a difficulty in balancing the threshold setting. If it is too high, it will reduce the coverage of false labels, while if it is too low, it will introduce more false labels and affect the training effect of the model.
[0012] To address the aforementioned issues, Bowen Zhang et al. proposed an improved method, "FlexMatch: Boosting Semi-Supervised Learning with Curriculum PseudoLabeling," at the 2021 NeurIPS conference. This method dynamically adjusts the pseudo-label selection threshold based on the learning status of each category through a curriculum learning mechanism, thereby improving the utilization rate of unlabeled samples to some extent. However, FlexMatch and similar methods still suffer from the following technical limitations:
[0013] (1) The generation of pseudo-labels still mainly relies on the model's prediction of a single sample, and does not make full use of the neighborhood structure information between samples in the feature space;
[0014] (2) When there is semantic similarity or confusion between categories, the model is prone to generating unstable pseudo-labels in the boundary region, resulting in inconsistent confidence.
[0015] (3) In the early stages of training, due to the limited predictive ability of the model, false labels may interfere with model optimization through gradient propagation, causing gradient oscillation, loss fluctuations, or even model performance degradation.
[0016] In summary, existing semi-supervised learning methods still have shortcomings in terms of sample selection mechanisms, robustness to pseudo-labels, and training stability. There is an urgent need to propose a semi-supervised learning method with stronger stability and generalization ability. Summary of the Invention
[0017] In view of the shortcomings of the prior art described above, the purpose of this application is to provide a semi-supervised learning method, device, electronic device and storage medium for neural networks, which can improve the stability and generalization ability of neural networks.
[0018] Firstly, this application provides a semi-supervised learning method for neural networks, wherein the neural network includes a backbone network, a main classifier head, and an auxiliary classifier head, and the semi-supervised learning method includes:
[0019] The unlabeled samples are augmented to obtain weakly augmented samples and strongly augmented samples.
[0020] The K-nearest neighbor graphs of weakly and strongly enhanced samples are calculated using neural networks, and soft pseudo-labels are generated based on the K-nearest neighbor graphs.
[0021] By inputting strongly enhanced samples into the neural network, the first probability distribution of the main classification head and the second probability distribution of the auxiliary classification head are obtained.
[0022] The unsupervised loss is obtained based on the first probability distribution and soft pseudo-labels;
[0023] The alignment loss is obtained based on the second probability distribution and the soft pseudo-labels;
[0024] The consistency loss is obtained by measuring the difference between the first probability distribution of a strongly augmented sample and its K-nearest neighbor in the graph.
[0025] The supervised loss of the main classifier head is calculated using labeled samples;
[0026] The total loss of the neural network is obtained by considering the supervised loss, unsupervised loss, consistency loss, and alignment loss.
[0027] The parameters of the neural network are optimized based on the total loss.
[0028] In one implementation of the first aspect, the step of using a neural network to calculate the K-nearest neighbor graph of weakly enhanced samples and strongly enhanced samples, and generating soft pseudo-labels based on the K-nearest neighbor graph, includes:
[0029] The weakly enhanced samples and the strongly enhanced samples are input into the neural network to obtain the third probability distribution of the main classifier head and the feature representation generated by the backbone network; in the third probability distribution, the class with the highest probability is the main class and the class with the second highest probability is the most confusing class.
[0030] The K-nearest neighbor graph is generated based on the feature representations of the weakly enhanced samples and the strongly enhanced samples.
[0031] The probabilities of the main category and the most confusing category are normalized, and the probabilities of the remaining categories are set to zero to obtain the compressed pseudo-labels of the weakly enhanced samples and the strongly enhanced samples.
[0032] The average neighbor label is obtained by calculating the average of the compressed pseudo-labels of each neighbor in the K-nearest neighbor graph of the weakly enhanced sample.
[0033] The average neighbor label is used as the soft pseudo-label for the weakly enhanced sample and the strongly enhanced sample.
[0034] In one implementation of the first aspect, obtaining the unsupervised loss based on the first probability distribution and the soft pseudo-label includes:
[0035] Determine whether the maximum probability in the first probability distribution of the strongly enhanced sample is greater than or equal to a preset threshold; if so, mark the strongly enhanced sample as a high-confidence sample.
[0036] Calculate the cross-entropy between the first probability distribution of the high-confidence sample and the corresponding soft pseudo-label to obtain the first soft cross-entropy loss;
[0037] The unsupervised loss is obtained by calculating the average of the first soft cross-entropy loss of each high-confidence sample in the same batch.
[0038] In one implementation of the first aspect, obtaining the alignment loss based on the second probability distribution and the soft pseudo-labels includes: calculating the KL divergence or Euclidean distance between the second probability distribution of the strongly enhanced sample and the corresponding soft pseudo-labels to obtain the alignment loss.
[0039] In one implementation of the first aspect, the consistency loss is obtained by measuring the difference between the first probability distribution of the strongly augmented sample and its K-nearest neighbor in-graph neighbors, including:
[0040] Calculate the KL divergence or Euclidean distance between the compressed pseudo-label of the strongly enhanced sample and the compressed pseudo-label of each neighbor to obtain the statistical distance;
[0041] The average value of each statistical distance is calculated to obtain the consistency loss.
[0042] In one implementation of the first aspect, calculating the supervised loss of the main classifier head using labeled samples includes:
[0043] The labeled samples are input into the neural network to obtain the fourth probability distribution of the main classification head;
[0044] The cross-entropy between the fourth probability distribution and the true labels of the labeled samples is calculated to obtain the supervised loss.
[0045] In one implementation of the first aspect, obtaining the total loss of the neural network based on the supervised loss, unsupervised loss, consistency loss, and alignment loss includes: weighted summing of the supervised loss, the unsupervised loss, the consistency loss, and the alignment loss to obtain the total loss of the neural network; wherein the weight of the alignment loss is less than or equal to 0.5.
[0046] Secondly, this application provides a semi-supervised learning device for neural networks, comprising:
[0047] The sample augmentation module is used to augment unlabeled samples to obtain weakly augmented and strongly augmented samples, and to calculate the K-nearest neighbor graph.
[0048] The label generation module is used to calculate the K-nearest neighbor graphs of weakly and strongly enhanced samples using neural networks, and generate soft pseudo-labels based on the K-nearest neighbor graphs.
[0049] The classification module is used to input strongly enhanced samples into the neural network to obtain the first probability distribution of the main classification head and the second probability distribution of the auxiliary classification head.
[0050] The first loss generation module is used to obtain the unsupervised loss based on the first probability distribution and the soft pseudo-label.
[0051] The second loss generation module is used to obtain the alignment loss based on the second probability distribution and the soft pseudo-label;
[0052] The third loss generation module is used to measure the difference between the first probability distribution of a strongly augmented sample and its K-nearest neighbor in the graph, and to obtain the consistency loss.
[0053] The fourth loss generation module is used to calculate the supervised loss of the main classification head using labeled samples;
[0054] The total loss generation module is used to obtain the total loss of the neural network based on the supervised loss, unsupervised loss, consistency loss, and alignment loss.
[0055] The parameter optimization module is used to optimize the parameters of the neural network based on the total loss.
[0056] Thirdly, this application provides an electronic device, including a memory and a processor, wherein the processor is configured to execute a computer program stored in the memory to enable the electronic device to perform the semi-supervised learning method of the neural network.
[0057] Fourthly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the semi-supervised learning method of the neural network.
[0058] As described above, the semi-supervised learning method, apparatus, electronic device, and storage medium for neural networks described in this application have the following significant advantages:
[0059] 1) Adaptive pseudo-tag compression mechanism
[0060] By using dynamic category space compression, pseudo-labels retain confidence information only on the main category and the most confusing category, explicitly characterizing model uncertainty and mitigating the problem of false labels on boundary samples.
[0061] 2) Enhanced neighborhood consistency
[0062] By utilizing neighborhood information in the feature space for pseudo-label propagation, the generated pseudo-labels not only rely on single-sample predictions but also incorporate local sample structures, thereby improving the consistency of pseudo-labels in similar sample regions.
[0063] 3) Improved training stability
[0064] The synergistic effect of compressed pseudo-labels and neighborhood propagation effectively suppresses gradient oscillations and loss fluctuations, improving the stability and convergence speed of the training process.
[0065] 4) Enhanced model generalization ability
[0066] The method can maintain the quality of pseudo-labels in complex scenarios with low confidence, class confusion, or sparse features, thereby improving the classification accuracy and overall generalization performance of semi-supervised models. Attached Figure Description
[0067] Figure 1 The flowchart shown is a semi-supervised learning method for neural networks as described in one embodiment of this application.
[0068] Figure 2 The flowchart shown is a semi-supervised learning method for neural networks as described in one embodiment of this application.
[0069] Figure 3 The flowchart shown is a step S200 in one embodiment of this application.
[0070] Figure 4 The diagram shown is a schematic diagram of step S210 in one embodiment of this application.
[0071] Figure 5 The diagram shown is a schematic diagram of step S230 in one embodiment of this application.
[0072] Figure 6 The diagram shown is a schematic diagram of step S240 in one embodiment of this application.
[0073] Figure 7 The diagram shown is a schematic representation of a semi-supervised learning device for a neural network in one embodiment of this application.
[0074] Figure 8 The diagram shown is a structural schematic of an electronic device according to an embodiment of this application. Detailed Implementation
[0075] The following specific examples illustrate the implementation of this application. Those skilled in the art can easily understand other advantages and effects of this application from the content disclosed in this specification. This application can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of this application. It should be noted that, unless otherwise specified, the following embodiments and features in the embodiments can be combined with each other.
[0076] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of this application. Therefore, the drawings only show the components related to this application and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.
[0077] Existing semi-supervised learning methods suffer from poor adaptability in pseudo-label selection, insufficient handling of class confusion, and low robustness to pseudo-label noise. When selecting pseudo-labels with a fixed threshold, existing semi-supervised learning methods fail to fully utilize the information from medium-confidence samples or the neighborhood structure between samples. This leads to unstable pseudo-labels for boundary samples, oscillations during training, and limitations on the model's generalization ability and training stability.
[0078] This application provides a semi-supervised learning method for neural networks, which generates high-quality pseudo-labels by adaptively compressing the class space and combining sample neighborhood information, thereby improving the stability, reliability and generalization ability of the semi-supervised model.
[0079] The principles and implementation methods of the semi-supervised learning method, apparatus, electronic device, and storage medium of the neural network in this embodiment will be described in detail below, so that those skilled in the art can understand the apparatus, electronic device, and storage medium of this embodiment without creative effort.
[0080] Please refer to Figure 1 , Figure 2 This embodiment provides a semi-supervised learning method for neural networks, the neural network including a backbone network and a main classifier H. main And auxiliary classification head H aux Semi-supervised learning methods include:
[0081] Step S100, for Figure 2 (a) The unlabeled sample shown is augmented to obtain Figure 2 (b) shows the weakly enhanced sample and Figure 2 (c) shows the strongly enhanced sample;
[0082] Step S200: Calculate the K-nearest neighbor graphs of weakly enhanced samples and strongly enhanced samples using a neural network, and generate soft pseudo-labels based on the K-nearest neighbor graphs;
[0083] Step S300: Input the strongly enhanced samples into the neural network to obtain the first probability distribution P of the main classifier head. s The second probability distribution of the auxiliary classification head
[0084] Step S400, according to the first probability distribution P s Unsupervised loss is obtained from soft pseudo-labeling.
[0085] Step S500, according to the second probability distribution Alignment loss obtained with soft pseudo-labels
[0086] Step S600: Measure the first probability distribution P of the strongly augmented sample and its K-nearest neighbor graph neighbors. sThe difference yields a consistency loss.
[0087] Step S700: Calculate the supervised loss of the main classifier head using labeled samples.
[0088] Step S800, based on the monitoring loss Unsupervised loss Consistency loss and alignment loss Obtain the total loss of the neural network
[0089] Step S900, based on the total loss Optimize the parameters of the neural network.
[0090] The semi-supervised learning method in this embodiment first performs weak and strong augmentation on unlabeled samples, generating weakly and strongly augmented samples. Then, the backbone network is used to extract feature representations of the weakly augmented samples and construct a K-nearest neighbor graph. Based on this, compressed pseudo-labels are generated by the main classifier and propagated on the K-nearest neighbor graph to form soft pseudo-labels that integrate neighborhood information. Guiding the generation of soft pseudo-labels through the K-nearest neighbor graph enables the soft pseudo-labels to have context awareness, improving their spatial consistency and robustness. Simultaneously, the main classifier and auxiliary classifier predict the strongly augmented samples. Unsupervised loss ensures that the main classifier maintains consistency with the pseudo-labels under strong augmentation, alignment loss enables the auxiliary classifier to learn the output distribution that matches the soft pseudo-labels, consistency loss further constrains the similarity between the strongly augmented samples and their neighbors in the output of the auxiliary classifier, and supervised loss provides reliable gradient signals from labeled data. Finally, the total loss is used to uniformly optimize the neural network parameters, thereby achieving effective utilization of unlabeled data and improving the model's generalization ability.
[0091] The steps S100 to S900 of the semi-supervised learning method of the neural network in this embodiment will be described in detail below.
[0092] In one embodiment, a neural network is used for image recognition.
[0093] In one embodiment, soft pseudo-labels generated from weakly enhanced samples are matched with corresponding strongly enhanced samples by sample ID, thereby achieving label association and alignment.
[0094] Please refer to Figures 2-6 In one embodiment, step S200 includes:
[0095] Step S210: Input the weakly enhanced samples and the strongly enhanced samples into the neural network to obtain the third probability distribution P of the main classifier head. wAnd obtain the feature representation generated by the backbone network; in the third probability distribution P w In the dataset, the category with the highest probability is the primary category (top-1), and the category with the second highest probability is the most confusing category (confuse-1). Weakly augmented samples preserve a more complete original semantic structure, ensuring the generation of stable and reliable soft pseudo-labels.
[0096] Step S220: Generate a K-nearest neighbor graph based on the feature representations of weakly and strongly enhanced samples. The K-nearest neighbor graph provides the basis for subsequent label propagation, and constrains soft pseudo-labels by utilizing the consistency of labels among samples of the same type.
[0097] Step S230: Normalize the probabilities of the main category and the most confusing category, and set the probabilities of the remaining categories to zero to obtain compressed pseudo-labels for weakly and strongly enhanced samples. Compressed pseudo-labels are constructed using Dynamic Class Space Compression (DCC) to allow the neural network model to focus on the two most easily confused categories, reducing interference from noisy categories.
[0098] Step S240: Calculate the average value of the compressed pseudo-labels of each neighbor in the K-nearest neighbor graph of the weakly enhanced sample to obtain the average neighbor label.
[0099] Step S250: The average neighbor label is used as the soft pseudo-label for weakly and strongly augmented samples. By using the overall prediction result of multiple samples within the K-nearest neighbor graph to replace the prediction result of a single sample, isolated errors generated in the unstable stage of the neural network model in the early stage of training can be corrected in a timely manner, the impact of isolated error labels on subsequent training can be suppressed, and the robustness of the model can be improved.
[0100] In one embodiment, in step S210, the unlabeled sample set is... Perform weak enhancement operations, inputting the main classification head network f θ The predicted probability distribution is obtained as follows:
[0101] p u =Softmax(f θ (x u ))=[p u1 ,p u2 ,…,p uc (6-1)
[0102] Where C is the total number of categories, p ui Indicates sample x u The probability of belonging to the i-th class.
[0103] Calculate the maximum value of the probability distribution:
[0104]
[0105] like (where τ is the confidence threshold, ranging from [0.8, 0.95]), then the prediction is considered reliable, and the sample participates in the construction of soft pseudo-labels; otherwise, a masking mechanism is used. u =0 to exclude them to prevent low-confidence samples from perturbing model training.
[0106] Please refer to Figure 4 By preserving the Top-1 class and its most confused class (Confuse-1) in the model's predictions, a local class subspace is constructed, guiding the model to focus on important discriminative dimensions and reducing the interference of irrelevant classes on training.
[0107] In one embodiment, the extraction process for the Top-1 category and the Confuse-1 category is as follows:
[0108] Let the predicted probability distribution be p u =[p1,p2,...,p c Select from:
[0109]
[0110] Where c1 is the Top-1 category, and c2 is the category with the highest predicted probability among the remaining C-1 categories, thus forming a local category space:
[0111] C sub ={c1,c2} (6-5)
[0112] Please refer to Figure 5 In one embodiment, the process of constructing compressed pseudo-tags is as follows:
[0113] Within the local class space, the original predicted probabilities are normalized to construct a compressed pseudo-label vector. Its definition is:
[0114]
[0115] Compared with traditional one-hot labels, this two-dimensional pseudo-label retains the confidence of the main category and explicitly models the uncertainty of the model, which helps to alleviate the loss oscillation caused by mislabeling of boundary samples.
[0116] In one embodiment, DCC is used to generate soft pseudo-tags. Calculate the unsupervised loss.
[0117] In one embodiment, soft pseudo-labels propagated from the neighborhood are used. Calculate the unsupervised loss and construct a binary mask based on the pseudo-label confidence.
[0118]
[0119] Where τ is a preset confidence threshold used to filter unlabeled samples with low confidence. The filtered samples correspond to m. i =0, and its loss term does not participate in the calculation of unsupervised loss during the accumulation and normalization process.
[0120] Based on this, unsupervised loss is defined as:
[0121]
[0122] Where CE(·,·) represents the cross-entropy function, B is the number of mini-batch samples, and ∈ is a minimal constant to prevent the denominator from being zero. This unsupervised loss is normalized only on the set of high-confidence samples that satisfy the confidence constraints, thus ensuring that each valid unlabeled sample has a consistent contribution weight to the unsupervised optimization process. Through this design, the unsupervised learning process is dominated by reliable pseudo-labels, guiding the discriminative representation learning of unlabeled samples in a self-training manner.
[0123] Please refer to Figure 5 In one embodiment, the probability distribution predicted by the neural network for the i-th sample is p. i , in p i In the dataset, the class with the highest probability is c1, and the class with the second highest probability is c2. Through dynamic class compression and normalization, the compressed pseudo-labels are: The data contains only two categories, where the probability of class c1 is... The probability of class c2 is Compressed pseudo tags Perform neighborhood label propagation in steps S240 and S250 to obtain the soft pseudo-label NPLP. Based on the second probability distribution... Alignment loss obtained with soft pseudo-labels
[0124] Please refer to Figure 6 In one embodiment, the construction process of the k-nearest neighbor graph in step S220 is as follows:
[0125] Using the backbone network in the current training phase, perform forward propagation on all samples to extract intermediate layer feature representations:
[0126] h i =g φ (x i ), i = 1, 2, ..., N (6-9)
[0127] Among them, g φ (x i ) represents the feature extraction network, and N is the total number of samples.
[0128] To facilitate the use of cosine similarity to measure the relationship between samples, the feature vectors are L2 normalized:
[0129]
[0130] This normalization ensures that each feature vector has a length of 1, thus simplifying the cosine similarity calculation to an inner product.
[0131] Define the cosine similarity matrix between samples:
[0132]
[0133] For each sample i, select the K most similar samples as neighbors and construct a K-nearest neighbor graph:
[0134]
[0135] Forming a sparse adjacency matrix Where A ij =1 indicates that sample j is a neighbor of sample i. This neighborhood structure preserves local manifold information in the feature space, providing a basis for subsequent label propagation.
[0136] In one embodiment, the soft pseudo-tag is constructed as follows:
[0137] The label distribution of each sample is updated iteratively by using the mean of neighboring labels, achieving a smooth label transition. The compressed pseudo-labels generated by DCC are then used. as the initial label matrix The average update is performed in the neighborhood, and the updated compressed pseudo-labels are used as soft pseudo-labels.
[0138]
[0139] Where α∈(0,1) is the propagation coefficient, which is used to control the proportion of the fusion of the label and the neighboring labels.
[0140] To avoid label drift and noise accumulation caused by excessive iterations, in one embodiment, the mean of the neighbor labels is used as an approximate propagation (i.e., only one round of propagation) to obtain soft pseudo-labels.
[0141]
[0142] The label vectors of the neighbors are averaged to form the soft pseudo-label of the current sample. After propagation, all samples (including unlabeled samples) obtain a class distribution based on the estimated neighbor labels.
[0143] It is worth noting that since the initial label of unlabeled samples is zero, propagation is actually the diffusion of the labels of labeled samples in the feature space. Because the graph structure is built based on feature similarity, the propagation process is essentially a label smoothing operation in the feature space.
[0144] In one embodiment, step S600 includes:
[0145] Step S610: Calculate the KL divergence or Euclidean distance between the compressed pseudo-label of the strongly enhanced sample and the compressed pseudo-label of each neighbor to obtain the statistical distance.
[0146] Step S620: Calculate the average value of each statistical distance to obtain the consistency loss.
[0147] In one embodiment, for each unlabeled sample, its Top-k nearest neighbors are selected from the feature space. A predicted probability distribution is generated using the main classification head, and compressed pseudo-labels are constructed in its local class subspace through dynamic class compression. The KL divergence or Euclidean distance between the strongly enhanced sample and its neighbors' compressed pseudo-labels is calculated to encourage their aggregation within the local class subspace, thereby compressing the intra-class variance. The consistency loss is calculated as follows:
[0148]
[0149] in, This indicates that the target sample is in the local class subspace C. sub The compressed pseudo-tags obtained on {c1,c2} It represents the compressed pseudo-label of its i-th neighbor sample in the same local class subspace; D(·|·) is the distance metric function, such as KL divergence or mean squared error (MSE).
[0150] In one embodiment, step S500 includes: calculating the KL divergence or Euclidean distance between the second probability distribution of the strongly enhanced sample and the corresponding soft pseudo-label to obtain the alignment loss.
[0151] In one embodiment, the goal of the auxiliary classification head is to enhance the neural network model's ability to distinguish "key class pairs" (target class + confusion class), thereby improving the overall classifier's generalization performance on boundary samples.
[0152] Specifically, regarding the soft pseudo-tags generated during propagation The output distribution p of the auxiliary classification head is required. (aux) To maintain consistency with this, further compress the class space and provide auxiliary supervision. The alignment loss is defined as:
[0153]
[0154] This mechanism enhances the discrimination ability of the auxiliary classification head in the compressed category subspace, making the model more effective in distinguishing between the main class and the confused class.
[0155] In one embodiment, step S700 includes:
[0156] Step S710: Input labeled samples into the neural network to obtain the fourth probability distribution of the main classification head;
[0157] Step S720: Calculate the cross-entropy between the fourth probability distribution and the true labels of the labeled samples to obtain the supervised loss.
[0158] In one embodiment, for labeled data, the neural network model is trained under full supervision using standard cross-entropy loss. Let a batch of labeled samples be... The main classification head outputs the predicted probability. This represents the input feature (e.g., image) of the i-th labeled sample. The true label of the sample is represented by a one-hot encoded vector or integer index, indicating the category to which the sample belongs. The calculation process for the supervised loss is as follows:
[0159]
[0160] Supervised loss enables the model to correctly classify labeled samples and provides a stable learning signal for semi-supervised training.
[0161] In one embodiment, step S800 includes: weighted summing of supervised loss, unsupervised loss, consistency loss and alignment loss to obtain the total loss of the neural network; wherein the weight of alignment loss is less than or equal to 0.5.
[0162] In one embodiment, the shrinkage loss is obtained based on the consistency loss and the alignment loss.
[0163]
[0164] Where, λ aux This is the weighting coefficient for the auxiliary supervision item.
[0165] In one embodiment, λ aux Less than or equal to 0.5.
[0166] The calculation process for the total loss is as follows:
[0167]
[0168] in:
[0169] This indicates supervised loss on labeled samples;
[0170] This represents the unsupervised loss generated based on the pseudo-soft labels from the main classification header;
[0171] This represents the contraction loss within the local category space;
[0172] λ * : These are the weighting coefficients for each loss term, used to balance the influence of supervised information and various unsupervised pseudo-label signals during training.
[0173] By assigning appropriate weights to each loss term, the influence of supervised information and various unsupervised pseudo-label signals can be dynamically balanced during training, effectively reducing noise caused by uncertain pseudo-labels and enhancing the model's ability to identify the true class boundaries. This comprehensive loss function provides the model with multi-angle and multi-level learning signals, ensuring the stability of the training process and improving its effectiveness.
[0174] The semi-supervised learning method for neural networks in this application can be deployed on a GPU-based deep learning training platform.
[0175] Training data can include standard visual datasets such as CIFAR-10, CIFAR-100, SVHN, and STL-10, and can also be extended to modalities such as speech and text.
[0176] Example parameter range: confidence threshold τ∈[0.9,0.95], number of neighbors K∈[5,20], label preservation coefficient α∈
[0177] [0.6, 0.9].
[0178] This neural network's semi-supervised learning method requires no additional model structure or complex optimization strategies, has low computational overhead, and is suitable for large-scale semi-supervised learning and automatic annotation tasks.
[0179] The scope of protection of the semi-supervised learning method for neural networks in this application is not limited to the execution order of the steps listed in this embodiment. Any solution implemented by adding, subtracting, or replacing steps in the prior art based on the principles of this application is included within the scope of protection of this application.
[0180] Please refer to Figure 7 This embodiment provides a semi-supervised learning device for neural networks, comprising:
[0181] The sample augmentation module is used to augment unlabeled samples to obtain weakly augmented and strongly augmented samples, and to calculate the K-nearest neighbor graph.
[0182] The label generation module is used to calculate the K-nearest neighbor graphs of weakly and strongly enhanced samples using neural networks, and generate soft pseudo-labels based on the K-nearest neighbor graphs.
[0183] The classification module is used to input strongly enhanced samples into the neural network to obtain the first probability distribution of the main classification head and the second probability distribution of the auxiliary classification head.
[0184] The first loss generation module is used to obtain the unsupervised loss based on the first probability distribution and the soft pseudo-label.
[0185] The second loss generation module is used to obtain the alignment loss based on the second probability distribution and the soft pseudo-label;
[0186] The third loss generation module is used to measure the difference between the first probability distribution of a strongly augmented sample and its K-nearest neighbor in the graph, and to obtain the consistency loss.
[0187] The fourth loss generation module is used to calculate the supervised loss of the main classification head using labeled samples;
[0188] The total loss generation module is used to obtain the total loss of the neural network based on the supervised loss, unsupervised loss, consistency loss, and alignment loss.
[0189] The parameter optimization module is used to optimize the parameters of the neural network based on the total loss.
[0190] In the embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, or methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of modules / units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules or units may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection of apparatuses or modules or units may be electrical, mechanical, or other forms.
[0191] The modules / units described as separate components may or may not be physically separate. The components shown as modules / units may or may not be physical modules; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules / units can be selected to achieve the objectives of the embodiments of this application, depending on actual needs. For example, the functional modules / units in the various embodiments of this application may be integrated into one processing module, or each module / unit may exist physically separately, or two or more modules / units may be integrated into one module / unit.
[0192] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0193] Please refer to Figure 8 This embodiment also provides an electronic device, which is a user's mobile device such as a mobile phone, PAD, wearable device, or smart AI device; the electronic device includes a memory for storing computer programs; and a processor for running the computer programs to implement the semi-supervised learning method of neural networks in the above embodiments.
[0194] The memory is connected to the processor via a system bus and communicates with it. The memory stores computer programs, and the processor runs the computer programs to enable the electronic device to perform actions such as... Figures 1 to 6 The semi-supervised learning method for the neural network is shown.
[0195] It should also be noted that the system bus mentioned above can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This system bus can be divided into address bus, data bus, control bus, etc. For ease of representation, only one thick line is used in the diagram, but this does not indicate that there is only one bus or one type of bus. The communication interface is used to enable communication between the database access device and other devices (such as clients, read-write databases, and read-only databases).
[0196] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0197] In addition, this embodiment also provides a storage medium storing program instructions, which, when executed by a processor, implement the semi-supervised learning method of the neural network in the above embodiments.
[0198] Those skilled in the art will understand that all or part of the steps in the methods of the above embodiments can be implemented by a program instructing a processor. The program can be stored in a computer-readable storage medium, which is a non-transitory medium, such as random access memory, read-only memory, flash memory, hard disk, solid-state drive, magnetic tape, floppy disk, optical disk, and any combination thereof. The storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. This available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., digital video disc (DVD)), or a semiconductor medium (e.g., solid-state drive (SSD)).
[0199] The descriptions of the processes or structures corresponding to the above figures each have their own emphasis. For parts of a process or structure that are not described in detail, please refer to the relevant descriptions of other processes or structures.
[0200] The above embodiments are merely illustrative of the principles and effects of this application and are not intended to limit this application. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of this application. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in this application should still be covered by the claims of this application.
Claims
1. A semi-supervised learning method for neural networks, characterized in that, Neural networks consist of a backbone network, a main classifier head, and an auxiliary classifier head. Semi-supervised learning methods include: The unlabeled samples are augmented to obtain weakly augmented samples and strongly augmented samples. The K-nearest neighbor graphs of weakly and strongly enhanced samples are calculated using neural networks, and soft pseudo-labels are generated based on the K-nearest neighbor graphs. By inputting strongly enhanced samples into the neural network, the first probability distribution of the main classification head and the second probability distribution of the auxiliary classification head are obtained. The unsupervised loss is obtained based on the first probability distribution and soft pseudo-labels; The alignment loss is obtained based on the second probability distribution and the soft pseudo-labels; The consistency loss is obtained by measuring the difference between the first probability distribution of a strongly augmented sample and its K-nearest neighbor in the graph. The supervised loss of the main classifier head is calculated using labeled samples; The total loss of the neural network is obtained by considering the supervised loss, unsupervised loss, consistency loss, and alignment loss. The parameters of the neural network are optimized based on the total loss.
2. The semi-supervised learning method for neural networks according to claim 1, characterized in that, The step of using a neural network to calculate the K-nearest neighbor graphs of weakly and strongly enhanced samples, and generating soft pseudo-labels based on the K-nearest neighbor graphs, includes: The weakly enhanced samples and the strongly enhanced samples are input into the neural network to obtain the third probability distribution of the main classifier head and the feature representation generated by the backbone network; in the third probability distribution, the class with the highest probability is the main class and the class with the second highest probability is the most confusing class. The K-nearest neighbor graph is generated based on the feature representations of the weakly enhanced samples and the strongly enhanced samples. The probabilities of the main category and the most confusing category are normalized, and the probabilities of the remaining categories are set to zero to obtain the compressed pseudo-labels of the weakly enhanced samples and the strongly enhanced samples. The average neighbor label is obtained by calculating the average of the compressed pseudo-labels of each neighbor in the K-nearest neighbor graph of the weakly enhanced sample. The average neighbor label is used as the soft pseudo-label for the weakly enhanced sample and the strongly enhanced sample.
3. The semi-supervised learning method for neural networks according to claim 1, characterized in that, The unsupervised loss obtained based on the first probability distribution and the soft pseudo-label includes: Determine whether the maximum probability in the first probability distribution of the strongly enhanced sample is greater than or equal to a preset threshold; if so, mark the strongly enhanced sample as a high-confidence sample. Calculate the cross-entropy between the first probability distribution of the high-confidence sample and the corresponding soft pseudo-label to obtain the first soft cross-entropy loss; The unsupervised loss is obtained by calculating the average of the first soft cross-entropy loss of each high-confidence sample in the same batch.
4. The semi-supervised learning method for neural networks according to claim 1, characterized in that, The step of obtaining the alignment loss based on the second probability distribution and the soft pseudo-labels includes: calculating the KL divergence or Euclidean distance between the second probability distribution of the strongly enhanced sample and the corresponding soft pseudo-labels to obtain the alignment loss.
5. The semi-supervised learning method for neural networks according to claim 2, characterized in that, The consistency loss is derived by measuring the difference between the first probability distribution of a strongly augmented sample and its K-nearest neighbor in-graph neighbors, including: Calculate the KL divergence or Euclidean distance between the compressed pseudo-label of the strongly enhanced sample and the compressed pseudo-label of each neighbor to obtain the statistical distance; The average value of each statistical distance is calculated to obtain the consistency loss.
6. The semi-supervised learning method for neural networks according to claim 1, characterized in that, The step of calculating the supervised loss of the main classifier head using labeled samples includes: The labeled samples are input into the neural network to obtain the fourth probability distribution of the main classification head; The cross-entropy between the fourth probability distribution and the true labels of the labeled samples is calculated to obtain the supervised loss.
7. The semi-supervised learning method for neural networks according to claim 1, characterized in that, The step of obtaining the total loss of the neural network based on the supervised loss, unsupervised loss, consistency loss, and alignment loss includes: weighted summing of the supervised loss, unsupervised loss, consistency loss, and alignment loss to obtain the total loss of the neural network; wherein the weight of the alignment loss is less than or equal to 0.
5.
8. A semi-supervised learning device for a neural network, characterized in that, include: The sample augmentation module is used to augment unlabeled samples to obtain weakly augmented and strongly augmented samples, and to calculate the K-nearest neighbor graph. The label generation module is used to calculate the K-nearest neighbor graphs of weakly and strongly enhanced samples using neural networks, and generate soft pseudo-labels based on the K-nearest neighbor graphs. The classification module is used to input strongly enhanced samples into the neural network to obtain the first probability distribution of the main classification head and the second probability distribution of the auxiliary classification head. The first loss generation module is used to obtain the unsupervised loss based on the first probability distribution and the soft pseudo-label. The second loss generation module is used to obtain the alignment loss based on the second probability distribution and the soft pseudo-label; The third loss generation module is used to measure the difference between the first probability distribution of a strongly augmented sample and its K-nearest neighbor in the graph, and to obtain the consistency loss. The fourth loss generation module is used to calculate the supervised loss of the main classification head using labeled samples; The total loss generation module is used to obtain the total loss of the neural network based on the supervised loss, unsupervised loss, consistency loss, and alignment loss. The parameter optimization module is used to optimize the parameters of the neural network based on the total loss.
9. An electronic device comprising a memory and a processor, characterized in that, The processor is used to execute the computer program stored in the memory to cause the electronic device to perform a semi-supervised learning method of a neural network as described in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the semi-supervised learning method of the neural network according to any one of claims 1 to 7.