Source-linked AI summary

DICE: Leveraging Sparsification for Out-of-Distribution Detection

Yiyou Sun, Yixuan Li

arXiv:2111.09805v2cs.LG

TL;DR

OOD detection must distinguish unfamiliar inputs despite overconfident predictions and methods that overlook sparsification. DICE uses contribution-directed post hoc weight sparsification, and the paper reports reduced OOD output variance, sharper score distributions, stronger separability, and competitive benchmark performance.

  • Problem

    OOD detection is challenging because neural networks can produce overconfident predictions on unfamiliar inputs, while existing methods largely overlook sparsification.

  • Method

    DICE ranks weights by contribution and selectively retains important weights for OOD detection using post hoc sparsification.

  • Results

    DICE reduces OOD output variance, sharpens score distributions, strengthens ID–OOD separability, and achieves competitive performance across common benchmarks.

  • Takeaways & Limitations

    Contribution-directed sparsification improves OOD detection while preserving ID classification accuracy.

  • Takeaways & Limitations

    The theoretical analysis assumes independent components, although it states that the theory can extend to correlated variables.

Abstract

from arXiv · show

Detecting out-of-distribution (OOD) inputs is a central challenge for safely deploying machine learning models in the real world. Previous methods commonly rely on an OOD score derived from the overparameterized weight space, while largely overlooking the role of sparsification. In this paper, we reveal important insights that reliance on unimportant weights and units can directly attribute to the brittleness of OOD detection. To mitigate the issue, we propose a sparsification-based OOD detection framework termed DICE. Our key idea is to rank weights based on a measure of contribution, and selectively use the most salient weights to derive the output for OOD detection. We provide both empirical and theoretical insights, characterizing and explaining the mechanism by which DICE improves OOD detection. By pruning away noisy signals, DICE provably reduces the output variance for OOD data, resulting in a sharper output distribution and stronger separability from ID data. We demonstrate the effectiveness of sparsification-based OOD detection on several benchmarks and establish competitive performance.

1 Introduction

OOD detection is difficult because neural networks can produce overconfident predictions on unfamiliar inputs while existing scores largely overlook sparsification. DICE addresses this by retaining contribution-important weights, reducing noisy OOD signals and improving separability while preserving ID accuracy.

  • Motivation: Overconfident predictions on unfamiliar inputs make reliable separation between in-distribution and OOD data difficult.OOD detection is important for safety-critical applications such as medical diagnosis and autonomous driving.
  • Motivation: Existing OOD methods commonly derive scores from overparameterized weights while overlooking sparsification.The paper identifies this as a gap in current OOD detection approaches.
  • Motivation: OOD inputs can activate many penultimate-layer units with noisy, high-variance contributions, unlike ID inputs that rely on a subset of units.The figure measures each unit’s weight × activation contribution and shows the contrast between CIFAR-10 ID and OOD behavior.
  • DICE: DICE ranks weights by contribution and selectively uses the most contributing weights to derive OOD detection outputs.Post hoc weight masking enables use with a pre-trained network.
  • Results: DICE prunes noisy signals, producing sharper output distributions and stronger ID–OOD separability while preserving ID classification accuracy.The paper combines empirical evaluations with theoretical analysis of the resulting variance reduction.
  • Results: DICE achieves competitive benchmark performance and reduces FPR95 by up to 12.55% versus the strong post hoc baseline ReAct.The reported evaluation covers CIFAR-10, CIFAR-100, and ImageNet benchmarks.

2 Preliminaries

OOD detection treats identification of known versus unknown inputs as a binary decision while retaining multiclass classification for ID samples. The paper illustrates that selective sparsification can reduce OOD output variance and sharpen score separation.

  • OOD detection: A reliable deployed classifier should classify known ID samples accurately and identify OOD inputs as unknown.OOD detection supports precautionary behavior when inputs fall outside the training distribution.
  • Method overview: Without sparsification, class logits sum weighted activations from all preceding units, producing high OOD output variance.DICE instead uses a selective subset of weights to reduce variance and improve score separability.
  • OOD detection: OOD detection is formulated as deciding whether a test sample comes from the ID marginal distribution or not.OOD distributions often simulate irrelevant unknown classes whose labels do not overlap with the model’s output labels.
  • OOD detection: A threshold classifies samples with scores S(x) at least λ as ID and lower-scoring samples as OOD.The threshold rule defines the direction of the score comparison.

3 Method

