title: Tensorflow: Dataset.from_generate() ValueError: setting an array element with a sequence
body: <h1><strong>Goal</strong></h1>
  
  <p>I want to use tensor as part of input in the dataset.from_generator method.</p>
  
  <h1><strong>Error Message</strong></h1>
  
  <pre><code>---------------------------------------------------------------------------
  InvalidArgumentError                      Traceback (most recent call last)
  /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
     1321     try:
  -&gt; 1322       return fn(*args)
     1323     except errors.OpError as e:
  
  /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/client/session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)
     1306       return self._call_tf_sessionrun(
  -&gt; 1307           options, feed_dict, fetch_list, target_list, run_metadata)
     1308 
  
  /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/client/session.py in _call_tf_sessionrun(self, options, feed_dict, fetch_list, target_list, run_metadata)
     1408           self._session, options, feed_dict, fetch_list, target_list,
  -&gt; 1409           run_metadata)
     1410     else:
  
  InvalidArgumentError: ValueError: setting an array element with a sequence.
  Traceback (most recent call last):
  
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/ops/script_ops.py", line 157, in __call__
      ret = func(*args)
  
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 391, in generator_py_func
      nest.flatten_up_to(output_types, values), flattened_types)
  
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 390, in &lt;listcomp&gt;
      for ret, dtype in zip(
  
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/ops/script_ops.py", line 124, in _convert
      result = np.asarray(value, dtype=dtype, order="C")
  
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numpy/core/numeric.py", line 492, in asarray
      return array(a, dtype, copy=False, order=order)
  
  ValueError: setting an array element with a sequence.
  
  
       [[Node: PyFunc = PyFunc[Tin=[DT_INT64], Tout=[DT_FLOAT, DT_FLOAT], token="pyfunc_150"](arg0)]]
       [[Node: IteratorGetNext_22 = IteratorGetNext[output_shapes=[&lt;unknown&gt;, &lt;unknown&gt;], output_types=[DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](OneShotIterator_22)]]
  
  During handling of the above exception, another exception occurred:
  </code></pre>
  
  <h1><strong>Error Reproduce</strong></h1>
  
  <p>if you replace the definition of <code>b=tf.ones...</code> with <code>b = np.rand..</code>,the error will disappear. </p>
  
  <pre><code>import numpy as np
  import tensorflow as tf
  
  def _create_generator():
      for i in range(3):
          a = np.random.randn(3,2)
          b = tf.ones([1],tf.float32)
          #b= np.random.randn(1)
          result = {}
          result['a'] =  a
          result['b'] = b
          yield result
  
  
  gen = _create_generator()
  
  dataset = tf.data.Dataset().from_generator(_create_generator,
                          output_shapes={'a':None,'b':None},
                          output_types ={'a':tf.float32, 'b':tf.float32}).batch(1)
  iterator = dataset.make_one_shot_iterator()
  features = iterator.get_next()
  
  
  init = tf.initialize_all_variables()
  with tf.Session() as sess:
      sess.run(init)
      print(sess.run(features))
  </code></pre>
  
  <h1>Why do I have to use tensor as input</h1>
  
  <p>Well, This is because my real program needs to use the output of another tf.data.Dataset as part of the Input(data is stored in format of TFRecords). So it will raise exact the same error as you will see after running this snippet of code. Right now I don't have any idea to make around and fix this problem indirectly(without using tensor as input).</p>
  
  <h1><strong>Why I need to use Dataset.from_generator</strong></h1>
  
  <p>There is a hack to use estimator.predict() without loading the graph every times you call it, which is to use generator to keep the entry open and it will presume you have not done with 'single' prediction. Then Tensorflow won't load the model graph again and again.</p>
  
  <hr>
  
  <p>If you need more bg info about my info. let me know it. Thank you!</p>
  
  <p>Edit1:</p>
  
  <h1><strong>Why I have to use Dataset API</strong></h1>
  
  <p>The data volume is huge and originally saved on <code>hdfs</code>. So the pipeline was processed in Spark and saved in format of <code>TFRecord</code>. And as far as I know I can only use <code>Dataset</code> api to restore my data here(also kind of considering the performance here).</p>