# mejji/contextualizing-retinal-vessel-segmentation architecture

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

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

## Overview

This repository implements retinal-vessel segmentation: CNN models produce per-pixel probability maps, graph generation converts those maps into vessel-connectivity structures, and VGN refines predictions using global topology. The principal workflow spans CNN training/inference, graph construction, then VGN training/inference and saved segmentation outputs; a Tkinter demo browses staged results. README documents dataset support, CNN/VGN variants, and output artifacts. Sampled source confirms graph-generation and data-layer behavior; some training, inference, and model wiring is based on README descriptions and the file tree.

Main entry points: [`code/train_CNN.py`](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/train_CNN.py) (CNN training), [`code/util.py`](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/util.py) (Graph data layer), [`code/test_CNN.py`](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/test_CNN.py) (CNN inference), [`code/train_VGN.py`](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/train_VGN.py) (VGN training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cnn["CNN Segmentation"]
  node_cnntrain["CNN training<br/>[train_CNN.py]"]
  node_cnnmodel["CNN models<br/>[model.py]"]
  node_dau2model["DA-U²Net<br/>[DAU2Net.py]"]
  node_aff["Adaptive fusion<br/>[AFF_Module.py]"]
  node_cnntest["CNN inference<br/>[test_CNN.py]"]
  node_cnnutil["Image data layer<br/>[util.py]"]
  node_probmaps["Probability maps"]
end

subgraph group_graphs["Vessel Graphs"]
  node_graphgen["Graph generation<br/>[make_graph_db.py]"]
  node_fastgraph["Fast graph generation"]
  node_graphfiles["Graph files"]
end

subgraph group_vgn["Graph Refinement"]
  node_vgntrain["VGN training<br/>[train_VGN.py]"]
  node_vgntest["VGN inference<br/>[test_VGN.py]"]
  node_vgnmodel["VGN model<br/>[model.py]"]
  node_graphdata["Graph data layer<br/>[util.py]"]
  node_dautrain["DAU VGN training<br/>[train_VGN_DAU.py]"]
  node_dauutil["DAU data layer<br/>[util_vgn.py]"]
end

subgraph group_outputs["Results and Viewing"]
  node_segmentations["Refined outputs"]
  node_postprocess["Map postprocessing"]
  node_viewer["Demo viewer<br/>[demo.py]"]
end

node_operator(("Researcher"))
node_datasets[("Fundus datasets")]

node_operator -->|"trains model"| node_cnntrain
node_operator -->|"runs inference"| node_cnntest
node_datasets -->|"image and labels"| node_cnnutil
node_cnntrain -->|"optimizes"| node_cnnmodel
node_cnntrain -->|"loads batches"| node_cnnutil
node_cnntest -->|"runs model"| node_cnnmodel
node_cnntest -->|"loads images"| node_cnnutil
node_cnntest -->|"writes maps"| node_probmaps
node_cnntrain -.->|"optional model"| node_dau2model
node_cnntrain -.->|"optional fusion"| node_aff
node_probmaps -->|"provides predictions"| node_graphgen
node_graphgen -->|"writes graphs"| node_graphfiles
node_probmaps -.->|"provides predictions"| node_fastgraph
node_fastgraph -.->|"writes graphs"| node_graphfiles
node_operator -->|"trains refinement"| node_vgntrain
node_operator -->|"runs refinement"| node_vgntest
node_graphfiles -->|"loaded by"| node_graphdata
node_probmaps -->|"loaded with graphs"| node_graphdata
node_datasets -->|"labels and masks"| node_graphdata
node_vgntrain -->|"requests batches"| node_graphdata
node_vgntest -->|"requests batches"| node_graphdata
node_vgntrain -->|"optimizes"| node_vgnmodel
node_vgntest -->|"runs model"| node_vgnmodel
node_vgntrain -->|"saves predictions"| node_segmentations
node_vgntest -->|"saves predictions"| node_segmentations
node_dauutil -.->|"provides batches"| node_dautrain
node_dautrain -.->|"saves results"| node_segmentations
node_segmentations -.->|"processed by"| node_postprocess
node_operator -->|"browses results"| node_viewer
node_segmentations -->|"displays stages"| node_viewer

click node_cnntrain "https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/train_CNN.py"
click node_cnnmodel "https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/Modules/model.py"
click node_dau2model "https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/Modules/DAU2Net.py"
click node_aff "https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/Modules/AFF_Module.py"
click node_cnntest "https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/test_CNN.py"
click node_cnnutil "https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/util.py"
click node_graphgen "https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/GenGraph/make_graph_db.py"
click node_fastgraph "https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/GenGraph/make_graph_db_fast_parity.py"
click node_vgntrain "https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/train_VGN.py"
click node_vgntest "https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/test_VGN.py"
click node_vgnmodel "https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/Modules/model.py"
click node_graphdata "https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/util.py"
click node_dautrain "https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/DAU_HRF_codes/train_VGN_DAU.py"
click node_dauutil "https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/DAU_HRF_codes/util_vgn.py"
click node_postprocess "https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/postprocess_prob_maps.py"
click node_viewer "https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/demo.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cnntrain,node_cnnmodel,node_dau2model,node_aff,node_cnntest,node_cnnutil,node_probmaps toneBlue
class node_graphgen,node_fastgraph,node_graphfiles,node_datasets toneAmber
class node_vgntrain,node_vgntest,node_vgnmodel,node_graphdata,node_dautrain,node_dauutil toneMint
class node_segmentations,node_postprocess,node_viewer toneRose
class node_operator toneIndigo
```

## Components

### CNN Segmentation

- [CNN training](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/train_CNN.py): `code/train_CNN.py`
- [CNN models](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/Modules/model.py): `code/Modules/model.py`
- [DA-U²Net](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/Modules/DAU2Net.py): `code/Modules/DAU2Net.py`
- [Adaptive fusion](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/Modules/AFF_Module.py): `code/Modules/AFF_Module.py`
- [CNN inference](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/test_CNN.py): `code/test_CNN.py`
- [Image data layer](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/util.py): `code/util.py`
- **Probability maps**

### Vessel Graphs

- [Graph generation](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/GenGraph/make_graph_db.py): `code/GenGraph/make_graph_db.py`
- [Fast graph generation](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/GenGraph/make_graph_db_fast_parity.py): `code/GenGraph/make_graph_db_fast_parity.py`
- **Graph files**

### Graph Refinement

- [VGN training](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/train_VGN.py): `code/train_VGN.py`
- [VGN inference](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/test_VGN.py): `code/test_VGN.py`
- [VGN model](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/Modules/model.py): `code/Modules/model.py`
- [Graph data layer](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/util.py): `code/util.py`
- [DAU VGN training](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/DAU_HRF_codes/train_VGN_DAU.py): `DAU_HRF_codes/train_VGN_DAU.py`
- [DAU data layer](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/DAU_HRF_codes/util_vgn.py): `DAU_HRF_codes/util_vgn.py`

### Results and Viewing

- **Refined outputs**
- [Map postprocessing](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/code/postprocess_prob_maps.py): `code/postprocess_prob_maps.py`
- [Demo viewer](https://github.com/mejji/contextualizing-retinal-vessel-segmentation/blob/main/demo.py): `demo.py`

### Other components

- **Researcher**
- **Fundus datasets**

## Connections

- Researcher → CNN training: trains model
- Researcher → CNN inference: runs inference
- Fundus datasets → Image data layer: image and labels
- CNN training → CNN models: optimizes
- CNN training → Image data layer: loads batches
- CNN inference → CNN models: runs model
- CNN inference → Image data layer: loads images
- CNN inference → Probability maps: writes maps
- CNN training → DA-U²Net: optional model
- CNN training → Adaptive fusion: optional fusion
- Probability maps → Graph generation: provides predictions
- Graph generation → Graph files: writes graphs
- Probability maps → Fast graph generation: provides predictions
- Fast graph generation → Graph files: writes graphs
- Researcher → VGN training: trains refinement
- Researcher → VGN inference: runs refinement
- Graph files → Graph data layer: loaded by
- Probability maps → Graph data layer: loaded with graphs
- Fundus datasets → Graph data layer: labels and masks
- VGN training → Graph data layer: requests batches
- VGN inference → Graph data layer: requests batches
- VGN training → VGN model: optimizes
- VGN inference → VGN model: runs model
- VGN training → Refined outputs: saves predictions
- VGN inference → Refined outputs: saves predictions
- DAU data layer → DAU VGN training: provides batches
- DAU VGN training → Refined outputs: saves results
- Refined outputs → Map postprocessing: processed by
- Researcher → Demo viewer: browses results
- Refined outputs → Demo viewer: displays stages
