Project guide

Project Guide | Retina Scan AI

Free medical-imaging model-card template for explainability and validation boundaries. This guide organizes the repository's original implementation notes for AI validation reviewers and medical-imaging prototype teams.

Reviewed 2026-07-28. This page is derived from checked-in repository evidence and links back to its source.

Live Demo

Non-clinical retinal-image classification research sandbox using ResNet18 transfer learning with Grad-CAM interpretability. It classifies synthetic or explicitly approved fundus-style images into 5 demonstration categories: Normal, Diabetic Retinopathy, Glaucoma, Cataract, and Age-related Macular Degeneration (AMD).

Validation review pack: `docs/architecture-pack.md`

System Overview

A non-clinical vision validation workflow that demonstrates model-governance review patterns while clearly staying outside diagnostic, medical-device, and production-readiness claims.

AreaDetails
UsersIndustrial AI validation teams, ML governance teams, health-tech prototype teams, and model-governance evaluators.
Technical pathValidate the demo, README, architecture notes, and quality gate before deeper workflow review.
System scopeResNet18 classification, Grad-CAM, DICOM integration notes, HIPAA-aligned governance, RBAC/OIDC framing, and model card.
Operating boundaryResearch prototype only, not diagnosis and not a medical device; clinical or production use would require formal validation, site review, and regulatory assessment.
Evaluation pathInspect validation templates, model card, risk notes, Grad-CAM outputs, and test/evaluation scripts.

Evaluation Path

Architecture Notes

Architecture

Input Image (224x224)
    │
    ▼
┌──────────────────────┐
│  ResNet18 Backbone    │  ← ImageNet pretrained weights
│  (Feature Extractor)  │
└──────────┬───────────┘
           │ 512-dim features
           ▼
┌──────────────────────┐
│  Classification Head  │
│  Dropout(0.3) →       │
│  Linear(512→256) →    │
│  ReLU → Dropout(0.2)  │
│  → Linear(256→5)      │
└──────────┬───────────┘
           │
           ▼
    5-class prediction

Key Features

Project Structure

retina-scan-ai/
├── src/
│   ├── config.py        # Hyperparameters and class labels
│   ├── dataset.py       # Custom dataset with augmentation pipeline
│   ├── model.py         # ResNet18 transfer learning architecture
│   ├── train.py         # Training loop with early stopping
│   ├── evaluate.py      # Confusion matrix, ROC curves, classification report
│   ├── gradcam.py       # Grad-CAM visualization for interpretability
│   └── inference.py     # Single-image prediction wrapper
├── api/
│   ├── main.py          # FastAPI inference server
│   └── schemas.py       # Request/response models
├── tests/
│   ├── test_model.py    # Model architecture tests
│   ├── test_dataset.py  # Dataset and transform tests
│   ├── test_train.py    # Training component tests
│   └── test_api.py      # API endpoint tests
├── scripts/
│   └── download_data.py # Dataset preparation utility
├── Dockerfile
├── docker-compose.yml
├── pyproject.toml
└── requirements.txt

Setup

pip install -r requirements.txt

Prepare Dataset


## Option 1: Use ODIR-5K dataset from Kaggle
python scripts/download_data.py <csv_path> <images_dir>


## Option 2: Generate synthetic data for pipeline testing
python scripts/download_data.py --synthetic 100

Expected directory structure:

data/retina/
├── Normal/
├── Diabetic_Retinopathy/
├── Glaucoma/
├── Cataract/
└── AMD/

Train

python -m src.train

Outputs:

Evaluate

python -m src.evaluate checkpoints/best_model.pth

Outputs:

Grad-CAM Visualization

python -m src.gradcam <image_path> checkpoints/best_model.pth

Inference API

uvicorn api.main:app --host 0.0.0.0 --port 8000


## Predict
curl -X POST http://localhost:8000/predict -F "file=@retina_image.jpg"


## Grad-CAM
curl -X POST http://localhost:8000/gradcam -F "file=@retina_image.jpg" -o gradcam.png

HTTP image uploads are capped at 16 MiB and 50 million decoded pixels by default. Expensive prediction and Grad-CAM work is limited to one in-flight operation per process, and Grad-CAM artifacts use request-scoped temporary directories that are removed after the response is sent. Deployments can tune these safeguards with RETINA_MAX_UPLOAD_BYTES, RETINA_MAX_IMAGE_PIXELS, and RETINA_MAX_CONCURRENT_INFERENCES.

Docker


## Inference server
docker compose up api


## Training
docker compose --profile training run train

Tests

pytest -v

Dataset

Designed for the ODIR-5K (Ocular Disease Intelligent Recognition) dataset containing 5,000 retinal fundus photographs across 8 disease categories, filtered to 5 primary classes.

Tech Stack

ComponentTechnology
Deep LearningPyTorch, torchvision
ModelResNet18 (transfer learning)
InterpretabilityGrad-CAM
Evaluationscikit-learn, matplotlib, seaborn
APIFastAPI, Uvicorn
ContainerDocker, Docker Compose
Testingpytest
DICOMpydicom, pynetdicom (via dicom/)
Identity FederationOIDC (Keycloak/Okta/Azure AD via access/)
AuditHash-chained event log (via audit/)

Not a Medical Device

This repository is research code. It has not been FDA-cleared, CE-marked, or approved by any regulatory body for clinical use. Any deployment for clinical care requires regulatory clearance, IRB review, and integration with a quality management system. See compliance/fda-samd-considerations.md and risk/known-limitations.md for details.

Compliance & Governance

This service includes compliance and governance artifacts that align with typical healthcare-AI deployment requirements. Refer to the relevant directory for details.

AreaDirectoryNotes
HIPAAcompliance/hipaa-mapping.mdEach Security Rule safeguard → this repo's approach
FDA SaMDcompliance/fda-samd-considerations.mdEducational framing; not legal advice
EU MDRcompliance/mdr-ce-considerations.mdCE marking considerations
GDPRcompliance/gdpr-dpia.mdDPIA template
PHI handlingcompliance/phi-handling.mdStorage, transmission, anonymization
Model cardgovernance/model-card.mdGoogle-style Model Card
Datasheetgovernance/datasheet.mdGebru-style Datasheet for ODIR-5K
Fairnessgovernance/fairness-evaluation.mdPer-subgroup metrics, disparity detection
Explainabilitygovernance/explainability-design.mdGrad-CAM rationale and limits
Biases and limitsgovernance/bias-and-limitations.mdDocumented biases, unsupported populations

Deferred Clinical Artifacts

docs/clinical/ contains planning artifacts for reviewers who need to understand what would be required before any clinical workflow discussion. These files are not evidence of clinical deployment, diagnostic performance, regulatory clearance, or production readiness:

dicom/ has the DICOM integration code (C-STORE SCP listener, anonymizer, GSPS generator, audit logger).

access/ has the RBAC + OIDC reference layer with example reviewer roles.

audit/ has the HIPAA-aligned hash-chained audit logger and compliance officer search tooling.

clinical_ui/ has a static HTML mockup for human-review discussion, not clinical use.

Validation

validation/ contains templates for planning a validation study. They are discovery artifacts, not active clinical-study results:

Risk Management

risk/ follows ISO 14971:2019:

Related Projects

ProjectRelationship
weld-defect-visionSibling vision project — industrial defect detection with YOLOv8
enterprise-llm-adoption-kitShared governance patterns (RBAC, audit, RAG)
AegisOpsOperator handoff and incident analysis — regulated incident-response patterns

Cloud + AI Architecture

Enterprise Productization

System Architecture

Service Architecture

Search And Service Surface