# hanli6688/anomalylvm architecture

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

- Interactive diagram: https://gitdiagram.com/hanli6688/anomalylvm
- Repository: https://github.com/hanli6688/anomalylvm

## Overview

AnomalyLVM is presented as a unified zero-shot anomaly-detection framework for image classification and pixel-level localization, with industrial and medical dataset support. The visible workflow is training/validation in `train.py`, which requests datasets and evaluates a trainer; the trainer implementation and dataset registry are absent from the tree. `model/model.py` sketches visual feature fusion, localization, feature enhancement, and text-based scoring. The README documents broader capabilities, but several are placeholders in the sampled model; those implementation limits are reflected below.

Main entry points: [`model/model.py`](https://github.com/hanli6688/anomalylvm/blob/main/model/model.py) (AnomalyLVM), [`train.py`](https://github.com/hanli6688/anomalylvm/blob/main/train.py) (Train and validate), [`model/clip_model.py`](https://github.com/hanli6688/anomalylvm/blob/main/model/clip_model.py) (CLIP model), [`dataset`](https://github.com/hanli6688/anomalylvm/tree/main/dataset) (Dataset adapters)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Dataset adapters"]
  node_datasets["Dataset adapters"]
end

subgraph group_runtime["Training workflow"]
  node_train["Train and validate<br/>[train.py]"]
end

subgraph group_model["Anomaly model"]
  node_anomalylvm["AnomalyLVM<br/>[model.py]"]
  node_sam2["Frozen SAM2 encoder<br/>[model.py]"]
  node_dinox["Frozen DINO-X encoder<br/>[model.py]"]
  node_fusion["Fusion decoder<br/>[model.py]"]
  node_fem["Feature enhancement<br/>[model.py]"]
  node_prompt["Prompt learner<br/>[model.py]"]
  node_textencoder["Frozen CLIP text<br/>[model.py]"]
  node_clip["CLIP model<br/>[clip_model.py]"]
  node_tokenizer["Simple tokenizer"]
  node_cliputils["CLIP utilities<br/>[utils.py]"]
end

node_operator(("Experiment operator"))

node_operator -->|"runs"| node_train
node_train -->|"requests data"| node_datasets
node_anomalylvm -->|"extracts features"| node_sam2
node_anomalylvm -->|"extracts features"| node_dinox
node_anomalylvm -->|"decodes features"| node_fusion
node_anomalylvm -->|"refines map"| node_fem
node_anomalylvm -->|"creates prompts"| node_prompt
node_anomalylvm -->|"encodes prompts"| node_textencoder
node_clip -->|"uses utilities"| node_cliputils

click node_train "https://github.com/hanli6688/anomalylvm/blob/main/train.py"
click node_datasets "https://github.com/hanli6688/anomalylvm/tree/main/dataset"
click node_anomalylvm "https://github.com/hanli6688/anomalylvm/blob/main/model/model.py"
click node_sam2 "https://github.com/hanli6688/anomalylvm/blob/main/model/model.py"
click node_dinox "https://github.com/hanli6688/anomalylvm/blob/main/model/model.py"
click node_fusion "https://github.com/hanli6688/anomalylvm/blob/main/model/model.py"
click node_fem "https://github.com/hanli6688/anomalylvm/blob/main/model/model.py"
click node_prompt "https://github.com/hanli6688/anomalylvm/blob/main/model/model.py"
click node_textencoder "https://github.com/hanli6688/anomalylvm/blob/main/model/model.py"
click node_clip "https://github.com/hanli6688/anomalylvm/blob/main/model/clip_model.py"
click node_tokenizer "https://github.com/hanli6688/anomalylvm/blob/main/model/simple_tokenizer.py"
click node_cliputils "https://github.com/hanli6688/anomalylvm/blob/main/model/utils.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_datasets toneBlue
class node_train toneAmber
class node_anomalylvm,node_sam2,node_dinox,node_fusion,node_fem,node_prompt,node_textencoder,node_clip,node_tokenizer,node_cliputils toneMint
class node_operator toneIndigo
```

## Components

### Dataset adapters

- [Dataset adapters](https://github.com/hanli6688/anomalylvm/tree/main/dataset): `dataset`

### Training workflow

- [Train and validate](https://github.com/hanli6688/anomalylvm/blob/main/train.py): `train.py`

### Anomaly model

- [AnomalyLVM](https://github.com/hanli6688/anomalylvm/blob/main/model/model.py): `model/model.py`
- [Frozen SAM2 encoder](https://github.com/hanli6688/anomalylvm/blob/main/model/model.py): `model/model.py`
- [Frozen DINO-X encoder](https://github.com/hanli6688/anomalylvm/blob/main/model/model.py): `model/model.py`
- [Fusion decoder](https://github.com/hanli6688/anomalylvm/blob/main/model/model.py): `model/model.py`
- [Feature enhancement](https://github.com/hanli6688/anomalylvm/blob/main/model/model.py): `model/model.py`
- [Prompt learner](https://github.com/hanli6688/anomalylvm/blob/main/model/model.py): `model/model.py`
- [Frozen CLIP text](https://github.com/hanli6688/anomalylvm/blob/main/model/model.py): `model/model.py`
- [CLIP model](https://github.com/hanli6688/anomalylvm/blob/main/model/clip_model.py): `model/clip_model.py`
- [Simple tokenizer](https://github.com/hanli6688/anomalylvm/blob/main/model/simple_tokenizer.py): `model/simple_tokenizer.py`
- [CLIP utilities](https://github.com/hanli6688/anomalylvm/blob/main/model/utils.py): `model/utils.py`

### Other components

- **Experiment operator**

## Connections

- Experiment operator → Train and validate: runs (evidence: `train.py`)
- Train and validate → Dataset adapters: requests data (evidence: `train.py`)
- AnomalyLVM → Frozen SAM2 encoder: extracts features (evidence: `model/model.py`)
- AnomalyLVM → Frozen DINO-X encoder: extracts features (evidence: `model/model.py`)
- AnomalyLVM → Fusion decoder: decodes features (evidence: `model/model.py`)
- AnomalyLVM → Feature enhancement: refines map (evidence: `model/model.py`)
- AnomalyLVM → Prompt learner: creates prompts (evidence: `model/model.py`)
- AnomalyLVM → Frozen CLIP text: encodes prompts (evidence: `model/model.py`)
- CLIP model → CLIP utilities: uses utilities (evidence: `model/clip_model.py`)
