Skip to content
heliaEDGE
Reference
HELIA

tf_data

TensorFlow tf.data adapters: generators, arrays and batches from other loaders.

Machine-readable model

function

Adapt caller-owned schedules to tf.data without changing sample weights.

helia_edge/data/tf_data.py:56

create_interleaved_dataset_from_generator(
data_generator: Callable[[Iterator[T]], Iterable[K]],
id_generator: Callable[[list[T]], Iterator[T]],
ids: list[T],
spec: tf.TensorSpec | tuple[tf.TensorSpec, ...] | dict[str, tf.TensorSpec],
preprocess: Callable[[K], K] | None = None,
num_workers: int = 4,
*,
stream_mode: StreamMode | str = StreamMode.GLOBAL,
deterministic: bool = True,
) -> tf.data.Dataset

Adapt caller-owned schedules to tf.data without changing sample weights.

GLOBAL preserves one finite/repeated stream. FINITE partitions terminating, partition-independent generators; deterministic mode preserves partition order. num_workers counts generators, not processes. See https://ambiqai.github.io/helia-edge/guide/input-pipeline/.

function

Helper function to create dataset from static data

helia_edge/data/tf_data.py:124

create_dataset_from_data(x: npt.NDArray, y: npt.NDArray, spec: tuple[tf.TensorSpec, ...]) -> tf.data.Dataset

Helper function to create dataset from static data

Parameters of create_dataset_from_data
NameTypeDefaultDescription
xnpt.NDArrayRequiredNumpy data
ynpt.NDArrayRequiredNumpy labels
Returns of create_dataset_from_data
TypeDescription
tf.data.Datasettf.data.Dataset: Dataset
function

Get output signature from sample outputs

helia_edge/data/tf_data.py:139

get_output_signature(
outputs: keras.KerasTensor | npt.NDArray | tuple[keras.KerasTensor | npt.NDArray],
) -> tf.TensorSpec | tuple[tf.TensorSpec, ...]

Get output signature from sample outputs

Parameters of get_output_signature
NameTypeDefaultDescription
outputskeras.KerasTensor | npt.NDArray | tuple[keras.KerasTensor | npt.NDArray]RequiredOutputs. A tensor or tuple of tensors. Either KerasTensor, tf.Tensor, or numpy array.
Returns of get_output_signature
TypeDescription
tf.TensorSpec | tuple[tf.TensorSpec, ...]tf.TensorSpec: Tensor spec
function

Get output signature from a function

helia_edge/data/tf_data.py:165

get_output_signature_from_fn(
fn: Callable[..., keras.KerasTensor],
*args=(),
) -> tf.TensorSpec | tuple[tf.TensorSpec, ...]

Get output signature from a function

Parameters of get_output_signature_from_fn
NameTypeDefaultDescription
fnCallable[..., tf.Tensor]RequiredFunction
Returns of get_output_signature_from_fn
TypeDescription
tf.TensorSpec | tuple[tf.TensorSpec, ...]tf.TensorSpec: Tensor spec
function

Get output signature from a generator

helia_edge/data/tf_data.py:179

get_output_signature_from_gen(
gen: Callable[..., Iterator[Any]],
*args: Any = (),
) -> tf.TensorSpec | tuple[tf.TensorSpec, ...]

Get output signature from a generator

Parameters of get_output_signature_from_gen
NameTypeDefaultDescription
genCallable[..., Iterator[Any]]RequiredGenerator factory
Returns of get_output_signature_from_gen
TypeDescription
tf.TensorSpec | tuple[tf.TensorSpec, ...]tf.TensorSpec: Tensor spec
function

Wrap a re-iterable of NumPy batches, such as a Grain dataset, as a tf.data.Dataset.

helia_edge/data/tf_data.py:193

to_tf_dataset(dataset: Iterable[Any], output_signature: tf.TensorSpec | tuple | dict[str, Any]) -> tf.data.Dataset

Wrap a re-iterable of NumPy batches, such as a Grain dataset, as a tf.data.Dataset.

Elements pass through in order, one iter(dataset) per pass of the returned dataset; nothing is batched, shuffled or read in parallel here. Do that in dataset.

Parameters of to_tf_dataset
NameTypeDefaultDescription
datasetIterable[Any]RequiredRe-iterable whose ``iter()`` starts from the first element.
output_signaturetf.TensorSpec | tuple | dict[str, Any]Required``tf.TensorSpec`` structure matching one element. Use ``None`` for a batch dimension that varies, such as a smaller last batch.
Returns of to_tf_dataset
TypeDescription
tf.data.Datasettf.data.Dataset: Built with ``tf.data.Dataset.from_generator``.
Errors raised by to_tf_dataset
TypeDescription
ImportErrorIf TensorFlow is not installed (``helia-edge[tensorflow]``).