Git Product home page Git Product logo

neglabel's Introduction

Negative Label Guided OOD Detection with Pretrained Vision-Language Models

Official PyTorch implementation of the ICLR 2024 (Spotlight) paper:

Negative Label Guided OOD Detection with Pretrained Vision-Language Models

Xue Jiang, Feng Liu, Zhen Fang, Hong Chen, Tongliang Liu, Feng Zheng, Bo Han

Abstract: In this paper, we propose a novel post hoc OOD detection method, called NegLabel, which takes a vast number of negative labels from extensive corpus databases. We design a novel scheme for the OOD score collaborated with negative labels. Theoretical analysis helps to understand the mechanism of negative labels. Extensive experiments demonstrate that our method NegLabel achieves state-of-the-art performance on various OOD detection benchmarks and generalizes well on multiple VLM architectures. Furthermore, our method NegLabel exhibits remarkable robustness against diverse domain shifts.

Installation

The project is based on MMClassification. MMClassification is an open source image classification toolbox based on PyTorch. It is a part of the OpenMMLab project.

Below are quick steps for installation:

conda create -n open-mmlab python=3.8 pytorch==1.10 torchvision==0.11.2 cudatoolkit=11.3 -c pytorch -y
conda activate open-mmlab
pip install openmim
cd NegLabel
mim install -e .
pip install ftfy regex tqdm
pip install git+https://github.com/openai/CLIP.git

Dataset Preparation

In-distribution dataset

Please download ImageNet-1k and place the training data (not necessary) and validation data in ./data/id_data/imagenet_train and ./data/id_data/imagenet_val, respectively.

Out-of-distribution dataset

Following MOS, we use the following 4 OOD datasets for evaluation: iNaturalist, SUN, Places, and Textures.

Please refer to MOS, download OOD datasets and put them into ./data/ood_data/.

About Negative Labels

We provide the wordnet database in ./txtfiles. We dynamically calculate and select negative labels based on the given ID labels and the database before the inference stage. We do not directly provide txt files for the selected negative labels. For details, please refer to ./mmcls/models/classifiers/multi_modal.py/#L140.

OOD Detection Evaluation

To reproduce our results, please run:

bash ./run.sh

Citation

@inproceedings{jiang2024neglabel,
  title={Negative Label Guided OOD Detection with Pretrained Vision-Language Models},
author={Xue Jiang and Feng Liu and Zhen Fang and Hong Chen and Tongliang Liu and Feng Zheng and Bo Han},
  booktitle = {International Conference on Learning Representations (ICLR)},
  year={2024}
}

neglabel's People

Contributors

xuejiang16 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

tmlr-group

neglabel's Issues

AttributeError: 'ConfigDict' object has no attribute 'train'

I got this error when running dist_train.sh:
Traceback (most recent call last): File "/data/lq/projects/neg_label/tools/train.py", line 203, in <module> main() File "/data/lq/projects/neg_label/tools/train.py", line 176, in main datasets = [build_dataset(cfg.data.train)] File "/data/lq/anaconda3/envs/open-mmlab/lib/python3.8/site-packages/mmcv/utils/config.py", line 50, in __getattr__ raise ex AttributeError: 'ConfigDict' object has no attribute 'train'
Whether 'clip.py' is the config file of train?
If not , could author share the config file of train.py?Thanks!

Would you provide the negative labels

Thanks for sharing your great work.
Would you provide the negative labels after NegMining? Providing negative labels of datasets like ImageNet would be much helpful, allowing for the direct utilization of the negative labels.

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.