Skip to content

Commit a3ffb95

Browse files
Merge pull request #1401 from arpan-dhatt:master
PiperOrigin-RevId: 290795049
2 parents 2b1f605 + 6d44da4 commit a3ffb95

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tensorflow_datasets/core/dataset_utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ def as_numpy(dataset, graph=None):
191191
In TF 1 (i.e. graph mode), `tf.RaggedTensor`s are returned as
192192
`tf.ragged.RaggedTensorValue`s.
193193
194+
Example:
195+
196+
```
197+
ds = tfds.load(name="mnist", split="train")
198+
ds_numpy = tfds.as_numpy(ds) # Convert `tf.data.Dataset` to Python generator
199+
for ex in ds_numpy:
200+
# `{'image': np.array(shape=(28, 28, 1)), 'labels': np.array(shape=())}`
201+
print(ex)
202+
```
203+
194204
Args:
195205
dataset: a possibly nested structure of `tf.data.Dataset`s and/or
196206
`tf.Tensor`s.

0 commit comments

Comments
 (0)