Can't convert a object to a numpy iterator


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,
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?


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 can be found here and it has no such method indeed.

Answered By – Szymon Maszke

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published