# sunny2109/rdg architecture

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

- Interactive diagram: https://gitdiagram.com/sunny2109/rdg
- Repository: https://github.com/sunny2109/rdg

## Overview

1. This repository is a BasicSR-based research package for one primary task: efficient video super-resolution for real-time rendering, using the RDG architecture. The codebase is organized around the standard BasicSR lifecycle: dataset preparation, model training, validation/testing, metric evaluation, and checkpoint packaging.

2. The main execution entry points are `basicsr/train.py` and `basicsr/test.py`, both driven by YAML configs in `options/train` and `options/test`. Those configs are the central wiring layer: they select datasets, model wrappers, losses, optimizers, schedulers, logging behavior, and output locations.

3. The core network lives in `basicsr/archs/rdg_arch.py` and `basicsr/archs/rdg_block.py`. RDG is described in the README as an asymmetric UNet-style super-resolution network with a dynamic feature modulator and auxiliary G-buffer guidance, which means the architecture is not a plain image SR backbone; it is designed to fuse rendering buffers and image features during decoding.

4. Model-level training logic is separated from the network definition. The `basicsr/models` package provides BasicSR model wrappers such as `base_model.py`, `sr_model.py`, `video_*_model.py`, and GAN/SR variants. These classes own optimization, checkpointing, EMA or scheduler logic, and the training/validation step orchestration, while the arch files provide the forward network itself.

5. Data handling is a major subsystem. `basicsr/data` contains multiple dataset types for paired images, single images, video datasets, real-world SR datasets, FFHQ, REDS, Vimeo90K, and render-oriented data. For RDG, the render/video-oriented loaders are the important boundary because they feed aligned LR frames, HR targets, and auxiliary guidance such as G-buffers or render metadata.

6. The data pipeline is configurable and modular. It includes sampling, transforms, degradation simulation, LMDB access, prefetching, and dataset-specific metadata files under `basicsr/data/meta_info`. This makes the training input path flexible: raw image folders, LMDB databases, and video sequences can all be normalized into BasicSR dataloaders.

7. Dataset creation and preprocessing are handled by scripts in `scripts/data_preparation`. These cover LMDB generation, subimage extraction, meta-info generation, TFRecord extraction, and dataset downloads. The README also shows the project’s domain-specific data source: Blender/Cycles renders producing paired HR/LR video and auxiliary buffers for the rendering scenario.

8. Evaluation is split into library metrics and standalone scripts. `basicsr/metrics` implements PSNR/SSIM, FID, and NIQE, while `scripts/metrics` provides command-line calculators for folders and benchmark sets. Test runs write outputs into `results/`, which also stores logs for reproducibility.

9. The repo includes custom low-level CUDA/C++ ops under `basicsr/ops`: deformable convolution, fused bias/activation, and upsample-filter-downsample kernels. These are performance-critical building blocks used by some models in the broader BasicSR family and indicate that the repository supports both accuracy-oriented and efficiency-oriented architectures.

10. Common infrastructure is concentrated in `basicsr/utils`: option parsing, registries, distributed training utilities, logging, file clients, image/flow/color helpers, LMDB helpers, and miscellaneous math/image processing utilities. This layer is what makes the architecture configurable and portable across local disks, LMDB-backed datasets, and distributed GPU training.

11. The repository also ships pretrained checkpoints in `checkpoints/` and example results in `results/`, so the operational flow is reproducible without retraining. Release automation is present through GitHub Actions and packaging files, showing that the project is meant to be installed as a Python package as well as run as a research codebase.

12. For architecture diagram purposes, the main boundaries are: external datasets and pretrained weights; the BasicSR config-and-registry layer; dataset/preprocessing pipeline; RDG network architecture; model/training wrappers; metrics/output artifacts. The key end-to-end flow is data preparation → dataloader → RDG forward pass with guidance buffers → loss/optimization → checkpointing → evaluation on test sets → metrics and rendered outputs.