DICE derives OOD scores by retaining weights associated with the most important unit contributions, then applies the resulting sparse output to downstream scoring. Its post hoc masking reduces irrelevant output contributions without changing the pretrained network parameters.

  • Method overview: DICE selectively uses important weights to derive the output for OOD detection, reducing irrelevant information in the final output.Without sparsification, all weighted activations are summed; DICE instead reduces OOD output variance and improves separability from ID data.
  • Contribution matrix: The contribution matrix V measures each unit’s average weight × activation contribution to every output class using in-distribution data.For class c, v_c is estimated as the expectation of element-wise weight–activation products over the in-distribution dataset.
  • Contribution matrix: DICE constructs a mask by retaining the k largest entries in V and computes logits with the element-wise masked weight matrix.The resulting output is f^DICE(x; θ) = (M ⊙ W)^T h(x) + b.
  • OOD scoring: DICE can be imposed by post hoc masking of the final layer and used with thresholding, energy, or maximum softmax probability OOD scores.The energy score maps DICE logits to a scalar and is relatively lower for ID data; the threshold is typically selected to retain a high fraction of correctly classified ID samples.
  • Sparsity parameter: The sparsity parameter p = 1 − k/(m·C) specifies the fraction of weights dropped, with p = 0 recovering the dense output.Larger p values indicate more dropped weights.

4 Experiments

Experiments evaluate DICE on CIFAR and ImageNet OOD benchmarks against post hoc and other competitive baselines. DICE improves FPR95 over dense energy scoring and ReAct, while sparsity reduces OOD score variance under suitable settings.

  • CIFAR benchmarks: DICE is evaluated on CIFAR-10 and CIFAR-100 using six OOD datasets and DenseNet-101 models trained on standard 50,000-image training splits.The CIFAR OOD datasets are Textures, SVHN, Places365, LSUN-Crop, LSUN-Resize, and iSUN.
  • Baselines: DICE is compared with post hoc OOD methods including MSP, ODIN, Mahalanobis, Generalized ODIN, Energy, and ReAct.Most methods use the same pretrained model, while Generalized ODIN requires retraining.
  • CIFAR benchmarks: On CIFAR-100, DICE reduces average FPR95 by 18.73% versus vanilla energy and by 12.55% versus ReAct.The averages are computed over six OOD test datasets.
  • CIFAR benchmarks: DICE preserves ID classification accuracy because the original fully connected layer can be used after an input is identified as ID.The authors describe this post hoc procedure as yielding identical classification accuracy with minimal overhead.
  • ImageNet benchmark: On ImageNet, DICE reduces FPR95 from 58.41% to 34.75% against energy scoring, a 23.66% improvement from sparsification.The evaluation uses a pretrained ResNet-50 and four OOD datasets spanning fine-grained, scene, and textural images.

5 Discussion and Ablations

The ablations show that moderate, contribution-directed sparsification improves OOD detection by reducing noisy output variance, while excessive sparsity harms performance. DICE’s directed unit and weight selection outperforms random, magnitude-based, and alternative subset-selection strategies.

  • Ablation on sparsity parameter p: Mild sparsity improves OOD detection, but performance degrades when sparsity becomes extreme, such as p = 0.99.The improvement is especially pronounced from p = 0 to p = 0.1.
  • Effect of variance reduction for output distribution: DICE reduces OOD output variance and produces a sharper distribution with stronger separability from ID data.Without sparsity, the OOD output distribution has larger variance and is less separable from ID data.
  • Ablation on pruning methods: Post hoc sparsification is designed for pretrained networks, avoiding retraining overhead that can hinder deployment in production environments.The method operates directly on a pretrained network through post hoc sparsification.
  • Ablation on pruning methods: At the same sparsity, DICE shows a 41.53% FPR95 gap over weight dropout, indicating the value of directed rather than random pruning.The ablation attributes the gap to dropping weights according to contribution.
  • Ablation on pruning methods: DICE outperforms L1-norm-based pruning by up to 18.06% FPR95 because contribution-directed pruning removes weights that can introduce noisy signals.Large-magnitude negative weights may remain under L1-norm pruning and corrupt the output.
  • Ablation on unit selection: Among subset-selection strategies, DICE’s top-k unit-contribution selection outperforms bottom-k, top+bottom-k, and random-k variants.Table 4 reports FPR95 averaged over multiple test datasets.

6 Why does DICE improve OOD detection?

