# ruoyuguo/mda-net architecture

> Architecture diagram of the GitHub repository ruoyuguo/mda-net, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ruoyuguo/mda-net
- Repository: https://github.com/ruoyuguo/mda-net

## Overview

##### Project type and purpose
- This is a research‐oriented PyTorch implementation of the “Multi‐degradation‐adaptation Network (MDA‐Net)” for fundus image enhancement (Medical Image Analysis, 2024).
- It provides scripts to generate/degrade datasets, define/train deep networks, and evaluate saved models on benchmark data.

##### File structure
- Top-level files and scripts:
- train.py / train_from_scratch.sh: orchestrate model training and checkpointing
- eval.py: loads a saved checkpoint and runs inference/evaluation
- dataset/ directory:
- Raw CSVs for labels (Label_EyeQ_*.csv, MIL_*.csv)
- Data-generation and degradation scripts (gen_data_stage1/2, degrad_de.py, degrad_de_visual.py)
- Utility modules for parameter loading and augmentation
- network/ directory:
- Model definitions (DANet.py, DCouple.py, kpn_network.py) and their helper functions
- clf.py: classification or feature branch
- utils/ directory:
- Dataset wrappers (drive_dataset.py, eyeq_dataset.py, refuge_dataset.py, etc.)
- Logging, metric calculations, loss functions

