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 sharedfit/score/predictcontract. - Features (
oodkit.data) - a singleFeatures(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) -ScoreBankaligns 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), andoodkit.contrib.cocofor COCO / COCO-O ingestion withoutpycocotools.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file oodkit-0.1.1.tar.gz.
File metadata
- Download URL: oodkit-0.1.1.tar.gz
- Upload date:
- Size: 74.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9b67adafb888c1de6fae1d8055af30831596bb1141b29069bb7b1efef2e2a5e
|
|
| MD5 |
2dc66118f217ff9a399fa324b7af1b34
|
|
| BLAKE2b-256 |
b9fe52bf3d375632c3ddb4048d3d45869657ddca39618e2a533c74614376e922
|
File details
Details for the file oodkit-0.1.1-py3-none-any.whl.
File metadata
- Download URL: oodkit-0.1.1-py3-none-any.whl
- Upload date:
- Size: 96.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6cec3c7e7074a03d5e5813505d77a7aae0b2b53d2ca5b9ac93a6b0b2ca7c1df
|
|
| MD5 |
7c90fa70a784ea8e27806a9fe3d13dcc
|
|
| BLAKE2b-256 |
94857db11b1a18f0093e21dd7e7c0140532e12a1f6c617a0df6d1979c4acdaad
|