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-09-03
- Stars
- ★ 351
- Forks
- 27
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 资源文件 5
- 参考文档references/api-reference.md8.7 KB
- 参考文档references/troubleshooting.md6.0 KB
- 参考文档references/workflows.md6.7 KB
- 脚本scripts/include_exclude_smoke.py2.6 KB
- 脚本scripts/transform_history_smoke.py2.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
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).