# crimama/decoflow architecture

> Architecture diagram of the GitHub repository crimama/decoflow, 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/crimama/decoflow
- Repository: https://github.com/crimama/decoflow

## Overview

DeCoFlow is a continual industrial anomaly-detection system: users select a dataset and continual-learning scenario, train task-adapted normalizing flows, then evaluate anomaly and routing performance. Its documented DCL, task-specific alignment, auxiliary coupling, and tail-aware learning capabilities are represented alongside data loading, feature extraction, and task routing. The graph follows the README and SOURCE INDEX; unsampled implementation details are not inferred as direct calls.

Main entry points: [`decoflow/trainer/continual_trainer.py`](https://github.com/crimama/decoflow/blob/main/decoflow/trainer/continual_trainer.py) (Continual trainer), [`run_decoflow.py`](https://github.com/crimama/decoflow/blob/main/run_decoflow.py) (Training entry point), [`decoflow/extractors/__init__.py`](https://github.com/crimama/decoflow/blob/main/decoflow/extractors/__init__.py) (Extractor factory), [`decoflow/models/decoflow_nf.py`](https://github.com/crimama/decoflow/blob/main/decoflow/models/decoflow_nf.py) (DeCoFlow normalizing flow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and setup"]
  node_runner["Training entry point<br/>[run_decoflow.py]"]
  node_config["Ablation configuration<br/>[ablation.py]"]
end

subgraph group_data["Data and features"]
  node_datasets["Dataset registry and tasks<br/>[datasets.py]"]
  node_dataset_loaders["Dataset loaders"]
  node_extractor_factory["Extractor factory<br/>[__init__.py]"]
  node_vit_extractor["ViT feature extraction<br/>[vit_extractor.py]"]
  node_cnn_extractor["CNN feature extraction<br/>[cnn_extractor.py]"]
  node_hooks["Feature hooks<br/>[hooks.py]"]
  node_position["Positional embeddings"]
end

subgraph group_learning["Continual learning"]
  node_trainer["Continual trainer"]
  node_flow["DeCoFlow normalizing flow<br/>[decoflow_nf.py]"]
  node_dcl["Decomposed coupling<br/>[dcl.py]"]
  node_adapters["Task adapters<br/>[adapters.py]"]
  node_router["Prototype routing<br/>[routing.py]"]
  node_dsm["Denoising score matching<br/>[dsm.py]"]
  node_logger["Training logger<br/>[logger.py]"]
end

subgraph group_evaluation["Evaluation and analysis"]
  node_evaluator["Anomaly evaluation<br/>[evaluator.py]"]
  node_tail_analysis["Tail-aware analysis"]
  node_gradient_analysis["Gradient analysis"]
  node_latent_analysis["Latent analysis<br/>[latent_analyzer.py]"]
  node_score_analysis["Score analysis<br/>[score_analyzer.py]"]
end

node_user(("Researcher"))

node_user -->|"starts training"| node_runner
node_runner -->|"configures"| node_config
node_runner -->|"starts training"| node_trainer
node_runner -.->|"selects task data"| node_datasets
node_datasets -->|"selects loader"| node_dataset_loaders
node_runner -.->|"selects extractor"| node_extractor_factory
node_extractor_factory -->|"creates ViT extractor"| node_vit_extractor
node_extractor_factory -->|"creates CNN extractor"| node_cnn_extractor
node_vit_extractor -->|"registers hooks"| node_hooks
node_cnn_extractor -->|"uses aggregator"| node_hooks
node_trainer -.->|"extracts features"| node_vit_extractor
node_trainer -.->|"adds embeddings"| node_position
node_trainer -->|"trains tasks"| node_flow
node_flow -->|"uses coupling layers"| node_dcl
node_flow -->|"uses adapters"| node_adapters
node_trainer -->|"routes tasks"| node_router
node_trainer -->|"uses optional loss"| node_dsm
node_trainer -->|"logs training"| node_logger
node_user -->|"requests evaluation"| node_evaluator
node_evaluator -->|"reads task data"| node_datasets
node_evaluator -.->|"evaluates model"| node_trainer
node_user -.->|"runs analysis"| node_tail_analysis
node_user -.->|"runs analysis"| node_gradient_analysis
node_user -.->|"runs analysis"| node_latent_analysis
node_user -.->|"runs analysis"| node_score_analysis

click node_runner "https://github.com/crimama/decoflow/blob/main/run_decoflow.py"
click node_config "https://github.com/crimama/decoflow/blob/main/decoflow/config/ablation.py"
click node_datasets "https://github.com/crimama/decoflow/blob/main/decoflow/data/datasets.py"
click node_dataset_loaders "https://github.com/crimama/decoflow/tree/main/decoflow/data"
click node_extractor_factory "https://github.com/crimama/decoflow/blob/main/decoflow/extractors/__init__.py"
click node_vit_extractor "https://github.com/crimama/decoflow/blob/main/decoflow/extractors/vit_extractor.py"
click node_cnn_extractor "https://github.com/crimama/decoflow/blob/main/decoflow/extractors/cnn_extractor.py"
click node_hooks "https://github.com/crimama/decoflow/blob/main/decoflow/extractors/hooks.py"
click node_position "https://github.com/crimama/decoflow/blob/main/decoflow/models/position_embedding.py"
click node_trainer "https://github.com/crimama/decoflow/blob/main/decoflow/trainer/continual_trainer.py"
click node_flow "https://github.com/crimama/decoflow/blob/main/decoflow/models/decoflow_nf.py"
click node_dcl "https://github.com/crimama/decoflow/blob/main/decoflow/models/dcl.py"
click node_adapters "https://github.com/crimama/decoflow/blob/main/decoflow/models/adapters.py"
click node_router "https://github.com/crimama/decoflow/blob/main/decoflow/models/routing.py"
click node_dsm "https://github.com/crimama/decoflow/blob/main/decoflow/models/dsm.py"
click node_evaluator "https://github.com/crimama/decoflow/blob/main/decoflow/evaluation/evaluator.py"
click node_tail_analysis "https://github.com/crimama/decoflow/blob/main/decoflow/analysis/tail_aware_analysis.py"
click node_gradient_analysis "https://github.com/crimama/decoflow/blob/main/decoflow/analysis/gradient_analyzer.py"
click node_latent_analysis "https://github.com/crimama/decoflow/blob/main/decoflow/analysis/latent_analyzer.py"
click node_score_analysis "https://github.com/crimama/decoflow/blob/main/decoflow/analysis/score_analyzer.py"
click node_logger "https://github.com/crimama/decoflow/blob/main/decoflow/utils/logger.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_runner,node_config toneBlue
class node_datasets,node_dataset_loaders,node_extractor_factory,node_vit_extractor,node_cnn_extractor,node_hooks,node_position toneAmber
class node_trainer,node_flow,node_dcl,node_adapters,node_router,node_dsm,node_logger toneMint
class node_evaluator,node_tail_analysis,node_gradient_analysis,node_latent_analysis,node_score_analysis toneRose
class node_user toneIndigo
```

## Components

### Entry and setup

- [Training entry point](https://github.com/crimama/decoflow/blob/main/run_decoflow.py): `run_decoflow.py`
- [Ablation configuration](https://github.com/crimama/decoflow/blob/main/decoflow/config/ablation.py): `decoflow/config/ablation.py`

### Data and features

- [Dataset registry and tasks](https://github.com/crimama/decoflow/blob/main/decoflow/data/datasets.py): `decoflow/data/datasets.py`
- [Dataset loaders](https://github.com/crimama/decoflow/tree/main/decoflow/data): `decoflow/data`
- [Extractor factory](https://github.com/crimama/decoflow/blob/main/decoflow/extractors/__init__.py): `decoflow/extractors/__init__.py`
- [ViT feature extraction](https://github.com/crimama/decoflow/blob/main/decoflow/extractors/vit_extractor.py): `decoflow/extractors/vit_extractor.py`
- [CNN feature extraction](https://github.com/crimama/decoflow/blob/main/decoflow/extractors/cnn_extractor.py): `decoflow/extractors/cnn_extractor.py`
- [Feature hooks](https://github.com/crimama/decoflow/blob/main/decoflow/extractors/hooks.py): `decoflow/extractors/hooks.py`
- [Positional embeddings](https://github.com/crimama/decoflow/blob/main/decoflow/models/position_embedding.py): `decoflow/models/position_embedding.py`

### Continual learning

- [Continual trainer](https://github.com/crimama/decoflow/blob/main/decoflow/trainer/continual_trainer.py): `decoflow/trainer/continual_trainer.py`
- [DeCoFlow normalizing flow](https://github.com/crimama/decoflow/blob/main/decoflow/models/decoflow_nf.py): `decoflow/models/decoflow_nf.py`
- [Decomposed coupling](https://github.com/crimama/decoflow/blob/main/decoflow/models/dcl.py): `decoflow/models/dcl.py`
- [Task adapters](https://github.com/crimama/decoflow/blob/main/decoflow/models/adapters.py): `decoflow/models/adapters.py`
- [Prototype routing](https://github.com/crimama/decoflow/blob/main/decoflow/models/routing.py): `decoflow/models/routing.py`
- [Denoising score matching](https://github.com/crimama/decoflow/blob/main/decoflow/models/dsm.py): `decoflow/models/dsm.py`
- [Training logger](https://github.com/crimama/decoflow/blob/main/decoflow/utils/logger.py): `decoflow/utils/logger.py`

### Evaluation and analysis

- [Anomaly evaluation](https://github.com/crimama/decoflow/blob/main/decoflow/evaluation/evaluator.py): `decoflow/evaluation/evaluator.py`
- [Tail-aware analysis](https://github.com/crimama/decoflow/blob/main/decoflow/analysis/tail_aware_analysis.py): `decoflow/analysis/tail_aware_analysis.py`
- [Gradient analysis](https://github.com/crimama/decoflow/blob/main/decoflow/analysis/gradient_analyzer.py): `decoflow/analysis/gradient_analyzer.py`
- [Latent analysis](https://github.com/crimama/decoflow/blob/main/decoflow/analysis/latent_analyzer.py): `decoflow/analysis/latent_analyzer.py`
- [Score analysis](https://github.com/crimama/decoflow/blob/main/decoflow/analysis/score_analyzer.py): `decoflow/analysis/score_analyzer.py`

### Other components

- **Researcher**

## Connections

- Researcher → Training entry point: starts training (evidence: `README.md`)
- Training entry point → Ablation configuration: configures
- Training entry point → Continual trainer: starts training
- Training entry point → Dataset registry and tasks: selects task data
- Dataset registry and tasks → Dataset loaders: selects loader (evidence: `decoflow/data/datasets.py`)
- Training entry point → Extractor factory: selects extractor
- Extractor factory → ViT feature extraction: creates ViT extractor (evidence: `decoflow/extractors/__init__.py`)
- Extractor factory → CNN feature extraction: creates CNN extractor (evidence: `decoflow/extractors/__init__.py`)
- ViT feature extraction → Feature hooks: registers hooks (evidence: `decoflow/extractors/vit_extractor.py`)
- CNN feature extraction → Feature hooks: uses aggregator (evidence: `decoflow/extractors/cnn_extractor.py`)
- Continual trainer → ViT feature extraction: extracts features
- Continual trainer → Positional embeddings: adds embeddings
- Continual trainer → DeCoFlow normalizing flow: trains tasks (evidence: `decoflow/trainer/continual_trainer.py`)
- DeCoFlow normalizing flow → Decomposed coupling: uses coupling layers (evidence: `decoflow/models/decoflow_nf.py`)
- DeCoFlow normalizing flow → Task adapters: uses adapters (evidence: `decoflow/models/decoflow_nf.py`)
- Continual trainer → Prototype routing: routes tasks (evidence: `decoflow/trainer/continual_trainer.py`)
- Continual trainer → Denoising score matching: uses optional loss (evidence: `decoflow/trainer/continual_trainer.py`)
- Continual trainer → Training logger: logs training (evidence: `decoflow/trainer/continual_trainer.py`)
- Researcher → Anomaly evaluation: requests evaluation (evidence: `README.md`)
- Anomaly evaluation → Dataset registry and tasks: reads task data (evidence: `decoflow/evaluation/evaluator.py`)
- Anomaly evaluation → Continual trainer: evaluates model
- Researcher → Tail-aware analysis: runs analysis
- Researcher → Gradient analysis: runs analysis
- Researcher → Latent analysis: runs analysis
- Researcher → Score analysis: runs analysis
