# jayeshdambale/retinal-vessel-segmentation architecture

> Architecture diagram of the GitHub repository jayeshdambale/retinal-vessel-segmentation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jayeshdambale/retinal-vessel-segmentation
- Repository: https://github.com/jayeshdambale/retinal-vessel-segmentation

## Overview

##### Project Type and Purpose
- This is a deep-learning image-segmentation pipeline (“tool”) specialized for retinal vessel detection using a U-Net architecture.
- It ingests raw fundus images, prepares datasets (DRIVE, CHASE), trains a U-Net model, saves weights, and runs inference to output segmented vessel masks.

##### Main Components
a. Data Ingestion & Preparation
- Raw dataset files (e.g., DRIVE)
- Script: prepare_datasets_DRIVE.py
- Output: preprocessed images & masks in a “data/” staging area
b. Training Pipeline
- Script: run_training.py
- Core logic (imported from src/): model instantiation (U-Net encoder/decoder), loss definition, optimizer, training loop
- Dependencies: TensorFlow/Keras, NumPy, OpenCV, Matplotlib
- Output: trained model weights in models/
c. Testing & Inference
- Script: run_testing.py
- Loads saved weights, runs prediction on new images, computes metrics, saves segmented outputs to an output directory
d. Configuration
- configuration.txt holds hyperparameters (learning rate, batch size, dataset paths)
e. Utilities
- Any helper functions (e.g., IO routines, metric calculations) in utils/

##### Relationships & Data Flow
1. “Raw Images” → prepare_datasets_DRIVE.py → “Preprocessed Data”
2. Preprocessed Data → run_training.py → “Trained Weights”
– Internally, U-Net (Encoder ↔ Decoder) transforms tensor batches → loss → backprop
3. New Images + Trained Weights → run_testing.py → “Segmented Masks + Metrics”

##### Architectural Patterns & Design Principles
- Pipeline pattern: clear separation between data prep, training, inference
- Modular code: scripts invoke functions in src/ (model code), utils/ (helpers)
- Config-driven: hyperparameters and paths in configuration.txt
- Reproducibility: gitignore, requirements.txt, consistent folder layout

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Ingestion & Preparation
    subgraph "Data Ingestion & Preparation"
        raw["Raw Images (.png)"]:::data
        prep["Data Prep (prepare_datasets_DRIVE.py)"]:::data
        data_stage["Preprocessed Data"]:::data
    end
    click prep "https://github.com/jayeshdambale/retinal-vessel-segmentation/blob/main/prepare_datasets_DRIVE.py"

    %% Training Pipeline
    subgraph "Training Pipeline"
        train["Training (run_training.py)"]:::compute
        subgraph "U-Net Model"
            encoder["Encoder"]:::compute
            decoder["Decoder"]:::compute
        end
        loss["Loss Function"]:::compute
        opt["Optimizer"]:::compute
        weights_cyl["Model Weights (.h5)"]:::storage
    end
    click train "https://github.com/jayeshdambale/retinal-vessel-segmentation/blob/main/run_training.py"

    %% Testing & Inference
    subgraph "Testing & Inference"
        test["Inference (run_testing.py)"]:::compute
        metrics["Metrics (IoU, Dice)"]:::compute
        output_cyl["Segmented Masks"]:::storage
    end
    click test "https://github.com/jayeshdambale/retinal-vessel-segmentation/blob/main/run_testing.py"

    %% Utilities & Configuration
    subgraph "Utilities & Config"
        utils["Utils/"]:::config
        config["configuration.txt"]:::config
        readme["README.md"]:::config
    end
    click config "https://github.com/jayeshdambale/retinal-vessel-segmentation/blob/main/configuration.txt"
    click readme "https://github.com/jayeshdambale/retinal-vessel-segmentation/blob/main/README.md"

    %% External Resources
    env["Python Env\n(TensorFlow, NumPy,\nOpenCV, Matplotlib)"]:::external
    gpu["GPU Resource"]:::external

    %% Data Flow
    raw -->|".png images"| prep -->|"preprocessed .png/.mask"| data_stage
    data_stage --> train
    train --> encoder --> decoder --> loss --> opt --> weights_cyl
    weights_cyl --> test --> output_cyl
    test --> metrics --> output_cyl

    %% Dependencies
    train --> env
    test --> env
    train --> gpu

    %% Styles
    classDef data fill:#D6E6FF,stroke:#333,stroke-width:1px
    classDef compute fill:#D5FFD6,stroke:#333,stroke-width:1px
    classDef storage fill:#FFE5B4,stroke:#333,stroke-width:1px
    classDef config fill:#FFE6E6,stroke:#333,stroke-width:1px,stroke-dasharray:5 5
    classDef external fill:#F0F0F0,stroke:#333,stroke-width:1px
```
