1

I am using Tensorflow 1.14.0 and tensorflow_datasets 1.2.0

When trying to run the following code

import tensorflow as tf
import tensorflow_datasets as tfds

smallnorb = tfds.load("smallnorb")
smallnorb_train, smallnorb_test = smallnorb["train"], smallnorb["test"]
assert isinstance(smallnorb_train, tf.data.Dataset)
smallnorb_train = smallnorb_train.as_numpy_iterator()

I get the following error

AttributeError: 'DatasetV1Adapter' object has no attribute 'as_numpy_iterator'

According to the tensorflow_datasets docs this should work.

Why won't it? And why am I getting a DatasetV1Adapter object in the first place?

2 Answers 2

4

You are using wrong tensorflow and tensorflow_datasets versions.

Please use 2.x unless you need 1.x for some very specific reasons.

This code works if you use tensorflow 2.1.0 and tensorflow_datasets 2.0.0. Proper documentation for 1.x of tf.data.Dataset can be found here and it has no such method indeed.

1

As @szymon mentioned, tensorflow-1.14 does not support the as_numpy_iterator. You should move your code to tf>=2.0

A handy tip which I frequently use is firing up a REPL python shell in one of the bash shells and use dir(tf.data.Dataset) to list all the attributes & methods that can be called from that object. You can further use the help(tf.data.Dataset.xxx) for parameters and return values of that method.

>>> import tensorflow as tf
>>> dir(tf.data.Dataset) 
... <output>

>>> help(tf.data.Dataset.from_tensor_slices)
... and so on

If you do the same, you'll find that as_numpy_iterator won't be present in the dir(tf.data.Dataset) list output, hence the error.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.