• Stars
    star
    306
  • Rank 136,456 (Top 3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created almost 3 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

source code for ICLR'22 paper "VOS: Learning What You Donโ€™t Know by Virtual Outlier Synthesis"

VOS

This is the source code accompanying the paper VOS: Learning What You Donโ€™t Know by Virtual Outlier Synthesis by Xuefeng Du, Zhaoning Wang, Mu Cai, and Yixuan Li

The codebase is heavily based on ProbDet and Detectron2.

Ads

Checkout our CVPR'22 work STUD on object detection in video datasets, NeurIPS'22 work SIREN on OOD detection for detection transformers if you are interested!

Update

02/05/2023---we have uploaded the code here for reproducing the figure 1 of our paper.

05/08/2022---We have updated the openreview with the new results of using a nonlinear MLP for binary classification instead of the logistic regression, which is slightly better. Please check the code and models here.

Requirements

pip install -r requirements.txt

In addition, install detectron2 following here.

Dataset Preparation

PASCAL VOC

Download the processed VOC 2007 and 2012 dataset from here.

The VOC dataset folder should have the following structure:

 โ””โ”€โ”€ VOC_DATASET_ROOT
     |
     โ”œโ”€โ”€ JPEGImages
     โ”œโ”€โ”€ voc0712_train_all.json
     โ””โ”€โ”€ val_coco_format.json

COCO

Download COCO2017 dataset from the official website.

Download the OOD dataset (json file) when the in-distribution dataset is Pascal VOC from here.

Download the OOD dataset (json file) when the in-distribution dataset is BDD-100k from here.

Put the two processed OOD json files to ./anntoations

The COCO dataset folder should have the following structure:

 โ””โ”€โ”€ COCO_DATASET_ROOT
     |
     โ”œโ”€โ”€ annotations
        โ”œโ”€โ”€ xxx (the original json files)
        โ”œโ”€โ”€ instances_val2017_ood_wrt_bdd_rm_overlap.json
        โ””โ”€โ”€ instances_val2017_ood_rm_overlap.json
     โ”œโ”€โ”€ train2017
     โ””โ”€โ”€ val2017

BDD-100k

Donwload the BDD-100k images from the official website.

Download the processed BDD-100k json files from here and here.

The BDD dataset folder should have the following structure:

 โ””โ”€โ”€ BDD_DATASET_ROOT
     |
     โ”œโ”€โ”€ images
     โ”œโ”€โ”€ val_bdd_converted.json
     โ””โ”€โ”€ train_bdd_converted.json

OpenImages

Download our OpenImages validation splits here. We created a tarball that contains the out-of-distribution data splits used in our paper for hyperparameter tuning. Do not modify or rename the internal folders as those paths are hard coded in the dataset reader. The OpenImages dataset is created in a similar way following this paper.

The OpenImages dataset folder should have the following structure:

 โ””โ”€โ”€ OEPNIMAGES_DATASET_ROOT
     |
     โ”œโ”€โ”€ coco_classes
     โ””โ”€โ”€ ood_classes_rm_overlap

Visualization of the OOD datasets

The OOD images with respect to different in-distribution datasets can be downloaded from ID-VOC-OOD-COCO, ID-VOC-OOD-openimages, ID-BDD-OOD-COCO, ID-BDD-OOD-openimages.

Training

Firstly, enter the detection folder by running

cd detection

Before training, modify the dataset address by changing "dataset-dir" according to your local dataset address.

Vanilla Faster-RCNN with VOC as the in-distribution dataset


python train_net.py
--dataset-dir path/to/dataset/dir
--num-gpus 8
--config-file VOC-Detection/faster-rcnn/vanilla.yaml 
--random-seed 0 
--resume

Vanilla Faster-RCNN with BDD as the in-distribution dataset

python train_net.py 
--dataset-dir path/to/dataset/dir
--num-gpus 8 
--config-file BDD-Detection/faster-rcnn/vanilla.yaml 
--random-seed 0 
--resume

VOS on ResNet

python train_net_gmm.py 
--dataset-dir path/to/dataset/dir
--num-gpus 8 
--config-file VOC-Detection/faster-rcnn/vos.yaml 
--random-seed 0 
--resume

VOS on RegNet

Before training using the RegNet as the backbone, download the pretrained RegNet backbone from here.

python train_net_gmm.py 
--dataset-dir path/to/dataset/dir
--num-gpus 8 
--config-file VOC-Detection/faster-rcnn/regnetx.yaml 
--random-seed 0 
--resume

Before training on VOS, change "VOS.STARTING_ITER" and "VOS.SAMPLE_NUMBER" in the config file to the desired numbers in paper.

Evaluation

Evaluation with the in-distribution dataset to be VOC

Firstly run on the in-distribution dataset:

python apply_net.py 
--dataset-dir path/to/dataset/dir
--test-dataset voc_custom_val 
--config-file VOC-Detection/faster-rcnn/vos.yaml 
--inference-config Inference/standard_nms.yaml 
--random-seed 0 
--image-corruption-level 0 
--visualize 0

Then run on the OOD dataset:

python apply_net.py
--dataset-dir path/to/dataset/dir
--test-dataset coco_ood_val 
--config-file VOC-Detection/faster-rcnn/vos.yaml 
--inference-config Inference/standard_nms.yaml 
--random-seed 0 
--image-corruption-level 0 
--visualize 0

Obtain the metrics using:

python voc_coco_plot.py 
--name vos 
--thres xxx 
--energy 1 
--seed 0

Here the threshold is determined according to ProbDet. It will be displayed in the screen as you finish evaluating on the in-distribution dataset.

Evaluation with the in-distribution dataset to be BDD

Firstly run on the in-distribution dataset:

python apply_net.py 
--dataset-dir path/to/dataset/dir
--test-dataset bdd_custom_val 
--config-file BDD-Detection/faster-rcnn/vos.yaml 
--inference-config Inference/standard_nms.yaml 
--random-seed 0 
--image-corruption-level 0 
--visualize 0

Then run on the OOD dataset:

python apply_net.py 
--dataset-dir path/to/dataset/dir
--test-dataset coco_ood_val_bdd 
--config-file BDD-Detection/faster-rcnn/vos.yaml 
--inference-config Inference/standard_nms.yaml 
--random-seed 0 
--image-corruption-level 0 
--visualize 0

Obtain the metrics using:

python bdd_coco_plot.py
--name vos 
--thres xxx 
--energy 1 
--seed 0

Pretrained models

The pretrained models for Pascal-VOC can be downloaded from vanilla and VOS-ResNet and VOS-RegNet.

The pretrained models for BDD-100k can be downloaded from vanilla and VOS-ResNet and VOS-RegNet.

VOS on Classification models

Train on WideResNet

cd classification/CIFAR/ & 
python train_virtual.py 
--start_epoch 40 
--sample_number 1000 
--sample_from 10000 
--select 1 
--loss_weight 0.1 

where "start_epoch" denotes the starting epoch of the uncertainty regularization branch.

"sample_number" denotes the size of the in-distribution queue.

"sample_from" and "select" are used to approximate the likelihood threshold during virtual outlier synthesis.

"loss_weight" denotes the weight of the regularization loss.

Please see Section 3 and Section 4.1 in the paper for details.

Train on DenseNet

cd classification/CIFAR/ &
python train_virtual_dense.py 
--start_epoch 40 
--sample_number 1000 
--sample_from 10000 
--select 1 
--loss_weight 0.1 

Evaluation on different classifiers

cd classification/CIFAR/ & 
python test.py 
--model_name xx 
--method_name xx 
--score energy 
--num_to_avg 10

where "model_name" denotes the model architectures. ("res" denotes the WideResNet and "dense" denotes the DenseNet.)

"method_name" denotes the checkpoint name you are loading.

Pretrained models

We provide the pretrained models using WideResNet and DenseNet with the in-distribution dataset to be CIFAR-10.

Citation

If you found any part of this code is useful in your research, please consider citing our paper:

 @article{du2022vos,
      title={VOS: Learning What You Donโ€™t Know by Virtual Outlier Synthesis}, 
      author={Du, Xuefeng and Wang, Zhaoning and Cai, Mu and Li, Yixuan},
      journal={Proceedings of the International Conference on Learning Representations},
      year={2022}
}

More Repositories

1

knn-ood

Code for ICML 2022 paper "Out-of-distribution Detection with Deep Nearest Neighbors"
Python
171
star
2

stud

source code for CVPR'22 paper "Unknown-Aware Object Detection: Learning What You Donโ€™t Know from Videos in the Wild"
Python
117
star
3

large_scale_ood

MOS: Towards Scaling Out-of-distribution Detection for Large Semantic Space
Python
83
star
4

MCM

PyTorch implementation of MCM (Delving into out-of-distribution detection with vision-language representations), NeurIPS 2022
Python
65
star
5

dream-ood

source code for NeurIPS'23 paper "Dream the Impossible: Outlier Imagination with Diffusion Models"
Python
59
star
6

gradnorm_ood

On the Importance of Gradients for Detecting Distributional Shifts in the Wild
Python
52
star
7

npos

source code for ICLR'23 paper "Non-parametric Outlier Synthesis"
Python
51
star
8

react

Code for NeurIPS 2021 paper "ReAct: Out-of-distribution Detection With Rectified Activations"
Python
50
star
9

dice

Code for ECCV 2022 paper "DICE: Leveraging Sparsification for Out-of-Distribution Detection"
Python
39
star
10

opencon

Code for TMLR 2023 paper "OpenCon: Open-world Contrastive Learning"
Python
34
star
11

MOOD

Code for CVPR2021 paper: MOOD: Multi-level Out-of-distribution Detection
Python
33
star
12

siren

source code for NeurIPS'22 paper "SIREN: Shaping Representations for Detecting Out-of-Distribution Objects"
Python
32
star
13

multi-label-ood

Python
31
star
14

cider

PyTorch implementation of CIDER (How to exploit hyperspherical embeddings for out-of-distribution detection), ICLR 2023
Python
25
star
15

poem

PyTorch implementation of POEM (Out-of-distribution detection with posterior sampling), ICML 2022
Python
23
star
16

Spurious_OOD

Python
21
star
17

vit-spurious-robustness

Python
20
star
18

picle

Official code for ICML 2024 paper on Persona In-Context Learning (PICLe)
Python
20
star
19

NSCL

Code for ICML 2023 paper "When and How Does Known Class Help Discover Unknown Ones? Provable Understandings Through Spectral Analysis"
Python
13
star
20

sal

source code for ICLR'24 paper "How does unlabeled data provably help OOD detection?"
Python
10
star
21

sorl

Code for NeurIPS 2023 paper "A Graph-Theoretic Framework for Understanding Open-World Semi-Supervised Learning"
Python
7
star
22

scone

Python
7
star
23

hypo

Python
6
star
24

id_label

source code for ICML'24 paper "When and how does in-distribution label help out-of-distribution detection?"
Python
4
star
25

PG-DRO

Official Implementation of AAAI 2023 paper "Distributionally Robust Optimization with Probabilistic Groups"
Python
4
star
26

haloscope

source code for NeurIPS'24 paper "HaloScope: Harnessing Unlabeled LLM Generations for Hallucination Detection"
3
star