GithubHelp home page GithubHelp logo

ph-ood / post-hoc-ood Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 12.13 MB

Post-hoc Out-of-Distribution Detection

Python 85.00% Jupyter Notebook 15.00%
ood ood-detection out-of-distribution-detection energy-based-model pytorch dirichlet-distribution ebm energy-based-deep-learning

post-hoc-ood's Introduction

Post-hoc Out-of-Distribution Detection

Example directory structure:

.
├── code
├── data
│  ├── cifar10
│  │  ├── test
│  │  └── train
│  └── mnist
│     ├── test
│     └── train
├── weights
│  ├── cifar10
│  └── mnist
├── results
│  ├── plots
│  └── raw
└── README.md

Data

Data Subsets

  • Run python3 split_data.py -d <dataset_name> -s <subset>
  • This creates a new dataset in the data/ directory with the name <dataset_name>_<ext> with only the data from the specified subset
  • For example, python3 split_data -d mnist -s "3,5,6,9" creates a new dataset mnist_3569 with only the specified classes

Training a Classifier Model

  • Add model definition to models
  • Change the model used in run_classifier.py
  • Run python3 run_classifier.py <dataset_name>
  • This saves the weights of the trained model in weights/<dataset_name> directory

OOD Scores

  • To add/modify a OOD score, add it as a function in scores.py

Pretrained Scoring

  • Change pretrained model path in test_ood.py
  • Run python3 test_ood.py -i <id_dataset_name> -o <ood_dataset_name> -s <score_name> -n <model_name> -m <model_metric> -e <model_epochs>
  • This saves scores for ID and OOD data as .npy files in results/raw

OOD Finetuning

  • Run python3 finetune_ood.py -i <id_dataset_name> -f <finetune_dataset_name> -n <model_name> -m <model_metric> -e <model_epochs>
  • This behaves like run_classifier.py and saves the model and the test predictions in the same way

Finetuning Losses

  • To add/modify a finetuning loss, add it as a nn.Module in losses.py

Plots and Metrics for OOD Detection

  • Run python3 analyze_scores.py -i <id_dataset_name> -o <ood_dataset_name> -s <score_name>
  • This saves the density plots for the scores in results/plots

Running on Colab

  • Create a Google Drive folder having the same root structure and upload the data
  • Add a colab notebook to this folder, mount drive
  • cd to created folder and run the .py scripts from notebook command line
  • Sync to and from Drive when needed

References


(This work was done as a course project for CS726: Advanced Machine Learning, Spring 2022, IIT Bombay)

post-hoc-ood's People

Contributors

hrshtv avatar

Stargazers

 avatar  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.