# davidcoach/retouchformer_aaai_24 architecture

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

- Interactive diagram: https://gitdiagram.com/davidcoach/retouchformer_aaai_24
- Repository: https://github.com/davidcoach/retouchformer_aaai_24

## Overview

RetouchFormer is a research implementation for high-quality face retouching: it predicts imperfection regions and synthesizes replacement content using clean-face priors and selective transformer attention. The documented workflow trains on paired FFHQR source/target images, with semi-supervised unpaired data, then evaluates or retouches images. The graph includes the training/data path and model components, plus documented capabilities. Some links reflect imports listed by the source index; unsampled inference wiring and several internal model interactions are left unasserted.

Main entry points: [`core/trainer.py`](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/trainer.py) (Trainer), [`model/RetouchFormer.py`](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/model/RetouchFormer.py) (Retouch generator), [`core/dataset.py`](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/dataset.py) (Face datasets), [`train.py`](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/train.py) (Training entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Training and evaluation"]
  node_train["Training entry<br/>[train.py]"]
  node_trainer["Trainer<br/>[trainer.py]"]
  node_dataset["Face datasets<br/>[dataset.py]"]
  node_eval["Evaluation entry<br/>[eval.py]"]
  node_retouch_entry["Image retouch entry<br/>[img_retouching.py]"]
end

subgraph group_model["Retouching model"]
  node_generator["Retouch generator<br/>[RetouchFormer.py]"]
  node_prior_mask["Prior and mask VQ"]
  node_transformer["Window attention stages"]
  node_face_prior["GPEN face prior<br/>[gpen_model.py]"]
  node_discriminator["GAN discriminator<br/>[RetouchFormer.py]"]
  node_spectral["Spectral normalization<br/>[spectral_norm.py]"]
end

subgraph group_support["Training support"]
  node_loss["Training losses<br/>[loss.py]"]
  node_scheduler["Learning-rate scheduler<br/>[lr_scheduler.py]"]
  node_metrics["Quality metrics<br/>[metrics.py]"]
  node_distributed["Distributed setup<br/>[dist.py]"]
  node_face_embed["IRSE face model<br/>[model_irse.py]"]
  node_helpers["Model helpers<br/>[helpers.py]"]
  node_utils["Data utilities<br/>[utils.py]"]
  node_window_utils["Window utilities<br/>[make_windows.py]"]
  node_core_spectral["Core spectral norm<br/>[spectral_norm.py]"]
end

subgraph group_kernels["Model operations"]
  node_fused_act["Fused activation<br/>[fused_act.py]"]
  node_upfirdn["Resampling operator<br/>[upfirdn2d.py]"]
end

node_user(("Researcher"))

node_user -->|"starts training"| node_train
node_train -->|"starts"| node_trainer
node_trainer -->|"loads datasets"| node_dataset
node_trainer -->|"uses losses"| node_loss
node_trainer -->|"uses schedule"| node_scheduler
node_eval -->|"imports"| node_dataset
node_retouch_entry -->|"imports"| node_dataset
node_generator -->|"imports prior model"| node_prior_mask
node_generator -->|"imports stages"| node_transformer
node_generator -->|"imports encoder/decoder"| node_face_prior
node_generator -->|"imports normalization"| node_spectral
node_trainer -.->|"trains retouch model"| node_generator
node_trainer -.->|"trains adversary"| node_discriminator
node_trainer -.->|"reports quality"| node_metrics
node_dataset -->|"imports utilities"| node_utils
node_metrics -->|"imports utilities"| node_utils
node_loss -->|"imports face model"| node_face_embed
node_face_embed -->|"imports helpers"| node_helpers
node_face_prior -->|"imports resampling"| node_upfirdn

click node_train "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/train.py"
click node_trainer "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/trainer.py"
click node_dataset "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/dataset.py"
click node_eval "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/eval.py"
click node_retouch_entry "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/img_retouching.py"
click node_generator "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/model/RetouchFormer.py"
click node_prior_mask "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/model/modules/soft_mask_generation.py"
click node_transformer "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/model/network_vrt_pair_qkv.py"
click node_face_prior "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/model/gpen_model.py"
click node_discriminator "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/model/RetouchFormer.py"
click node_spectral "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/model/modules/spectral_norm.py"
click node_loss "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/loss.py"
click node_scheduler "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/lr_scheduler.py"
click node_metrics "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/metrics.py"
click node_distributed "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/dist.py"
click node_face_embed "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/model_irse.py"
click node_helpers "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/helpers.py"
click node_utils "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/utils.py"
click node_window_utils "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/make_windows.py"
click node_core_spectral "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/spectral_norm.py"
click node_fused_act "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/op/fused_act.py"
click node_upfirdn "https://github.com/davidcoach/retouchformer_aaai_24/blob/main/op/upfirdn2d.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_train,node_trainer,node_dataset,node_eval,node_retouch_entry toneBlue
class node_generator,node_prior_mask,node_transformer,node_face_prior,node_discriminator,node_spectral toneAmber
class node_loss,node_scheduler,node_metrics,node_distributed,node_face_embed,node_helpers,node_utils,node_window_utils,node_core_spectral toneMint
class node_fused_act,node_upfirdn toneRose
class node_user toneIndigo
```

## Components

### Training and evaluation

- [Training entry](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/train.py): `train.py`
- [Trainer](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/trainer.py): `core/trainer.py`
- [Face datasets](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/dataset.py): `core/dataset.py`
- [Evaluation entry](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/eval.py): `eval.py`
- [Image retouch entry](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/img_retouching.py): `img_retouching.py`

### Retouching model

- [Retouch generator](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/model/RetouchFormer.py): `model/RetouchFormer.py`
- [Prior and mask VQ](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/model/modules/soft_mask_generation.py): `model/modules/soft_mask_generation.py`
- [Window attention stages](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/model/network_vrt_pair_qkv.py): `model/network_vrt_pair_qkv.py`
- [GPEN face prior](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/model/gpen_model.py): `model/gpen_model.py`
- [GAN discriminator](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/model/RetouchFormer.py): `model/RetouchFormer.py`
- [Spectral normalization](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/model/modules/spectral_norm.py): `model/modules/spectral_norm.py`

### Training support

- [Training losses](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/loss.py): `core/loss.py`
- [Learning-rate scheduler](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/lr_scheduler.py): `core/lr_scheduler.py`
- [Quality metrics](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/metrics.py): `core/metrics.py`
- [Distributed setup](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/dist.py): `core/dist.py`
- [IRSE face model](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/model_irse.py): `core/model_irse.py`
- [Model helpers](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/helpers.py): `core/helpers.py`
- [Data utilities](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/utils.py): `core/utils.py`
- [Window utilities](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/make_windows.py): `core/make_windows.py`
- [Core spectral norm](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/core/spectral_norm.py): `core/spectral_norm.py`

### Model operations

- [Fused activation](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/op/fused_act.py): `op/fused_act.py`
- [Resampling operator](https://github.com/davidcoach/retouchformer_aaai_24/blob/main/op/upfirdn2d.py): `op/upfirdn2d.py`

### Other components

- **Researcher**

## Connections

- Researcher → Training entry: starts training (evidence: `README.md`)
- Training entry → Trainer: starts (evidence: `train.py`)
- Trainer → Face datasets: loads datasets (evidence: `core/trainer.py`)
- Trainer → Training losses: uses losses (evidence: `core/trainer.py`)
- Trainer → Learning-rate scheduler: uses schedule (evidence: `core/trainer.py`)
- Evaluation entry → Face datasets: imports (evidence: `eval.py`)
- Image retouch entry → Face datasets: imports (evidence: `img_retouching.py`)
- Retouch generator → Prior and mask VQ: imports prior model (evidence: `model/RetouchFormer.py`)
- Retouch generator → Window attention stages: imports stages (evidence: `model/RetouchFormer.py`)
- Retouch generator → GPEN face prior: imports encoder/decoder (evidence: `model/RetouchFormer.py`)
- Retouch generator → Spectral normalization: imports normalization (evidence: `model/RetouchFormer.py`)
- Trainer → Retouch generator: trains retouch model
- Trainer → GAN discriminator: trains adversary
- Trainer → Quality metrics: reports quality
- Face datasets → Data utilities: imports utilities (evidence: `core/dataset.py`)
- Quality metrics → Data utilities: imports utilities (evidence: `core/metrics.py`)
- Training losses → IRSE face model: imports face model (evidence: `core/loss.py`)
- IRSE face model → Model helpers: imports helpers (evidence: `core/model_irse.py`)
- GPEN face prior → Resampling operator: imports resampling (evidence: `model/gpen_model.py`)
