Skip to content

limchaos/Likelihood-OOD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Revisiting Likelihood-Based Out-of-Distribution Detection by Modeling Representations

This is the pytorch implementation of our paper [Revisiting Likelihood-Based Out-of-Distribution Detection by Modeling Representations], a comprehensive investigation for OOD detection using likelihood estimated by diffusion models on image representations. The pip package can be found here!

Requirments

  • Python >=3.7
  • pytorch-cuda = 11.8
  • scipy = 1.13.1
  • faiss-gpu = 1.8.2
  • einops = 0.8.0
  • torchdiffeq = 0.2.4

You can also use Anaconda

conda env create -f environment.yaml

to manage the enviroment.

DataSets

Dataset source can be downloaded here, we use the same dataset as in VIM and GEN,

  • ImageNet. The ILSVRC 2012 dataset as In-distribution (ID) dataset. The training subset we used is this file.
  • OpenImage-O. The OpenImage-O dataset is a subset of the OpenImage-V3 testing set. The filelist is here.
  • Texture. We rule out four classes that coincides with ImageNet. The filelist used in the paper is here.
  • iNaturalist. Follow the instructions in the link to prepare the iNaturalist OOD dataset.
  • ImageNet-O. Follow the guide to download the ImageNet-O OOD dataset.
mkdir data
cd data
ln -s /path/to/imagenet imagenet
ln -s /path/to/openimage_o openimage_o
ln -s /path/to/texture texture
ln -s /path/to/inaturalist inaturalist
ln -s /path/to/imagenet_o imagenet_o
cd ..

Pretrained Model Preparation

Self-supervised encoder

For DINO, DINOv2 and MAE, we use all the encoders from the official repo.

Supervised encoder

For all supervised encoders, we refer to VIM.

Train

export LR=2e-3 && export EPOCH=200 && WD=0 && DIR=output1

mkdir -p ./checkpoint/${DIR}/con
mkdir -p ./checkpoint/${DIR}/uncon

python run.py dinov2 ${LR} ${EPOCH} ${WD} imagenet2012_train_random_200k.pkl ${DIR} #-logit -norm

or check train.sh.

Evaluate

export DIR=output1
mkdir -p ./eval/${DIR}

python eval.py dinov2 ${DIR} #-logit -norm

or check eval.sh.

TODO

  • Add 2d toy data training and visualization
  • Add histopathology data
  • Add code for arbitrary encoder

Acknowledgement

Part of the code is modified from VIM, RCG and Score-Based Generative Modeling through Stochastic Differential Equations.

Reference

@inproceedings{ding2025revisiting,
  title={Revisiting likelihood-based out-of-distribution detection by modeling representations},
  author={Ding, Yifan and Aleksandraus, Arturas and Ahmadian, Amirhossein and Unger, Jonas and Lindsten, Fredrik and Eilertsen, Gabriel},
  booktitle={Scandinavian Conference on Image Analysis},
  pages={166--179},
  year={2025},
  organization={Springer}
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors