title: Tensorflow Dataset API doubles graph protobuff filesize
body: <p><strong>Summary</strong>: Using the new tf.contrib.data.Dataset doubles the size of my graph protobuff file and I'm unable to visualize the graph in Tensorboard.</p>
  
  <p><strong>The details:</strong></p>
  
  <p>I'm trying out the new TensorFlow <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/docs_src/programmers_guide/datasets.md" rel="nofollow noreferrer"><code>tf.contrib.data.Dataset</code></a> functionality together with the <a href="https://www.tensorflow.org/api_docs/python/tf/contrib/learn/Experiment" rel="nofollow noreferrer"><code>tf.contrib.learn.Experiment</code></a> framework. My input data is defined as <a href="https://www.tensorflow.org/get_started/input_fn" rel="nofollow noreferrer">input functions</a> which return tensors of features and labels.</p>
  
  <p>If I create my input function with the <a href="https://www.tensorflow.org/api_docs/python/tf/train/slice_input_producer" rel="nofollow noreferrer"><code>tf.train.slice_input_producer</code></a> function like in the following codeblock (full code <a href="https://gist.github.com/peterroelants/bbb67fb4e7dad69c79102fec90737a53#file-mnist_old_data-py" rel="nofollow noreferrer">here</a>), then my resulting <code>graph.pbtxt</code> file is 620M and the <code>.meta</code> files are around 165M in size.</p>
  
  <pre><code>def train_inputs():
      with tf.name_scope('Training_data'):
          x = tf.constant(mnist.train.images.reshape([-1, 28, 28, 1]))
          y = tf.constant(mnist.train.labels)
          sliced_input = tf.train.slice_input_producer(
              tensor_list=[x, y], shuffle=True)
          return tf.train.shuffle_batch(
              sliced_input, batch_size=batch_size,
              capacity=10000, min_after_dequeue=batch_size*10)
  </code></pre>
  
  <p>Now if I create my input function with the new <a href="https://www.tensorflow.org/api_docs/python/tf/contrib/data/Dataset#from_tensor_slices" rel="nofollow noreferrer"><code>tf.contrib.data.Dataset.from_tensor_slices</code></a> like in the following codeblock (full code <a href="https://gist.github.com/peterroelants/bbb67fb4e7dad69c79102fec90737a53#file-mnist_new_dataset-py" rel="nofollow noreferrer">here</a>), then my resulting <code>graph.pbtxt</code> file doubles in size to 1.3G and the <code>.meta</code> files double in size to 330M. </p>
  
  <pre><code>def train_inputs():
      with tf.name_scope('Training_data'):
          images = mnist.train.images.reshape([-1, 28, 28, 1])
          labels = mnist.train.labels
          dataset = tf.contrib.data.Dataset.from_tensor_slices(
              (images, labels))
          dataset = dataset.repeat(None)  # Infinite
          dataset = dataset.shuffle(buffer_size=10000)
          dataset = dataset.batch(batch_size)
          iterator = dataset.make_one_shot_iterator()
          next_example, next_label = iterator.get_next()
          return next_example, next_label
  </code></pre>
  
  <p>Now because the <code>graph.pbtxt</code> file is so big TensorBoard takes ages to parse this file, and I'm unable to debug my model graph visually.
  I found in the <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/docs_src/programmers_guide/datasets.md" rel="nofollow noreferrer">Dataset documentation</a> that this increase in size comes from: <em>"the contents of the array will be copied multiple times"</em> and the <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/docs_src/programmers_guide/datasets.md#consuming-numpy-arrays" rel="nofollow noreferrer">solution</a> would be to use placeholders. However, in this case, I would need to feed in the numpy arrays into the placeholders with an active session to initialize the iterator:</p>
  
  <pre><code>sess.run(iterator.initializer, feed_dict={features_placeholder: features, labels_placeholder: labels})
  </code></pre>
  
  <p>This seems, however, to be out of my control when using the <code>tf.contrib.learn.Experiment</code> framework.</p>
  
  <p>How can I initialize the iterator's initialiser with the Experiment framework? Or find a workaround to using the Dataset API without increasing my graph size?</p>