Source-linked AI summary

How to Exploit Hyperspherical Embeddings for Out-of-Distribution Detection?

Yifei Ming, Yiyou Sun, Ousmane Dia, Yixuan Li

arXiv:2203.04450v3cs.CVcs.LG

TL;DR

OOD detection requires representations that separate unknown inputs from known classes, whereas off-the-shelf contrastive objectives may prioritize ID classification. CIDER learns hyperspherical embeddings with compactness and dispersion losses, and reports superior OOD detection performance while linking embedding properties to detection quality.

  • Problem

    Existing contrastive objectives can support ID classification but are not optimally designed for separating OOD inputs, motivating better representation learning for OOD detection.

    Source: §1 · p. 1
  • Method

    CIDER jointly optimizes dispersion and compactness losses over hyperspherical embeddings to separate class prototypes and pull samples toward their prototypes.

    Source: §1 · p. 2, §3.1 · p. 3
  • Results

    CIDER outperforms competitive OOD detection methods across common benchmarks and improves ID-OOD separability by 42.36% relative to SupCon across five OOD datasets.

    Source: §4.3 · p. 8, §6 · p. 9
  • Takeaways & Limitations

    Hyperspherical embedding quality, especially inter-class dispersion and compactness, is related to OOD detection performance and can support multiple distance-based scores.

    Source: §1 · p. 2, §4.2 · p. 6

Abstract

from arXiv · show

Out-of-distribution (OOD) detection is a critical task for reliable machine learning. Recent advances in representation learning give rise to distance-based OOD detection, where testing samples are detected as OOD if they are relatively far away from the centroids or prototypes of in-distribution (ID) classes. However, prior methods directly take off-the-shelf contrastive losses that suffice for classifying ID samples, but are not optimally designed when test inputs contain OOD samples. In this work, we propose CIDER, a novel representation learning framework that exploits hyperspherical embeddings for OOD detection. CIDER jointly optimizes two losses to promote strong ID-OOD separability: a dispersion loss that promotes large angular distances among different class prototypes, and a compactness loss that encourages samples to be close to their class prototypes. We analyze and establish the unexplored relationship between OOD detection performance and the embedding properties in the hyperspherical space, and demonstrate the importance of dispersion and compactness. CIDER establishes superior performance, outperforming the latest rival by 19.36% in FPR95. Code is available at https://github.com/deeplearning-wisc/cider.

1 INTRODUCTION

OOD detection aims to identify unknown inputs reliably, but existing contrastive objectives can produce embeddings that classify ID samples without sufficiently separating OOD data. CIDER addresses this gap by jointly shaping hyperspherical embeddings for compactness and dispersion, improving OOD detection performance.

  • OOD detection determines whether a test input belongs to the known distribution or comes from an unknown distribution.Source: §1 · p. 1
  • Distance-based methods use feature embeddings and assume OOD samples lie relatively far from ID data clusters.Source: §1 · p. 1
  • Existing contrastive objectives can suffice for ID classification while remaining sub-optimal for OOD detection.Source: §1 · p. 1
  • CIDER jointly optimizes dispersion and compactness losses to create hyperspherical embeddings with separated class prototypes and samples close to their prototypes.Source: §1 · p. 2
  • 42.36% relative improvement in ID-OOD separability is achieved by CIDER compared to SupCon on CIFAR-10.Source: §1 · p. 2
  • 13.33% error reduction in FPR95 is achieved by CIDER compared to the latest rival on CIFAR-100.Source: §1 · p. 2
  • CIDER establishes the relationship between hyperspherical embedding quality and OOD detection and remains effective under varied settings, including ImageNet.Source: §1 · p. 2

2 PRELIMINARIES

OOD detection is formulated as deciding whether a test sample belongs to the ID distribution or an OOD distribution. CIDER’s framework uses normalized hyperspherical embeddings and combines compactness with dispersion to shape the representation space.

  • OOD detection is treated as binary classification between samples from the ID distribution and samples from an OOD distribution.Source: §2 · p. 2
  • An OOD score classifies samples as ID when their score exceeds a threshold selected to retain a high fraction of correctly classified ID data.Source: §2 · p. 2
  • Hyperspherical embeddings lie on the surface of a unit hypersphere, whose points have constant Euclidean norm.Source: §2 · p. 2
  • CIDER’s compactness and dispersion terms encourage samples to remain close to class prototypes while different prototypes become more angularly separated.Source: Figure 1 · p. 3

3 METHOD

CIDER learns hyperspherical embeddings by modeling classes with von Mises–Fisher distributions and jointly optimizing compactness and dispersion. The framework uses these complementary properties to align samples with their class prototypes while separating class prototypes angularly for OOD detection.

Framework overview

  • CIDER uses an encoder and projection head to produce normalized hyperspherical feature embeddings for its training objective.The encoder maps augmented inputs to high-dimensional features, while the projection head produces lower-dimensional representations that are normalized before applying the loss.Source: §3 · p. 3

