title: "TypeError: 'Tensor' object is not iterable" error with tensorflow Estimator
body: <p>I have a procedurally generated (infinite) data source and am trying to use this as input to the high-level Tensorflow <code>Estimator</code> to train a image-based 3D object detector.</p>
  
  <p>I set up the Dataset just as in the Tensorflor Estimator <a href="https://www.tensorflow.org/get_started/estimator#complete_neural_network_source_code" rel="noreferrer">Quickstart</a>, and my <code>dataset_input_fn</code> returns a tuple of features and labels <code>Tensor</code>'s, just as the <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/estimator/estimator.py#L264-L266" rel="noreferrer"><code>Estimator.train</code></a> function specifies, and how this <a href="https://www.tensorflow.org/programmers_guide/datasets#using_high-level_apis" rel="noreferrer">tutorial shows</a>, but I am getting an error when trying to call the train function:</p>
  
  <p><code>TypeError: 'Tensor' object is not iterable.</code></p>
  
  <p>What am I doing wrong?</p>
  
  <hr>
  
  <pre><code>    def data_generator():
          """
          Generator for image (features) and ground truth object positions (labels)
  
          Sample an image and object positions from a procedurally generated data source
          """
          while True:
              source.step()  # generate next data point
  
              object_ground_truth = source.get_ground_truth() # list of 9 floats
              cam_img = source.get_cam_frame()  # image (224, 224, 3) 
              yield (cam_img, object_ground_truth)
  
      def dataset_input_fn():
          """
          Tensorflow `Dataset` object from generator
          """
  
          dataset = tf.data.Dataset.from_generator(data_generator, (tf.uint8, tf.float32), \
              (tf.TensorShape([224, 224, 3]), tf.TensorShape([9])))
          dataset = dataset.batch(16)
  
          iterator = dataset.make_one_shot_iterator()
  
          features, labels = iterator.get_next()
          return features, labels
  
      def main():
          """
          Estimator [from Keras model](https://www.tensorflow.org/programmers_guide/estimators#creating_estimators_from_keras_models) 
  
          Try to call `est_vgg.train()` leads to the error
          """
          ....
          est_vgg16 = tf.keras.estimator.model_to_estimator(keras_model=keras_vgg16)
          est_vgg16.train(input_fn=dataset_input_fn, steps=10)
          ....
  </code></pre>
  
  <p>Here is the <a href="https://github.com/matwilso/rock_detector/blob/79b092f261aaf31e5088bcc8a03ee925fe5cda2e/rock_detector.py#L118" rel="noreferrer">full code</a> </p>
  
  <p>(note: things are named differently from this question)</p>
  
  <p>Here is the stack trace:</p>
  
  <pre><code>Traceback (most recent call last):
    File "./rock_detector.py", line 155, in &lt;module&gt;
      main()
    File "./rock_detector.py", line 117, in main
      est_vgg16.train(input_fn=dataset_input_fn, steps=10)
    File "/usr/local/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 302, in train
      loss = self._train_model(input_fn, hooks, saving_listeners)
    File "/usr/local/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 711, in _train_model
      features, labels, model_fn_lib.ModeKeys.TRAIN, self.config)
    File "/usr/local/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 694, in _call_model_fn
      model_fn_results = self._model_fn(features=features, **kwargs)
    File "/usr/local/lib/python3.6/site-packages/tensorflow/python/keras/_impl/keras/estimator.py", line 145, in model_fn
      labels)
    File "/usr/local/lib/python3.6/site-packages/tensorflow/python/keras/_impl/keras/estimator.py", line 92, in _clone_and_build_model
      keras_model, features)
    File "/usr/local/lib/python3.6/site-packages/tensorflow/python/keras/_impl/keras/estimator.py", line 58, in _create_ordered_io
      for key in estimator_io_dict:
    File "/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 505, in __iter__
      raise TypeError("'Tensor' object is not iterable.")
  TypeError: 'Tensor' object is not iterable.
  </code></pre>