AGENT SKILL

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

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

Core TorchIO 2.0 Rules

  • Construct in-memory images as tio.ScalarImage(tensor) and tio.LabelMap(tensor), where tensors are 4D (C, I, J, K).
  • Use tio.Normalize(...) / tio.RescaleIntensity(...) with keyword-only range arguments such as out_min, out_max, in_min, and in_max.
  • Use one transform class for fixed and random behavior: scalar parameters are deterministic, tuples are sampled ranges, tio.Choice([...]) samples discrete values, and torch.distributions.Distribution objects can supply custom sampling.
  • Apply p to gate a transform; in real SubjectsBatch inputs, transforms that support it use per_instance=True by default to sample/gate each element independently.
  • Use include=[...] and exclude=[...] with exact image keys from a Subject; intensity transforms already skip LabelMap images unless they are label-aware transforms.
  • Keep labels safe during spatial operations by relying on default label_interpolation="nearest" or setting it explicitly when using Spatial, Affine, ElasticDeformation, Resample, or Resize.

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-model for Subject, Image, ScalarImage, LabelMap, Study, Points, and BoundingBoxes construction basics.
  • Use patch-workflows for GridSampler, UniformSampler, WeightedSampler, LabelSampler, Queue, SubjectsLoader, and PatchAggregator.
  • Use cli-and-io for the torchio transform command and file conversion workflows.

04 同仓库更多 Skills

VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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).

★ 351