Simple visual anomaly detection from normal images.
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.
New here? Start with the five-minute quickstart.
- 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.
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.1uv 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.
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.
Create or edit config.yml and set dataset_path to your dataset.
Select the algorithm in the configuration:
algorithm: padim # padim | patchcore | efficientadanomavision train --config config.ymlanomavision detect --config config.yml --img_path ./dataset/bottle/testanomavision export --config config.yml --format onnxSee Export and deployment for deployment-specific options.
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_packageFor every supplied model, Autopilot:
- Evaluates the model on the validation split.
- Calibrates an image-level anomaly threshold.
- Measures inference latency on the selected device.
- Calculates image-level and pixel-level metrics when localization maps are available.
- Checks localization quality and false-positive behavior.
- Applies the target latency constraint when selecting the production candidate.
- 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.
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.
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.
| 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 |
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)AnomaVision is released under the MIT License. See LICENSE.
Found a problem or have an idea? Feel free to open an issue or contribute to the project.
