Wascally Wabbit
Wascally Wabbit

Reputation: 49

Initializing a basic, one-shot iterator in tensorflow

I am a new user of tensorflow, and am working with Datasets. As a primer, I have copied and used the following sample code from the tensorflow site:

# the sample code doesn't tell me where the session comes from, so I wrote these few lines:
def my_initializer():
    return tf.global_variables_initializer()
sess = tf.InteractiveSession()
my_initializer()

# back to sample code
dataset = tf.contrib.data.Dataset.range(100)
iterator = dataset.make_one_shot_iterator()
next_element = iterator.get_next()

for i in range(100):
  value = sess.run(next_element)  # <--- death stalks this line
  assert i == value

On the 1st call to sess.run() I see the following error:

NotFoundError (see above for traceback): Function _make_dataset_989f6fa6 is not defined. [[Node: OneShotIterator = OneShotIteratorcontainer="", dataset_factory=_make_dataset_989f6fa6[], output_shapes=[[]], output_types=[DT_INT64], shared_name="", _device="/job:localhost/replica:0/task:0/cpu:0"]]

I have been bitten by a similar error every time I try to use an iterator. The objective here is simply to get a handle on the basic mechanics of feeding data to a graph. I do have a graph, but I have left it out of this post, because I don't think that is the problem at all.

Obviously, I am not understanding something very simple. Could someone help me out? Thank you.

Upvotes: 1

Views: 3285

Answers (1)

mrry
mrry

Reputation: 126154

If you see the error message "Function ... is not defined" when creating a tf.data.Dataset or tf.data.Iterator, upgrade to a newer version of TensorFlow. The error message is caused by a bug in TensorFlow 1.2, which was fixed in TensorFlow 1.3.

Upvotes: 1

Related Questions