BaCon: Boosting Imbalanced Semi-supervised Learning via Balanced Feature-Level Contrastive Learning

Qianhan Feng, Lujing Xie, Shijie Fang, Tong Lin

TL;DR

BaCon (Balanced Feature-Level Contrastive Learning) tackles the "double whammy" of class imbalance and limited labels in semi-supervised learning. By directly regularizing the feature embedding space rather than just reweighting samples, it achieves state-of-the-art accuracy and shows remarkable robustness even in extreme "long-tail" scenarios.

What Problem Does This Paper Address?

Deep learning models thrive on massive, balanced, labeled datasets. In the real world, however, we usually face two hurdles: Semi-supervised Learning (SSL), where most data is unlabeled, and Class Imbalance, where a few "head" classes have many samples while "tail" classes have very few.

Existing Class Imbalanced SSL (CISSL) methods mostly work at the instance level—they try to reweight or resample specific data points. The authors argue this is insufficient. Because the model's backbone is naturally biased toward majority classes, the gradients it receives are skewed. Even clever tricks like auxiliary classifiers can't fully correct this if the underlying feature representations are fundamentally "clumped" or poorly separated for minority classes.

Figure 1: Gradient of ABC on representation layer is still biased. In contrast, BaCon provides an extra gradient that narrows the gap between the estimated gradient g and the ideal optimal gradient ˆg. r is the feature representation.
Figure 1: Standard methods (a) suffer from biased gradients. BaCon (b) adds a feature-level contrastive loss that pulls the representation toward an ideal, balanced gradient direction.

Methods

BaCon is designed as a "plug-in" component for existing SSL frameworks (like FixMatch or ABC). It introduces a novel contrastive loss that shapes the feature space directly through three key mechanisms:

  1. Global Positive Anchors: Instead of comparing individual samples, BaCon maintains a memory bank to calculate class-wise feature centers. Every sample is "pulled" toward its respective class center in the embedding space.
  2. Reliable Negative Selection (RNS): Contrastive learning needs "negative" samples to push away from. In imbalanced SSL, picking negatives is risky because pseudo-labels are often wrong. RNS uses a high-confidence threshold and a ranking mechanism to ensure the model only pushes away from samples that are truly likely to belong to different classes.
  3. Balanced Temperature Adjusting (BTA): This is the "secret sauce" for imbalance. The authors realized that feature centers for tail classes are less reliable because they are averaged over fewer samples. BTA dynamically adjusts the "temperature" (the strength of the attraction/repulsion) based on class size and training progress, preventing the model from over-fitting to noisy tail-class centers early on.
Figure 3: Overall training procedure of BaCon. The circle and star filled with squares represent the current representation and the corresponding positive anchor point, respectively. Circles filled with slashes in different colors represent negative instance features belonging to different classes in the current mini-batch.
Figure 3: The BaCon architecture, showing how features are projected, stored in a memory bank, and regularized via contrastive loss.

Datasets

The authors evaluated BaCon on "Long-Tail" (LT) versions of standard benchmarks, where class distributions follow an exponential decay:

  • CIFAR10-LT & CIFAR100-LT: Standard image classification tasks modified for extreme imbalance.
  • SVHN-LT: Street View House Numbers, a digit recognition task.
  • STL10-LT: A dataset specifically designed for SSL, where the unlabeled data distribution might differ from the labeled data.

Key Insights and Ideas

  • Representation is King: The authors proved that if you freeze a model with a balanced feature representation, even a simple classifier trained on imbalanced data performs significantly better (+6.12% accuracy). This confirms that the bottleneck in CISSL is the feature extractor itself.
  • Contrastive Learning as a Balancer: By forcing the model to map features to distinct, equidistant class centers, BaCon naturally counteracts the tendency of majority classes to "collapse" the feature space.
  • Dynamic Adaptation: The use of BTA (Figure 3) shows that "one size fits all" hyperparameters don't work for imbalanced data. Tail classes need a gentler learning curve to avoid drifting toward noisy anchors.
Figure 2: FixMatch-based ABC is trained in two steps as shown in (b) as the comparison of the normally trained one in (a). Remarkable improvement can be observed in (c).
Figure 2: A "two-step" experiment showing that a balanced feature representation is the key to unlocking higher performance in imbalanced settings.

Key Results

BaCon consistently outperformed state-of-the-art methods across all benchmarks:

  • CIFAR10-LT: Achieved 84.46% accuracy, surpassing the previous best (CoSSL) by 0.37% and the instance-level ABC by 1.21%.
  • CIFAR100-LT: Reached 57.96%, a 0.63% improvement over CoSSL.
  • Robustness: In extreme tests where the unlabeled data distribution was the inverse of the labeled data (a nightmare scenario for most SSL models), BaCon maintained high accuracy while competitors saw performance drops of over 10%.

Qualitatively, t-SNE visualizations (Figure 4) show that BaCon produces much cleaner, more separable clusters for all classes compared to standard FixMatch or ABC.

Figure 4: t-SNE visualization results of balanced test set learned by algorithms trained on CIFAR10-LT.
Figure 4: t-SNE plots show that BaCon (c) creates significantly more distinct and separable class boundaries than its predecessors.

Limitations and Future Work

While BaCon is powerful, the paper notes a few areas for further exploration:

  • Warmup Period: The method requires a "warmup" phase to populate the memory bank with reliable features before the contrastive loss is activated.
  • Computational Overhead: Maintaining a memory bank and calculating class centers adds some memory and compute cost, though the authors suggest it is manageable on modern GPUs (like the RTX 3090 used in the study).
  • Prior Knowledge: Like many CISSL methods, it assumes we know the imbalance ratio of the labeled data, which might not always be perfectly clear in the wild.

Summary updated

BibTeX
@inproceedings{feng2024bacon,
  author = {Qianhan Feng and Lujing Xie and Shijie Fang and Tong Lin},
  title = {{BaCon: Boosting Imbalanced Semi-supervised Learning via Balanced Feature-Level Contrastive Learning}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2024},
  doi = {10.1609/aaai.v38i11.29084},
}
Figure