title: tensors are from different graphs
body: <p>I am new to tensorflow. Trying to create an input pipeline from <code>tfrecords</code>.
  Below is my code snippet to create batches and feed into my <code>estimator</code> :  </p>
  
  <pre><code>def generate_input_fn(image,label,batch_size=BATCH_SIZE):
      logging.info('creating batches...')    
      dataset = tf.data.Dataset.from_tensors((image, label)) #&lt;-- dataset is 'TensorDataset'
      dataset = dataset.repeat().batch(batch_size)
      iterator=dataset.make_initializable_iterator()
      iterator.initializer
      return iterator.get_next()
  </code></pre>
  
  <p>The line <code>iterator=dataset.make_initializable_iterator()</code>:</p>
  
  <blockquote>
    <p>ValueError: Tensor("count:0", shape=(), dtype=int64, device=/device:CPU:0) must be from the same graph as Tensor("TensorDataset:0", shape=(), dtype=variant).</p>
  </blockquote>
  
  <p>I think I am accidentally using tensors from different graphs, but I have no idea how and in which line of code. I have no idea which tensor is <strong>count:0</strong>
  or whichone is <strong>TensorDataset:0</strong>.</p>
  
  <p>Could anyone please help me debug this.</p>
  
  <p>Error log:</p>
  
  <pre><code>      File "task.py", line 189, in main
      estimator.train(input_fn=lambda:generate_input_fn(image=image_data, label=label_data),steps=3,hooks=[logging_hook])
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/estimator.py", line 352, in train
      loss = self._train_model(input_fn, hooks, saving_listeners)
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/estimator.py", line 809, in _train_model
      input_fn, model_fn_lib.ModeKeys.TRAIN))
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/estimator.py", line 668, in _get_features_and_labels_from_input_fn
      result = self._call_input_fn(input_fn, mode)
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/estimator.py", line 760, in _call_input_fn
      return input_fn(**kwargs)
    File "task.py", line 189, in &lt;lambda&gt;
      estimator.train(input_fn=lambda:generate_input_fn(image=image_data, label=label_data),steps=3,hooks=[logging_hook])
    File "task.py", line 152, in generate_input_fn
      iterator=dataset.make_initializable_iterator()
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/data/ops/dataset_ops.py", line 107, in make_initializable_iterator
      initializer = gen_dataset_ops.make_iterator(self._as_variant_tensor(),
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/data/ops/dataset_ops.py", line 1399, in _as_variant_tensor
      self._input_dataset._as_variant_tensor(),  # pylint: disable=protected-access
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/data/ops/dataset_ops.py", line 1156, in _as_variant_tensor
      sparse.as_dense_types(self.output_types, self.output_classes)))
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_dataset_ops.py", line 1696, in repeat_dataset
      output_types=output_types, output_shapes=output_shapes, name=name)
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 350, in _apply_op_helper
      g = ops._get_graph_from_inputs(_Flatten(keywords.values()))
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 5284, in _get_graph_from_inputs
      _assert_same_graph(original_graph_element, graph_element)
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 5220, in _assert_same_graph
      original_item))
  ValueError: Tensor("count:0", shape=(), dtype=int64, device=/device:CPU:0) must be from the same graph as Tensor("TensorDataset:0", shape=(), dtype=variant).
  </code></pre>
  
  <p>If I modify the function to:</p>
  
  <pre><code>image_placeholder=tf.placeholder(image.dtype,shape=image.shape)
  label_placeholder=tf.placeholder(label.dtype,shape=label.shape)
  dataset = tf.data.Dataset.from_tensors((image_placeholder, label_placeholder))
  </code></pre>
  
  <p>i.e. add placeholder, then I get output :</p>
  
  <pre><code>INFO:tensorflow:Create CheckpointSaverHook.
  INFO:tensorflow:Create CheckpointSaverHook.
  INFO:tensorflow:Graph was finalized.
  INFO:tensorflow:Graph was finalized.
  2018-03-18 01:56:55.902917: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
  Killed
  </code></pre>