This repo contains the official implementation for the CVPR2023 paper:
Balanced Energy Regularization Loss for Out-of-distribution Detection
by Hyunjun Choi, Hawook Jeong, and Jin Young Choi.
![thumbnail_intro](https://private-user-images.githubusercontent.com/31534910/247373237-06f91c9a-6238-4a4c-a0df-6a8d44e0b438.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzQ0NzUzODAsIm5iZiI6MTczNDQ3NTA4MCwicGF0aCI6Ii8zMTUzNDkxMC8yNDczNzMyMzctMDZmOTFjOWEtNjIzOC00YTRjLWEwZGYtNmE4ZDQ0ZTBiNDM4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDEyMTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQxMjE3VDIyMzgwMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTIwN2UxY2YxMzMzNmZlY2I3MWYyY2ZiZTFlOTkxOTViMGJjYjE0NGI4NDQ5NmQ5OGY1YTVjZWJmM2M5Y2YyZTUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0._e3TpMj0VcBeACb3MaE94ag3xKGKuwK-XOJWmFNTlHI)
Our code heavily relies on the implementation of Energy-based Out-of-distribution Detection and PEBAL
We follow the installation process of PEBAL
All data tree has to be inserted in path: Balanced_Energy/segmentation/code/dataset
We use cifar10, cifar100 as training data
We use auxiliary data as 300K random images following Outlier Exposure
We test on the SC-OOD benchmark ,this should be inserted in data tree which can be downloaded from SC-OOD UDG
classification/data
├── cifar10
├── cifar100
├── data
│ ├── images
│ └── imglist
└── tinyimages80m
└── 300K_random_images.npy
The project is based on the pytorch 1.8.1 with python 3.8.
- create conda env
$ conda env create -f balanced.yml
- install the torch 1.8.1
$ conda activate balanced # IF cuda version < 11.0 $ pip install torch==1.8.1+cu102 torchvision==0.9.1+cu102 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html # IF cuda version >= 11.0 (e.g., 30x or above) $ pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
All checkpoint is in the zip files following google drive link:
put the checkpoint in the path : Balanced_Energy/segmentation/ckpts/pebal_balanced/
additionally, to finetune from the nvidia cityscapes model,
we follow Meta-OoD and use the deeplabv3+ checkpoint in here. you'll need to put it in "ckpts/pretrained_ckpts" directory, and please note that downloading the checkpoint before running the code is necessary
put the checkpoint in the path : Balanced_Energy/classification/snapshots/pretrained
Open Balanced_Energy/segmentation/code/config/config.py
Set the root path for datasets
- python code/main.py in the Balanced_Energy/segmentation/
- python code/test.py in the Balanced_Energy/segmentation/
in the Balanced_Energy/classification/
run ResNet18 balanced_energy_fine_tune training and testing for cifar10 with trial index 3
bash inf_run_res.sh energy_ft 0 3
run ResNet18 balanced_energy_fine_tune training and testing for cifar100 with trial index 3
bash inf_run_res.sh energy_ft 1 3
run ResNet18 balanced_energy_fine_tune training and testing for cifar10-LT with trial index 3
bash inf_run_im_res.sh energy_ft 0 3
run ResNet18 balanced_energy_fine_tune training and testing for cifar100-LT with trial index 3
bash inf_run_im_res.sh energy_ft 1 3
the setting of hyperparameter alpha and gamma can be controlled in the bash script
If you find this project useful, please consider the citation:
@inproceedings{choi2023balanced,
title={Balanced Energy Regularization Loss for Out-of-Distribution Detection},
author={Choi, Hyunjun and Jeong, Hawook and Choi, Jin Young},
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
pages={15691--15700},
year={2023}
}