GPU-accelerated Python library that reimplements pyradiomics with full feature parity
Project description
fastrad
FastRadiomics (fastrad) is a GPU-accelerated Python library for calculating radiomics features from medical images. It aims to be a high-performance alternative to PyRadiomics, built from the ground up to achieve deep feature extraction parity with significantly faster execution times by utilizing PyTorch for tensor operations.
Features
- Full Parity with PyRadiomics: Extracts the exact same features as the original PyRadiomics implementations.
- Hardware Acceleration: Native PyTorch backend seamlessly targets multi-core CPUs, CUDA-enabled GPUs, and Apple Silicon (MPS)* out of the box.
- IBSI Compliant: Passed standard Image Biomarker Standardisation Initiative (IBSI) digital phantom validation testing.
- Memory vs Speed Trade-off: By materializing full tensors throughout computation,
fastradfundamentally trades CPU memory footprint for significant reductions in execution time. - Supported Feature Classes:
- First Order
- Shape (2D and 3D)
- GLCM (Gray Level Co-occurrence Matrix)
- GLRLM (Gray Level Run Length Matrix)
- GLSZM (Gray Level Size Zone Matrix)
- GLDM (Gray Level Dependence Matrix)
- NGTDM (Neighbourhood Gray Tone Difference Matrix)
- DICOM Handling: Accepts DICOM paths out-of-the-box (powered by
pydicomandSimpleITK).
* Note: Some PyTorch MPS operations do not natively support FP64 floating-point operations. Since statistical features require extremely high precision for parity, CUDA or CPU are the primary recommended execution targets.
Installation
You can install fastrad and its core dependencies easily:
# Clone the repository
git clone https://github.com/helloerikaaa/fastrad.git
cd fastrad
# Install standard CPU dependencies
pip install .
# For NVIDIA GPU hardware acceleration (CUDA)
pip install ".[cuda]"
Basic Usage
fastrad employs a feature extractor interface similar to PyRadiomics but significantly optimized for volume operations.
Quick Start
from fastrad import MedicalImage, Mask, FeatureExtractor, FeatureSettings
# 1. Load an image (DICOM directory) and mask
image = MedicalImage("/path/to/dicom_dir")
mask = Mask("/path/to/mask.nrrd")
# 2. Configure extractor settings
settings = FeatureSettings(
feature_classes=["firstorder", "shape", "glcm"], # specify needed features
bin_width=25.0,
device="auto" # use "cuda", "cpu", or "auto"
)
# 3. Extract Features
extractor = FeatureExtractor(settings)
features = extractor.execute(image, mask)
for feature_name, value in features.items():
print(f"{feature_name}: {value}")
CPU vs CUDA Performance
Offloading to GPU using fastrad dramatically reduces Feature Extraction runtime latency compared to PyRadiomics on CPU. Utilizing "cuda" in your FeatureSettings initializes tensors on the GPU automatically.
# Utilizing CUDA for hardware-accelerated processing
settings_gpu = FeatureSettings(
feature_classes=["firstorder", "shape", "glcm", "glrlm", "glszm", "gldm", "ngtdm"],
bin_width=25.0,
device="cuda"
)
extractor = FeatureExtractor(settings_gpu)
features = extractor.execute(image, mask)
Documentation & Examples
fastrad ships with an extensive set of clinical tutorials housed in the examples/ directory of this repository. They demonstrate advanced applications using actual hospital dataset configurations:
01_basic_extraction.py: Fundamental integration setup and extraction limits.02_gpu_acceleration.py: Native setup for deploying parallel operations upon NVidia devices.03_batch_processing_tcia.py: Writing loops evaluating clinical cohorts simultaneously.04_advanced_configuration.py: Managing geometric warping warnings, spacing overrides, and PyTorch dynamic memory error mitigations safely.
To read the robust framework User Guide, see the docs/user_guide.rst and docs/learn.rst modules.
Benchmarks & Scientific Stability
The repository contains a fully automated benchmarking suite (benchmarks/report_generator.py) that evaluates computation time, memory efficiency, and numeric stability against PyRadiomics to produce the fastrad_scientific_report.md.
Highlights from the latest scientific validation (fastrad_scientific_report.md):
- IBSI Compliance: 100% compliant with the Phase 1 digital phantom (all absolute relative deviations ≤ 1e-13%).
- Numerical Parity: 100% of internal features match PyRadiomics within a
1e-4tolerance on real TCIA clinical segmentation masks. - Runtime CPU Performance: Up to 25.3x single-threaded CPU speedup per feature class, and 4.31x overall speedup compared to a multi-thread PyRadiomics execution.
- GPU Acceleration: Up to 25.0x overall pipeline speedup (and 49x for firstorder features) natively utilizing CUDA PyTorch tensor streams.
- Memory Efficiency: Utilizes full dense tensors rather than scalar loops, resulting in a higher peak RAM footprint on large clinical ROIs (requires ~7.6 GB for a 30mm radius mask) in exchange for parallel speed.
- Stability: Tested rigorously under perturbations and scan-rescan test-retest datasets, confirming statistically equivalent ICC variances with PyRadiomics (paired Wilcoxon p>0.40).
- Robustness: Provides graceful, PyRadiomics-parity handling of edge cases (Empty Masks, Single-Voxel masks).
Run the full scientific benchmark suite locally to regenerate the physical report:
python benchmarks/report_generator.py
Running Tests
Tests assert extraction values strictly adhere to the baseline output created by PyRadiomics to ensure fidelity for scientific rigor, including compliance with the IBSI (Image Biomarker Standardisation Initiative) phantom benchmarks.
To run the test suite:
pip install ".[test]"
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastrad-0.1.0.tar.gz.
File metadata
- Download URL: fastrad-0.1.0.tar.gz
- Upload date:
- Size: 71.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcb4576374310c541eb8a4bacfe3fe657c844d12839dc38d0246cd50c1563575
|
|
| MD5 |
286a90c389c37513c99c10c20450c31e
|
|
| BLAKE2b-256 |
fc114f6f4019023882ee6d8cd0613e5d38d411863804ee0f75506a9940198ca0
|
Provenance
The following attestation bundles were made for fastrad-0.1.0.tar.gz:
Publisher:
python-publish.yml on helloerikaaa/fastrad
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastrad-0.1.0.tar.gz -
Subject digest:
dcb4576374310c541eb8a4bacfe3fe657c844d12839dc38d0246cd50c1563575 - Sigstore transparency entry: 1200971385
- Sigstore integration time:
-
Permalink:
helloerikaaa/fastrad@82e37148e41118ad16e48788258886b5351af9e7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/helloerikaaa
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@82e37148e41118ad16e48788258886b5351af9e7 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file fastrad-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastrad-0.1.0-py3-none-any.whl
- Upload date:
- Size: 32.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26445221c37095bf1951106b79cdebd2652f9ca8d3c592b8503795630dce9c11
|
|
| MD5 |
462aeabd6fcb36225d4474b053714486
|
|
| BLAKE2b-256 |
994e797f7b0d8bb4184d60bf3562d08207799d1fb44d811b5aea53d5bb9d0dbc
|
Provenance
The following attestation bundles were made for fastrad-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on helloerikaaa/fastrad
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastrad-0.1.0-py3-none-any.whl -
Subject digest:
26445221c37095bf1951106b79cdebd2652f9ca8d3c592b8503795630dce9c11 - Sigstore transparency entry: 1200971420
- Sigstore integration time:
-
Permalink:
helloerikaaa/fastrad@82e37148e41118ad16e48788258886b5351af9e7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/helloerikaaa
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@82e37148e41118ad16e48788258886b5351af9e7 -
Trigger Event:
workflow_dispatch
-
Statement type: