Production-oriented visual anomaly detection from normal images.
AnomaVision supports PaDiM and lightweight PatchCore, image-level scores, pixel-level maps, and deployment exports.
Try it first: live demo · five-minute CPU quickstart · runnable examples · reproducible benchmark
- Train with normal images only; anomaly labels are not required for training.
- Use PaDiM for the default fast baseline or PatchCore for a compact nearest-neighbor memory bank.
- Run inference through PyTorch, ONNX Runtime, OpenVINO, or native TensorRT.
- Export FP16 or calibrated INT8 TensorRT engines for NVIDIA production deployments.
Benchmark results and reproduction details are documented in docs/benchmark.md. Treat benchmark numbers as workload-specific, and reproduce them on your own hardware before making production claims.
pip install uv
uv pip install "anomavision[cpu]"For NVIDIA GPUs, choose the matching extra such as anomavision[cu121]. Source installation and environment setup are described in docs/installation.md. For the shortest CPU path, use the copy-ready examples/quickstart_cpu.yml configuration and follow docs/quickstart.md.
Use an MVTec-style directory. Training uses only the good images:
dataset/
└── bottle/
├── train/good/
└── test/
├── good/
└── scratch/
Before running the command, open config.yml and set dataset_path to the folder that contains your class folder, for example ./dataset. Keep class_name: bottle if your data is stored under ./dataset/bottle/.
anomavision train --config config.ymlThe default configuration trains PaDiM. To use the ultra-light PatchCore path, change these values in config.yml:
algorithm: patchcore
layer_indices: [0]
coreset_ratio: 0.02
max_memory_patches: 2048
patch_grid: 14The model and compact deployment artifact are saved under model_data_path.
anomavision detect --config config.yml --img_path ./dataset/bottle/test
anomavision eval --config config.yml# Portable ONNX export
anomavision export --config config.yml --format onnx
# Native TensorRT FP16 export
anomavision export --config config.yml --format tensorrt \
--device cuda --tensorrt-precision fp16
# Native TensorRT calibrated INT8 export
anomavision export --config config.yml --format tensorrt \
--device cuda --tensorrt-precision int8 \
--calib-dir ./dataset/bottle/train/good --calib-samples 100Every command provides help:
anomavision --help
anomavision train --help
anomavision export --helpProduction Autopilot is the easiest way to move from two trained models to one deployable choice. It compares PaDiM and ultra-light PatchCore on the same labeled test split, calibrates a separate threshold for each, profiles median and P95 latency on your hardware, checks localization health, and packages the selected artifact with a self-contained HTML dashboard.
Train both candidate models first, then run the complete labeled split on CPU:
anomavision autopilot \
--config config.yml \
--padim_model ./distributions/padim/bottle/anomav_exp/model.pt \
--patchcore_model ./distributions/patchcore/bottle/anomav_exp/model.pt \
--device cpu \
--validation_split 1.0 \
--target_latency_ms 50 \
--output_dir ./production_packageOpen production_package/production_autopilot_report.html to see the selected model, AUROC, calibrated threshold, localization diagnostics, memory, median latency, P95 latency, and deployment recommendation. The package also contains deployment_manifest.json, localization_report.md, and the selected model artifact. See docs/production_deployment.md for GPU, TensorRT, INT8, and packaging details.
The same pipeline supports compact edge inference and spatial anomaly localization. In each result strip, the panels show the input image, the detected boundary, and the anomaly heatmap from left to right.
PaDiM models the feature distribution of normal images. Its heatmap is typically smoother and emphasizes regions that differ from that learned distribution.
PatchCore compares image patches with a compact normal-feature memory bank. Its heatmap can show more local texture and sharper nearest-patch differences while using bounded memory for production inference.
| Model | Best starting point | Memory use | Production note |
|---|---|---|---|
| PaDiM | Fast, simple baseline | Low | Recommended first experiment |
| Lightweight PatchCore | Lower-memory nearest-patch baseline | Very low by default | Use coreset_ratio, max_memory_patches, and patch_grid to control latency |
| Topic | Guide |
|---|---|
| Installation | docs/installation.md |
| Five-minute workflow | docs/quickstart.md |
| CLI and configuration | docs/cli.md, docs/config.md |
| Python API | docs/api.md |
| PatchCore and TensorRT deployment | docs/production_deployment.md |
| Runnable CPU, PatchCore, and TensorRT examples | examples/README.md |
| Benchmark methodology | docs/benchmark.md |
| Troubleshooting | docs/troubleshooting.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)The most useful path to adoption is a small, reproducible example rather than more README text: publish one benchmark script, one production export example, a model card with hardware and preprocessing details, and a short comparison against Anomalib. Invite users to reproduce the result, report failures, and contribute adapters for their own datasets. See docs/production_deployment.md for the project’s recommended release checklist.
AnomaVision is released under the MIT License. See LICENSE.


