Skip to content

Latest commit

 

History

559 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AnomaVision

AnomaVision banner

Simple visual anomaly detection from normal images.

PyPI version PyPI downloads Python 3.10 to 3.12 PyTorch 2.0 or newer ONNX export ready TensorRT supported OpenVINO supported CI status MIT license KV260 DPU support

AnomaVision is a production-oriented computer vision toolkit for detecting defects and unusual patterns from normal images.

It supports three anomaly detection methods:

  • PaDiM — a simple, fast feature-distribution baseline.
  • PatchCore — a lightweight memory-based method designed for efficient inference.
  • EfficientAD — a lightweight student-teacher method designed for fast industrial anomaly detection.

Training requires only normal (good) images. Labeled test images can then be used for evaluation, threshold calibration, and production model selection.

Open the AnomaVision live demo

New here? Start with the five-minute quickstart.

What can AnomaVision do?

  • Train anomaly detection models using normal images.
  • Detect image-level anomalies and generate anomaly heatmaps.
  • Evaluate anomaly detection and localization performance.
  • Calibrate anomaly thresholds from validation data.
  • Export models to ONNX, OpenVINO, and TensorRT where supported.
  • Run production model selection with Production Autopilot.
  • Export and compile PaDiM and PatchCore to XModel for the AMD/Xilinx Kria KV260.

Quick start

1. Install

Option A — From Source

git clone https://github.com/DeepKnowledge1/AnomaVision.git
cd AnomaVision

uv venv --python 3.11 .venv
source .venv/bin/activate        # Windows: .venv\Scripts\Activate.ps1

uv sync --extra cpu              # CPU
uv sync --extra cu121            # CUDA 12.1

Option B — From PyPI

uv pip install "anomavision[cpu]"

# NVIDIA GPU
uv pip install "anomavision[cu118]"
uv pip install "anomavision[cu121]"
uv pip install "anomavision[cu124]"

For other environments, see Installation.

2. Prepare your dataset

Use an MVTec-style structure:

dataset/
└── bottle/
    ├── ground_truth/
    │   ├── broken_large/
    │   ├── broken_small/
    │   └── contamination/
    ├── test/
    │   ├── broken_large/
    │   ├── broken_small/
    │   ├── contamination/
    │   └── good/
    └── train/
        └── good/

Training uses only train/good. Test images may contain defects.

3. Train

Create or edit config.yml and set dataset_path to your dataset.

Select the algorithm in the configuration:

algorithm: padim       # padim | patchcore | efficientad
anomavision train --config config.yml

4. Detect

anomavision detect --config config.yml --img_path ./dataset/bottle/test

5. Export

anomavision export --config config.yml --format onnx

See Export and deployment for deployment-specific options.

Production Autopilot

Production Autopilot compares trained anomaly models on the same validation data, measures their performance and latency on the target device, calibrates thresholds, and selects the best candidate for deployment.

PaDiM, PatchCore, and EfficientAD can be supplied as independent candidate models. The model paths are provided directly through the CLI:

anomavision autopilot \
  --config config.yml \
  --padim_model ./distributions/padim/bottle/anomav_exp/model.pt \
  --patchcore_model ./distributions/patchcore/bottle/anomav_exp/model.pt \
  --efficientad_model ./distributions/efficientad/bottle/anomav_exp/model.pt \
  --device cpu \
  --validation_split 1.0 \
  --target_latency_ms 50 \
  --output_dir ./production_package

How selection works

For every supplied model, Autopilot:

  1. Evaluates the model on the validation split.
  2. Calibrates an image-level anomaly threshold.
  3. Measures inference latency on the selected device.
  4. Calculates image-level and pixel-level metrics when localization maps are available.
  5. Checks localization quality and false-positive behavior.
  6. Applies the target latency constraint when selecting the production candidate.
  7. Packages the selected model and writes a deployment manifest.

If multiple models satisfy the latency target, the model with the strongest image-level AUROC is preferred, with latency used as a tie-breaker.

Output

Autopilot creates a production package containing:

production_package/
├── model.pt
├── deployment_manifest.json
├── localization_report.md
└── production_autopilot_report.html

The HTML report is a self-contained dashboard showing the candidate comparison, selected model, AUROC, calibrated threshold, latency, localization diagnostics, and deployment recommendation.

KV260 support

AnomaVision supports a Vitis AI workflow for PaDiM and PatchCore on the AMD/Xilinx Kria KV260.

PyTorch → INT8 quantization → XModel → KV260 DPU compilation

Both PaDiM and PatchCore currently compile with 1 DPU subgraph in the KV260 compiler.

See the complete KV260 XModel Guide.

XModel compilation has been validated in the Vitis AI environment. Final on-device KV260 validation requires the physical hardware.

Documentation

Topic Guide
Quick start docs/quickstart.md
Installation docs/installation.md
CLI and configuration docs/cli.md, docs/config.md
Python API docs/api.md
KV260 / XModel docs/kv260_xmodel.md
Production deployment docs/production_deployment.md
Benchmarks docs/benchmark.md
Troubleshooting docs/troubleshooting.md
Examples examples/README.md
Contributing docs/contributing.md

Python example

import torch
from torch.utils.data import DataLoader
import anomavision

train_set = anomavision.AnodetDataset("./dataset/bottle/train/good")
train_loader = DataLoader(train_set, batch_size=16, shuffle=False)

model = anomavision.Padim(backbone="resnet18", device=torch.device("cpu"))
model.fit(train_loader)

batch = next(iter(train_loader))
if isinstance(batch, (tuple, list)):
    batch = batch[0]

scores, maps = model.predict(batch)

License

AnomaVision is released under the MIT License. See LICENSE.

Questions and contributions

Found a problem or have an idea? Feel free to open an issue or contribute to the project.

About

Production visual anomaly detection from normal images with PaDiM, ultra-light PatchCore, Production Autopilot, ONNX, OpenVINO, and TensorRT INT8 export.

Topics

Resources

Contributing

Stars

34 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages