# gpcv-liujin/rednet-pytorch architecture

> Architecture diagram of the GitHub repository gpcv-liujin/rednet-pytorch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gpcv-liujin/rednet-pytorch
- Repository: https://github.com/gpcv-liujin/rednet-pytorch

## Overview

##### Project type and purpose
- This is a research‑oriented, open‑source deep learning tool (PyTorch implementation of REDNet) for large-scale multi‑view stereo reconstruction.
- Its primary function is to read a preprocessed aerial dataset, train the REDNet network, and generate depth maps and associated outputs.

##### File structure
- Top‑level scripts:
- train.py — orchestrates training and testing
- predict_whu.py — wrapper for inference (if any)
- Directories:
- datasets/ — data I/O, preprocessing, and evaluation routines for the WHU MVS dataset
- models/ — model definitions: base module, MVSNet, REDNet, RMVSNet
- checkpoints/ — saved model weights
- Utilities:
- utils.py — shared helpers (logging, metrics, I/O, etc.)

##### Extract insights from the README
- Environment: Python 3.7, PyTorch 1.1.0, CUDA GPU
- Workflow:
- Download & unzip WHU_MVS_dataset
- Configure paths in train.py
- Run Python scripts for train or test
- Output: depth maps, probability maps, images, camera parameters

a. Main components
1. External Dataset (WHU_MVS_dataset)
2. Data Preparation & Loader (datasets/)
3. Preprocessing Module (datasets/preprocess.py)
4. Model Zoo (models/)
– Module (base classes)
– mvsnet, rednet, rmvsnet implementations
5. Training Controller (train.py)
6. Checkpoint Store (checkpoints/)
7. Inference Engine (train.py in test mode or predict_whu.py)
8. Evaluation & Output Writer (datasets/whu_eval.py + utils.py)
9. GPU Compute (NVIDIA TITAN RTX)
10. Python & PyTorch Runtime

b. Relationships & data flow
- Data Batches → Model (forward pass) → Loss Computation → Backprop
- Training Controller ↔️ GPU Compute
- Model ↔ Checkpoints (save & load)
- Inference Engine uses trained Checkpoints + Data Loader → Model → Output Writer
- Output files written back to Dataset folder structure

c. Architectural patterns & design principles
- Modular design:
- Clear separation of data I/O, model definitions, training logic, and utilities
- Reusability:
- Base Module class for multiple networks
- Extensibility:
- New architectures can plug into models/ and be selected in train.py
- Single‑process GPU pipeline controlled by Python script

d. Key technologies and libraries
- Python 3.7, Anaconda environment
- PyTorch 1.1.0 (torch, torch.nn, torch.optim)
- NumPy, OpenCV (for image I/O)
- CUDA/cuDNN on NVIDIA TITAN RTX 2080Ti

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Data Layer"
        ExtDataset["External Dataset (WHU_MVS)"]:::external
        DataIO["Data Loader (datasets/data_io.py)"]:::data
        Preproc["Preprocessor (datasets/preprocess.py)"]:::data
        WHUSpec["WHU Dataset Interface (datasets/whu.py)"]:::data
        Evaluator["Evaluator & Output Writer (datasets/whu_eval.py)"]:::data
    end

    subgraph "Compute Layer"
        Runtime["Python Runtime & PyTorch"]:::util
        GPU["GPU Compute (NVIDIA TITAN RTX)"]:::external
        Trainer["Training Controller (train.py)"]:::compute
        Inference["Inference Engine (predict_whu.py)"]:::compute
        subgraph "Model Zoo"
            ModuleBase["Base Module (models/module.py)"]:::compute
            MVSNet["MVSNet (models/mvsnet.py)"]:::compute
            REDNet["REDNet (models/rednet.py)"]:::compute
            RMVSNet["RMVSNet (models/rmvsnet.py)"]:::compute
        end
    end

    subgraph "Storage Layer"
        Checkpoints["Checkpoint Store (checkpoints/whu_rednet/)"]:::storage
    end

    Utils["Shared Utilities (utils.py)"]:::util

    ExtDataset -->|"raw images+cams"| DataIO
    WHUSpec --> DataIO
    DataIO -->|"loaded tensors"| Preproc
    Preproc -->|"processed batches"| Trainer
    Preproc -->|"input data"| Inference

    Runtime --> Trainer
    Runtime --> Inference
    Runtime --> DataIO
    Runtime --> Preproc

    Trainer -->|"forward/backward"| ModuleBase
    Trainer --> MVSNet
    Trainer --> REDNet
    Trainer --> RMVSNet
    Inference --> ModuleBase
    Inference --> MVSNet
    Inference --> REDNet
    Inference --> RMVSNet

    Trainer --> GPU
    GPU --> Trainer

    Trainer -->|"save weights"| Checkpoints
    Checkpoints -->|"load weights"| Inference

    Inference -->|"predictions"| Evaluator

    Trainer --> Utils
    DataIO --> Utils
    Evaluator --> Utils
    Inference --> Utils

    click ExtDataset "https://github.com/gpcv-liujin/rednet-pytorch/tree/main/external folder"
    click DataIO "https://github.com/gpcv-liujin/rednet-pytorch/blob/main/datasets/data_io.py"
    click Preproc "https://github.com/gpcv-liujin/rednet-pytorch/blob/main/datasets/preprocess.py"
    click WHUSpec "https://github.com/gpcv-liujin/rednet-pytorch/blob/main/datasets/whu.py"
    click Evaluator "https://github.com/gpcv-liujin/rednet-pytorch/blob/main/datasets/whu_eval.py"
    click ModuleBase "https://github.com/gpcv-liujin/rednet-pytorch/blob/main/models/module.py"
    click MVSNet "https://github.com/gpcv-liujin/rednet-pytorch/blob/main/models/mvsnet.py"
    click REDNet "https://github.com/gpcv-liujin/rednet-pytorch/blob/main/models/rednet.py"
    click RMVSNet "https://github.com/gpcv-liujin/rednet-pytorch/blob/main/models/rmvsnet.py"
    click Trainer "https://github.com/gpcv-liujin/rednet-pytorch/blob/main/train.py"
    click Inference "https://github.com/gpcv-liujin/rednet-pytorch/blob/main/predict_whu.py"
    click Checkpoints "https://github.com/gpcv-liujin/rednet-pytorch/tree/main/checkpoints/whu_rednet/"
    click Utils "https://github.com/gpcv-liujin/rednet-pytorch/blob/main/utils.py"

    classDef data fill:#a2c4c9,stroke:#000
    classDef compute fill:#b6d7a8,stroke:#000
    classDef storage fill:#f9cb9c,stroke:#000
    classDef util fill:#cccccc,stroke:#000
    classDef external fill:#d9d9d9,stroke:#000
```
