Skip to content

Latest commit

 

History

471 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AnomaVision

AnomaVision banner

Production-oriented 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

AnomaVision supports PaDiM and lightweight PatchCore, image-level scores, pixel-level maps, and deployment exports.

Open the AnomaVision live demo

Try it first: live demo · five-minute CPU quickstart · runnable examples · reproducible benchmark

Why use it?

  • 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.

Quickstart

1. Install

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.

2. Prepare data

Use an MVTec-style directory. Training uses only the good images:

dataset/
└── bottle/
    ├── train/good/
    └── test/
        ├── good/
        └── scratch/

3. Train

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.yml

The 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: 14

The model and compact deployment artifact are saved under model_data_path.

4. Detect and evaluate

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

5. Export

# 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 100

Every command provides help:

anomavision --help
anomavision train --help
anomavision export --help

Production Autopilot

Production 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_package

Open 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.

Visual overview

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: distribution-based heatmap

PaDiM models the feature distribution of normal images. Its heatmap is typically smoother and emphasizes regions that differ from that learned distribution.

PaDiM input, boundary, and heatmap example

Ultra-light PatchCore: nearest-patch heatmap

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.

PatchCore input, boundary, and heatmap example

Choosing a model

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

Documentation

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

Python API

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)

Community and adoption

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.

License

AnomaVision is released under the MIT License. See LICENSE.

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

32 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages