omniloader.schema.spec¶
Declarative schema for features and targets across heterogeneous datasets.
The building blocks here let each dataset declare what it provides (features and targets, their shapes, dtypes and placeholder values) without committing to how those values are stored or what modality they represent. Everything is described in purely structural terms:
a vector value has no sequence axis — shape
()(a scalar) or(F,);a sequence value has a leading sequence axis of length
T— shape(T,)or(T, F).
A spec is a sequence exactly when its time_dim is set; otherwise it is a
vector. No modality (video/audio/text/…) or model concept appears anywhere.
UnifiedSchema merges the per-dataset declarations into the single union
schema that SampleUnifier uses to bring every raw
sample into a common, masked format.
Classes¶
Structural declaration of a single named value (a feature or a target). |
|
The set of features and targets a single dataset provides. |
|
Union of several |
Functions¶
|
Resolve a dtype given as a string or |
Module Contents¶
- omniloader.schema.spec.resolve_dtype(dtype: str | torch.dtype) torch.dtype[source]¶
Resolve a dtype given as a string or
torch.dtype.- Parameters:
dtype – Either a
torch.dtypeor one of the string keys in_DTYPES(e.g."float32").- Returns:
The corresponding
torch.dtype.- Raises:
ValueError – If
dtypeis a string that is not a known dtype name.
- class omniloader.schema.spec.TensorSpec[source]¶
Structural declaration of a single named value (a feature or a target).
The same spec type describes both inputs and supervision targets; its role is determined by whether it is placed in
DatasetSchema.featuresorDatasetSchema.targets.The shape is derived from two independent, optional axes plus an optional trailing shape:
time_dim— lengthTof the sequence axis. WhenNonethe value is a vector (no sequence axis); when set the value is a sequence.feature_dim— sizeFof the trailing feature axis. WhenNonethe value is a scalar along that axis. Sugar forshape=(F,).shape— the full trailing shape for structured values that are not a single flat feature axis, e.g. an image(C, H, W). Mutually exclusive withfeature_dim.
So the representable shapes are
(),(F,),(T,),(T, F)and, withshapeset,(*shape,)or(T, *shape)— covering scalar labels, feature vectors, scalar sequences (e.g. one value per step), feature sequences, and structured (e.g. image) sequences:TensorSpec( name="eye_image", time_dim=15, # T shape=(3, 64, 64), # C, H, W dtype=torch.float32, ) # value_shape == (15, 3, 64, 64); mask_shape == (15,)
A structured value is masked exactly like a feature sequence: one flag per time step, valid or not as a whole (no per-pixel masking).
- Parameters:
name – Unique key under which the value appears in a sample dict.
feature_dim – Size of the trailing feature axis
F.Nonefor a scalar along that axis. Mutually exclusive withshape.shape – Full trailing (non-time) shape, for structured values such as images. Mutually exclusive with
feature_dim.time_dim – Length
Tof the sequence axis.Nonefor a vector.dtype – Element dtype, as a
torch.dtypeor string name.placeholder – Fill value used when a dataset does not provide this key. Defaults to
0(use e.g.-1as an ignore index for class ids).
- property is_sequence: bool¶
Whether the value has a sequence axis (
time_dimis set).
- property trailing_shape: tuple[int, ...]¶
The non-time trailing shape, from
shapeorfeature_dim.- Returns:
self.shapeif set, else(feature_dim,)if set, else().
- property value_shape: tuple[int, ...]¶
Shape of the placeholder value tensor for a single sample.
- Returns:
trailing_shape, prefixed withtime_dimwhen the spec is a sequence.
- property mask_shape: tuple[int, ...]¶
Shape of the boolean validity mask for a single sample.
- Returns:
(T,)for a sequence value (one flag per step) and()for a vector value (one flag for the whole value).
- class omniloader.schema.spec.DatasetSchema[source]¶
The set of features and targets a single dataset provides.
A value is a feature or a target purely by which list it is placed in; both use the same
TensorSpec.- Parameters:
features – Input feature specs the dataset supplies.
targets – Supervision target specs the dataset supplies.
- property specs: list[TensorSpec]¶
All feature and target specs concatenated.
- property keys: set[str]¶
Names of every feature and target the dataset provides.
- class omniloader.schema.spec.UnifiedSchema(schemas: list[DatasetSchema])[source]¶
Union of several
DatasetSchemaobjects into one shared schema.The unified schema is the deduplicated union of every feature and target across the input datasets. Specs that share a name must agree on shape and dtype. Order is preserved: features/targets appear in the order they are first encountered.
- Parameters:
schemas – Per-dataset schemas to merge.
- property specs: list[TensorSpec]¶
All feature and target specs in the unified schema.
- property feature_keys: list[str]¶
Names of the input features in schema order.
- property target_keys: list[str]¶
Names of the supervision targets in schema order.
- property keys: set[str]¶
Names of every feature and target in the unified schema.
- spec(name: str) TensorSpec[source]¶
Return the spec registered under
name.- Parameters:
name – Feature or target name.
- Returns:
The matching
TensorSpec.- Raises:
KeyError – If no spec with that name exists.