Main entry points: [`basicsr/models/video_render_model.py`](https://github.com/sunny2109/rdg/blob/main/basicsr/models/video_render_model.py) (SR Models), [`basicsr/data/transforms.py`](https://github.com/sunny2109/rdg/blob/main/basicsr/data/transforms.py) (Data Utils), [`basicsr/test.py`](https://github.com/sunny2109/rdg/blob/main/basicsr/test.py) (Test), [`options/train/train_RDG_x4.yml`](https://github.com/sunny2109/rdg/blob/main/options/train/train_RDG_x4.yml) (Train YAMLs)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_external["External Inputs"]
end

subgraph group_g_config["BasicSR Wiring"]
  node_n_train["Train<br/>entrypoint<br/>[train.py]"]
  node_n_test["Test<br/>entrypoint<br/>[test.py]"]
  node_n_train_cfg["Train YAMLs<br/>config<br/>[train_RDG_x4.yml]"]
  node_n_test_cfg["Test YAMLs<br/>config<br/>[test_RDG_x4.yml]"]
end

subgraph group_g_data["Data Pipeline"]
  node_n_data_utils{{"Data Utils<br/>pipeline support<br/>[transforms.py]"}}
  node_n_render_data[("Render Data<br/>dataset<br/>[render_dataset.py]")]
  node_n_video_data[("Video Data<br/>dataset<br/>[reds_dataset.py]")]
  node_n_image_data[("Image Data<br/>dataset")]
end

subgraph group_g_model["RDG Core"]
  node_n_model_wrap{{"SR Models<br/>training wrappers"}}
  node_n_rdg_arch{{"RDG Arch<br/>network<br/>[rdg_arch.py]"}}
  node_n_rdg_block{{"RDG Blocks<br/>network blocks<br/>[rdg_block.py]"}}
  node_n_losses{{"Losses<br/>optimization<br/>[basic_loss.py]"}}
end

subgraph group_g_eval["Evaluation"]
  node_n_metrics{{"Metrics<br/>evaluation<br/>[psnr_ssim.py]"}}
  node_n_results["Results<br/>artifacts"]
end

subgraph group_g_infra["Infrastructure"]
  node_n_registry{{"Registry<br/>core plumbing<br/>[registry.py]"}}
  node_n_ops{{"CUDA Ops<br/>accelerated ops<br/>[deform_conv.py]"}}
end

node_n_train -->|"loads"| node_n_train_cfg
node_n_test -->|"loads"| node_n_test_cfg
node_n_train_cfg -->|"builds"| node_n_registry
node_n_test_cfg -->|"builds"| node_n_registry
node_n_registry -->|"creates"| node_n_data_utils
node_n_data_utils -->|"feeds"| node_n_image_data
node_n_data_utils -->|"feeds"| node_n_video_data
node_n_data_utils -->|"feeds"| node_n_render_data
node_n_train_cfg -->|"selects"| node_n_model_wrap
node_n_model_wrap -->|"runs"| node_n_rdg_arch
node_n_model_wrap -->|"depends on"| node_n_rdg_block
node_n_model_wrap -->|"optimizes"| node_n_losses
node_n_rdg_arch -.->|"accelerates"| node_n_ops
node_n_rdg_block -.->|"accelerates"| node_n_ops
node_n_test -->|"evaluates"| node_n_metrics
node_n_model_wrap -->|"reports"| node_n_metrics
node_n_test -->|"writes"| node_n_results
node_n_train -->|"logs"| node_n_results

click node_n_train "https://github.com/sunny2109/rdg/blob/main/basicsr/train.py"
click node_n_test "https://github.com/sunny2109/rdg/blob/main/basicsr/test.py"
click node_n_train_cfg "https://github.com/sunny2109/rdg/blob/main/options/train/train_RDG_x4.yml"
click node_n_test_cfg "https://github.com/sunny2109/rdg/blob/main/options/test/test_RDG_x4.yml"
click node_n_registry "https://github.com/sunny2109/rdg/blob/main/basicsr/utils/registry.py"
click node_n_data_utils "https://github.com/sunny2109/rdg/blob/main/basicsr/data/transforms.py"
click node_n_render_data "https://github.com/sunny2109/rdg/blob/main/basicsr/data/render_dataset.py"
click node_n_video_data "https://github.com/sunny2109/rdg/blob/main/basicsr/data/reds_dataset.py"
click node_n_image_data "https://github.com/sunny2109/rdg/blob/main/basicsr/data/paired_image_dataset.py"
click node_n_model_wrap "https://github.com/sunny2109/rdg/blob/main/basicsr/models/video_render_model.py"
click node_n_rdg_arch "https://github.com/sunny2109/rdg/blob/main/basicsr/archs/rdg_arch.py"
click node_n_rdg_block "https://github.com/sunny2109/rdg/blob/main/basicsr/archs/rdg_block.py"
click node_n_losses "https://github.com/sunny2109/rdg/blob/main/basicsr/losses/basic_loss.py"
click node_n_metrics "https://github.com/sunny2109/rdg/blob/main/basicsr/metrics/psnr_ssim.py"
click node_n_results "https://github.com/sunny2109/rdg/blob/main/results/RDG/test_RDG_20250318_163208.log"
click node_n_ops "https://github.com/sunny2109/rdg/blob/main/basicsr/ops/dcn/deform_conv.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_n_train,node_n_test,node_n_train_cfg,node_n_test_cfg toneAmber
class node_n_data_utils,node_n_render_data,node_n_video_data,node_n_image_data toneMint
class node_n_model_wrap,node_n_rdg_arch,node_n_rdg_block,node_n_losses toneRose
class node_n_metrics,node_n_results toneIndigo
class node_n_registry,node_n_ops toneTeal
```

## Components

### BasicSR Wiring

Entry points and configuration layer that assemble the run.

- [Train](https://github.com/sunny2109/rdg/blob/main/basicsr/train.py): entrypoint · Main training script. · `basicsr/train.py`
- [Test](https://github.com/sunny2109/rdg/blob/main/basicsr/test.py): entrypoint · Main evaluation script. · `basicsr/test.py`
- [Train YAMLs](https://github.com/sunny2109/rdg/blob/main/options/train/train_RDG_x4.yml): config · Training options for RDG variants. · `options/train/train_RDG_x4.yml`
- [Test YAMLs](https://github.com/sunny2109/rdg/blob/main/options/test/test_RDG_x4.yml): config · Testing options for RDG variants. · `options/test/test_RDG_x4.yml`

### Data Pipeline

Dataset loaders and preprocessing for image, video, and render data.

- [Data Utils](https://github.com/sunny2109/rdg/blob/main/basicsr/data/transforms.py): pipeline support · Transforms, sampling, prefetching, degradation, and dataset helpers. · `basicsr/data/transforms.py`
- [Render Data](https://github.com/sunny2109/rdg/blob/main/basicsr/data/render_dataset.py): dataset · Render-oriented loaders for paired frames and auxiliary guidance. · `basicsr/data/render_dataset.py`
- [Video Data](https://github.com/sunny2109/rdg/blob/main/basicsr/data/reds_dataset.py): dataset · Video sequence loaders used for SR training and testing. · `basicsr/data/reds_dataset.py`
- [Image Data](https://github.com/sunny2109/rdg/blob/main/basicsr/data/paired_image_dataset.py): dataset · Paired and single-image datasets for generic SR workflows. · `basicsr/data/paired_image_dataset.py`

### RDG Core

Network definition and training wrappers.

- [SR Models](https://github.com/sunny2109/rdg/blob/main/basicsr/models/video_render_model.py): training wrappers · Base model classes and video/render-specific orchestration. · `basicsr/models/video_render_model.py`
- [RDG Arch](https://github.com/sunny2109/rdg/blob/main/basicsr/archs/rdg_arch.py): network · Asymmetric UNet-style SR backbone with guidance fusion. · `basicsr/archs/rdg_arch.py`
- [RDG Blocks](https://github.com/sunny2109/rdg/blob/main/basicsr/archs/rdg_block.py): network blocks · Building blocks and modulation components for RDG. · `basicsr/archs/rdg_block.py`
- [Losses](https://github.com/sunny2109/rdg/blob/main/basicsr/losses/basic_loss.py): optimization · Pixel, perceptual, and GAN loss implementations. · `basicsr/losses/basic_loss.py`

### Evaluation

Metrics and result artifacts.

- [Metrics](https://github.com/sunny2109/rdg/blob/main/basicsr/metrics/psnr_ssim.py): evaluation · PSNR, SSIM, FID, and NIQE implementations. · `basicsr/metrics/psnr_ssim.py`
- [Results](https://github.com/sunny2109/rdg/blob/main/results/RDG/test_RDG_20250318_163208.log): artifacts · Checkpointed outputs and logged test runs. · `results/RDG/test_RDG_20250318_163208.log`

### Infrastructure

Common utilities and custom performance ops.

- [Registry](https://github.com/sunny2109/rdg/blob/main/basicsr/utils/registry.py): core plumbing · Option parsing, registries, logging, distributed utilities, and runtime helpers. · `basicsr/utils/registry.py`
- [CUDA Ops](https://github.com/sunny2109/rdg/blob/main/basicsr/ops/dcn/deform_conv.py): accelerated ops · Custom deformable convolution, fused activation, and upfirdn2d kernels. · `basicsr/ops/dcn/deform_conv.py`

## Connections

- Train → Train YAMLs: loads · Training entry point is driven by YAML options.
- Test → Test YAMLs: loads · Testing entry point is driven by YAML options.
- Train YAMLs → Registry: builds · Config values instantiate datasets, models, losses, and logging.
- Test YAMLs → Registry: builds · Config values instantiate test-time datasets and metrics.
- Registry → Data Utils: creates · Registry and helpers assemble dataloading and preprocessing.
- Data Utils → Image Data: feeds · Transforms and sampling support image datasets.
- Data Utils → Video Data: feeds · Transforms and sampling support video datasets.
- Data Utils → Render Data: feeds · Transforms and metadata support render-oriented datasets.
- Train YAMLs → SR Models: selects · Config chooses the model wrapper used for optimization.
- SR Models → RDG Arch: runs · Model wrapper calls the RDG network forward pass.
- SR Models → RDG Blocks: depends on · Wrapper uses RDG architectural components indirectly through the network.
- SR Models → Losses: optimizes · Training wrapper owns loss computation and backprop.
- RDG Arch → CUDA Ops: accelerates · Network variants can rely on custom CUDA/C++ operators.
- RDG Blocks → CUDA Ops: accelerates · Block implementations may use fused and deformable ops.
- Test → Metrics: evaluates · Testing pipeline computes image quality metrics.
- SR Models → Metrics: reports · Validation hooks compare outputs using metrics.
- Test → Results: writes · Inference outputs and logs are stored under results/.
- Train → Results: logs · Training and validation artifacts are written to output directories.
