StackDataset
DatasetStackDataset(args: Dataset = (), kwargs: Dataset = {})Bundle several map-style datasets so each index returns a stacked tuple.
The bundled datasets must agree in length. Item i is the tuple
(d_1[i], d_2[i], \dots, d_K[i]) for each child dataset — handy
when paired modalities (image, caption, label) live in separate
sources but share a common index.
Accepts either positional children (StackDataset(d1, d2)) or
keyword children (StackDataset(image=d1, label=d2)); the two
forms are mutually exclusive. Positional construction returns
tuples; keyword construction returns dicts keyed by the supplied
names.
Parameters
*argsDataset= ()**kwargs.**kwargsDataset= {}*args.Notes
Equivalent in spirit to a per-index zip across child datasets,
but exposed as a Dataset so it can drive a sampler-based
DataLoader. All children must satisfy len(d_k) == n
for some shared n; otherwise construction raises ValueError.
Examples
>>> images = TensorDataset(X_img)
>>> labels = TensorDataset(y_lbl)
>>> ds = StackDataset(image=images, label=labels)
>>> sample = ds[0]
>>> sorted(sample.keys())
['image', 'label']Methods (3)
__init__
→None__init__(args: Dataset = (), kwargs: Dataset = {})Bundle child datasets either positionally or by keyword.
Parameters
*argsDataset= ()**kwargsDataset= {}Raises
ValueError__len__
→int__len__()Return the common length shared by all bundled child datasets.
__getitem__
→tuple or dict__getitem__(idx: int)Return one sample drawn from each child at index idx.
Parameters
idxintReturns
tuple or dictA tuple of child samples if the dataset was built positionally, otherwise a dict keyed by the keyword names supplied at construction time.