preprocessing
Preprocessing Utility API
This module provides utility functions for preprocessing data.
Functions:
-
parse_factor
–Parse factor
-
convert_inputs_to_tf_dataset
–Convert inputs to tf.data.Dataset
-
create_interleaved_dataset_from_generator
–Create interleaved dataset from generator
-
create_dataset_from_data
–Create dataset from data
-
get_output_signature
–Get output signature
-
get_output_signature_from_fn
–Get output signature from function
-
get_output_signature_from_gen
–Get output signature from generator
Functions
convert_inputs_to_tf_dataset
Convert inputs to tf.data.Dataset.
Source code in neuralspot_edge/utils/preprocessing.py
create_interleaved_dataset_from_generator
create_interleaved_dataset_from_generator(data_generator: Callable[[Generator[T, None, None]], Generator[K, None, None]], id_generator: Callable[[list[T]], Generator[T, None, None]], ids: list[T], spec: tuple[tf.TensorSpec, tf.TensorSpec], preprocess: Callable[[K], K] | None = None, num_workers: int = 4) -> tf.data.Dataset
Create TF dataset pipeline by interleaving multiple workers across ids
The id_generator is used to generate ids for each worker. The data_generator is used to generate data for each id.
Parameters:
-
data_generator
(Callable[[Generator[T, None, None]], Generator[K, None, None]]
) –Data generator
-
id_generator
(Callable[[list[T]], Generator[T, None, None]]
) –Id generator
-
ids
(list[T]
) –List of ids
-
spec
(tuple[TensorSpec, TensorSpec]
) –Tensor spec
-
preprocess
(Callable[[K], K] | None
, default:None
) –Preprocess function. Defaults to None.
-
num_workers
(int
, default:4
) –Number of workers. Defaults to 4.
Returns:
-
Dataset
–tf.data.Dataset: Dataset
Source code in neuralspot_edge/utils/preprocessing.py
create_dataset_from_data
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:
Returns:
-
Dataset
–tf.data.Dataset: Dataset
Source code in neuralspot_edge/utils/preprocessing.py
get_output_signature
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:
-
outputs
(KerasTensor | NDArray | tuple[KerasTensor | NDArray]
) –Outputs. A tensor or tuple of tensors. Either KerasTensor, tf.Tensor, or numpy array.
Returns:
-
TensorSpec | tuple[TensorSpec]
–tf.TensorSpec: Tensor spec
Source code in neuralspot_edge/utils/preprocessing.py
get_output_signature_from_fn
get_output_signature_from_fn(fn: Callable[..., keras.KerasTensor], *args) -> tf.TensorSpec | tuple[tf.TensorSpec]
get_output_signature_from_gen
get_output_signature_from_gen(gen: Generator[T, None, None], *args) -> tf.TensorSpec | tuple[tf.TensorSpec]