# cvlab-kaist/tair architecture

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

- Interactive diagram: https://gitdiagram.com/cvlab-kaist/tair
- Repository: https://github.com/cvlab-kaist/tair

## Overview

This repository presents TeReDiff, a text-aware image-restoration system. The principal user workflow runs a low-quality image through the restoration pipeline, which uses diffusion and sampling components to produce a restored image; training is documented as separate restoration-only, text-spotting-only, and joint stages. The README also describes SA-Text and Real-Text datasets and a text-spotting module. Several connections below are based on README documentation rather than sampled implementation; the tree includes substantial Detectron2 code, but it is supporting infrastructure rather than the product’s main workflow.

Main entry points: [`terediff/pipeline.py`](https://github.com/cvlab-kaist/tair/blob/main/terediff/pipeline.py) (Restoration pipeline), [`train.py`](https://github.com/cvlab-kaist/tair/blob/main/train.py) (Training entry point), [`testr/adet/modeling/transformer_detector.py`](https://github.com/cvlab-kaist/tair/blob/main/testr/adet/modeling/transformer_detector.py) (Text detector), [`val.py`](https://github.com/cvlab-kaist/tair/blob/main/val.py) (Validation entry point)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Datasets"]
  node_sa_text[("SA-Text")]
  node_real_text[("Real-Text")]
  node_degradation["Degradation transforms<br/>[degradation.py]"]
end

subgraph group_restore["Image restoration"]
  node_restoration_pipeline["Restoration pipeline<br/>[pipeline.py]"]
  node_restoration_models["Restoration networks<br/>[unet.py]"]
  node_diffusion_sampler["Diffusion samplers"]
  node_clip_text["Text encoder<br/>[transformer.py]"]
end

subgraph group_spot["Text spotting"]
  node_spot_data["Spotting data mapper<br/>[dataset_mapper.py]"]
  node_spot_detector["Text detector"]
  node_spot_loss["Spotting losses<br/>[losses.py]"]
  node_spot_eval["Text evaluation"]
end

subgraph group_operation["Training and evaluation"]
  node_training["Training entry point<br/>[train.py]"]
  node_validation["Validation entry point<br/>[val.py]"]
end

node_user(("Researcher"))
node_restored["Restored images"]

node_user -->|"runs inference"| node_restoration_pipeline
node_restoration_pipeline -->|"uses restoration"| node_restoration_models
node_restoration_pipeline -->|"selects sampler"| node_diffusion_sampler
node_restoration_pipeline -.->|"uses text conditioning"| node_clip_text
node_restoration_pipeline -->|"produces images"| node_restored
node_sa_text -->|"supplies training data"| node_training
node_real_text -->|"supplies evaluation data"| node_validation
node_degradation -.->|"supports training"| node_training
node_training -->|"trains stage one"| node_restoration_models
node_training -->|"trains stage two"| node_spot_detector
node_training -->|"jointly trains stage three"| node_restoration_pipeline
node_spot_data -.->|"prepares inputs"| node_spot_detector
node_spot_detector -.->|"computes losses"| node_spot_loss
node_spot_detector -.->|"evaluates predictions"| node_spot_eval
node_validation -.->|"runs validation"| node_restoration_pipeline

click node_degradation "https://github.com/cvlab-kaist/tair/blob/main/terediff/dataset/degradation.py"
click node_restoration_pipeline "https://github.com/cvlab-kaist/tair/blob/main/terediff/pipeline.py"
click node_restoration_models "https://github.com/cvlab-kaist/tair/blob/main/terediff/model/unet.py"
click node_diffusion_sampler "https://github.com/cvlab-kaist/tair/tree/main/terediff/sampler"
click node_clip_text "https://github.com/cvlab-kaist/tair/blob/main/terediff/model/open_clip/transformer.py"
click node_spot_data "https://github.com/cvlab-kaist/tair/blob/main/testr/adet/data/dataset_mapper.py"
click node_spot_detector "https://github.com/cvlab-kaist/tair/blob/main/testr/adet/modeling/transformer_detector.py"
click node_spot_loss "https://github.com/cvlab-kaist/tair/blob/main/testr/adet/modeling/testr/losses.py"
click node_spot_eval "https://github.com/cvlab-kaist/tair/blob/main/testr/adet/evaluation/text_eval_script.py"
click node_training "https://github.com/cvlab-kaist/tair/blob/main/train.py"
click node_validation "https://github.com/cvlab-kaist/tair/blob/main/val.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_sa_text,node_real_text,node_degradation toneBlue
class node_restoration_pipeline,node_restoration_models,node_diffusion_sampler,node_clip_text toneAmber
class node_spot_data,node_spot_detector,node_spot_loss,node_spot_eval toneMint
class node_training,node_validation toneRose
class node_user,node_restored toneIndigo
```

## Components

### Datasets

- **SA-Text**
- **Real-Text**
- [Degradation transforms](https://github.com/cvlab-kaist/tair/blob/main/terediff/dataset/degradation.py): `terediff/dataset/degradation.py`

### Image restoration

- [Restoration pipeline](https://github.com/cvlab-kaist/tair/blob/main/terediff/pipeline.py): `terediff/pipeline.py`
- [Restoration networks](https://github.com/cvlab-kaist/tair/blob/main/terediff/model/unet.py): `terediff/model/unet.py`
- [Diffusion samplers](https://github.com/cvlab-kaist/tair/tree/main/terediff/sampler): `terediff/sampler`
- [Text encoder](https://github.com/cvlab-kaist/tair/blob/main/terediff/model/open_clip/transformer.py): `terediff/model/open_clip/transformer.py`

### Text spotting

- [Spotting data mapper](https://github.com/cvlab-kaist/tair/blob/main/testr/adet/data/dataset_mapper.py): `testr/adet/data/dataset_mapper.py`
- [Text detector](https://github.com/cvlab-kaist/tair/blob/main/testr/adet/modeling/transformer_detector.py): `testr/adet/modeling/transformer_detector.py`
- [Spotting losses](https://github.com/cvlab-kaist/tair/blob/main/testr/adet/modeling/testr/losses.py): `testr/adet/modeling/testr/losses.py`
- [Text evaluation](https://github.com/cvlab-kaist/tair/blob/main/testr/adet/evaluation/text_eval_script.py): `testr/adet/evaluation/text_eval_script.py`

### Training and evaluation

- [Training entry point](https://github.com/cvlab-kaist/tair/blob/main/train.py): `train.py`
- [Validation entry point](https://github.com/cvlab-kaist/tair/blob/main/val.py): `val.py`

### Other components

- **Researcher**
- **Restored images**

## Connections

- Researcher → Restoration pipeline: runs inference
- Restoration pipeline → Restoration networks: uses restoration
- Restoration pipeline → Diffusion samplers: selects sampler (evidence: `terediff/pipeline.py`)
- Restoration pipeline → Text encoder: uses text conditioning
- Restoration pipeline → Restored images: produces images
- SA-Text → Training entry point: supplies training data
- Real-Text → Validation entry point: supplies evaluation data
- Degradation transforms → Training entry point: supports training
- Training entry point → Restoration networks: trains stage one
- Training entry point → Text detector: trains stage two
- Training entry point → Restoration pipeline: jointly trains stage three
- Spotting data mapper → Text detector: prepares inputs
- Text detector → Spotting losses: computes losses
- Text detector → Text evaluation: evaluates predictions
- Validation entry point → Restoration pipeline: runs validation
