(prototype) Add the View and Sample batch contract - #2033
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e2b3eec69a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for key in split[0][1]: | ||
| values = [meta[key] for _, meta in split] |
There was a problem hiding this comment.
Reject mismatched metadata before batching
When a batch mixes supported item forms, such as a view-only item followed by (views, target, filename) (for example at a ConcatDataset boundary), iterating only over the first item's metadata silently discards every target and filename from later items; reversing the same batch instead raises KeyError. Validate that all metadata key sets agree, as is already done for view counts and extras, so batch contents and ordering cannot determine whether labels are lost.
Useful? React with 👍 / 👎.
1 of 7 in a stack. Base:
master.A transform returns
list[Tensor]today, which covers two of the seven cases the library already serves, and it forked once intoMultiViewTransformV2because it could not carry a mask. Four incompatible return contracts ship right now and no caller can write one loop over them.Viewcarries the tensor plus what it is: a stream, a role, and anextrasdict for a mask, a grid or patch ids.Sampleholds the views and per-samplemeta, withby_roleandby_stream. Onecollatestacksdataand everyextrasentry, and takes no configuration because everything it needs arrived with the data.legacy_collateyields the old(views, labels, filenames).Nothing uses it yet. The transforms move in PR 5 of this stack.
collateis not re-exported fromlightly.data: the name is taken by the deprecatedlightly.data.collatemodule until that goes. Import it fromlightly.data.sample.One import fix rides along.
lightly/data/collate.pynow importsGaussianBlurand friends from their own modules, because going through thelightly.transformspackage closes an import loop once transforms needView.Testing:
pytest tests/data/test_sample.py, 10 cases covering stacking, extras, ragged batches and views labelled differently across samples.