omniloader.data.splits¶
Reproducible train/val/test index splitting.
split_indices() partitions range(n) into named splits by ratio, with an
optional stratification label so each split preserves the class proportions.
save_split_info() / load_split_info() persist the result (plus the
seed and ratios) so the exact split can be reused across runs.
Attributes¶
Functions¶
|
Partition |
|
Save splits (and optional metadata like seed/ratios) to JSON. |
|
Load the |
Module Contents¶
- omniloader.data.splits.DEFAULT_NAMES = ('train', 'valid', 'test')¶
- omniloader.data.splits.split_indices(n: int, ratios: collections.abc.Sequence[float] = (0.8, 0.1, 0.1), seed: int = 0, stratify: collections.abc.Sequence[int] | None = None, names: collections.abc.Sequence[str] = DEFAULT_NAMES) dict[str, list[int]][source]¶
Partition
range(n)into named, reproducible splits.- Parameters:
n – Number of samples to split.
ratios – Relative sizes per split (need not sum to one).
seed – Seed for the shuffle.
stratify – Optional per-index class labels of length
n; when given, each class is split byratiosso proportions are preserved.names – Split names, aligned with
ratios.
- Returns:
Mapping of split name to a sorted list of indices; the splits are disjoint and cover
range(n).- Raises:
ValueError – If
ratios/namesmismatch orstratifyhas the wrong length.
- omniloader.data.splits.save_split_info(splits: dict[str, list[int]], path: str | pathlib.Path, meta: dict[str, Any] | None = None) None[source]¶
Save splits (and optional metadata like seed/ratios) to JSON.
- Parameters:
splits – The split mapping from
split_indices().path – Destination
.jsonfile.meta – Optional extra fields (e.g.
{"seed": 0, "ratios": [...]}).
- omniloader.data.splits.load_split_info(path: str | pathlib.Path) dict[str, list[int]][source]¶
Load the
splitsmapping saved bysave_split_info().- Parameters:
path – Path to a JSON file written by
save_split_info().- Returns:
The split-name to index-list mapping.