Retinalysis inference
Run model ensembles for ophthalmic image classification, regression, segmentation and keypoint localisation. The library handles preprocessing, prediction and postprocessing, and is used by VascX for fundus image analysis.
Models can be loaded from local files or Hugging Face. You can also train your own models with retinalysis-models.
Installation
pip install retinalysis-inference
For GPU use, follow the PyTorch installation instructions to install a build suitable for your machine.
Running inference
Load a model
Load a local release by its path without the file extension and choose a device:
from pathlib import Path
import torch
from rtnls_inference.ensembles import make_ensemble
device = "cuda:0" if torch.cuda.is_available() else "cpu"
ensemble = make_ensemble("/path/to/model").to(device).eval()
The example notebooks also show how to load pretrained VascX models from Hugging Face.
Single image
Inference follows four steps:
# 1. Preprocess the image.
item = ensemble.preprocess_item({"image": "fundus.jpg"}, input_space="raw")
# 2. Make a batch of one.
batch = ensemble.make_batch([item])
# 3. Run the model.
predictions = ensemble.predict_batch(batch)
# 4. Postprocess the output.
result = ensemble.postprocess_batch(predictions, batch)[0]
Read the prediction from result["output"]. You can also pass a loaded uint8 RGB
NumPy image or PyTorch tensor in the image field.
Use input_space="preprocessed" for images that have already been through fundus
preprocessing. Segmentation masks and keypoints refer to the preprocessed image,
which is available in result["preprocessed_image"].
Batch inference
Create the input list, build a dataloader, then run inference:
# 1. Create the input list.
data = [{"image": path} for path in sorted(Path("images").glob("*.jpg"))]
# 2. Create the dataloader.
loader = ensemble.make_inference_dataloader(data, input_space="raw", batch_size=2)
# 3. Run inference and save the results.
results = ensemble.predict_dataloader(loader, dest_path="predictions")
- Classification, regression and keypoints return a DataFrame and save
predictions.csv. Omitdest_pathto keep the results in memory only. - Segmentation saves masks as it goes and returns a table listing the output
files, also saved as
manifest.csv.
To process results one at a time without saving files, use
ensemble.iter_predictions(loader). The notebooks below use this for visualizing
segmentation results.
Examples and further reading
Each notebook demonstrates single-image inference and a batch visualization:
- Segmentation: artery/vein and vessel masks.
- Classification: quality labels and probabilities.
- Keypoint localisation: fovea coordinates.
- ONNX: local ONNX segmentation releases.
Find pretrained models on Hugging Face. For input formats and additional options, see the method documentation in the ensemble base classes and the segmentation ensemble.
For raw logits and migrating older callers, see the short inference workflow guide.
Metadata
Release files for retinalysis-inference 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| retinalysis_inference-1.0.0.tar.gz | 10.3 MB | Without provenance | Details for retinalysis_inference-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| retinalysis_inference-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for retinalysis_inference-1.0.0-py3-none-any.whl |
Total release size: 10.3 MB
Release files / retinalysis_inference-1.0.0.tar.gz
| Download URL | retinalysis_inference-1.0.0.tar.gz |
|---|---|
| Size | 10.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e3f21075c81952083bb1775a77d2b5a37b5eacb5781f8a8cbec65156cb3bf84e
|
|
BLAKE2b-256 checksum How to use checksums |
78e1cd457d87807025b34e17a6801c3e09adfb4d8921f6213e07a44f3e9f34f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / retinalysis_inference-1.0.0-py3-none-any.whl
| Download URL | retinalysis_inference-1.0.0-py3-none-any.whl |
|---|---|
| Size | 68.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0a66bf938a06d58a0b42c633cd0a6aa224bcf0e3305bb4aed5995823e96b4914
|
|
BLAKE2b-256 checksum How to use checksums |
ab4e0677892f06128d50379960b10f28f7c27a41d011b6ffee48924d897f8bf6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Security for retinalysis-inference 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.