tfds.as_numpy | TensorFlow Datasets (original) (raw)
tfds.as_numpy
Stay organized with collections Save and categorize content based on your preferences.
Converts a tf.data.Dataset to an iterable of NumPy arrays.
tfds.as_numpy(
dataset: Tree[TensorflowElem]
) -> Tree[NumpyElem]
Used in the notebooks
Used in the tutorials |
---|
TensorFlow Datasets Text Classification with Movie Reviews Assess privacy risks with the TensorFlow Privacy Report Distributed Inference with JAX Generating Images with BigBiGAN |
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.RaggedTensorsare 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 astf.ragged.RaggedTensorValue
s.
Example:
ds = tfds.load(name="mnist", split="train")
ds_numpy = tfds.as_numpy(ds) # Convert `tf.data.Dataset` to Python generator
for ex in ds_numpy:
# `{'image': np.array(shape=(28, 28, 1)), 'labels': np.array(shape=())}`
print(ex)
Args | |
---|---|
dataset | a possibly nested structure of tf.data.Datasets and/ortf.Tensors. |
Returns |
---|
A structure matching dataset where tf.data.Datasets are converted to generators of NumPy arrays and tf.Tensors are converted to NumPy arrays. |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-04-26 UTC.