# jw-chae/cleancon architecture

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

- Interactive diagram: https://gitdiagram.com/jw-chae/cleancon
- Repository: https://github.com/jw-chae/cleancon

## Overview

CleanCon is an experimental pipeline for memory-based anomaly detection: it ranks training images by out-of-bag cross-image support, restricts which patches can enter a fixed-budget memory, then evaluates anomaly localization. The README emphasizes that the detector representation, coreset construction, memory size, and test-time scoring are otherwise held constant. The graph preserves feature caching, selection and audit stages, memory construction, scoring, and evaluation, plus the documented SoftPatch and retention-sweep branches. Some experiment internals were not excerpted, so those links are shown only where the README or source index supports them.

Main entry points: [`experiments/run_fixed_budget.py`](https://github.com/jw-chae/cleancon/blob/main/experiments/run_fixed_budget.py) (Fixed-budget runner), [`experiments/build_dinov2_train_cache.py`](https://github.com/jw-chae/cleancon/blob/main/experiments/build_dinov2_train_cache.py) (Cache extraction), [`cleancon/purification/oob.py`](https://github.com/jw-chae/cleancon/blob/main/cleancon/purification/oob.py) (OOB support scoring), [`cleancon/memory/builders/approx_greedy_coreset.py`](https://github.com/jw-chae/cleancon/blob/main/cleancon/memory/builders/approx_greedy_coreset.py) (Greedy coreset)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_features["Features and caches"]
  node_backbone["DINOv2 features"]
  node_feature_cache[("Feature cache<br/>[cache.py]")]
  node_cache_builders["Cache extraction"]
end

subgraph group_selection["Support-based selection"]
  node_oob["OOB support scoring<br/>[oob.py]"]
  node_projection["Soft projection<br/>[soft_projection.py]"]
  node_protocols["Protocol views<br/>[protocol_view.py]"]
  node_selection_rules["Retention and salvage<br/>[safe_expansion.py]"]
  node_softpatch["SoftPatch selection<br/>[softpatch.py]"]
end

subgraph group_detection["Memory and detection"]
  node_memory_builder["Greedy coreset"]
  node_memory_bank[("Memory bank<br/>[bank.py]")]
  node_fixed_budget["Fixed-budget runner"]
  node_map_postprocess["Anomaly maps<br/>[maps.py]"]
end

subgraph group_evaluation["Evaluation and analysis"]
  node_metric_eval["Detection metrics<br/>[metrics.py]"]
  node_retention_sweep["Retention sweep"]
  node_analysis["Paper analysis<br/>[aggregate_main.py]"]
end

node_researcher(("Experiment runner"))

node_researcher -->|"builds caches"| node_cache_builders
node_cache_builders -->|"extracts features"| node_backbone
node_cache_builders -.->|"writes features"| node_feature_cache
node_researcher -->|"runs comparison"| node_fixed_budget
node_fixed_budget -.->|"loads caches"| node_feature_cache
node_fixed_budget -->|"scores support"| node_oob
node_oob -.->|"computes residuals"| node_projection
node_fixed_budget -.->|"composes protocol"| node_protocols
node_fixed_budget -.->|"selects candidates"| node_selection_rules
node_fixed_budget -->|"offers variant"| node_softpatch
node_fixed_budget -->|"builds coreset"| node_memory_builder
node_memory_builder -->|"returns bank"| node_memory_bank
node_fixed_budget -->|"processes maps"| node_map_postprocess
node_fixed_budget -->|"evaluates detector"| node_metric_eval
node_researcher -->|"runs sweep"| node_retention_sweep
node_retention_sweep -->|"reuses runner"| node_fixed_budget
node_researcher -.->|"aggregates results"| node_analysis

click node_backbone "https://github.com/jw-chae/cleancon/blob/main/cleancon/models/backbones/dinov2_multilayer.py"
click node_feature_cache "https://github.com/jw-chae/cleancon/blob/main/cleancon/purification/cache.py"
click node_cache_builders "https://github.com/jw-chae/cleancon/blob/main/experiments/build_dinov2_train_cache.py"
click node_oob "https://github.com/jw-chae/cleancon/blob/main/cleancon/purification/oob.py"
click node_projection "https://github.com/jw-chae/cleancon/blob/main/cleancon/consensus/soft_projection.py"
click node_protocols "https://github.com/jw-chae/cleancon/blob/main/cleancon/purification/protocol_view.py"
click node_selection_rules "https://github.com/jw-chae/cleancon/blob/main/cleancon/purification/safe_expansion.py"
click node_softpatch "https://github.com/jw-chae/cleancon/blob/main/cleancon/purification/softpatch.py"
click node_memory_builder "https://github.com/jw-chae/cleancon/blob/main/cleancon/memory/builders/approx_greedy_coreset.py"
click node_memory_bank "https://github.com/jw-chae/cleancon/blob/main/cleancon/memory/bank.py"
click node_fixed_budget "https://github.com/jw-chae/cleancon/blob/main/experiments/run_fixed_budget.py"
click node_map_postprocess "https://github.com/jw-chae/cleancon/blob/main/cleancon/postprocess/maps.py"
click node_metric_eval "https://github.com/jw-chae/cleancon/blob/main/cleancon/eval/metrics.py"
click node_retention_sweep "https://github.com/jw-chae/cleancon/blob/main/experiments/run_retention_sweep.py"
click node_analysis "https://github.com/jw-chae/cleancon/blob/main/analysis/aggregate_main.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_backbone,node_feature_cache,node_cache_builders toneBlue
class node_oob,node_projection,node_protocols,node_selection_rules,node_softpatch toneAmber
class node_memory_builder,node_memory_bank,node_fixed_budget,node_map_postprocess toneMint
class node_metric_eval,node_retention_sweep,node_analysis toneRose
class node_researcher toneIndigo
```

## Components

### Features and caches

- [DINOv2 features](https://github.com/jw-chae/cleancon/blob/main/cleancon/models/backbones/dinov2_multilayer.py): `cleancon/models/backbones/dinov2_multilayer.py`
- [Feature cache](https://github.com/jw-chae/cleancon/blob/main/cleancon/purification/cache.py): `cleancon/purification/cache.py`
- [Cache extraction](https://github.com/jw-chae/cleancon/blob/main/experiments/build_dinov2_train_cache.py): `experiments/build_dinov2_train_cache.py`

### Support-based selection

- [OOB support scoring](https://github.com/jw-chae/cleancon/blob/main/cleancon/purification/oob.py): `cleancon/purification/oob.py`
- [Soft projection](https://github.com/jw-chae/cleancon/blob/main/cleancon/consensus/soft_projection.py): `cleancon/consensus/soft_projection.py`
- [Protocol views](https://github.com/jw-chae/cleancon/blob/main/cleancon/purification/protocol_view.py): `cleancon/purification/protocol_view.py`
- [Retention and salvage](https://github.com/jw-chae/cleancon/blob/main/cleancon/purification/safe_expansion.py): `cleancon/purification/safe_expansion.py`
- [SoftPatch selection](https://github.com/jw-chae/cleancon/blob/main/cleancon/purification/softpatch.py): `cleancon/purification/softpatch.py`

### Memory and detection

- [Greedy coreset](https://github.com/jw-chae/cleancon/blob/main/cleancon/memory/builders/approx_greedy_coreset.py): `cleancon/memory/builders/approx_greedy_coreset.py`
- [Memory bank](https://github.com/jw-chae/cleancon/blob/main/cleancon/memory/bank.py): `cleancon/memory/bank.py`
- [Fixed-budget runner](https://github.com/jw-chae/cleancon/blob/main/experiments/run_fixed_budget.py): `experiments/run_fixed_budget.py`
- [Anomaly maps](https://github.com/jw-chae/cleancon/blob/main/cleancon/postprocess/maps.py): `cleancon/postprocess/maps.py`

### Evaluation and analysis

- [Detection metrics](https://github.com/jw-chae/cleancon/blob/main/cleancon/eval/metrics.py): `cleancon/eval/metrics.py`
- [Retention sweep](https://github.com/jw-chae/cleancon/blob/main/experiments/run_retention_sweep.py): `experiments/run_retention_sweep.py`
- [Paper analysis](https://github.com/jw-chae/cleancon/blob/main/analysis/aggregate_main.py): `analysis/aggregate_main.py`

### Other components

- **Experiment runner**

## Connections

- Experiment runner → Cache extraction: builds caches (evidence: `README.md`)
- Cache extraction → DINOv2 features: extracts features (evidence: `experiments/build_dinov2_train_cache.py`)
- Cache extraction → Feature cache: writes features
- Experiment runner → Fixed-budget runner: runs comparison (evidence: `README.md`)
- Fixed-budget runner → Feature cache: loads caches
- Fixed-budget runner → OOB support scoring: scores support (evidence: `experiments/run_fixed_budget.py`)
- OOB support scoring → Soft projection: computes residuals
- Fixed-budget runner → Protocol views: composes protocol
- Fixed-budget runner → Retention and salvage: selects candidates
- Fixed-budget runner → SoftPatch selection: offers variant (evidence: `experiments/run_fixed_budget.py`)
- Fixed-budget runner → Greedy coreset: builds coreset (evidence: `experiments/run_fixed_budget.py`)
- Greedy coreset → Memory bank: returns bank (evidence: `cleancon/memory/builders/approx_greedy_coreset.py`)
- Fixed-budget runner → Anomaly maps: processes maps (evidence: `experiments/run_fixed_budget.py`)
- Fixed-budget runner → Detection metrics: evaluates detector (evidence: `experiments/run_fixed_budget.py`)
- Experiment runner → Retention sweep: runs sweep (evidence: `README.md`)
- Retention sweep → Fixed-budget runner: reuses runner (evidence: `experiments/run_retention_sweep.py`)
- Experiment runner → Paper analysis: aggregates results
