# rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework architecture

> Architecture diagram of the GitHub repository rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework
- Repository: https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework

## Overview

This repository trains retinal-image classifiers and serves diabetic-retinopathy predictions with visual explanations and model-comparison reporting. Its main workflow is OCT2017 CNN pretraining, APTOS training and QWK-based model selection, then web inference with Grad-CAM/attention explanations. The README documents the application’s comparison, results, and reference-gallery capabilities; the sampled source does not show every route or UI data path, so those links are documented rather than inferred from folder names.

Main entry points: [`train.py`](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/train.py) (Training pipeline), [`webapp/app.py`](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/webapp/app.py) (Flask inference app), [`data/dataset.py`](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/data/dataset.py) (Dataset loaders), [`explainability/explain.py`](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/explainability/explain.py) (Prediction explanations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_fundus["Fundus datasets"]
  node_preprocess["Preprocessing<br/>[preprocessing.py]"]
  node_datasets["Dataset loaders<br/>[dataset.py]"]
end

subgraph group_training["Training and evaluation"]
  node_trainer["Training pipeline<br/>[train.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
  node_engine["Train and evaluate<br/>[engine.py]"]
  node_metrics["Evaluation metrics<br/>[metrics.py]"]
  node_cnn["CNN classifier<br/>[cnn_model.py]"]
  node_vit["ViT classifier<br/>[vit_model.py]"]
  node_fusion["Fusion classifier<br/>[fusion_model.py]"]
  node_checkpoints["Selected weights"]
  node_reports["Training reports<br/>[generate_report.py]"]
  node_reportfiles["Benchmark report files"]
end

subgraph group_xai["Inference and explainability"]
  node_app["Flask inference app<br/>[app.py]"]
  node_explain["Prediction explanations<br/>[explain.py]"]
  node_gradcam["Grad-CAM<br/>[gradcam.py]"]
  node_rollout["Attention rollout"]
end

subgraph group_web["Web reports"]
  node_webreports["Web report exports"]
end

node_clinician(("Image submitter"))
node_visitor(("Web application user"))

node_fundus -->|"loads images"| node_datasets
node_datasets -->|"preprocesses images"| node_preprocess
node_trainer -->|"builds loaders"| node_datasets
node_trainer -->|"uses settings"| node_config
node_trainer -->|"trains CNN"| node_cnn
node_trainer -->|"trains ViT"| node_vit
node_trainer -->|"trains fusion"| node_fusion
node_trainer -->|"runs training"| node_engine
node_engine -->|"computes metrics"| node_metrics
node_trainer -->|"selects best model"| node_checkpoints
node_trainer -->|"writes results"| node_reports
node_reports -->|"writes reports"| node_reportfiles
node_trainer -->|"pretrains on OCT2017"| node_datasets
node_clinician -->|"uploads image"| node_app
node_app -->|"requests explanation"| node_explain
node_explain -->|"generates heatmap"| node_gradcam
node_explain -->|"computes attention"| node_rollout
node_app -.->|"compares models"| node_cnn
node_app -.->|"compares models"| node_vit
node_app -.->|"compares models"| node_fusion
node_visitor -->|"views results"| node_app
node_app -->|"serves report exports"| node_webreports
node_webreports -->|"reads metrics"| node_reportfiles

click node_preprocess "https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/data/preprocessing.py"
click node_datasets "https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/data/dataset.py"
click node_trainer "https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/train.py"
click node_config "https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/config.py"
click node_engine "https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/utils/engine.py"
click node_metrics "https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/utils/metrics.py"
click node_cnn "https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/models/cnn_model.py"
click node_vit "https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/models/vit_model.py"
click node_fusion "https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/models/fusion_model.py"
click node_checkpoints "https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/tree/main/checkpoints"
click node_reports "https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/reports/generate_report.py"
click node_reportfiles "https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/tree/main/outputs/reports"
click node_app "https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/webapp/app.py"
click node_explain "https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/explainability/explain.py"
click node_gradcam "https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/explainability/gradcam.py"
click node_rollout "https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/explainability/attention_rollout.py"
click node_webreports "https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/webapp/report_generator.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_fundus,node_preprocess,node_datasets,node_visitor toneBlue
class node_trainer,node_config,node_engine,node_metrics,node_cnn,node_vit,node_fusion,node_checkpoints,node_reports,node_reportfiles toneAmber
class node_app,node_explain,node_gradcam,node_rollout toneMint
class node_webreports toneRose
class node_clinician toneIndigo
```

## Components

### Data preparation

- **Fundus datasets**
- [Preprocessing](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/data/preprocessing.py): `data/preprocessing.py`
- [Dataset loaders](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/data/dataset.py): `data/dataset.py`

### Training and evaluation

- [Training pipeline](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/train.py): `train.py`
- [Runtime configuration](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/config.py): `config.py`
- [Train and evaluate](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/utils/engine.py): `utils/engine.py`
- [Evaluation metrics](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/utils/metrics.py): `utils/metrics.py`
- [CNN classifier](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/models/cnn_model.py): `models/cnn_model.py`
- [ViT classifier](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/models/vit_model.py): `models/vit_model.py`
- [Fusion classifier](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/models/fusion_model.py): `models/fusion_model.py`
- [Selected weights](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/tree/main/checkpoints): `checkpoints`
- [Training reports](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/reports/generate_report.py): `reports/generate_report.py`
- [Benchmark report files](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/tree/main/outputs/reports): `outputs/reports`

### Inference and explainability

- [Flask inference app](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/webapp/app.py): `webapp/app.py`
- [Prediction explanations](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/explainability/explain.py): `explainability/explain.py`
- [Grad-CAM](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/explainability/gradcam.py): `explainability/gradcam.py`
- [Attention rollout](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/explainability/attention_rollout.py): `explainability/attention_rollout.py`

### Web reports

- [Web report exports](https://github.com/rajkumarprt/multi-class-diabetic-retinopathy-detection-using-xai-driven-cnn-transformer-fusion-framework/blob/main/webapp/report_generator.py): `webapp/report_generator.py`

### Other components

- **Image submitter**
- **Web application user**

## Connections

- Fundus datasets → Dataset loaders: loads images (evidence: `data/dataset.py`)
- Dataset loaders → Preprocessing: preprocesses images (evidence: `data/dataset.py`)
- Training pipeline → Dataset loaders: builds loaders (evidence: `train.py`)
- Training pipeline → Runtime configuration: uses settings (evidence: `train.py`)
- Training pipeline → CNN classifier: trains CNN (evidence: `train.py`)
- Training pipeline → ViT classifier: trains ViT (evidence: `train.py`)
- Training pipeline → Fusion classifier: trains fusion (evidence: `train.py`)
- Training pipeline → Train and evaluate: runs training (evidence: `train.py`)
- Train and evaluate → Evaluation metrics: computes metrics (evidence: `utils/engine.py`)
- Training pipeline → Selected weights: selects best model (evidence: `README.md`)
- Training pipeline → Training reports: writes results (evidence: `train.py`)
- Training reports → Benchmark report files: writes reports (evidence: `reports/generate_report.py`)
- Training pipeline → Dataset loaders: pretrains on OCT2017 (evidence: `train.py`)
- Image submitter → Flask inference app: uploads image (evidence: `README.md`)
- Flask inference app → Prediction explanations: requests explanation (evidence: `webapp/app.py`)
- Prediction explanations → Grad-CAM: generates heatmap (evidence: `explainability/explain.py`)
- Prediction explanations → Attention rollout: computes attention (evidence: `explainability/explain.py`)
- Flask inference app → CNN classifier: compares models (evidence: `README.md`)
- Flask inference app → ViT classifier: compares models (evidence: `README.md`)
- Flask inference app → Fusion classifier: compares models (evidence: `README.md`)
- Web application user → Flask inference app: views results (evidence: `README.md`)
- Flask inference app → Web report exports: serves report exports (evidence: `webapp/app.py`)
- Web report exports → Benchmark report files: reads metrics (evidence: `webapp/report_generator.py`)
