Make subject batching lossless - #1494
Conversation
📖 Docs PreviewPreview of the documentation for this PR: 🔗 https://smokeshow.helpmanual.io/113u4m4m4d1y4e2f4a0t/ Built from 8fa6c2e |
There was a problem hiding this comment.
Pull request overview
This PR makes batching/unbatching of Subject/Image data lossless by validating schemas before stacking and preserving per-element payload (metadata, annotations, subclasses) and transform histories. It also introduces safer subject-wise processing via SubjectsBatch.map_subjects() and explicitly rejects spatial transforms when annotations are present (until coordinate updates are supported).
Changes:
- Add full schema validation for subjects/images before stacking, and preserve nested metadata/annotations + image subclass identity across batch round-trips.
- Track and round-trip both shared and per-element transform histories for
ImagesBatchandSubjectsBatch, including during wrapping/unwrapping inTransform. - Add
SubjectsBatch.map_subjects()and enforce annotation restrictions for spatial transforms (including lazy spatial forwards).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_transforms_base.py | Adjust tests to use a subject containing multiple images + metadata. |
| tests/test_batch.py | Add coverage for payload/history round-trips, schema validation, metadata/annotation-only batching, and map_subjects(). |
| src/torchio/transforms/transform.py | Preserve histories when wrapping/unwrapping batches and reject spatial transforms with annotations. |
| src/torchio/transforms/spatial/ensure_shape_multiple.py | Apply spatial-annotation rejection in the lazy forward path. |
| src/torchio/transforms/spatial/crop_or_pad.py | Apply spatial-annotation rejection in the lazy forward path. |
| src/torchio/data/batch.py | Implement lossless batching for images/subjects: schema validation, payload templates, annotation stores, and history helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4bd8001 to
2ea69be
Compare
4be07a8 to
a13d20a
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
f239e5b to
8fa6c2e
Compare
|
[Generated by a coding agent] Superseded by the simpler replacement stack:
The replacement keeps the same features while removing optional template state, shared/per-element history duality, and persisted private batching keys. |
[Generated by a coding agent]
Summary
SubjectsBatch.map_subjects()for safe subject-wise processingValidation
Stack (merge bottom-up)