Skip to main content

fastdrs

Fast diabetic retinopathy screening and model development toolkit for PyTorch.

fastdrs provides reusable components for building, training, evaluating, and eventually deploying diabetic retinopathy classification models. It is designed to separate the reusable ML functionality from the research and experimentation code in the diabetic-retinopathy-screening project.

Status: Early development (0.1.0)


Features

  • 🧠 Multiple vision architectures

    • ResNet18
    • ResNet50
    • DenseNet121
    • ConvNeXt-Tiny
    • Swin Transformer-Tiny
    • MobileNetV2
  • 🖼️ Fundus image preprocessing

    • Image resizing
    • ImageNet normalization
    • Data augmentation
    • Fundus boundary cropping
    • Ben Graham preprocessing
  • 📊 Dataset handling

    • Hugging Face datasets
    • EYEPACS-compatible datasets
    • Reproducible train/validation/test splitting
    • PyTorch Dataset and DataLoader integration
  • 🚂 Model training

    • PyTorch training loops
    • AdamW optimization
    • Cosine annealing learning-rate scheduling
    • Best-checkpoint saving
    • Optional Weights & Biases integration
  • 📈 Evaluation

    • Accuracy
    • Precision
    • Sensitivity/Recall
    • Specificity
    • Macro F1
    • Weighted F1
    • Confusion matrices
    • Per-class metrics
    • Inference latency
    • Model parameter and size estimates
  • 📱 Deployment

    • LiteRT export support is being developed for Android/on-device inference.

Installation

Basic installation

pip install fastdrs

Or with uv:

uv add fastdrs

Training dependencies

Training functionality requires the training dependencies:

pip install "fastdrs[training]"

or:

uv add "fastdrs[training]"

Development installation

Clone the repository and install the development environment with uv:

git clone https://github.com/MichaelMukiibi/diabetic-retinopathy-screening.git
cd diabetic-retinopathy-screening

uv sync

Quick Start

Build a model

from fastdrs.models import build_model, get_model_info

model = build_model(
    architecture="mobilenet_v2",
    num_classes=5,
    pretrained=True,
)

info = get_model_info(model)

print(info)

Example output:

{
    'total_parameters': ...,
    'trainable_parameters': ...,
    'model_size_mb': ...
}

Supported architectures

The model factory currently supports:

from fastdrs.models import build_model
Architecture Identifier
ResNet-50 resnet50
ResNet-18 resnet18
DenseNet-121 densenet121
ConvNeXt-Tiny convnext_tiny
Swin Transformer-Tiny swin_t
MobileNetV2 mobilenet_v2

For example:

model = build_model(
    architecture="resnet50",
    num_classes=5,
    pretrained=True,
)

Diabetic Retinopathy Classes

The classification pipeline uses five diabetic retinopathy severity classes:

Label Class
0 No DR
1 Mild
2 Moderate
3 Severe
4 Proliferative

The model outputs five logits corresponding to these classes.


Preprocessing

fastdrs provides preprocessing utilities specifically for retinal fundus images.

from fastdrs.preprocessing import get_transforms

train_transforms = get_transforms(
    img_size=224,
    is_train=True,
)

eval_transforms = get_transforms(
    img_size=224,
    is_train=False,
)

Ben Graham preprocessing can also be enabled:

train_transforms = get_transforms(
    img_size=224,
    is_train=True,
    use_ben_graham=True,
)

Individual preprocessing can be used directly:

from fastdrs.preprocessing import ben_graham_preprocessing

processed_image = ben_graham_preprocessing(
    image,
    img_size=224,
)

Dataset Loading

fastdrs supports Hugging Face datasets through its dataset utilities.

from fastdrs.data import create_dataloaders

train_loader, val_loader, test_loader, dataset_info = create_dataloaders(
    dataset_name="sngsfydy/aptos",
    batch_size=32,
    img_size=224,
)

The loader creation utility handles:

  • Dataset loading
  • Train/validation/test splitting
  • Image transformations
  • PyTorch DataLoader construction

Training

Training functionality is available through:

from fastdrs.training import train_model

results = train_model(
    architecture="resnet18",
    dataset_name="sngsfydy/aptos",
    epochs=10,
    batch_size=32,
    lr=1e-4,
    img_size=224,
)

