Coder Social home page Coder Social logo

himplos's Introduction

Classifier-Head Informed Feature Masking and Prototype-Based Logit Smoothing for Out-of-Distribution Detection

This is the source code for "Classifier-Head Informed Feature Masking and Prototype-Based Logit Smoothing for Out-of-Distribution Detection".

Usage

1. Dataset Preparation for Large-scale Experiment

In-distribution dataset

Please download ImageNet-1k and place the training data and validation data in ./data/ilsvrc2012/train and /data/ilsvrc2012/val, respectively.

Out-of-distribution dataset

We have 4 OOD datasets from iNaturalist, SUN, Places, and Textures, and de-duplicated concepts overlapped with ImageNet-1k.

For iNaturalist, SUN, and Places, we have sampled 10,000 images from the selected concepts for each dataset, which can be download via the following links:

wget http://pages.cs.wisc.edu/~huangrui/imagenet_ood_dataset/iNaturalist.tar.gz
wget http://pages.cs.wisc.edu/~huangrui/imagenet_ood_dataset/SUN.tar.gz
wget http://pages.cs.wisc.edu/~huangrui/imagenet_ood_dataset/Places.tar.gz

For Textures, we use the entire dataset, which can be downloaded from their original website.

Please put all downloaded OOD datasets into ./data/ood_data/.

2. Dataset Preparation for CIFAR Experiment

In-distribution dataset

The downloading process will start immediately upon running.

Out-of-distribution dataset

We provide links and instructions to download each dataset:

  • SVHN: download it and place it in the folder of /data/ood_data/SVHN. Then run python select_svhn_data.py to generate test subset.
  • Textures: download it and place it in the folder of ./data/ood_data/dtd/images.
  • Places365: download it and place it in the folder of ./data/ood_data/places365/test_subset. We randomly sample 10,000 images from the original test dataset.
  • LSUN-C: download it and place it in the folder of ./data/ood_data/LSUN-C.
  • LSUN-R: download it and place it in the folder of ./data/ood_data/LSUN_R.
  • iSUN: download it and place it in the folder of ./data/ood_data/iSUN.

For example, run the following commands in the root directory to download LSUN-C:

cd /data/ood_data
wget https://www.dropbox.com/s/fhtsw1m3qxlwj6h/LSUN.tar.gz
tar -xvzf LSUN.tar.gz

3. Pre-trained Model Preparation

For CIFAR, the model we used is in the checkpoints/network/baselinefolder.

For ImageNet, the model we used in the paper is the pre-trained ResNet-50 and MobileNetv2 provided by Pytorch. The download process will start upon running.

Preliminaries

It is tested under Python 3.9 environment, and requries some packages to be installed:

Precompute

We need precomputing for calculate class-mean feature vector.

Run ./scripts/run_precompute.sh. For example:

CIFAR-10/CIFAR-100 with DenseNet:

sh scripts/run_precompute.sh CIFAR-10/CIFAR-100 densenet

Demo

1. Demo code for Large-scale Experiment

Run ./scripts/run_eval.sh. For example:

CIFAR-10/CIFAR-100 with DenseNet:

sh scripts/run_eval.sh CIFAR-10/CIFAR-100 densenet HIMPLoS 60 1.6

2. Demo code for my CIFAR Experiment

Run ./scripts/run_eval.sh. For example:

ImageNet with ResNet-50:

sh scripts/run_eval.sh imagenet resnet50 HIMPLoS 30 0.8

himplos's People

Contributors

sunzh18 avatar

Watchers

 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.