Hyperspherical modeling

  • The von Mises–Fisher model represents each class with a unit-norm prototype, while κ controls concentration around its mean direction.Larger κ produces stronger concentration; κ = 0 gives a uniform distribution on the hypersphere.Source: §3.1 · p. 3

Compactness loss

  • The compactness loss encourages each sample embedding to align closely with its class prototype and assigns higher probability to the correct class than to incorrect classes.The loss follows from the negative log-likelihood of the class-conditional vMF model and uses the sample’s class index and a temperature parameter.Source: §3.2 · pp. 3–4, §3.1 · p. 3

Dispersion loss

  • The dispersion loss maximizes angular distances among different class prototypes, because OOD samples may lie between ID clusters.Larger angular separation between ID prototypes can improve the separability of OOD samples that fall between those clusters.Source: §3.2 · p. 4, Figure 2 · p. 4

Combined objective

  • CIDER combines dispersion and compactness as LCIDER = Ldis + λcLcomp to shape embeddings for both ID classification and OOD detection.The coefficient λc controls the relative importance of the two loss terms, which are described as complementary.Source: §3.2 · p. 4

Prototype estimation and update

  • CIDER updates class prototypes with an exponential-moving-average rule rather than repeatedly computing means over all training samples.The update uses factor α to combine the previous prototype with the normalized embedding of samples from the class.Source: §3.2 · p. 4

4 EXPERIMENTS

Experiments evaluate CIDER with distance-based OOD scores on CIFAR and ImageNet benchmarks, then analyze how its loss components shape hyperspherical embeddings. Across these evaluations, CIDER improves OOD detection and produces more compact, dispersed, and separable representations.

Experimental setup

  • CIFAR-100 experiments use ResNet-34, with CIFAR-100 as ID and SVHN, Places365, Textures, LSUN, and iSUN as OOD datasets.The evaluation reports FPR95, AUROC, and ID classification accuracy.Source: §4.1 · p. 5

Main results

  • CIDER improves OOD detection over competitive methods, reducing FPR95 by 20.3% versus SSD+ and 13.3% versus KNN+.It also reduces average FPR95 by 20.6% compared with CSI.Source: §4.2 · pp. 5–6, Table 1 · p. 6

OOD score ablation

  • CIDER improves performance with both non-parametric KNN and parametric Mahalanobis scores.CIDER with KNN reduces FPR95 by 13.33% versus SupCon+KNN, while CIDER+Maha reduces FPR95 by 22.77% versus SSD+.Source: §4.2 · p. 6, Table 2 · p. 6

Loss ablation

  • The compactness loss alone supports ID classification, while inter-class dispersion from the dispersion loss is key to OOD detection.The loss components work synergistically to improve hyperspherical embeddings for both tasks.Source: §4.2 · p. 6, Table 3 · p. 7

Embedding analysis

  • CIDER embeddings are more compact and distribute classes more uniformly than CE embeddings in UMAP visualizations.The visualization links improved compactness and dispersion with greater OOD separability.Source: §4.3 · p. 7, Figure 3 · p. 7
  • CIDER improves inter-class dispersion by 12.03 degrees over SSD+ and yields a relative 42.36% improvement in ID-OOD separability over SupCon across five OOD datasets.Higher separability indicates that OOD samples are easier to detect.Source: §4.3 · pp. 7–8

Additional analysis

  • CIDER remains competitive on large-scale ImageNet-100 evaluations and across ablations involving training and model settings.The ImageNet-100 study fine-tunes a pre-trained ResNet-34, while additional experiments vary batch size and architecture.Source: §4.4 · p. 8, Figure 4 · p. 8

5 RELATED WORKS

Related work spans OOD detection, contrastive representation learning, and deep metric learning. Prior representation-learning approaches often adapt general-purpose contrastive losses for OOD detection, while CIDER focuses on hyperspherical embeddings and prototype dispersion.

Contrastive representation learning

  • Contrastive representation learning aligns positive samples while dispersing negative samples across supervised, semi-supervised, and unsupervised settings.Source: §5 · p. 9

Representation learning for OOD detection

  • Prior OOD studies apply off-the-shelf losses such as SupCon and SimCLR, whereas CIDER focuses on hyperspherical embeddings.Source: §5 · p. 9

Deep metric learning

  • Deep metric learning develops embeddings for verification, re-identification, and retrieval, but prior work does not focus on embeddings designed for OOD detection.Source: §5 · p. 9

6 CONCLUSION AND OUTLOOK

CIDER uses hyperspherical embeddings and jointly optimizes compactness and dispersion to promote ID-OOD separability. The framework also introduces embedding-quality measurements and reports strong performance across OOD benchmarks.

  • CIDER jointly optimizes dispersion and compactness losses to promote strong ID-OOD separability.Source: §6 · p. 9
  • CIDER achieves superior performance on common OOD benchmarks, including large-scale OOD detection tasks.Source: §6 · p. 9
  • The work introduces measurements linking hyperspherical embedding quality with OOD detection performance and evaluates CIDER through extensive ablations.Source: §6 · p. 9

