Skip to main content

Simple out-of-distribution detection tools for ML and computer vision.

Project description

OODKit

A small Python library for out-of-distribution (OOD) detection in computer vision. Fit a detector on in-distribution features, score new samples (higher score = more OOD), and evaluate or compare methods with a consistent sklearn-style API.

OODKit works on either image-classification or object-detection data, and can take you from raw images to scored samples in a few steps.

Install

pip install oodkit

OODKit includes the runtime dependencies needed for detectors, embeddings, plots, and the example workflows.

What's in the box

  • Detectors (oodkit.detectors) - a family of OOD scorers (MSP, Energy, Mahalanobis, KNN, PCA / CoP / CoRP, PCAFusion, ViM, WDiscOOD) with a shared fit / score / predict contract.
  • Features (oodkit.data) - a single Features(logits=..., embeddings=...) container that every detector accepts.
  • Embedder (oodkit.embeddings) - helper tools that turn a dataset of images into logits/embeddings via a pretrained backbone, with disk-backed extraction so analysis can run on machines without a GPU.
  • Evaluation (oodkit.evaluation) - ScoreBank aligns scores from multiple detectors with labels and metadata; metrics (evaluate, evaluate_by_class) and plots (score_distributions, rank_grid, ROC / PR / correlation) all consume a bank.
  • Object-detection support - chip utilities (oodkit.data.chips, ChipDataset), image-level pooling (pool_image_scores), and oodkit.contrib.coco for COCO / COCO-O ingestion without pycocotools.

Minimal example

from oodkit.data import Features
from oodkit.detectors import Energy
from oodkit.evaluation import ScoreBank, evaluate

# You supply logits / embeddings however you like (numpy, torch, Embedder, ...).
id_feat = Features(logits=id_logits, embeddings=id_embeddings)
ood_feat = Features(logits=ood_logits, embeddings=ood_embeddings)

det = Energy()
det.fit(id_feat)

scores_id = det.score(id_feat)
scores_ood = det.score(ood_feat)

bank = ScoreBank(ood_labels=[0] * len(scores_id) + [1] * len(scores_ood))
bank.add("Energy", [*scores_id, *scores_ood])
print(evaluate(bank))  # AUROC, FPR@95, AUPR, ...

Examples

For full end-to-end runs (images to extraction to multiple detectors to comparison plots), see the example notebooks on GitHub:

  • ImageNet OOD showcase - classification OOD on ImageNet vs ImageNet-O.
  • COCO OOD showcase - object-detection OOD on COCO vs COCO-O (chips, image-level pooling, per-domain breakdowns, ranked chip galleries).
  • Notebook guide - dataset layouts, configurable paths, and notebook-specific notes.

Development

Contributing or running from a cloned checkout? See README_DEV.md.

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

oodkit-0.1.0.tar.gz (69.5 kB view details)

Uploaded Source

Built Distribution

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

oodkit-0.1.0-py3-none-any.whl (90.5 kB view details)

Uploaded Python 3

File details

Details for the file oodkit-0.1.0.tar.gz.

File metadata

  • Download URL: oodkit-0.1.0.tar.gz
  • Upload date:
  • Size: 69.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for oodkit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8ba5858de08306ddd4e9413d0e356760875cff8b91683636a0cf005000eba68a
MD5 e7b07338c4c33773d2d44060fa89db56
BLAKE2b-256 a2a3300043d5ed8a7d32bfe5975b5f6c52f0588fe1adda9f4dd7f23cd1bb4b19

See more details on using hashes here.

File details

Details for the file oodkit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: oodkit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 90.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for oodkit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 481500ef001b8ed1310b7caa295e54a8b7155640a94db5a7650288600711f197
MD5 368bfc6f50cd0a005d5cde449e47ab8b
BLAKE2b-256 42d8e6338d772d5494c75fa373cde80c720782722780603c51cf429a9793c73d

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