Home

Awesome

ReweightOOD: Loss Reweighting for Distance-based OOD Detection

This codebase provides a Pytorch implementation of:

ReweightOOD: Loss Reweighting for Distance-based OOD Detection.
ReweightOOD
Sudarshan Regmi, Bibek Panthi, Yifei Ming, Prashnna K. Gyawali, Danail Stoyanov, Binod Bhattarai

Abstract

Out-of-Distribution (OOD) detection is crucial for ensuring safety and reliability of neural networks in critical applications. Distance-based OOD detection is based on the assumption that OOD samples are mapped far from In-Distribution (ID) clusters in embedding space. A recent approach for obtaining OOD-detection-friendly embedding space has been contrastive optimization of pulling similar pairs and pushing apart dissimilar pairs. It assigns equal significance to all similarity instances with the implicit objective of maximizing the mean proximity between samples with their corresponding hypothetical class centroids. However, the emphasis should be directed towards reducing the Minimum Enclosing Sphere (MES) for each class and achieving higher inter-class dispersion to effectively mitigate the potential for ID-OOD overlap. Optimizing low-signal dissimilar pairs might potentially act against achieving maximal inter-class dispersion while less-optimized similar pairs prevent achieving smaller MES. Based on this, we propose a reweighting scheme ReweightOOD, that adopts the similarity optimization which prioritizes the optimization of less-optimized contrasting pairs while assigning lower importance to already well-optimized contrasting pairs. Such a reweighting scheme serves to minimize the MES for each class while achieving maximal inter-class dispersion. Experimental results on a challenging CIFAR100 benchmark using ResNet-18 network demonstrate that ReweightOOD outperforms supervised contrastive loss by a whopping 38% in the average FPR metric. In various classification datasets, our method provides a promising solution for enhancing OOD detection capabilities in neural networks.

ReweightOOD highlights in OpenOODv1.5 leaderboard [Updated: June 2024]

ranks 2nd in the far-OOD AUROC metric on CIFAR10 datasets.
ranks 1st in the far-OOD AUROC metric on CIFAR100 datasets.
ranks 5th in the far-OOD AUROC metric on ImageNet200 datasets (OOD).
ranks 2nd in the far-OOD AUROC metric on ImageNet200 datasets (FSOOD).
ranks 9th in the far-OOD AUROC metric on ImageNet-1k datasets (OOD).
ranks 6th in the far-OOD AUROC metric on ImageNet-1k datasets (FSOOD).

<p style="display: flex; align-items: center;"> <span>Check other works:</span>&nbsp;&nbsp;&nbsp; <a href="https://github.com/sudarshanregmi/t2fnorm"><img src="https://img.shields.io/badge/CVPRW'24-T2FNorm-fdd7e6?style=for-the-badge" alt="t2fnorm" style="margin-right: 10px;"></a> </p>

Follow OpenOOD official instruction to complete the setup.

pip install git+https://github.com/Jingkang50/OpenOOD

Method Illustration

<p align="center"> <img width="800" src="ReweightOOD.png"> </p>

Example Scripts for Training and Inference

Use the following scripts for training and inferencing the ReweightOOD model on different datasets:

Results