The training pipeline provides:

  • Training and validation loops
  • Cross-entropy loss
  • AdamW optimization
  • Cosine annealing
  • Best validation-loss checkpointing
  • Final test-set evaluation

A trained checkpoint is saved to the configured model directory.


Evaluation

Models can be evaluated using:

from fastdrs.evaluation import evaluate_model

results = evaluate_model(
    model,
    test_loader,
    device,
)

The returned results include:

accuracy
precision_macro
sensitivity_macro
specificity_macro
f1_macro
f1_weighted
inference_latency_ms
model_size_mb
total_parameters
confusion_matrix
per_class

This makes the evaluation output suitable for both ML benchmarking and deployment-oriented model comparison.


Project Architecture

fastdrs is developed as part of the diabetic retinopathy screening research project.

diabetic-retinopathy-screening/
│
├── src/
│   └── fastdrs/
│       ├── data.py
│       ├── preprocessing.py
│       ├── models.py
│       ├── training.py
│       ├── evaluation.py
│       └── deployment/
│
├── notebooks/
├── data/
├── models/
├── results/
│
└── deployment/
    └── android/

The fastdrs package contains the reusable ML functionality, while notebooks and project-level scripts are used for experimentation and research.


Deployment

On-device deployment is a major goal of the project.

The intended deployment pipeline is:

PyTorch Model
     │
     ▼
Trained Checkpoint
     │
     ▼
Model Export
     │
     ▼
LiteRT
     │
     ▼
.tflite Model
     │
     ▼
Android Application

LiteRT export functionality is being developed as an optional component so that users who only need the core ML functionality do not have to install the additional conversion stack.

The planned installation interface is:

pip install "fastdrs[export]"

Development

This project uses uv for dependency and environment management.

Install dependencies:

uv sync

Install training dependencies:

uv sync --extra training

Install all optional dependencies:

uv sync --all-extras

Run tests:

uv run pytest

Run linting:

uv run ruff check .

Build the package:

uv build

PyPI

The package is distributed through PyPI:

pip install fastdrs

The package can therefore be tested independently of the source repository, including in environments such as Google Colab.

For example:

!pip install fastdrs

Then:

from fastdrs.models import build_model

model = build_model(
    architecture="mobilenet_v2",
    num_classes=5,
)

print(model)

Research Project

fastdrs is being developed alongside a diabetic retinopathy screening research project using retinal fundus images.

The broader project investigates:

  • Diabetic retinopathy classification
  • Transfer learning
  • Vision architecture benchmarking
  • Resource-constrained inference
  • Model efficiency
  • On-device screening

The package is intended to make the resulting ML pipeline reusable beyond the original research repository.


License

This project is licensed under the MIT License.

See LICENSE for details.


Author

Michael Mukiibi

GitHub: @MichaelMukiibi


Disclaimer

fastdrs is a research and engineering toolkit. It is not a medical device and its predictions should not be used as a substitute for professional medical diagnosis or clinical decision-making.

Metadata

Release files for fastdrs 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastdrs 0.1.7
File Size Uploaded
fastdrs-0.1.7.tar.gz 3.9 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastdrs 0.1.7
File Interpreter ABI Platform
fastdrs-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 3.9 MB

Release files / fastdrs-0.1.7.tar.gz

Download URL fastdrs-0.1.7.tar.gz
Size 3.9 MB
Tags Source
SHA-256 checksum
How to use checksums
05d4c0eeb2033e3a3ba7a222fb6d6aa354246b0b6f61585126b12ef5f7e9101d
BLAKE2b-256 checksum
How to use checksums
60baf76f53c6103840e927b708492054f9f77da84e70906723e0fb7ce9b36af5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / fastdrs-0.1.7-py3-none-any.whl

Download URL fastdrs-0.1.7-py3-none-any.whl
Size 23.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ec716b4d45e16f3f4657b45e4a370f2f501849ececc657a6ef3836705284e7dd
BLAKE2b-256 checksum
How to use checksums
814e9f5ad48031af47a272e55e3424ea2f2a6edffe7a5c503fbbf2822feee46e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

0.1.13

2 release files

0.1.9

2 release files

0.1.8

2 release files

This release

0.1.7 This release

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page