Skip to content
/ hood Public

Out-of-Distribution Detection with Hilbert-Schmidt Independence Optimization

Notifications You must be signed in to change notification settings

jylins/hood

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Out-of-Distribution Detection with Hilbert-Schmidt Independence Optimization

This repository is the official PyTorch implementation of HOOD (HSIC assisted OOD detection).

0 Requirements

  • Python 3.6
  • PyTorch install = 1.6.0
  • torchvision install = 0.7.0
  • CUDA 10.1
  • Other dependencies: numpy, sklearn, six, pickle, lmdb

1 Training

We release a demo for the proposed HOOD method. The demo includes several OOD detection methods and baselines: MSP, OE, HOOD, HOOD+aug. All of the models are built based on WideResNet-40-2 architecture, trained for 100 epochs.

1.1 MSP

To train MSP for 100 epochs, run:

DATASET='cifar100'
MODEL='wrn'
seeds='0'
DIRNAME=${DATASET}_${MODEL}_msp

python train_base.py \
    ${DATASET} \
    --model ${MODEL} \
    --save ./outputs/${DIRNAME}/seed_${seed} \
    --seed ${seed}

1.2 OE

To train OE for 100 epochs, run:

DATASET='cifar100'
MODEL='wrn'
seeds='0'
DIRNAME=${DATASET}_${MODEL}_oe

python train.py \
    ${DATASET} \
    --model ${MODEL} \
    --save ./outputs/${DIRNAME}/seed_${seed} \
    --oe-weight 0.5 \
    --disable_random 1 \
    --seed ${seed}

1.3 HOOD

To train HOOD for 100 epochs, run:

DATASET='cifar100'
MODEL='wrn'
seeds='0'
hoodW=1.0
hoodT=5
augN=0
DIRNAME=${DATASET}_${MODEL}_hood_t${hoodT}_w${hoodW}_augn${augN}

python train.py \
    ${DATASET} \
    --model ${MODEL} \
    --save ./outputs/${DIRNAME}/seed_${seed} \
    --hsic-weight ${hoodW} \
    --hsic-tau ${hoodT} \
    --disable_random 1 \
    --aug 0 \
    --aug-n ${augN} \
    --seed ${seed}

1.4 HOOD+aug

To train HOOD+aug for 100 epochs, run:

DATASET='cifar100'
MODEL='wrn'
seeds='0'
hoodW=1.0
hoodT=5
augN=4
DIRNAME=${DATASET}_${MODEL}_hood_t${hoodT}_w${hoodW}_augn${augN}

python train.py \
    ${DATASET} \
    --model ${MODEL} \
    --save ./outputs/${DIRNAME}/seed_${seed} \
    --hsic-weight ${hoodW} \
    --hsic-tau ${hoodT} \
    --disable_random 1 \
    --aug 1 \
    --aug-n ${augN} \
    --seed ${seed}

2 Evaluation

We present a demo for two evaluation metrics, including Softmax (SFM) metric and Correlation (COR) metric.

2.1 Softmax Metric

DIRNAME=dirname_demo
seeds=seed_demo

python test.py \
    --method_name ${DIRNAME} \
    --save ./outputs/${DIRNAME}/seed_${seed} \
    --load ./outputs/${DIRNAME}/seed_${seed}/checkpoints/ckp-99.pth \
    --num_to_avg 10

2.2 Correlation Metric

DIRNAME=dirname_demo
seeds=seed_demo

python test_cor.py \
    --method_name ${DIRNAME} \
    --save ./outputs/${DIRNAME}/seed_${seed} \
    --load ./outputs/${DIRNAME}/seed_${seed}/checkpoints/ckp-99.pth \
    --num_to_avg 10

Citation

@article{lin2022out,
  title={Out-of-Distribution Detection with Hilbert-Schmidt Independence Optimization},
  author={Lin, Jingyang and Wang, Yu and Cai, Qi and Pan, Yingwei and Yao, Ting and Chao, Hongyang and Mei, Tao},
  journal={arXiv preprint arXiv:2209.12807},
  year={2022}
}

About

Out-of-Distribution Detection with Hilbert-Schmidt Independence Optimization

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published