Skip to main content

OOD Detection Library built using nbdev

Project description

OOD Detection

This library is used for OOD Detection where a model encounters new classes at test time that were not seen during training. The goal is to detect that such inputs do not belong to any of the training classes.

Install

pip install ood_detection

or

conda install -c yashkhandelwal ood_detection

Example Usage

import numpy as np
from sklearn.datasets import make_blobs
from ood_detection.core import *
# example dataset
n_samples = 1000
n_centers = 10
n_features = 1024

x, y = make_blobs(n_samples=n_samples, n_features=n_features, centers=n_centers, random_state=0)
# using the last 5 cluster as the test and rest as train
train_embedding = x[np.where(y < (n_centers - 5))]
train_labels = y[np.where(y < (n_centers - 5))]

test_embedding = x[np.where(y >= (n_centers - 5))]
test_labels = y[np.where(y >= (n_centers - 5))]
ood = OODMetric(train_embedding, train_labels)

in_distribution_rmd = ood.compute_rmd(train_embedding)
ood_rmd = ood.compute_rmd(test_embedding)
plt.hist([in_distribution_rmd, ood_rmd], label=["In Distribution", "OOD"])
plt.legend()
plt.show()

Built using NBDev

This OOD Detection library was built in a jupyter notebook with proper documentation and test cases. These test cases are verified before they are published to Github Pages, PyPi, Conda etc.

I’ve written down a NBDev Tutorial explaining the thought process of Jeremy Howard and folks at FastAI behind building it. The tutorial covers about how to get started, important functions and description of those I used with the issues I faced while exploring the tool for the first time.

Acknowledgements

Special thanks to Yugam Tiwari for explaining the code he has written for the OODMetric and helping me packaging in the library.

Thanks to Soma Dhavala for coming up with the idea to prepare NBDev Tutorial and helping with the initial reading and exploration material.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ood_detection-0.0.9.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ood_detection-0.0.9-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file ood_detection-0.0.9.tar.gz.

File metadata

  • Download URL: ood_detection-0.0.9.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for ood_detection-0.0.9.tar.gz
Algorithm Hash digest
SHA256 4aaa66b7233e6787897b74395b96ec5ce9353faa4a1760b2adafa2f7f029d405
MD5 93fb5fe3c60de506af34656456e32444
BLAKE2b-256 2f0686e2d068de2d7248e533bb86fd97975e51d93fe8f1a0542dab4429d61af3

See more details on using hashes here.

File details

Details for the file ood_detection-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: ood_detection-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for ood_detection-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 08c23cdbf17adb9c6df48531fe4696546cde5ed16bc2355d7e5adefa85b5a5ca
MD5 1132c8860c3137a2606b18d49efb99e9
BLAKE2b-256 b2b397962a562ce73a555dedf0edbab6e6e5691a32d656cf2c131ae2c5014e44

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page