{"id":24725,"library":"torchio","title":"TorchIO","description":"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.","status":"active","version":"1.1.0","language":"python","source_language":"en","source_url":"https://github.com/TorchIO-project/torchio","tags":["medical imaging","augmentation","pytorch","3D","preprocessing"],"install":[{"cmd":"pip install torchio","lang":"bash","label":"Install TorchIO from PyPI"}],"dependencies":[],"imports":[{"note":"In older versions (pre-0.18), SubjectsDataset was in torchio.data. Now it's exposed at top level.","wrong":"from torchio.data import SubjectsDataset","symbol":"SubjectsDataset","correct":"from torchio import SubjectsDataset"},{"note":"import from torchio directly is recommended and stable.","wrong":"from torchio.transforms import RandomAffine","symbol":"RandomAffine","correct":"from torchio import RandomAffine"}],"quickstart":{"code":"import torchio as tio\nimport torch\n\n# Create a subject with a 3D image\nsubject = tio.Subject(\n    img=tio.ScalarImage(tensor=torch.rand(1, 64, 64, 64)),\n    label=tio.LabelMap(tensor=torch.randint(0, 2, (1, 64, 64, 64))),\n)\nprint(subject)\n\n# Define a simple transform\ntransform = tio.Compose([\n    tio.RandomAffine(scales=(0.9, 1.2), degrees=10),\n    tio.RandomNoise(std=0.1),\n])\n\n# Apply transform\ntransformed = transform(subject)\nprint(transformed.shape)","lang":"python","description":"Create a minimal Subject with random data and apply transforms."},"warnings":[{"fix":"Upgrade Python to 3.10 or later, or pin torchio to <1.0.0 if stuck on older Python.","message":"TorchIO v1.0.0 dropped Python 3.7 and 3.8 support. Requires Python >=3.10.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use p=0.5 instead of p=50 for 50% probability.","message":"Transform 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.","severity":"gotcha","affected_versions":"all"},{"fix":"Use 'img' instead of 'image' when creating Subject.","message":"The 'image' parameter in Subject constructor is deprecated in favor of 'img'. Using 'image' will raise a warning and may be removed in future versions.","severity":"deprecated","affected_versions":">=0.18"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use 'from torchio import SubjectsDataset' instead of 'from torchio.data import SubjectsDataset'.","cause":"Old import path from torchio.data; torchio v0.18+ moved SubjectsDataset to top-level.","error":"ImportError: cannot import name 'SubjectsDataset' from 'torchio'"},{"fix":"Ensure the keys in the Subject dictionary match exactly. Use tio.ScalarImage(path) and assign to 'img' key.","cause":"Subject expects specific keys for images and labels, but the file may have different naming (e.g., 'image', 'seg').","error":"KeyError: 'img' or 'label' not found in Subject when loading from disk"},{"fix":"Add a batch dimension: tensor = tensor.unsqueeze(0) or use tio.ScalarImage with shape (1, C, D, H, W).","cause":"TorchIO expects batch dimension (B, C, D, H, W) even for single images. Many transforms fail on 3D tensors.","error":"RuntimeError: Expected 4D input but got 3D"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}