# caiyuanhao1998/retinexformer architecture

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

- Interactive diagram: https://gitdiagram.com/caiyuanhao1998/retinexformer
- Repository: https://github.com/caiyuanhao1998/retinexformer

## Overview

This repository is a low-light image-enhancement toolbox centered on Retinexformer, with MST++ as another model. Users can train or evaluate enhancement models on paired and benchmark datasets, or use the documented online demo to submit images. The training path assembles datasets and loaders, then runs the restoration model; supporting branches cover image handling, metrics, and distributed execution. The graph reflects README capabilities and indexed references; unsampled modules are represented only where their role is supported, and uncertain internal demo wiring is omitted.

Main entry points: [`basicsr/models/image_restoration_model.py`](https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/models/image_restoration_model.py) (Restoration Model), [`basicsr/train.py`](https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/train.py) (Training Runner), [`basicsr/data/paired_image_dataset.py`](https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/data/paired_image_dataset.py) (Paired Image Data), [`app.py`](https://github.com/caiyuanhao1998/retinexformer/blob/master/app.py) (Demo Interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_demo["Image Demo"]
  node_demo_app["Demo Interface<br/>[app.py]"]
  node_enhance_utils["Enhancement Helpers<br/>[utils.py]"]
end

subgraph group_data["Data Pipeline"]
  node_dataset_registry["Dataset Registry<br/>[__init__.py]"]
  node_paired_data["Paired Image Data"]
  node_benchmark_data["Benchmark Datasets"]
  node_data_indexing["Pair Indexing<br/>[data_util.py]"]
  node_transforms["Image Transforms<br/>[transforms.py]"]
  node_prefetch["Batch Prefetch"]
  node_file_client["Storage Client<br/>[file_client.py]"]
end

subgraph group_models["Enhancement Models"]
  node_restoration_model["Restoration Model"]
  node_model_base["Model Runtime<br/>[base_model.py]"]
  node_retinexformer["Retinexformer"]
  node_mst["MST++"]
  node_losses["Training Losses<br/>[losses.py]"]
end

subgraph group_runtime["Training and Evaluation"]
  node_train_entry["Training Runner<br/>[train.py]"]
  node_metrics["Image Metrics"]
  node_image_utils["Image Utilities<br/>[img_util.py]"]
  node_distributed["Distributed Runtime<br/>[dist_util.py]"]
end

node_user(("Image User"))
node_storage[("Image and Model Files")]

node_user -->|"submits image"| node_demo_app
node_train_entry -->|"creates dataset"| node_dataset_registry
node_train_entry -->|"selects prefetcher"| node_prefetch
node_dataset_registry -->|"registers datasets"| node_paired_data
node_paired_data -->|"indexes pairs"| node_data_indexing
node_paired_data -->|"augments and crops"| node_transforms
node_paired_data -->|"reads image bytes"| node_file_client
node_train_entry -->|"runs training"| node_restoration_model
node_restoration_model -->|"extends runtime"| node_model_base
node_restoration_model -->|"builds architecture"| node_retinexformer
node_restoration_model -.->|"supports architecture"| node_mst
node_restoration_model -.->|"computes losses"| node_losses
node_train_entry -->|"initializes distributed"| node_distributed
node_demo_app -.->|"uses helpers"| node_enhance_utils
node_demo_app -.->|"loads or returns images"| node_storage
node_train_entry -.->|"saves checkpoints"| node_storage
node_restoration_model -.->|"converts images"| node_image_utils
node_restoration_model -.->|"validates results"| node_metrics

click node_demo_app "https://github.com/caiyuanhao1998/retinexformer/blob/master/app.py"
click node_enhance_utils "https://github.com/caiyuanhao1998/retinexformer/blob/master/Enhancement/utils.py"
click node_train_entry "https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/train.py"
click node_dataset_registry "https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/data/__init__.py"
click node_paired_data "https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/data/paired_image_dataset.py"
click node_benchmark_data "https://github.com/caiyuanhao1998/retinexformer/tree/master/basicsr/data"
click node_data_indexing "https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/data/data_util.py"
click node_transforms "https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/data/transforms.py"
click node_prefetch "https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/data/prefetch_dataloader.py"
click node_file_client "https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/utils/file_client.py"
click node_restoration_model "https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/models/image_restoration_model.py"
click node_model_base "https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/models/base_model.py"
click node_retinexformer "https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/models/archs/RetinexFormer_arch.py"
click node_mst "https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/models/archs/MST_Plus_Plus_arch.py"
click node_losses "https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/models/losses/losses.py"
click node_metrics "https://github.com/caiyuanhao1998/retinexformer/tree/master/basicsr/metrics"
click node_image_utils "https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/utils/img_util.py"
click node_distributed "https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/utils/dist_util.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_demo_app,node_enhance_utils,node_user toneBlue
class node_dataset_registry,node_paired_data,node_benchmark_data,node_data_indexing,node_transforms,node_prefetch,node_file_client,node_storage toneAmber
class node_restoration_model,node_model_base,node_retinexformer,node_mst,node_losses toneMint
class node_train_entry,node_metrics,node_image_utils,node_distributed toneRose
```

## Components

### Image Demo

- [Demo Interface](https://github.com/caiyuanhao1998/retinexformer/blob/master/app.py): `app.py`
- [Enhancement Helpers](https://github.com/caiyuanhao1998/retinexformer/blob/master/Enhancement/utils.py): `Enhancement/utils.py`

### Data Pipeline

- [Dataset Registry](https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/data/__init__.py): `basicsr/data/__init__.py`
- [Paired Image Data](https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/data/paired_image_dataset.py): `basicsr/data/paired_image_dataset.py`
- [Benchmark Datasets](https://github.com/caiyuanhao1998/retinexformer/tree/master/basicsr/data): `basicsr/data`
- [Pair Indexing](https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/data/data_util.py): `basicsr/data/data_util.py`
- [Image Transforms](https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/data/transforms.py): `basicsr/data/transforms.py`
- [Batch Prefetch](https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/data/prefetch_dataloader.py): `basicsr/data/prefetch_dataloader.py`
- [Storage Client](https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/utils/file_client.py): `basicsr/utils/file_client.py`

### Enhancement Models

- [Restoration Model](https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/models/image_restoration_model.py): `basicsr/models/image_restoration_model.py`
- [Model Runtime](https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/models/base_model.py): `basicsr/models/base_model.py`
- [Retinexformer](https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/models/archs/RetinexFormer_arch.py): `basicsr/models/archs/RetinexFormer_arch.py`
- [MST++](https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/models/archs/MST_Plus_Plus_arch.py): `basicsr/models/archs/MST_Plus_Plus_arch.py`
- [Training Losses](https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/models/losses/losses.py): `basicsr/models/losses/losses.py`

### Training and Evaluation

- [Training Runner](https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/train.py): `basicsr/train.py`
- [Image Metrics](https://github.com/caiyuanhao1998/retinexformer/tree/master/basicsr/metrics): `basicsr/metrics`
- [Image Utilities](https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/utils/img_util.py): `basicsr/utils/img_util.py`
- [Distributed Runtime](https://github.com/caiyuanhao1998/retinexformer/blob/master/basicsr/utils/dist_util.py): `basicsr/utils/dist_util.py`

### Other components

- **Image User**
- **Image and Model Files**

## Connections

- Image User → Demo Interface: submits image
- Training Runner → Dataset Registry: creates dataset (evidence: `basicsr/train.py`)
- Training Runner → Batch Prefetch: selects prefetcher (evidence: `basicsr/train.py`)
- Dataset Registry → Paired Image Data: registers datasets (evidence: `basicsr/data/__init__.py`)
- Paired Image Data → Pair Indexing: indexes pairs (evidence: `basicsr/data/paired_image_dataset.py`)
- Paired Image Data → Image Transforms: augments and crops (evidence: `basicsr/data/paired_image_dataset.py`)
- Paired Image Data → Storage Client: reads image bytes (evidence: `basicsr/data/paired_image_dataset.py`)
- Training Runner → Restoration Model: runs training (evidence: `basicsr/train.py`)
- Restoration Model → Model Runtime: extends runtime (evidence: `basicsr/models/image_restoration_model.py`)
- Restoration Model → Retinexformer: builds architecture (evidence: `basicsr/models/image_restoration_model.py`)
- Restoration Model → MST++: supports architecture
- Restoration Model → Training Losses: computes losses
- Training Runner → Distributed Runtime: initializes distributed (evidence: `basicsr/train.py`)
- Demo Interface → Enhancement Helpers: uses helpers
- Demo Interface → Image and Model Files: loads or returns images
- Training Runner → Image and Model Files: saves checkpoints
- Restoration Model → Image Utilities: converts images
- Restoration Model → Image Metrics: validates results
