# xinntao/real-esrgan architecture

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

- Interactive diagram: https://gitdiagram.com/xinntao/real-esrgan
- Repository: https://github.com/xinntao/real-esrgan

## Overview

Real-ESRGAN is an image/video restoration and super-resolution system. The main user workflow is: select media and a model, load weights, run tiled or whole-image enhancement, optionally enhance faces, and write restored images or encoded video. A second major workflow trains models from synthetic degradations or paired data using BasicSR. The graph includes documented anime/general models, video processing, arbitrary scaling, and optional GFPGAN integration. Some orchestration is inferred from sampled entrypoints and README capabilities; unsampled BasicSR internals are left external.

Main entry points: [`realesrgan/utils.py`](https://github.com/xinntao/real-esrgan/blob/master/realesrgan/utils.py) (RealESRGAN Upsampler), [`inference_realesrgan.py`](https://github.com/xinntao/real-esrgan/blob/master/inference_realesrgan.py) (Image Inference), [`inference_realesrgan_video.py`](https://github.com/xinntao/real-esrgan/blob/master/inference_realesrgan_video.py) (Video Inference), [`realesrgan/data/realesrgan_dataset.py`](https://github.com/xinntao/real-esrgan/blob/master/realesrgan/data/realesrgan_dataset.py) (Synthetic Dataset)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inference["Inference Entry Points"]
  node_image_cli["Image Inference"]
  node_video_cli["Video Inference"]
end

subgraph group_runtime["Restoration Runtime"]
  node_upsampler["RealESRGAN Upsampler<br/>[utils.py]"]
  node_tile_processing["Tile Processing<br/>[utils.py]"]
  node_srvgg["SRVGG Network<br/>[srvgg_arch.py]"]
  node_basicsr_networks["BasicSR Networks"]
  node_model_weights["Model Weights<br/>[README.md]"]
  node_face_enhancer["Face Enhancer"]
end

subgraph group_video["Video Pipeline"]
  node_video_reader["Video Reader"]
  node_video_writer["Video Writer"]
end

subgraph group_training["Training System"]
  node_train_entry["Training Entry<br/>[train.py]"]
  node_synthetic_dataset["Synthetic Dataset"]
  node_paired_dataset["Paired Dataset"]
  node_training_model["Degradation Model"]
  node_discriminator["UNet Discriminator"]
end

node_user(("User"))
node_input_media["Input Media"]
node_output_media["Restored Media"]
node_ffmpeg["FFmpeg"]
node_training_store[("Training Data")]

node_user -->|"runs"| node_image_cli
node_user -->|"runs"| node_video_cli
node_image_cli -->|"reads"| node_input_media
node_image_cli -->|"enhances"| node_upsampler
node_image_cli -.->|"optionally uses"| node_face_enhancer
node_image_cli -->|"writes"| node_output_media
node_upsampler -->|"loads"| node_model_weights
node_upsampler -->|"runs"| node_srvgg
node_upsampler -->|"runs"| node_basicsr_networks
node_upsampler -->|"tiles"| node_tile_processing
node_face_enhancer -.->|"upsamples background"| node_upsampler
node_video_cli -->|"starts"| node_video_reader
node_video_reader -->|"reads"| node_input_media
node_video_reader -->|"decodes"| node_ffmpeg
node_video_cli -->|"restores frames"| node_upsampler
node_video_cli -->|"starts"| node_video_writer
node_video_writer -->|"encodes"| node_ffmpeg
node_video_writer -->|"writes"| node_output_media
node_train_entry -->|"configures"| node_synthetic_dataset
node_train_entry -.->|"configures"| node_paired_dataset
node_synthetic_dataset -->|"reads"| node_training_store
node_paired_dataset -->|"reads"| node_training_store
node_synthetic_dataset -->|"provides data"| node_training_model
node_paired_dataset -.->|"provides data"| node_training_model
node_training_model -->|"optimizes"| node_discriminator

click node_image_cli "https://github.com/xinntao/real-esrgan/blob/master/inference_realesrgan.py"
click node_video_cli "https://github.com/xinntao/real-esrgan/blob/master/inference_realesrgan_video.py"
click node_upsampler "https://github.com/xinntao/real-esrgan/blob/master/realesrgan/utils.py"
click node_tile_processing "https://github.com/xinntao/real-esrgan/blob/master/realesrgan/utils.py"
click node_srvgg "https://github.com/xinntao/real-esrgan/blob/master/realesrgan/archs/srvgg_arch.py"
click node_model_weights "https://github.com/xinntao/real-esrgan/blob/master/weights/README.md"
click node_video_reader "https://github.com/xinntao/real-esrgan/blob/master/inference_realesrgan_video.py"
click node_video_writer "https://github.com/xinntao/real-esrgan/blob/master/inference_realesrgan_video.py"
click node_train_entry "https://github.com/xinntao/real-esrgan/blob/master/realesrgan/train.py"
click node_synthetic_dataset "https://github.com/xinntao/real-esrgan/blob/master/realesrgan/data/realesrgan_dataset.py"
click node_paired_dataset "https://github.com/xinntao/real-esrgan/blob/master/realesrgan/data/realesrgan_paired_dataset.py"
click node_training_model "https://github.com/xinntao/real-esrgan/blob/master/realesrgan/models/realesrgan_model.py"
click node_discriminator "https://github.com/xinntao/real-esrgan/blob/master/realesrgan/archs/discriminator_arch.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_image_cli,node_video_cli,node_user toneBlue
class node_upsampler,node_tile_processing,node_srvgg,node_basicsr_networks,node_model_weights,node_face_enhancer,node_training_store toneAmber
class node_video_reader,node_video_writer toneMint
class node_train_entry,node_synthetic_dataset,node_paired_dataset,node_training_model,node_discriminator toneRose
class node_input_media,node_output_media,node_ffmpeg toneIndigo
```

## Components

### Inference Entry Points

- [Image Inference](https://github.com/xinntao/real-esrgan/blob/master/inference_realesrgan.py): `inference_realesrgan.py`
- [Video Inference](https://github.com/xinntao/real-esrgan/blob/master/inference_realesrgan_video.py): `inference_realesrgan_video.py`

### Restoration Runtime

- [RealESRGAN Upsampler](https://github.com/xinntao/real-esrgan/blob/master/realesrgan/utils.py): `realesrgan/utils.py`
- [Tile Processing](https://github.com/xinntao/real-esrgan/blob/master/realesrgan/utils.py): `realesrgan/utils.py`
- [SRVGG Network](https://github.com/xinntao/real-esrgan/blob/master/realesrgan/archs/srvgg_arch.py): `realesrgan/archs/srvgg_arch.py`
- **BasicSR Networks**
- [Model Weights](https://github.com/xinntao/real-esrgan/blob/master/weights/README.md): `weights/README.md`
- **Face Enhancer**

### Video Pipeline

- [Video Reader](https://github.com/xinntao/real-esrgan/blob/master/inference_realesrgan_video.py): `inference_realesrgan_video.py`
- [Video Writer](https://github.com/xinntao/real-esrgan/blob/master/inference_realesrgan_video.py): `inference_realesrgan_video.py`

### Training System

- [Training Entry](https://github.com/xinntao/real-esrgan/blob/master/realesrgan/train.py): `realesrgan/train.py`
- [Synthetic Dataset](https://github.com/xinntao/real-esrgan/blob/master/realesrgan/data/realesrgan_dataset.py): `realesrgan/data/realesrgan_dataset.py`
- [Paired Dataset](https://github.com/xinntao/real-esrgan/blob/master/realesrgan/data/realesrgan_paired_dataset.py): `realesrgan/data/realesrgan_paired_dataset.py`
- [Degradation Model](https://github.com/xinntao/real-esrgan/blob/master/realesrgan/models/realesrgan_model.py): `realesrgan/models/realesrgan_model.py`
- [UNet Discriminator](https://github.com/xinntao/real-esrgan/blob/master/realesrgan/archs/discriminator_arch.py): `realesrgan/archs/discriminator_arch.py`

### Other components

- **User**
- **Input Media**
- **Restored Media**
- **FFmpeg**
- **Training Data**

## Connections

- User → Image Inference: runs
- User → Video Inference: runs
- Image Inference → Input Media: reads
- Image Inference → RealESRGAN Upsampler: enhances
- Image Inference → Face Enhancer: optionally uses
- Image Inference → Restored Media: writes
- RealESRGAN Upsampler → Model Weights: loads
- RealESRGAN Upsampler → SRVGG Network: runs
- RealESRGAN Upsampler → BasicSR Networks: runs
- RealESRGAN Upsampler → Tile Processing: tiles
- Face Enhancer → RealESRGAN Upsampler: upsamples background
- Video Inference → Video Reader: starts
- Video Reader → Input Media: reads
- Video Reader → FFmpeg: decodes
- Video Inference → RealESRGAN Upsampler: restores frames
- Video Inference → Video Writer: starts
- Video Writer → FFmpeg: encodes
- Video Writer → Restored Media: writes
- Training Entry → Synthetic Dataset: configures
- Training Entry → Paired Dataset: configures
- Synthetic Dataset → Training Data: reads
- Paired Dataset → Training Data: reads
- Synthetic Dataset → Degradation Model: provides data
- Paired Dataset → Degradation Model: provides data
- Degradation Model → UNet Discriminator: optimizes
