Heng Gao, Jun Li
Fudan University
conda create -n openood python=3.8
pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu117
wget https://codeload.github.com/Vastlab/libMR/zip/refs/heads/master
cd python
pip install -r requirements.txt
cd ../
pip install .
cd ../
git clone https://github.com/Jingkang50/OpenOOD.git
cd OpenOOD
pip install -e .
pip install timmIn order to better adapt to the OpenOOD framework, we changed the vision_transformer.py in the Pytorch-Image-Models library as follows:
...
def forward(self, x, return_feature):
x = self.forward_features(x)
x, pre_logits = self.forward_head(x)
if return_feature:
return x, pre_logits
else:
return x
def get_fc(self):
fc = self.head
return fc.weight.cpu().detach().numpy(), fc.bias.cpu().detach().numpy()
def get_fc_layer(self):
return self.head
...Remark. All environment settings are listed in requirements.txt.
Our codebase accesses the datasets from ./data/ and pretrained models from ./results/checkpoints/ . One can download the datasets via running ./scripts/download/download.py.
├── ...
├── data
│ ├── benchmark_imglist
│ ├── images_classic
│ └── images_largescale
├── openood
├── results
│ ├── checkpoints
│ └── ...
├── scripts
├── main.py
├── ...
To synthesize OOD samples using Stable Diffusion, please refer to DreamOOD code repository for installation. Note that, here we use xformers==0.0.13. The synthesized data and token embeddings can be downloaded from this link. The following commands are the stepwise synthesis of OOD samples.
python outlier_generation/scripts/get_token_embed.py# CIFAR-10
python scripts/get_id_features_cifar10.py
# CIFAR-100
python scripts/get_id_features_cifar100.py# CIFAR-10
python scripts/get_embed_cifar10.py
# CIFAR-100
python scripts/get_embed_cifar100.pybash outlier_generation/generate_outliers_in_pixel_space.shHere is the pretrained weights of teacher models for Knowledge Distillation.
| In-Distribution Dataset | Download Links |
|---|---|
| CIFAR-10 | OneDrive |
| CIFAR-100 | OneDrive |
# Trained by OAL on CIAFR-10
bash scripts/basics/cifar10/train_cifar10_oal.sh
# Trained by OAL on CIFAR-100
bash scripts/basics/cifar100/train_cifar100_oal.sh# Test on CIFAR-100 using EBO score
bash scripts/ood/ebo/cifar100_test_ood_ebo.sh
# Test on CIFAR-10 using EBO score
bash scripts/ood/ebo/cifar10_test_ood_ebo.shBefore running this command, please load the pretrained models for testing.
The Leaderboard link is: https://zjysteven.github.io/OpenOOD/
OAL is developed based on OpenOOD, Pytorch-Image-Models and DreamOOD. Thanks to their great works.

