Giter Site home page Giter Site logo

pkulwj1994 / long-tailed-ood-detection Goto Github PK

View Code? Open in Web Editor NEW

This project forked from amazon-science/long-tailed-ood-detection

0.0 1.0 0.0 804 KB

Official implementation for "Partial and Asymmetric Contrastive Learning for Out-of-Distribution Detection in Long-Tailed Recognition" (ICML'22 Long Presentation)

Home Page: https://proceedings.mlr.press/v162/wang22aq/wang22aq.pdf

License: Apache License 2.0

Shell 0.17% Python 99.83%

long-tailed-ood-detection's Introduction

Partial and Asymmetric Contrastive Learning for Out-of-Distribution Detection in Long-Tailed Recognition

This is the official implementation of the Partial and Asymmetric Contrastive Learning for Out-of-Distribution Detection in Long-Tailed Recognition paper at ICML 22 (Long Presentation).

Stage 1 training: Training main branch using PASCL loss

CIFAR10-LT:

python stage1.py --gpu 0 --ds cifar10 --Lambda2 0.1 --T 0.07 \
    --drp <where_you_store_all_your_datasets> --srp <where_to_save_the_ckpt>

CIFAR100-LT:

python stage1.py --gpu 0 --ds cifar100 --Lambda2 0.02 --T 0.2 \
    --drp <where_you_store_all_your_datasets> --srp <where_to_save_the_ckpt>

ImageNet-LT:

python stage1.py --gpu 0 --ds imagenet --md ResNet50 -e 100 --opt sgd --decay multisteps --lr 0.1 --wd 5e-5 --tb 100 \
    --ddp --dist_url tcp://localhost:23457 \
    --drp <where_you_store_all_your_datasets> --srp <where_to_save_the_ckpt>

Stage 2 training: Finetune auxiliary classification head (ABF)

CIFAR10-LT:

python stage2.py --gpu 0 --ds cifar10 \
    --drp <where_you_store_all_your_datasets> \
    --pretrained_exp_str <the_name_of_your_stage1_training_experiment>

CIFAR100-LT:

python stage2.py --gpu 0 --ds cifar100 \
    --drp <where_you_store_all_your_datasets> \
    --pretrained_exp_str <the_name_of_your_stage1_training_experiment>

ImageNet-LT:

python stage2.py --gpu 0 --ds imagenet -e 3 --opt sgd --decay multisteps --lr 0.01 --wd 5e-5 --tb 100 \
    --ddp --dist_url tcp://localhost:23457 \
    --pretrained_exp_str <the_name_of_your_stage1_training_experiment>

--pretrained_exp_str should be something like e200-b256-adam-lr0.001-wd0.0005-cos_Lambda0.5-Lambda20.1-T0.07-sign-k0.5

Testing

CIFAR10-LT:

for dout in texture svhn cifar tin lsun places365
do
python test.py --gpu 0 --ds cifar10 --dout $dout \
    --drp <where_you_store_all_your_datasets> \
    --ckpt_path <where_you_save_the_ckpt>
done

CIFAR100-LT:

for dout in texture svhn cifar tin lsun places365
do
python test.py --gpu 0 --ds cifar100 --dout $dout \
    --drp <where_you_store_all_your_datasets> \
    --ckpt_path <where_you_save_the_ckpt>
done

ImageNet-LT:

python test_imagenet.py --gpu 0 \
    --drp <where_you_store_all_your_datasets> \
    --ckpt_path <where_you_save_the_ckpt>

Use stage 1 model to test OOD detection performance and stage 2 model to test in-distribution classification performance. Stage 1 and 2 models have identical parameters except those few in BN, the last fully connected layers and the small convolutions in skip connections on ImageNet models. We save them as two separate models for convenience.

To train or test our pretrained ImageNet model using ImageNet-10k dataset, you need to download it on your own and place it in the path indicated by --drp.

Pretrained models

Pretrained models are available on Google Drive

Acknowledgement

Part of our codes are adapted from these repos:

pytorch-cifar - https://github.com/kuangliu/pytorch-cifar - MIT license

SupContrast - https://github.com/HobbitLong/SupContrast - BSD-2-Clause license

outlier-exposure - https://github.com/hendrycks/outlier-exposure - Apache-2.0 license

Long-Tailed-Recognition.pytorch - https://github.com/KaihuaTang/Long-Tailed-Recognition.pytorch - GPL-3.0 license

Citation

@inproceedings{wang2022partial,
  title={Partial and Asymmetric Contrastive Learning for Out-of-Distribution Detection in Long-Tailed Recognition},
  author={Wang, Haotao and Zhang, Aston and Zhu, Yi and Zheng, Shuai and Li, Mu and Smola, Alex J and Wang, Zhangyang},
  booktitle={International Conference on Machine Learning},
  pages={23446--23458},
  year={2022},
}

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

long-tailed-ood-detection's People

Contributors

astonzhang avatar amazon-auto avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.