Intermediate Layer Classifiers for OOD generalization

Arnas Uselis, Seong Joon Oh

Abstract

Conventional deep learning paradigms assume that the final layers of a neural network provide the most refined representations for classification. However, this research demonstrates that for out-of-distribution (OOD) generalization, these final layers often over-specialize to training shortcuts and spurious correlations. By employing Intermediate Layer Classifiers (ILCs)—simple linear probes attached to earlier stages of a frozen backbone—we can access more robust, invariant features. Our findings show that intermediate layers frequently outperform the final layer in OOD scenarios, yielding accuracy improvements of up to 25% without additional backbone training.

Introduction

Deep Neural Networks (DNNs) frequently rely on "shortcuts"—spurious correlations between labels and environmental factors—to achieve high accuracy on training data. For instance, a model trained to identify camels primarily in desert settings may fail to recognize a camel on a beach, having learned that "sand" is the primary predictive feature for "camel." This brittleness is the core challenge of Out-of-Distribution (OOD) generalization.

While standard practice involves "last-layer retraining" (freezing the backbone and updating only the final linear head), this approach assumes the penultimate layer contains the most useful features. This paper challenges that assumption, arguing that the final layers are often the most "polluted" by training-set shortcuts, while earlier layers retain more generalizable information.

Methodology

The authors propose the use of Intermediate Layer Classifiers (ILCs). The methodology is straightforward and requires no modification to the underlying model architecture:

  1. Backbone Freezing: A pre-trained backbone (e.g., ResNet or Vision Transformer) is frozen to preserve its learned feature hierarchy.
  2. Probe Attachment: Simple linear probes (affine transformations) are attached to multiple intermediate layers throughout the network.
  3. Evaluation Scenarios:
    • Few-shot: Probes are trained on a minimal amount of OOD data.
  4. Zero-shot: Probes are trained solely on in-distribution (ID) data, but an OOD validation set is used to select the optimal layer for deployment.

This approach tests the hypothesis that earlier representations, which focus on fundamental shapes and textures, are more stable under distribution shifts than the high-level, shortcut-heavy features found at the network's end.

Experimental Framework

The study evaluates ILCs across nine datasets representing four distinct types of distribution shifts:

  • Conditional Shifts: CMNIST (Colored MNIST).
  • Subpopulation Shifts: CelebA, Waterbirds, and Multi-CelebA (focusing on minority group performance).
  • Input Noise: CIFAR-10C and CIFAR-100C (corrupted by environmental noise like blur or snow).
  • Natural/Style Shifts: ImageNet-A, ImageNet-R, ImageNet-Cue Conflict, and ImageNet-Silhouette.

Key Insights and Analysis

The Pen-Penultimate Advantage

A consistent finding across nearly all experiments was the superiority of the layer immediately preceding the penultimate layer (denoted as $L-2$). This layer consistently outperformed the final layer ($L-1$) in OOD tasks, suggesting that the very last stages of feature extraction are where the most significant over-specialization occurs.

The Tunnel Effect and Sensitivity

The authors introduce a "sensitivity score" to quantify how much a layer's representations fluctuate when moving from ID to OOD data. The data reveals that final layers are significantly more sensitive to these shifts. This is attributed to the "Tunnel Effect": as data progresses deeper into a network, it is compressed to fit training labels. If those labels are associated with spurious cues, the final layers effectively "forget" the robust features present in earlier layers.

Zero-Shot Robustness

Remarkably, even when probes were trained exclusively on in-distribution data, selecting an intermediate layer based on a small OOD validation set led to massive performance gains. This indicates that robust features are inherently present within standard pre-trained models; they are simply discarded or ignored by the final classification head.

Results

The quantitative results underscore the efficacy of ILCs:

  • CelebA: Selecting an optimal intermediate layer resulted in a 25% gain in zero-shot OOD accuracy.
  • CMNIST: Intermediate layers improved zero-shot accuracy by 7% and few-shot accuracy by 12% over standard last-layer retraining.
  • Waterbirds: In zero-shot settings, the pen-penultimate layer achieved 87.1% worst-group accuracy, significantly higher than the 79.4% achieved by the final layer.
  • Architectural Consistency: These trends were observed in both convolutional (ResNet) and transformer-based (ViT) architectures, suggesting that the degradation of robust features in final layers is a fundamental property of deep learning hierarchies.

Conclusion and Future Work

This research highlights that the "best" features for generalization are often hidden in the intermediate layers of a network. While ILCs provide a powerful tool for OOD tasks, challenges remain regarding model selection—specifically, how to identify the optimal layer without requiring OOD validation data. Future research may also explore the application of ILCs to large-scale foundation models and LLMs, where the depth of the feature hierarchy presents even greater opportunities for discovering robust representations.

Summary updated

BibTeX
@inproceedings{uselis2025intermediate,
  author = {Arnas Uselis and Seong Joon Oh},
  title = {{Intermediate Layer Classifiers for OOD generalization}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=ByCV9xWfNK},
}
Figure