Skip to content

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

License

Notifications You must be signed in to change notification settings

openvinotoolkit/anomalib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

samet-akcaydjdamelnashwinvaidya17Samet Akcaydependabot[bot]
Jan 8, 2025
084331d · Jan 8, 2025
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Anomalib Logo - A deep learning library for anomaly detection

A library for benchmarking, developing and deploying deep learning anomaly detection algorithms


Key FeaturesDocsNotebooksLicense

python pytorch lightning openvino

Pre-Merge Checks codecov Downloads

ReadTheDocs Anomalib - Gurubase docs


🌟 Announcing v2.0.0 Beta Release! 🌟

We're excited to announce the beta release of Anomalib v2.0.0! This version introduces significant improvements and customization options to enhance your anomaly detection workflows. Please be aware that there are several API changes between v1.2.0 and v2.0.0, so please be careful when updating your existing pipelines. We invite you to try it out and share your feedback:

We value your input! Please test and share feedback via GitHub Issues or our Discussions

Install beta: pip install anomalib==2.0.0-beta.1

👋 Introduction

Anomalib is a deep learning library that aims to collect state-of-the-art anomaly detection algorithms for benchmarking on both public and private datasets. Anomalib provides several ready-to-use implementations of anomaly detection algorithms described in the recent literature, as well as a set of tools that facilitate the development and implementation of custom models. The library has a strong focus on visual anomaly detection, where the goal of the algorithm is to detect and/or localize anomalies within images or videos in a dataset. Anomalib is constantly updated with new algorithms and training/inference extensions, so keep checking!

A prediction made by anomalib

Key features

  • Simple and modular API and CLI for training, inference, benchmarking, and hyperparameter optimization.
  • The largest public collection of ready-to-use deep learning anomaly detection algorithms and benchmark datasets.
  • Lightning based model implementations to reduce boilerplate code and limit the implementation efforts to the bare essentials.
  • The majority of models can be exported to OpenVINO Intermediate Representation (IR) for accelerated inference on Intel hardware.
  • A set of inference tools for quick and easy deployment of the standard or custom anomaly detection models.

📦 Installation

Anomalib provides multiple installation options to suit your needs. Choose the one that best fits your requirements:

🚀 Quick Install (Stable)

# Basic installation
pip install anomalib

# Full installation with all dependencies
pip install anomalib[full]

🌟 Beta Version (v2.0.0-beta.1)

Try our latest beta release with new features and improvements:

# Basic beta installation
pip install anomalib==2.0.0-beta.1

# Full beta installation with all dependencies
pip install anomalib[full]==2.0.0-beta.1

🛠️ Installation Options

Use the CLI for customized installation:

# Get help for installation options
anomalib install -h

# Full package installation
anomalib install

# Core package only (for training and evaluation)
anomalib install --option core

# OpenVINO optimization support
anomalib install --option openvino

🔧 Development Install

For contributing or customizing the library:

git clone https://github.com/openvinotoolkit/anomalib.git
cd anomalib
pip install -e .

# Full development installation with all dependencies
pip install -e .[full]

🧠 Training

Anomalib supports both API and CLI-based training approaches:

🔌 Python API

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

# Initialize components
datamodule = MVTec()
model = Patchcore()
engine = Engine()

# Train the model
engine.fit(datamodule=datamodule, model=model)

⌨️ Command Line

# Train with default settings
anomalib train --model Patchcore --data anomalib.data.MVTec

# Train with custom category
anomalib train --model Patchcore --data anomalib.data.MVTec --data.category transistor

# Train with config file
anomalib train --config path/to/config.yaml

🤖 Inference

Anomalib provides multiple inference options including Torch, Lightning, Gradio, and OpenVINO. Here's how to get started:

🔌 Python API

# Load model and make predictions
predictions = engine.predict(
    datamodule=datamodule,
    model=model,
    ckpt_path="path/to/checkpoint.ckpt",
)

⌨️ Command Line

# Basic prediction
anomalib predict --model anomalib.models.Patchcore \
                 --data anomalib.data.MVTec \
                 --ckpt_path path/to/model.ckpt

# Prediction with results
anomalib predict --model anomalib.models.Patchcore \
                 --data anomalib.data.MVTec \
                 --ckpt_path path/to/model.ckpt \
                 --return_predictions

📘 Note: For advanced inference options including Gradio and OpenVINO, check our Inference Documentation.

⚙️ Hyperparameter Optimization

Anomalib supports hyperparameter optimization (HPO) using Weights & Biases and Comet.ml.

# Run HPO with Weights & Biases
anomalib hpo --backend WANDB --sweep_config tools/hpo/configs/wandb.yaml

📘 Note: For detailed HPO configuration, check our HPO Documentation.

🧪 Experiment Management

Track your experiments with popular logging platforms through PyTorch Lightning loggers:

  • 📊 Weights & Biases
  • 📈 Comet.ml
  • 📉 TensorBoard

Enable logging in your config file to track:

  • Hyperparameters
  • Metrics
  • Model graphs
  • Test predictions

📘 Note: For logging setup, see our Logging Documentation.

📊 Benchmarking

Evaluate and compare model performance across different datasets:

# Run benchmarking with default configuration
anomalib benchmark --config tools/benchmarking/benchmark_params.yaml

💡 Tip: Check individual model performance in their respective README files:

✍️ Reference

If you find Anomalib useful in your research or work, please cite:

@inproceedings{akcay2022anomalib,
  title={Anomalib: A deep learning library for anomaly detection},
  author={Akcay, Samet and Ameln, Dick and Vaidya, Ashwin and Lakshmanan, Barath and Ahuja, Nilesh and Genc, Utku},
  booktitle={2022 IEEE International Conference on Image Processing (ICIP)},
  pages={1706--1710},
  year={2022},
  organization={IEEE}
}

👥 Contributing

We welcome contributions! Check out our Contributing Guide to get started.

Contributors to openvinotoolkit/anomalib

Thank you to all our contributors!

About

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

Topics

Resources

License

Code of conduct

Security policy

Citation

Stars

Watchers

Forks

Packages

No packages published

Languages