A ALGORITHM DETAILS AND DISCUSSIONS

CIDER trains normalized hyperspherical embeddings with compactness and dispersion objectives, while prototypes are updated using exponential moving averages. The framework distinguishes prototype dispersion from instance-level contrastive uniformity and from cross-entropy training.

CIDER training framework

Prototype updates

Relation to contrastive losses

Relation to cross-entropy

Embedding measurements

B EXPERIMENTAL DETAILS

The experiments use specified hardware, projection-head architectures, training schedules, and KNN-based OOD scores. Settings vary across CIFAR-10, CIFAR-100, model scale, and batch size.

Software and hardware

Architecture

Training

  • CIFAR-10 models train for 100 epochs, while CIFAR-100 models train for 200 epochs under scheduled learning-rate decay.Source: B EXPERIMENTAL DETAILS · p. 15

OOD detection score

C ADDITIONAL ABLATION STUDIES

Additional ablations show that CIDER remains effective across batch sizes, prototype-update choices, hyperparameters, and architectures. EMA prototypes provide stronger stability, while moderate loss-weight changes preserve performance.

Batch size

  • CIDER outperforms SupCon across different batch sizes, aided by instance-to-prototype compactness and class-conditional prototypes that reduce batch-size dependence.The prototype updates capture class-average statistics and provide a memory-efficient alternative to instance-to-instance distance measurement.Source: C ADDITIONAL ABLATION STUDIES · p. 15, Figure 6 · p. 16

Loss weights

Prototype updates

  • For CIFAR-100, α = 0.5 achieves average FPR95 of 46.89% under KNN, while larger α values improve CIFAR-10 performance.Detection remains competitive across a wide range of prototype moving-average discount factors.Source: C ADDITIONAL ABLATION STUDIES · p. 16

Optimization

  • A relatively high initial learning rate is preferable, whereas a small temperature τ produces better OOD detection performance.Too small an initial learning rate, such as 0.1, degrades performance.Source: C ADDITIONAL ABLATION STUDIES · p. 16

Architecture

  • CIDER improves FPR95 across various test sets with ResNet-50, following the trend observed with ResNet-34.The architecture ablation attributes the improvement to the learned representation.Source: C ADDITIONAL ABLATION STUDIES · p. 16

Prototype update rules

Stability

D RESULTS ON LARGE-SCALE DATASETS

CIDER is evaluated when fine-tuning pre-trained models on ImageNet-100 and remains competitive with SupCon. Using the same KNN detection score, it outperforms SupCon across all tested OOD datasets.

Fine-tuning setup

  • CIDER and SupCon are compared by fine-tuning ImageNet-pre-trained ResNet-34 on ImageNet-100 for 10 epochs.The final residual block and nonlinear projection head are updated while earlier residual blocks are frozen.Source: D RESULTS ON LARGE-SCALE DATASETS · p. 17

Architecture context

  • CIDER’s architecture ablation on ResNet-50 reports results based on that network.The supplied architecture caption identifies the evaluation backbone but does not state a numerical comparison.Source: Figure 9 · p. 18

Results

  • With the same KNN detection score, CIDER consistently outperforms SupCon across all OOD test datasets.The comparison is reported for ImageNet-100 ID data.Source: Figure 10 · p. 18

E RESULTS ON CIFAR-10

The CIFAR-10 evaluation uses matched encoder and embedding settings for contrastive methods while varying the training objective, with Mahalanobis scoring used for several methods including CIDER.

Evaluation setup

  • For contrastive-loss methods, CIFAR-10 uses the same network encoder and embedding dimension while varying only the training objective.The evaluation uses Mahalanobis scoring for SSD+, CE+SimCLR, SupCon, and CIDER.Source: E RESULTS ON CIFAR-10 · p. 18

F ID CLASSIFICATION ACCURACY

ID classification accuracy is reported separately for CIFAR-10 and CIFAR-100, with contrastive methods evaluated using linear probes on normalized features. The supplied passages identify the relevant tables but provide no accuracy values.

Evaluation protocol

  • For contrastive methods including KNN+, SSD+, and CIDER, ID classification uses linear probes on normalized features.This follows the common practice used for contrastive representation learning.Source: F ID CLASSIFICATION ACCURACY · p. 18

CIFAR-10 results

  • CIDER is described as achieving strong OOD detection performance and ID classification accuracy on CIFAR-10.The supplied table caption does not provide the corresponding numerical values.Source: Table 7 · p. 19

CIFAR-10

  • Table 8 reports ID classification accuracy on CIFAR-10.The supplied table passage provides the table’s topic but no numerical values.Source: Table 8 · p. 19

CIFAR-100

  • Table 9 reports ID classification accuracy on CIFAR-100.The supplied table passage provides the table’s topic but no numerical values.Source: Table 9 · p. 19
Loading 2203.04450v3…