##### Extract additional insights from README
- Training can be launched via a single shell script
- eval.py supports selecting any saved checkpoint by index/epoch and specifying dataset paths
- Outputs (enhanced images, metrics) are written under ./myoutput/<run_id>/

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Preparation Layer
    subgraph "Data Preparation" 
        direction TB
        RawData(("Raw Data & Labels")):::data
        GenStage1["gen_data_stage1.py / gen_data_stage1.sh"]:::data
        GenStage2["gen_data_stage2.py / gen_data_stage2.sh / gen_data_stage2_pce.py / gen_data_stage2_pce.sh"]:::data
        Degradation["degrad_de.py / degrad_de_pce.py / degrad_de_visual.py"]:::data
        DegradUtils["load_params_de.py / utils_de.py / main_degradation_pcenet.py"]:::data
        Preprocess["preprocess_dataset.ipynb"]:::data
        DatasetLoader["drive_dataset.py / eyeq_dataset.py / eyeq_simple_dataset.py / refuge_dataset.py"]:::data
    end

    %% Model & Training Layer
    subgraph "Model & Training" 
        direction TB
        Network["DANet.py / DANet_utils.py / DCouple.py / kpn_network.py / kpn_utils.py / clf.py"]:::model
        TrainCtrl["train.py / train_from_scratch.sh"]:::model
        Utils["logger.py / myloss.py / metrics.py / utils.py"]:::model
        Checkpoint(("Checkpoint Store")):::data
    end

    %% Evaluation & Output Layer
    subgraph "Evaluation & Output"
        direction TB
        EvalCtrl["eval.py"]:::eval
        Output(("Enhanced Images & metrics.csv")):::eval
    end

    %% Data Flow
    RawData -->|CSV, Images| GenStage1
    GenStage1 -->|Stage1 Data| GenStage2
    GenStage2 -->|Stage2 Data| Degradation
    Degradation -->|Degraded Data| DegradUtils
    DegradUtils -->|Processed Data| Preprocess
    Preprocess -->|Augmented Images| DatasetLoader
    DatasetLoader -->|Batches| Network
    Network -->|Model Graph| TrainCtrl
    Utils -->|Logging/Loss/Metrics| TrainCtrl
    TrainCtrl -->|Checkpoint.pth| Checkpoint
    Checkpoint -->|Saved Model| EvalCtrl
    EvalCtrl -->|Inference| Output

    %% Click Events - Data Preparation
    click RawData "https://github.com/ruoyuguo/mda-net/blob/main/dataset/Label_EyeQ_train.csv"
    click RawData "https://github.com/ruoyuguo/mda-net/blob/main/dataset/Label_EyeQ_test.csv"
    click RawData "https://github.com/ruoyuguo/mda-net/blob/main/dataset/MIL_*.csv"
    click GenStage1 "https://github.com/ruoyuguo/mda-net/blob/main/dataset/gen_data_stage1.py"
    click GenStage1 "https://github.com/ruoyuguo/mda-net/blob/main/dataset/gen_data_stage1.sh"
    click GenStage2 "https://github.com/ruoyuguo/mda-net/blob/main/dataset/gen_data_stage2.py"
    click GenStage2 "https://github.com/ruoyuguo/mda-net/blob/main/dataset/gen_data_stage2.sh"
    click GenStage2 "https://github.com/ruoyuguo/mda-net/blob/main/dataset/gen_data_stage2_pce.py"
    click GenStage2 "https://github.com/ruoyuguo/mda-net/blob/main/dataset/gen_data_stage2_pce.sh"
    click Degradation "https://github.com/ruoyuguo/mda-net/blob/main/dataset/degrad_de.py"
    click Degradation "https://github.com/ruoyuguo/mda-net/blob/main/dataset/degrad_de_pce.py"
    click Degradation "https://github.com/ruoyuguo/mda-net/blob/main/dataset/degrad_de_visual.py"
    click DegradUtils "https://github.com/ruoyuguo/mda-net/blob/main/dataset/load_params_de.py"
    click DegradUtils "https://github.com/ruoyuguo/mda-net/blob/main/dataset/utils_de.py"
    click DegradUtils "https://github.com/ruoyuguo/mda-net/blob/main/dataset/main_degradation_pcenet.py"
    click Preprocess "https://github.com/ruoyuguo/mda-net/blob/main/dataset/preprocess_dataset.ipynb"
    click DatasetLoader "https://github.com/ruoyuguo/mda-net/blob/main/utils/drive_dataset.py"
    click DatasetLoader "https://github.com/ruoyuguo/mda-net/blob/main/utils/eyeq_dataset.py"
    click DatasetLoader "https://github.com/ruoyuguo/mda-net/blob/main/utils/eyeq_simple_dataset.py"
    click DatasetLoader "https://github.com/ruoyuguo/mda-net/blob/main/utils/refuge_dataset.py"

    %% Click Events - Model & Training
    click Network "https://github.com/ruoyuguo/mda-net/blob/main/network/DANet.py"
    click Network "https://github.com/ruoyuguo/mda-net/blob/main/network/DANet_utils.py"
    click Network "https://github.com/ruoyuguo/mda-net/blob/main/network/DCouple.py"
    click Network "https://github.com/ruoyuguo/mda-net/blob/main/network/kpn_network.py"
    click Network "https://github.com/ruoyuguo/mda-net/blob/main/network/kpn_utils.py"
    click Network "https://github.com/ruoyuguo/mda-net/blob/main/network/clf.py"
    click TrainCtrl "https://github.com/ruoyuguo/mda-net/blob/main/train.py"
    click TrainCtrl "https://github.com/ruoyuguo/mda-net/blob/main/train_from_scratch.sh"
    click Utils "https://github.com/ruoyuguo/mda-net/blob/main/utils/logger.py"
    click Utils "https://github.com/ruoyuguo/mda-net/blob/main/utils/myloss.py"
    click Utils "https://github.com/ruoyuguo/mda-net/blob/main/utils/metrics.py"
    click Utils "https://github.com/ruoyuguo/mda-net/blob/main/utils/utils.py"

    %% Click Events - Evaluation
    click EvalCtrl "https://github.com/ruoyuguo/mda-net/blob/main/eval.py"

    %% Styles
    classDef data fill:#add8e6,stroke:#000,stroke-width:1px
    classDef model fill:#90ee90,stroke:#000,stroke-width:1px
    classDef eval fill:#ffa500,stroke:#000,stroke-width:1px
```
