Registry / ai-ml / torchio

torchio

JSON →
library1.2.1pypypi✓ verified 85d ago

TorchIO is a Python library for medical image processing with PyTorch, offering data loading, preprocessing, augmentation, and sampling for 3D medical images. Version 1.1.0 requires Python >=3.10. Release cadence is irregular, with multiple minor and patch releases per year.

pip install torchio
INSTALL
IMPORT
SIG · TORCHIO
T
torchio
ai-mlpythonv1.2.1
Install
76.5s avg
Import
8185ms
Disk
5299MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 86s
py 3.11
✕ build_error
✓ 80.7s
py 3.12
✕ build_error
✓ 71.5s
py 3.13
✕ build_error
✓ 67.9s
py 3.9
✕ build_error
✕ timeout
5299MB installed
● package 5299MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SubjectsDataset
from torchio import SubjectsDataset
from torchio.data import SubjectsDataset
In older versions (pre-0.18), SubjectsDataset was in torchio.data. Now it's exposed at top level.
RandomAffine
from torchio import RandomAffine
from torchio.transforms import RandomAffine
import from torchio directly is recommended and stable.

Create a minimal Subject with random data and apply transforms.

import torchio as tio import torch # Create a subject with a 3D image subject = tio.Subject( img=tio.ScalarImage(tensor=torch.rand(1, 64, 64, 64)), label=tio.LabelMap(tensor=torch.randint(0, 2, (1, 64, 64, 64))), ) print(subject) # Define a simple transform transform = tio.Compose([ tio.RandomAffine(scales=(0.9, 1.2), degrees=10), tio.RandomNoise(std=0.1), ]) # Apply transform transformed = transform(subject) print(transformed.shape)
Debug
Known issues
breakingTorchIO v1.0.0 dropped Python 3.7 and 3.8 support. Requires Python >=3.10.
fix
Upgrade Python to 3.10 or later, or pin torchio to <1.0.0 if stuck on older Python.
affects: >=1.0.0
gotchaTransform arguments like 'p' (probability) are now in the range [0,1] for all random transforms, but some older code used percentages. Always pass a float between 0 and 1.
fix
Use p=0.5 instead of p=50 for 50% probability.
affects: all
deprecatedThe 'image' parameter in Subject constructor is deprecated in favor of 'img'. Using 'image' will raise a warning and may be removed in future versions.
fix
Use 'img' instead of 'image' when creating Subject.
affects: >=0.18
Errors
Common errors & fixes
ImportError: cannot import name 'SubjectsDataset' from 'torchio'
Old import path from torchio.data; torchio v0.18+ moved SubjectsDataset to top-level.
fix
Use 'from torchio import SubjectsDataset' instead of 'from torchio.data import SubjectsDataset'.
KeyError: 'img' or 'label' not found in Subject when loading from disk
Subject expects specific keys for images and labels, but the file may have different naming (e.g., 'image', 'seg').
fix
Ensure the keys in the Subject dictionary match exactly. Use tio.ScalarImage(path) and assign to 'img' key.
RuntimeError: Expected 4D input but got 3D
TorchIO expects batch dimension (B, C, D, H, W) even for single images. Many transforms fail on 3D tensors.
fix
Add a batch dimension: tensor = tensor.unsqueeze(0) or use tio.ScalarImage with shape (1, C, D, H, W).
Upgrade
Version history
1.2.1latest on PyPI · released Jun 2, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
40 hits · last 30 days
node
36
Amazon
1
OpenAI (training)
1
Resources
torchio — pip install torchio · libregistry