DICE improves OOD detection by retaining contribution-ranked units, reducing noisy output variation and increasing ID–OOD separability. Its analysis attributes these gains to lower output variance and, additionally, preserved or enlarged mean differences.

  • DICE reduces output variance by pruning irrelevant or noisy unit contributions from the output sum.The analysis models unit contributions as random variables and first establishes variance additivity for independent variables.
  • DICE ranks units by contribution on ID data and uses the top units to compute the sparsified output.The contribution vector is based on weight × activation, and the selected units are those ranked highest by average ID contribution.
  • For correlated variables, the covariance terms imply a larger variance reduction for the top-unit submatrix than for the full matrix.The analysis states that the summed non-zero covariance terms are greater in the full matrix than in the top-unit submatrix.
  • DICE enlarges the ID–OOD score gap through reduced variances and maintained or increased differences in output means.The paper links this gap to stronger separability, including for energy scores based on the logits.
  • DICE preserves important ID information while reducing noisy signals affecting both ID and OOD outputs.The combined variance reduction on both distributions leads to stronger separability.

7 Related Work

Related work spans scoring-function methods, training-time regularization, and neural-network pruning or sparsification. DICE focuses on post hoc weight sparsification for OOD detection, distinguishing it from activation truncation and retraining-based approaches.

  • Scoring-function methods use confidence, energy, distance, gradient, or Bayesian approaches, but previous methods did not consider weight sparsification.ReAct is identified as the closest work because it truncates high activations at test time.
  • Training-time regularization methods shape predictions or energies for outlier data, whereas this paper focuses on post hoc methods.Post hoc methods avoid retraining overhead and are described as broadly applicable in production settings.
  • Prior pruning and sparsification work commonly uses sparse regularization or architecture modification, while DICE operates post hoc on a pretrained network.This distinction makes DICE a convenient sparsification strategy without changing the training procedure.
  • OOD detection addresses semantic shifts with disjoint labels, unlike OOD generalization, which targets accurate prediction under distributional change.The related-work discussion distinguishes these tasks by their objectives and label relationships.

8 Conclusion

The paper concludes that contribution-directed sparsification is a simple post hoc strategy for OOD detection. DICE combines theoretical variance reduction with empirical performance improvements by retaining important weights and removing noisy signals.

  • DICE ranks weights by contribution and uses the most significant weights to derive OOD-detection outputs.The strategy is designed as a simple sparsification method for overparameterized networks.
  • DICE provably reduces OOD output variance, producing a sharper output distribution and stronger separation from ID data.The conclusion attributes the improved separability to pruning noisy signals.
  • Extensive experiments show that DICE significantly improves OOD-detection performance for overparameterized networks.

A Reproducibility

The reproducibility materials describe public datasets, theoretical proofs, baseline settings, pretrained models, tuning procedures, and experimental hardware. The paper also reports that the code and dataset are openly available.

  • The experiments use publicly available datasets described in the paper’s dataset sections.
  • The complete theoretical proof is provided in Appendix E, and baseline descriptions and hyperparameters are specified in Appendix B.
  • ImageNet main results use a PyTorch-provided ResNet50 model in the post hoc evaluation setting.
  • The codebase and dataset are available online, and experiments were conducted on NVIDIA GeForce RTX 2080Ti GPUs.
  • DICE selects sparsity using Gaussian-noise validation images sampled from N(0, 1), with candidate p values from 0.1 through 0.99.The reported selected values are p=0.9 for CIFAR-10/100 and p=0.7 for ImageNet.
  • The selected sparsity setting is evaluated averaged across all considered OOD test datasets.

D More results on the effect of Sparsity Parameter p

The appendix evaluates how the sparsity parameter p affects OOD detection and classification across models trained on CIFAR-10 and ImageNet, with a similar trend reported for CIFAR-100.

  • p = {0.1, 0.3, 0.5, 0.7, 0.9, 0.99} is used to vary the sparsity parameter in the experiments.
  • The evaluation summarizes both OOD detection and classification performance for DenseNet models trained on CIFAR-10 and ImageNet.
  • Results are averaged over the test datasets described in Section 4.

E Variance Reduction with Correlated Variables

The correlated-variable analysis expresses output variance through covariance terms and argues that contribution-directed sparsification removes covariance contributions, producing variance reduction on OOD data.

  • Without sparsification, output variance equals the covariance diagonal sum plus twice the sum of upper-triangular covariance terms.
  • The covariance matrix of unit contributions is primarily zero on SVHN, indicating largely independent variables in the analyzed setting.
  • 2.2 is the measured value of 2 times the summed covariance terms for OOD data, supporting significant variance reduction with DICE.
  • DICE improves MSP performance empirically, although it remains below the main reported results, while the theory targets logit outputs compatible with energy scoring.
Loading 2111.09805v2…