omniloader.loader¶
The OmniLoader meta-dataset that unifies several disjoint datasets.
OmniLoader concatenates any number of source datasets, each paired with
a DatasetSchema, and presents them as one dataset whose
every sample follows the shared UnifiedSchema. Keys a
given source lacks are filled with placeholder tensors and all-False masks by
the SampleUnifier, so a single batch may freely mix
samples from different datasets. A MixingStrategy
(obtained via OmniLoader.make_sampler()) controls how the datasets are
balanced across an epoch.
Classes¶
A map-style dataset that reports its length and returns dict samples. |
|
Unify multiple datasets into a single masked, concatenated dataset. |
Module Contents¶
- class omniloader.loader.SizedDataset[source]¶
Bases:
ProtocolA map-style dataset that reports its length and returns dict samples.
- class omniloader.loader.OmniLoader(datasets: collections.abc.Sequence[SizedDataset], schemas: collections.abc.Sequence[omniloader.schema.spec.DatasetSchema], schema: omniloader.schema.spec.UnifiedSchema | None = None, pad_features: bool = True, transform: omniloader.transforms.Transform | None = None, training: bool = True, seed: int = 0)[source]¶
Bases:
torch.utils.data.DatasetUnify multiple datasets into a single masked, concatenated dataset.
- Parameters:
datasets – The source datasets. Each must implement
__len__and return adictfrom__getitem__.schemas – One
DatasetSchemaper dataset, declaring what it provides. Merged into aUnifiedSchemawhenschemais not given.schema – Optional pre-built unified schema. When
None, it is the union ofschemas.pad_features – Whether the unifier pads/crops sequence values to their declared
time_dim. SeeSampleUnifier.transform – Optional per-sample transform (normalization/augmentation) applied after unification. See
omniloader.transforms.training – Whether augmentations in
transformare active. SetFalsefor validation/test loaders.seed – Base seed for per-sample augmentation randomness. Combined with the current epoch (see
set_epoch()) and the sample index so that augmentation is reproducible and independent of worker count.
- Raises:
ValueError – If
datasetsis empty or its length differs fromschemas.
- set_epoch(epoch: int) None[source]¶
Set the epoch used to seed per-sample augmentation.
Call once per epoch (the
OmniDataModuledoes this automatically) so augmentation differs across epochs yet stays reproducible.- Parameters:
epoch – The upcoming epoch number.
- locate(index: int) tuple[int, int][source]¶
Map a global index to
(dataset_index, local_index).- Parameters:
index – Global index in
[0, len(self)). Negative indices count from the end.- Returns:
The owning dataset’s position and the local index within it.
- Raises:
IndexError – If
indexis out of range.
- __getitem__(index: int) dict[str, Any][source]¶
Return the unified sample at a global index.
- Parameters:
index – Global index into the concatenated dataset.
- Returns:
The sample mapped onto the unified schema with masks and metadata.
- describe(max_samples: int = 64) omniloader.introspection.Report[source]¶
Summarise this loader’s datasets (coverage, valid fractions, classes).
- Parameters:
max_samples – Samples read per dataset for the statistics.
- Returns:
A
Report.
- validate(num_samples: int = 4, strict: bool = False) list[str][source]¶
Check each dataset’s raw samples against its declared specs.
- Parameters:
num_samples – Samples probed per dataset.
strict – Raise
ValueErrorif any mismatch is found.
- Returns:
A list of issue strings (empty when everything matches).
- sequence_lengths(key: str) list[int][source]¶
Return the native sequence length of
keyfor every sample.Reads each source sample’s raw value (bypassing unification/transforms) and reports the length of its sequence axis, or
0when the sample lacks the key. Intended to feedLengthBucketBatchSampler.Note
This iterates the entire dataset once —
O(N)reads. For HDF5 back ends prefer computing it once and caching the result.- Parameters:
key – A sequence feature or target name.
- Returns:
A list of per-sample lengths, indexed by global sample index.
- make_sampler(strategy: omniloader.sampling.strategies.MixingStrategy | None = None, seed: int = 0, subsample: collections.abc.Sequence[omniloader.sampling.strategies.SubsampleConfig | None] | None = None, epoch: int = 0) omniloader.sampling.sampler.OmniSampler[source]¶
Build an
OmniSamplerfor driving aDataLoader.- Parameters:
strategy – A mixing strategy. When
None, aProportionalStrategyover the dataset sizes is used.seed – Base seed for the default strategy (ignored if
strategyis given).subsample – Per-dataset subsample configs for the default strategy.
epoch – Initial epoch for the sampler.
- Returns:
A sampler yielding global indices per epoch.