算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
patch-workflows【设计与创意】Design TorchIO patch-based training queues and dense patch inference loops with samplers, SubjectsLoader batches, PatchLocation metadata, and PatchAggregator.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
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.
GridSampler plus PatchAggregator; see dense inference.UniformSampler, WeightedSampler, or LabelSampler, optionally buffered by Queue; see training queues.python scripts/patch_workflow_smoke.py --help, then python scripts/patch_workflow_smoke.py from this sub-skill directory.tio.ScalarImage(tensor) and labels as tio.LabelMap(tensor); do not use source=tensor.(C, I, J, K) and loader batches are 5D (B, C, I, J, K).SubjectsLoader returns a SubjectsBatch: named images are accessed as batch.t1.data or batch["t1"].data.patch.patch_location; after batching, use batch.metadata["patch_location"].PatchAggregator.add_batch() expects model outputs shaped (B, C, I, J, K) and a list of one PatchLocation per batch item.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()
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()
Subject, ScalarImage, and LabelMap objects, use the parent data-model guidance.