On the distribution of penultimate activations of classification networks

Minkyo Seo, Yoonho Lee, Suha Kwak

Abstract

This paper studies probability distributions of penultimate activations of classification networks. We show that, when a classification network is trained with the cross-entropy loss, its final classification layer and penultimate activations form a generative-discriminative pair. Specifically, the penultimate layer implicitly follows a von Mises-Fisher (vMF) distribution, where the final layer's weights act as the distribution's parameters. By leveraging this insight, we develop Class-wise Knowledge Distillation (CKD) and improve class-conditional image generation.

Introduction

In deep learning, the "penultimate activations"—the features immediately preceding the final softmax layer—are often treated as a black box. While these high-dimensional representations are known to be useful for downstream tasks like image retrieval, a formal probabilistic model for their distribution has been lacking. This gap creates challenges in two key areas:

  1. Knowledge Distillation (KD): Standard KD relies on a "teacher" network's response to specific input data. If the data distribution shifts (e.g., due to noise), the teacher's outputs become unreliable, degrading the "student" network's performance.
  2. Generative Modeling: Conditional generative models often struggle to integrate class labels effectively, frequently relying on simple concatenation that fails to capture the complex inter-class relationships learned by a classifier.

The Implicit von Mises-Fisher Distribution

The authors bridge this gap by mathematically analyzing the cross-entropy loss. They demonstrate that the normalized activations ($\bar{a}$) for a given class follow a von Mises-Fisher (vMF) distribution. In this model, the mean direction is defined by the normalized weight vector ($\bar{w}_i$) of the final layer for that class, while the concentration parameter ($\kappa$) indicates how tightly the features cluster around that vector.

Evolution of penultimate activation clusters over training epochs on MNIST. The features increasingly align with the directional prototypes defined by the final layer weights.

This discovery suggests that the weights of the final layer are not merely arbitrary parameters but serve as "prototypes" or centers for each class in the feature space. Interestingly, the authors found that normalizing both activations and weights—thereby discarding magnitude and keeping only direction—results in only a marginal drop in accuracy (e.g., ~1% on ResNet-152), confirming that the angle between features and weights is the primary driver of classification.

Class-wise Knowledge Distillation (CKD)

Building on the vMF model, the authors propose Class-wise Knowledge Distillation (CKD). Unlike standard KD, where the student mimics the teacher's output for every individual image, CKD allows the student to learn the teacher's internal class relationships by sampling from the derived vMF distributions.

Comparison between standard Knowledge Distillation (Algorithm 1) and the proposed Class-wise Knowledge Distillation (Algorithm 2).

Because CKD does not rely on the teacher's response to specific (and potentially noisy) input images, it is significantly more stable under domain shift. For example, if a teacher is fed a blurry image, standard KD forces the student to learn that specific uncertainty. CKD avoids this by using the teacher's "idealized" class distributions instead of its noisy per-image outputs.

Experimental Results

The theory was validated across several benchmarks including MNIST, ImageNet, CIFAR-10, and CIFAR-100.

  • Robustness to Domain Shift: Under severe photometric noise on CIFAR-100, standard KD accuracy dropped from 74.9% to 51.3%. In contrast, CKD maintained a much higher accuracy of 72.4%.
  • Generative Priors: Using the vMF distribution as a prior in a Hyperspherical VAE (HVAE-L) yielded superior Log-Likelihood and ELBO scores compared to standard conditional VAEs. Qualitatively, the latent space exhibited smoother transitions between classes (e.g., a digit '1' gradually morphing into a '2').
  • Improved GANs: Integrating the vMF prior into SNGAN improved the Inception Score (IS) on CIFAR-10 from 8.406 to 8.511, indicating higher diversity and quality in generated images.

Conclusion

This work reveals that classification networks implicitly learn a structured directional distribution in their penultimate layer. By formalizing this as a von Mises-Fisher distribution, we can perform data-free affinity estimation and more robust knowledge transfer. Future work may involve dynamically learning the concentration parameter $\kappa$ or utilizing vMF distribution overlaps for improved uncertainty estimation and anomaly detection.

Summary updated

BibTeX
@inproceedings{seo2021distribution,
  author = {Minkyo Seo and Yoonho Lee and Suha Kwak},
  title = {{On the distribution of penultimate activations of classification networks}},
  booktitle = {Conference on Uncertainty in Artificial Intelligence},
  year = {2021},
  url = {https://openreview.net/forum?id=p1KmZ95qjX},
}
Figure