transforms
Build TorchIO 2.0 preprocessing and augmentation pipelines with deterministic/random transforms, composition, include/exclude routing, per-instance batches, history, inverse replay, and MONAI/Cornucopia adapters.
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-08
- Stars
- ★ 11
- Forks
- 3
01 前言 Front Matter
- name
- transforms
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Build TorchIO 2.0 preprocessing and augmentation pipelines with deterministic/random transforms, composition, include/exclude routing, per-instance batches, history, inverse replay, and MONAI/Cornucopia adapters.
- disable-model-invocation
- true
02 资源文件 3
- 参考文档references/api-reference.md8.7 KB
- 参考文档references/troubleshooting.md6.0 KB
- 参考文档references/workflows.md6.7 KB
03 SKILL.md 正文
TorchIO Transforms
Use this sub-skill when an agent needs to design, migrate, debug, or validate TorchIO transform pipelines. It focuses on TorchIO 2.0 APIs: transform class names are Flip, Affine, Noise, Gamma, etc. rather than older RandomFlip/RandomAffine names, and random behavior is controlled by parameter ranges, Choice, distributions, and p.
Route by Task
- Build or migrate a pipeline: start with
references/workflows.mdfor preprocessing/augmentation patterns and TorchIO 2.0 migration notes. - Check constructor names and semantics: use
references/api-reference.mdfor base arguments, transform families, composition, parameter ranges, adapters, and inverse/history APIs. - Debug transform behavior: use
references/troubleshooting.mdfor include/exclude mistakes, no-op warnings, label interpolation, inverse limits, and optional dependency failures. - Validate history/inverse mechanics: run
scripts/transform_history_smoke.pyon synthetic tensors. - Validate scalar/label routing: run
scripts/include_exclude_smoke.pyon synthetic tensors.
Core TorchIO 2.0 Rules
- Construct in-memory images as
tio.ScalarImage(tensor)andtio.LabelMap(tensor), where tensors are 4D(C, I, J, K). - Use
tio.Normalize(...)/tio.RescaleIntensity(...)with keyword-only range arguments such asout_min,out_max,in_min, andin_max. - Use one transform class for fixed and random behavior: scalar parameters are deterministic, tuples are sampled ranges,
tio.Choice([...])samples discrete values, andtorch.distributions.Distributionobjects can supply custom sampling. - Apply
pto gate a transform; in realSubjectsBatchinputs, transforms that support it useper_instance=Trueby default to sample/gate each element independently. - Use
include=[...]andexclude=[...]with exact image keys from aSubject; intensity transforms already skipLabelMapimages unless they are label-aware transforms. - Keep labels safe during spatial operations by relying on default
label_interpolation="nearest"or setting it explicitly when usingSpatial,Affine,ElasticDeformation,Resample, orResize.
Minimal Pipeline Pattern
import torch
import torchio as tio
subject = tio.Subject(
t1=tio.ScalarImage(torch.rand(1, 32, 32, 32)),
seg=tio.LabelMap(torch.randint(0, 3, (1, 32, 32, 32))),
)
pipeline = tio.Compose([
tio.Resample(target=1.0),
tio.CropOrPad(target_shape=(32, 32, 32)),
tio.Normalize(out_min=-1, out_max=1, include=["t1"]),
tio.Flip(axes=(0, 1, 2), flip_probability=0.5, p=0.5),
tio.OneOf({
tio.Noise(std=(0.01, 0.05)): 0.7,
tio.Blur(std=(0.5, 1.5)): 0.3,
}),
])
transformed = pipeline(subject)
assert transformed.t1.shape == transformed.seg.shape
assert transformed.seg.data.dtype == subject.seg.data.dtype
assert transformed.applied_transforms
Related Sub-skills
- Use the root TorchIO skill and
data-modelforSubject,Image,ScalarImage,LabelMap,Study,Points, andBoundingBoxesconstruction basics. - Use
patch-workflowsforGridSampler,UniformSampler,WeightedSampler,LabelSampler,Queue,SubjectsLoader, andPatchAggregator. - Use
cli-and-iofor thetorchio transformcommand and file conversion workflows.
04 同仓库更多 Skills
obsidian-clipper-template-creator
Guide for creating templates for the Obsidian Web Clipper. Use when you want to create a new clipping template, understand available variables, or format clipped content.
obsidian-clipper-template-creator
Guide for creating templates for the Obsidian Web Clipper. Use when you want to create a new clipping template, understand available variables, or format clipped content.
python-api
Programmatic Object-Detection-Metrics API guidance for BoundingBox, BoundingBoxes, Evaluator, enums, coordinate conversion, AP/mAP semantics, and source-style import diagnostics.
file-evaluation
Folder-based PASCAL VOC AP/mAP evaluation from ground-truth and detection text files.
object-detection-metrics
Guides legacy Object-Detection-Metrics PASCAL VOC AP/mAP evaluation from detection text folders and direct Python API classes.
nx-workspace-patterns
Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.