open-edge-platform/anomalib

An anomaly detection library comprising state-of-the-art algorithms and features such as experiment management, hyper-parameter optimization, and edge inference.

📚 What is Anomalib?

Anomalib is an open‑source Python library that bundles state‑of‑the‑art deep‑learning models for visual anomaly detection – spotting defects or out‑of‑distribution objects in images and video. It provides:

  • A modular API and a command‑line interface for training, inference and benchmarking.
  • Ready‑to‑use implementations of many research papers (PatchCore, PaDiM, STFPM, etc.) built on PyTorch Lightning to keep boiler‑plate low.
  • Export pipelines to OpenVINO so models can run fast on Intel CPUs/GPUs.
  • Optional tooling for experiment tracking (W&B, Comet, TensorBoard) and a low‑code web UI called Anomalib Studio for non‑programmers.

The focus is on image‑based anomaly detection, but the library also supports tabular data via a Tabular helper.


🚀 Getting Started

Installation

  • Standard – pip install anomalib (or uv pip install anomalib).
  • Hardware‑specific extras – add [cu126], [cu130], [rocm], [xpu], etc., to pull in the right PyTorch build.
  • Optional features – [openvino], [clip], [vlm], [loggers], [notebooks], or [full] for everything.
  • From source – clone the repo and use uv sync --extra <backend> or pip install -e "[dev,<backend>]".

Quick Training (Python API)

from anomalib.data import MVTecAD
from anomalib.models import Patchcore
from anomalib.engine import Engine

dm = MVTecAD()
model = Patchcore()
engine = Engine()
engine.fit(datamodule=dm, model=model)

Quick Training (CLI)

anomalib train --model Patchcore --data anomalib.data.MVTecAD

Inference

  • API – engine.predict(datamodule=dm, model=model, ckpt_path='…')
  • CLI – anomalib predict --model Patchcore --data MVTecAD --ckpt_path model.ckpt
  • Supports Torch, Lightning, Gradio UI, and OpenVINO‑accelerated inference.

🛠️ Key Features

Feature Why it matters
Modular API & CLI Switch models, datasets, or configs without rewriting code.
Large model collection Access many published anomaly‑detection methods in one place.
Lightning‑based Handles training loops, checkpointing, mixed‑precision, and multi‑GPU with minimal code.
OpenVINO export Turn a PyTorch checkpoint into an Intel‑optimized IR for low‑latency edge deployment.
Inference tools Ready‑made scripts for batch prediction, Gradio demo, or ROS/MQTT integration.
Anomalib Studio A pre‑release no‑code web app (Docker or standalone) for training and deploying models via a UI.
Experiment logging Plug‑in to W&B, Comet, TensorBoard, etc., via Lightning loggers.
Hardware‑aware extras Install only what you need for CPU, CUDA, ROCm, or Intel XPU back‑ends.

📊 Benchmarking & Evaluation

Run a full benchmark with a single command:

anomalib benchmark --config tools/experimental/benchmarking/sample.yaml

The command evaluates selected models on standard datasets (e.g., MVTec‑AD) and prints metrics such as AUROC, pixel‑level AUC, and inference speed.


🤖 Anomalib Studio (Low‑Code UI)

  • Web‑based – runs a FastAPI backend and a React frontend.
  • Connects to USB/IP cameras, image folders, or streams.
  • Outputs to ROS messages, MQTT, etc., for industrial pipelines.
  • Distributed as a Docker image or a standalone UI.
  • Still pre‑release – expect API changes.

📚 Documentation & Community

  • Full docs: https://anomalib.readthedocs.io
  • Example notebooks in examples/notebooks
  • Discussion forum and GitHub Issues for support.
  • Contribute via the guide in CONTRIBUTING.md.

🎓 Who Should Use This?

  • Researchers needing a reproducible baseline for visual anomaly detection papers.
  • Industrial engineers building defect‑detection pipelines on edge devices (Intel CPUs/GPUs, NVIDIA GPUs, AMD ROCm).
  • Data scientists who want a plug‑and‑play library to experiment with different anomaly‑detection architectures without writing low‑level training loops.

📦 Quick Reference

  • Python version: 3.10+
  • Core deps: PyTorch 2.6+, Lightning 2.2+, OpenVINO 2024.0 (optional)
  • License: Apache‑2.0 (see LICENSE)
  • Latest release: v2.6.2 (security hardening for Tabular.from_file).

Feel free to explore the repo, try the CLI, and dive into the notebooks to see anomaly detection in action!

Related

  • Project
  • Project
  • Project
  • Project
  • Project