# lime-j/rdnet architecture

> Architecture diagram of the GitHub repository lime-j/rdnet, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lime-j/rdnet
- Repository: https://github.com/lime-j/rdnet

## Overview

##### Project type and purpose
- This is a research‐oriented deep‐learning pipeline (“Reversible Decoupling Network”) implemented in PyTorch. Its goal is single‐image reflection removal: given an image with unwanted reflections, the network decouples transmission and reflection features and reconstructs a clean image.

##### File structure
- Top‐level scripts:
- train.py  – orchestrates training
- test_sirs.py – runs evaluation with pretrained checkpoints
- engine.py – core training/validation loops and scheduling
- script.py – auxiliary or legacy entrypoint
- data/ – dataset definitions and preprocessing
- models/ – model definitions
- arch/ – building blocks (encoders, decoders, reversible units, prompts)
- base_model.py, networks.py, losses.py – abstractions for training
- options/ – CLI and configuration (argpars­ing, omegaconf)
- tools/ – logging, visualization, TensorBoard writer, model utilities
- util/ – HTML reporting, scheduler helpers, general utilities
- pretrained/ – place for downloaded checkpoints
- figures/ – static assets (for README)

##### Insights from README
- Describes two main workflows: TRAIN (train.py) and TEST (test_sirs.py)
- Dependencies: PyTorch ≥2.0, einops, timm, tensorboard, etc.
- Emphasis on reversible encoder, prompt generator, and use of TPU/Cloud.

##### Essential details to capture
- Option parsing → component instantiation
- Data module feeding into reversible encoder + prompt generator
- Loss computation and optimizer scheduling
- Checkpoint read/write and evaluation path
- Logging hooks (TensorBoard, HTML reports)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Scripts
    Train["train.py"]:::script
    Eval["test_sirs.py"]:::script
    Aux["script.py"]:::script

    %% CLI & Configuration
    subgraph "CLI & Configuration"
        Config["options/"]:::config
    end

    %% Data & Preprocessing
    subgraph "Data Ingestion & Preprocessing"
        Data["data/"]:::data
    end

    %% Model Architecture
    subgraph "Model Architecture"
        subgraph "Building Blocks"
            Arch["models/arch/"]:::model
        end
        subgraph "Base & Networks"
            Base["models/base_model.py"]:::model
            Networks["models/networks.py"]:::model
            Losses["models/losses.py"]:::model
            LossesOpt["models/losses_opt.py"]:::model
        end
    end

    %% Training Engine & Scheduler
    subgraph "Execution Engine"
        Engine["engine.py"]:::engine
        Scheduler["util/schedulers.py"]:::engine
    end

    %% Logging & Visualization
    subgraph "Logging & Visualization"
        TB["tools/TensorboardWriter.py"]:::log
        HTML["util/html.py"]:::log
        Viz["util/visualizer.py"]:::log
    end

    %% Checkpoint Management
    subgraph "Checkpoint Management"
        Saver["tools/saver.py"]:::storage
        Pretrained["pretrained/"]:::storage
    end

    %% Workflow Connections
    Train -->|parses| Config
    Train -->|loads| Data
    Train -->|loads| Arch
    Train -->|loads| Base
    Train -->|starts| Engine

    Config -->|provides options| Engine
    Data -->|feeds batches| Engine
    Arch -->|forward pass| Engine
    Base -->|defines network| Engine
    Networks -->|instantiates| Engine
    Losses -->|computes| Engine
    LossesOpt -->|computes| Engine
    Scheduler -->|schedules| Engine
    Engine -->|logs metrics| TB
    Engine -->|logs reports| HTML
    Engine -->|logs visuals| Viz
    Engine -->|saves checkpoints| Saver
    Saver -->|writes| Pretrained

    Eval -->|loads| Config
    Eval -->|loads| Pretrained
    Eval -->|loads| Arch
    Eval -->|runs inference via| Engine
    Engine -->|outputs| Viz
    Engine -->|outputs| HTML

    Aux -->|legacy entry| Config

    %% Click Events
    click Data "https://github.com/lime-j/rdnet/tree/main/data/"
    click Arch "https://github.com/lime-j/rdnet/tree/main/models/arch/"
    click Base "https://github.com/lime-j/rdnet/blob/main/models/base_model.py"
    click Networks "https://github.com/lime-j/rdnet/blob/main/models/networks.py"
    click Losses "https://github.com/lime-j/rdnet/blob/main/models/losses.py"
    click LossesOpt "https://github.com/lime-j/rdnet/blob/main/models/losses_opt.py"
    click Engine "https://github.com/lime-j/rdnet/blob/main/engine.py"
    click Scheduler "https://github.com/lime-j/rdnet/blob/main/util/schedulers.py"
    click Config "https://github.com/lime-j/rdnet/tree/main/options/"
    click TB "https://github.com/lime-j/rdnet/blob/main/tools/TensorboardWriter.py"
    click HTML "https://github.com/lime-j/rdnet/blob/main/util/html.py"
    click Viz "https://github.com/lime-j/rdnet/blob/main/util/visualizer.py"
    click Saver "https://github.com/lime-j/rdnet/blob/main/tools/saver.py"
    click Pretrained "https://github.com/lime-j/rdnet/tree/main/pretrained/"
    click Train "https://github.com/lime-j/rdnet/blob/main/train.py"
    click Eval "https://github.com/lime-j/rdnet/blob/main/test_sirs.py"
    click Aux "https://github.com/lime-j/rdnet/blob/main/script.py"

    %% Styles
    classDef script fill:#f9f,stroke:#333,stroke-width:2px
    classDef config fill:#ff9,stroke:#333,stroke-width:2px
    classDef data fill:#9cf,stroke:#333,stroke-width:2px
    classDef model fill:#9f9,stroke:#333,stroke-width:2px
    classDef engine fill:#f96,stroke:#333,stroke-width:2px
    classDef log fill:#c9f,stroke:#333,stroke-width:2px
    classDef storage fill:#fcc,stroke:#333,stroke-width:2px
```
