The crux of effective out-of-distribution (OOD) detection lies in acquiring a robust in-distribution (ID) representation, distinct from OOD samples. While previous methods predominantly leaned on recognition-based techniques for this purpose, they often resulted in shortcut learning, lacking comprehensive representations. In our study, we conducted a comprehensive analysis, exploring distinct pretraining tasks and employing various OOD score functions. The results highlight that the feature representations pre-trained through reconstruction yield a notable enhancement and narrow the performance gap among various score functions. This suggests that even simple score functions can rival complex ones when leveraging reconstruction-based pretext tasks. Reconstruction-based pretext tasks adapt well to various score functions. As such, it holds promising potential for further expansion. Our OOD detection framework, MOODv2, employs the masked image modeling pretext task. Without bells and whistles, MOODv2 impressively enhances 14.30% AUROC to 95.68% on ImageNet and achieves 99.98% on CIFAR-10.
framework
Performance
table
Usage
To predict an input image is in-distribution or out-of-distribution, we support the following OOD detection methods:
MSP
MaxLogit
Energy
Energy+React
ViM
Residual
GradNorm
Mahalanobis
KL-Matching
bash
1python src/demo.py \2 --img_path imgs/DTD_cracked_0004.jpg \# change to your image path if needed3 --cfg configs/beit-base-p16_224px.py \4 --checkpoint pretrain/beitv2-base_3rdparty_in1k_20221114-73e11905.pth \5 --fc data/fc.pkl \6 --id_train_feature data/imagenet_train.pkl \7 --id_val_feature data/imagenet_test.pkl \8 --methods MSP MaxLogit Energy Energy+React ViM Residual GradNorm Mahalanobis
For the example OOD image imgs/DTD_cracked_0004.jpg, you are supposed to get: