# joanshen0508/fundus-correction-cofe-net architecture

> Architecture diagram of the GitHub repository joanshen0508/fundus-correction-cofe-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/joanshen0508/fundus-correction-cofe-net
- Repository: https://github.com/joanshen0508/fundus-correction-cofe-net

## Overview

##### Project Type & Purpose
- This is a Python-based deep learning pipeline for:
- Modeling realistic degradations of retinal fundus images (blur, uneven illumination, artifacts).
- Training and applying a clinical-oriented enhancement network (Cofe-Net variations) to restore image quality.

##### File Structure & Architectural Patterns
- Top-level scripts
- train.py – orchestrates training loop (data loading → forward/backward passes → checkpointing).
- test.py – runs inference on low-quality inputs, logs outputs.
- Data layer
- data/ & datasets/ – dataset classes (aligned, unaligned, single), helper scripts for A/B pairing, grayscale transforms.
- util/get_data.py – common data-loading utilities.
- Degradation pipeline
- degradation_code/ – realistic degradation model (main_degradation.py, degrad_de.py, utils_de.py).
- motion_blur/ – PSF generation, blur/degrade functions.
- Model layer
- models/ – base_model, HDRCNN variants, Cofe-Net encoders/decoders, loss functions, network definitions.
- options/ – CLI argument parsers for train/test; defines hyperparameters, data paths, model settings.
- Utility layer
- util/ – HTML logger, image pooling, metrics, visualization.
- Examples & assets
- examples/parameters – sample JSON parameter sets.
- img/ – sample input/output images and masks.

##### README for Technical Stack & Flow
- Core frameworks: PyTorch (implied by model definitions, .py extension and typical DL patterns), JSON for parameter configuration.
- Workflow described:
1. Simulate degradations via degradation_code & motion_blur.
2. Load degraded + ground-truth via dataset classes.
3. Train Cofe-Net variants (e.g., encode_decode_vessel_2scale_share_res_atten).

##### Main Components & Interactions
a. Data Ingestion
- Raw fundus images → data/ and datasets/ classes → produces PyTorch Dataset objects.
b. Degradation Module
- degradation_code & motion_blur produce synthetic low-quality inputs from raw images.
c. Training Pipeline
- train.py uses options/train_options.py → config object → data loader → model forward/backward → loss (models/losses.py) → checkpoint saving.
d. Inference & Visualization
- test.py uses options/test_options.py → loads checkpoint → feeds degraded images → util/html.py & util/visualizer.py generate output galleries.
e. Parameterization
- examples/parameters/*.json define per-run degradation settings loaded by run_pre_process.py or main_degradation.py.

##### Architectural Patterns & Design Principles
- Modular separation of concern:
- “data” vs. “degradation_code” vs. “models” vs. “util” vs. “options.”
- Plugin-style extensibility: new degradation scripts or network variants drop into respective folders.
- CLI-driven pipeline orchestration via options/*.py.
- Reusable base classes: base_model.py, base_dataset.py, base_data_loader.py.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Layer
    subgraph "Data Layer"
        direction TB
        RawImages["Raw Fundus Images"]:::data_storage
        DataFolder["data/"]:::data
        click DataFolder "https://github.com/joanshen0508/fundus-correction-cofe-net/tree/master/data/"
        DatasetsFolder["datasets/"]:::data
        click DatasetsFolder "https://github.com/joanshen0508/fundus-correction-cofe-net/tree/master/datasets/"
        GetDataUtil["util/get_data.py"]:::data
        click GetDataUtil "https://github.com/joanshen0508/fundus-correction-cofe-net/blob/master/util/get_data.py"
    end

    %% Degradation Layer
    subgraph "Degradation Layer"
        direction TB
        DegradationCode["degradation_code/"]:::degr
        click DegradationCode "https://github.com/joanshen0508/fundus-correction-cofe-net/tree/master/degradation_code/"
        MotionBlur["motion_blur/"]:::degr
        click MotionBlur "https://github.com/joanshen0508/fundus-correction-cofe-net/tree/master/motion_blur/"
    end

    %% Model Layer
    subgraph "Model Layer"
        direction TB
        ModelsFolder["models/"]:::model
        click ModelsFolder "https://github.com/joanshen0508/fundus-correction-cofe-net/tree/master/models/"
    end

    %% CLI / Options Layer
    subgraph "CLI / Options Layer"
        direction TB
        OptionsFolder["options/"]:::cli
        click OptionsFolder "https://github.com/joanshen0508/fundus-correction-cofe-net/tree/master/options/"
        TrainScript["train.py"]:::cli
        TestScript["test.py"]:::cli
    end

    %% Utility Layer
    subgraph "Utility Layer"
        direction TB
        UtilFolder["util/"]:::util
        click UtilFolder "https://github.com/joanshen0508/fundus-correction-cofe-net/tree/master/util/"
    end

    %% Example Assets
    subgraph "Example Assets & Params"
        direction TB
        ParamsFolder["examples/parameters/"]:::asset
        click ParamsFolder "https://github.com/joanshen0508/fundus-correction-cofe-net/tree/master/examples/parameters/"
        ImgFolder["img/"]:::asset
        click ImgFolder "https://github.com/joanshen0508/fundus-correction-cofe-net/tree/master/img/"
        DataList["data_list.txt"]:::asset
        click DataList "https://github.com/joanshen0508/fundus-correction-cofe-net/blob/master/data_list.txt"
    end

    %% Data Flow
    RawImages -->|input| DegradationCode
    RawImages -->|input| MotionBlur
    DegradationCode -->|"synthetic low-quality"| DegradedImages["Degraded Images"]:::data
    MotionBlur -->|"synthetic blur"| DegradedImages
    DegradedImages -->|"paired with clean"| DataFolder
    DegradedImages --> DataFolder
    DataFolder --> DataLoader["DataLoader Objects"]:::data
    DatasetsFolder --> DataLoader
    GetDataUtil --> DataLoader

    DataLoader --> ModelsFolder
    TrainScript -->|uses| OptionsFolder
    TestScript -->|uses| OptionsFolder
    TrainScript --> DataLoader
    TrainScript --> ModelsFolder
    TestScript --> ModelsFolder
    TestScript --> UtilFolder
    ModelsFolder --> Outputs["Model Outputs"]:::model
    Outputs --> UtilFolder
    Outputs --> ImgFolder

    %% Class Definitions
    classDef data_storage fill:#cff,stroke:#036,stroke-width:1px;
    classDef data fill:#cceeff,stroke:#036,stroke-width:1px;
    classDef degr fill:#ffdead,stroke:#a33,stroke-width:1px;
    classDef model fill:#c8e6c9,stroke:#2e7d32,stroke-width:1px;
    classDef cli fill:#e0e0e0,stroke:#616161,stroke-width:1px;
    classDef util fill:#f5f5f5,stroke:#424242,stroke-width:1px;
    classDef asset fill:#fff9c4,stroke:#f9a825,stroke-width:1px;
```
