Replacing tf.placeholder and feed_dict with tf.data API Replacing tf.placeholder and feed_dict with tf.data API python python

Replacing tf.placeholder and feed_dict with tf.data API


It took a bit for me to get my head around too. You're on the right track. The entire Dataset definition is just part of the graph. I generally create it as a different class from my Model class and pass the dataset into the Model class. I specify the Dataset class I want to load on the command line and then load that class dynamically, thereby decoupling the Dataset and the graph modularly.

Notice that you can (and should) name all the tensors in the Dataset, it really helps make things easy to understand as you pass data through the various transformations you'll need.

You can write simple test cases that pull samples from the iterator.get_next() and displays them, you'll have something like sess.run(next_element_tensor), no feed_dict as you've correctly noted.

Once you get your head around it you'll probably start liking the Dataset input pipeline. It forces you to modularize your code well, and it forces it into a structure that's easy to unit test.

Make sure you read the developers guide, there are tons of examples there:

https://www.tensorflow.org/programmers_guide/datasets

Another thing I'll note is how easy it is to work with a train and test dataset with this pipeline. That's important because you often perform data augmentation on the training dataset that you don't perform on the test dataset, from_string_handle allows you to do that and is clearly described in the guide above.


The line tf.reset_default_graph() in the constructor of the model from the original code I was given was causing it. Removing that fixed it.