datasetsFPR@95AUROCAUPR_INAUPR_OUT
cifar10037.68 ± 0.9789.64 ± 0.0890.33 ± 0.1188.55 ± 0.09
tin23.79 ± 0.8694.09 ± 0.3095.43 ± 0.2492.31 ± 0.44
nearood30.74 ± 0.7991.86 ± 0.1692.88 ± 0.1790.43 ± 0.19
mnist6.33 ± 0.7198.40 ± 0.1994.91 ± 0.5299.73 ± 0.03
svhn0.32 ± 0.0399.87 ± 0.0199.65 ± 0.0399.96 ± 0.00
texture10.48 ± 0.8498.09 ± 0.1398.83 ± 0.0897.12 ± 0.21
places36517.05 ± 1.1595.82 ± 0.3190.46 ± 0.6298.64 ± 0.12
farood8.54 ± 0.3598.05 ± 0.1095.96 ± 0.2698.86 ± 0.05
datasetsFPR@95AUROCAUPR_INAUPR_OUT
cifar1086.11 ± 1.3363.31 ± 0.7660.62 ± 1.2562.48 ± 0.73
tin64.70 ± 0.4879.24 ± 0.0584.21 ± 0.1370.19 ± 0.11
nearood75.41 ± 0.8671.27 ± 0.4172.42 ± 0.6966.34 ± 0.40
mnist35.22 ± 1.8089.90 ± 1.5573.43 ± 1.5398.19 ± 0.39
svhn8.83 ± 1.0198.44 ± 0.1996.33 ± 0.3999.44 ± 0.07
texture32.64 ± 2.9893.11 ± 0.5695.25 ± 0.3990.17 ± 0.72
places36554.02 ± 2.0083.04 ± 0.5165.02 ± 1.5993.35 ± 0.14
farood32.68 ± 0.4991.12 ± 0.3382.51 ± 0.4695.29 ± 0.06
datasetsFPR@95AUROCAUPR_INAUPR_OUT
ssb_hard68.20 ± 0.3676.34 ± 0.3542.35 ± 0.2893.45 ± 0.13
ninco48.54 ± 0.8984.36 ± 0.1589.99 ± 0.1375.66 ± 0.24
nearood58.37 ± 0.5780.35 ± 0.2266.17 ± 0.1784.55 ± 0.15
inaturalist24.24 ± 0.6493.93 ± 0.1794.38 ± 0.1793.96 ± 0.15
textures14.54 ± 0.4497.33 ± 0.1498.35 ± 0.0895.95 ± 0.21
openimage_o31.61 ± 0.2590.72 ± 0.0988.30 ± 0.0393.56 ± 0.10
farood23.46 ± 0.3193.99 ± 0.0893.68 ± 0.0794.49 ± 0.12
datasetsFPR@95AUROCAUPR_INAUPR_OUT
ssb_hard89.85 ± 0.1246.11 ± 0.1948.35 ± 0.1349.29 ± 0.20
ninco81.63 ± 0.2857.24 ± 0.4291.51 ± 0.0814.80 ± 0.29
nearood85.74 ± 0.1851.68 ± 0.1869.93 ± 0.0632.04 ± 0.18
inaturalist66.34 ± 0.4177.03 ± 0.3593.39 ± 0.0947.05 ± 0.81
textures52.51 ± 1.0589.20 ± 0.5398.31 ± 0.0862.10 ± 1.82
openimage_o72.40 ± 0.1468.68 ± 0.7086.39 ± 0.2645.00 ± 0.69
farood63.75 ± 0.3678.31 ± 0.4692.70 ± 0.1151.38 ± 0.92
datasetsFPR@95AUROCAUPR_INAUPR_OUT
ssb_hard86.361.159.7760.37
ninco58.7580.0796.7832.58
nearood72.5370.5878.2746.48
inaturalist21.4393.5598.4672.67
textures5.1998.8499.8593.85
openimage_o33.8592.0596.9780.57
farood20.1694.8298.4382.36
datasetsFPR@95AUROCAUPR_INAUPR_OUT
ssb_hard92.1643.8265.4728.58
ninco74.4562.596.777.24
nearood83.353.1681.1217.91
inaturalist44.780.3697.6321.29
textures21.3895.2799.7160.32
openimage_o56.1379.495.9632.85
farood40.7485.0197.7638.16

Pre-trained checkpoints

Pre-trained models are available in the given links:

Please consider citing our work if you find it useful.

@InProceedings{Regmi_2024_CVPR_1,
    author    = {Regmi, Sudarshan and Panthi, Bibek and Ming, Yifei and Gyawali, Prashnna K and Stoyanov, Danail and Bhattarai, Binod},
    title     = {ReweightOOD: Loss Reweighting for Distance-based OOD Detection},
    booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) Workshops},
    month     = {June},
    year      = {2024},
    pages     = {131-141}
}

Acknowledgment

This codebase builds upon OpenOOD.