# hjwn/mvtec-anomaly-detection architecture

> Architecture diagram of the GitHub repository hjwn/mvtec-anomaly-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hjwn/mvtec-anomaly-detection
- Repository: https://github.com/hjwn/mvtec-anomaly-detection

## Overview

This is a CPU-oriented MVTec AD anomaly-detection and model-comparison project. Its workflow loads normal training images and labeled test images, fits one of three detection methods, produces image scores and anomaly maps, and evaluates results. The README also describes a benchmark workflow that compares models across categories and seeds, summarizes performance and efficiency scenarios, and produces visualizations. The sampled `src/run.py` shows the single-run path; benchmark internals and visualization wiring are documented but not sampled, so those links are not inferred.

Main entry points: [`src/run.py`](https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/run.py) (Single-run CLI), [`src/benchmark.py`](https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/benchmark.py) (Benchmark CLI), [`src/methods/padim.py`](https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/methods/padim.py) (PaDiM), [`src/methods/patchcore.py`](https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/methods/patchcore.py) (PatchCore)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Data and execution"]
  node_dataset["Dataset loader<br/>[mvtec.py]"]
  node_runner["Single-run CLI<br/>[run.py]"]
  node_benchmark["Benchmark CLI<br/>[benchmark.py]"]
end

subgraph group_detectors["Detection methods"]
  node_ae["AutoEncoder<br/>[ae.py]"]
  node_padim["PaDiM<br/>[padim.py]"]
  node_patchcore["PatchCore<br/>[patchcore.py]"]
  node_features["ResNet features"]
  node_output["Method output contract<br/>[base.py]"]
end

subgraph group_evaluation["Evaluation and analysis"]
  node_auroc["Image AUROC<br/>[auroc.py]"]
  node_scoring["Scenario scoring<br/>[scoring.py]"]
end

subgraph group_results["Benchmark results"]
  node_reports["Benchmark reports<br/>[benchmark.py]"]
  node_visuals["Maps and overlays<br/>[benchmark.py]"]
end

node_user(("Researcher"))
node_mvtec[("MVTec AD data")]

node_user -->|"runs"| node_runner
node_mvtec -->|"provides images"| node_dataset
node_runner -->|"loads train and test"| node_dataset
node_runner -->|"selects and fits"| node_ae
node_runner -->|"selects and fits"| node_padim
node_runner -->|"selects and fits"| node_patchcore
node_runner -->|"constructs backbone"| node_features
node_padim -->|"extracts features"| node_features
node_patchcore -->|"extracts features"| node_features
node_ae -->|"returns"| node_output
node_padim -->|"returns"| node_output
node_patchcore -->|"returns"| node_output
node_runner -->|"evaluates scores"| node_auroc
node_user -->|"runs comparisons"| node_benchmark
node_benchmark -.->|"uses analysis logic"| node_scoring
node_benchmark -->|"produces summaries"| node_reports
node_benchmark -->|"produces visualizations"| node_visuals

click node_dataset "https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/datasets/mvtec.py"
click node_runner "https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/run.py"
click node_benchmark "https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/benchmark.py"
click node_ae "https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/methods/ae.py"
click node_padim "https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/methods/padim.py"
click node_patchcore "https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/methods/patchcore.py"
click node_features "https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/models/feature_extractor.py"
click node_output "https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/methods/base.py"
click node_auroc "https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/metrics/auroc.py"
click node_scoring "https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/utils/scoring.py"
click node_reports "https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/benchmark.py"
click node_visuals "https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/benchmark.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dataset,node_runner,node_benchmark toneBlue
class node_ae,node_padim,node_patchcore,node_features,node_output,node_mvtec toneAmber
class node_auroc,node_scoring toneMint
class node_reports,node_visuals toneRose
class node_user toneIndigo
```

## Components

### Data and execution

- [Dataset loader](https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/datasets/mvtec.py): `src/datasets/mvtec.py`
- [Single-run CLI](https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/run.py): `src/run.py`
- [Benchmark CLI](https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/benchmark.py): `src/benchmark.py`

### Detection methods

- [AutoEncoder](https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/methods/ae.py): `src/methods/ae.py`
- [PaDiM](https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/methods/padim.py): `src/methods/padim.py`
- [PatchCore](https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/methods/patchcore.py): `src/methods/patchcore.py`
- [ResNet features](https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/models/feature_extractor.py): `src/models/feature_extractor.py`
- [Method output contract](https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/methods/base.py): `src/methods/base.py`

### Evaluation and analysis

- [Image AUROC](https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/metrics/auroc.py): `src/metrics/auroc.py`
- [Scenario scoring](https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/utils/scoring.py): `src/utils/scoring.py`

### Benchmark results

- [Benchmark reports](https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/benchmark.py): `src/benchmark.py`
- [Maps and overlays](https://github.com/hjwn/mvtec-anomaly-detection/blob/main/src/benchmark.py): `src/benchmark.py`

### Other components

- **Researcher**
- **MVTec AD data**

## Connections

- Researcher → Single-run CLI: runs (evidence: `src/run.py`)
- MVTec AD data → Dataset loader: provides images (evidence: `src/datasets/mvtec.py`)
- Single-run CLI → Dataset loader: loads train and test (evidence: `src/run.py`)
- Single-run CLI → AutoEncoder: selects and fits (evidence: `src/run.py`)
- Single-run CLI → PaDiM: selects and fits (evidence: `src/run.py`)
- Single-run CLI → PatchCore: selects and fits (evidence: `src/run.py`)
- Single-run CLI → ResNet features: constructs backbone (evidence: `src/run.py`)
- PaDiM → ResNet features: extracts features (evidence: `src/run.py`)
- PatchCore → ResNet features: extracts features (evidence: `src/run.py`)
- AutoEncoder → Method output contract: returns (evidence: `src/methods/ae.py`)
- PaDiM → Method output contract: returns (evidence: `src/methods/padim.py`)
- PatchCore → Method output contract: returns (evidence: `src/methods/patchcore.py`)
- Single-run CLI → Image AUROC: evaluates scores (evidence: `src/run.py`)
- Researcher → Benchmark CLI: runs comparisons (evidence: `README.md`)
- Benchmark CLI → Scenario scoring: uses analysis logic
- Benchmark CLI → Benchmark reports: produces summaries (evidence: `README.md`)
- Benchmark CLI → Maps and overlays: produces visualizations (evidence: `README.md`)
