Announcing the TensorFlow Dev Summit 2020 Learn more

tfds.as_numpy

View source on GitHub

Converts a tf.data.Dataset to an iterable of NumPy arrays.

tfds.as_numpy(
    dataset,
    graph=None
)

as_numpy converts a possibly nested structure of tf.data.Datasets and tf.Tensors to iterables of NumPy arrays and NumPy arrays, respectively.

Note that because TensorFlow has support for ragged tensors and NumPy has no equivalent representation, tf.RaggedTensors are left as-is for the user to deal with them (e.g. using to_list()). In TF 1 (i.e. graph mode), tf.RaggedTensors are returned as tf.ragged.RaggedTensorValues.

Args:

Returns:

A structure matching dataset where tf.data.Datasets are converted to generators of NumPy arrays and tf.Tensors are converted to NumPy arrays.