patch-workflows
Design TorchIO patch-based training queues and dense patch inference loops with samplers, SubjectsLoader batches, PatchLocation metadata, and PatchAggregator.
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-08
- Stars
- ★ 11
- Forks
- 3
01 前言 Front Matter
- name
- patch-workflows
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Design TorchIO patch-based training queues and dense patch inference loops with samplers, SubjectsLoader batches, PatchLocation metadata, and PatchAggregator.
- disable-model-invocation
- true
02 资源文件 3
- 参考文档references/api-reference.md5.9 KB
- 参考文档references/troubleshooting.md5.7 KB
- 参考文档references/workflows.md5.6 KB
03 SKILL.md 正文
Patch Workflows
Use this sub-skill when an agent needs to train or infer on large 3D images by sampling patches instead of processing whole volumes. It covers GridSampler, UniformSampler, WeightedSampler, LabelSampler, Queue, SubjectsLoader, ImagesLoader, PatchLocation, and PatchAggregator.
Route by Goal
- Need dense whole-volume inference: use
GridSamplerplusPatchAggregator; see dense inference. - Need stochastic training patches: use
UniformSampler,WeightedSampler, orLabelSampler, optionally buffered byQueue; see training queues. - Need to choose sampler or batch access patterns: see API reference.
- Hit shape, overlap, probability map, or metadata errors: see troubleshooting.
- Want a runnable synthetic sanity check: run
python scripts/patch_workflow_smoke.py --help, thenpython scripts/patch_workflow_smoke.pyfrom this sub-skill directory.
Current API Reminders
- Construct in-memory images as
tio.ScalarImage(tensor)and labels astio.LabelMap(tensor); do not usesource=tensor. - Image tensors are 4D
(C, I, J, K)and loader batches are 5D(B, C, I, J, K). SubjectsLoaderreturns aSubjectsBatch: named images are accessed asbatch.t1.dataorbatch["t1"].data.- Patch locations are stored on individual patch subjects as
patch.patch_location; after batching, usebatch.metadata["patch_location"]. PatchAggregator.add_batch()expects model outputs shaped(B, C, I, J, K)and a list of onePatchLocationper batch item.
Minimal Dense Inference Pattern
sampler = tio.GridSampler(subject, patch_size=(64, 64, 64), patch_overlap=16)
loader = tio.SubjectsLoader(sampler, batch_size=4)
aggregator = tio.PatchAggregator(
spatial_shape=subject.spatial_shape,
overlap_mode="hann",
patch_overlap=16,
)
for batch in loader:
logits = model(batch.t1.data)
locations = batch.metadata["patch_location"]
aggregator.add_batch(logits, locations)
volume_logits = aggregator.get_output()
Minimal Training Queue Pattern
sampler = tio.UniformSampler(subjects[0], patch_size=(64, 64, 64))
queue = tio.Queue(
subjects,
patch_sampler=sampler,
max_length=300,
patches_per_volume=10,
num_workers=4,
transform=train_transform,
)
loader = tio.SubjectsLoader(queue, batch_size=16)
for batch in loader:
inputs = batch.t1.data
targets = batch.seg.data
loss = criterion(model(inputs), targets)
loss.backward()
Boundaries
- For creating
Subject,ScalarImage, andLabelMapobjects, use the parent data-model guidance. - For choosing augmentations or preprocessing transforms, use the transforms sub-skill.
- For command-line operations, use the CLI and I/O sub-skill.
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.