title: tensorflow - Can I have entries in my input array that are tuples? Doing this throws 'Unable to get element from the feed as bytes.'
body: <p>Ultimately my question is: Is it possible to have run tensorflow's DNNClassifier on samples in which one entry is a tuple or set of tuples?</p>
  
  <p>What I want is to run a classifier on a bunch of samples.  Mostly the samples are numbers, but I also want one of the entries to be a set of numbers, e.g. a sample is &lt;1, 2, 3, 4, (1.5, 1.6, 1.4), 2>.  I actually want the weird entry to be a set of tuples of potentially different sizes, like one sample is &lt;1, 2, 3, 4, (1.5, 1.6, 1.4), 2> and the second sample is &lt;11, 12, 13, 14, (0.5, 0.1, 00, 0.1, 0.2, 0.0), 12> with different lengths of just that one entry (here, index 4) per sample (and ultimately with each of those entries being 3 different numbers), but I'm trying to get anything working that isn't just a list of numbers.  </p>
  
  <p>Edit: If there is a better way to do this, like a different thing in tensorflow, a particular function in Matlab that can deal with the multiple-tuple entry that I want in my samples, please suggest it!</p>
  
  <p>So this works:</p>
  
  <pre><code>import tensorflow as tf
  import numpy as np
  
  trainX = np.array([
              [19, 1] ,
              [10, 3] ,
              [0, 0] ,
              [11, 14] ,
              ])
  print(trainX)
  print(trainX.shape)
  
  trainY = np.array([ 1, 1, 0, 1 ])
  print(trainY)
  print(trainY.shape)
  
  feature_columns = [tf.contrib.layers.real_valued_column("", dimension=2)]
  classifier = tf.contrib.learn.DNNClassifier(feature_columns=feature_columns,
                                              n_classes=3, 
                                              hidden_units=[10])
  
  classifier.fit(x=trainX, y=trainY, steps=2000)
  
  print("Done.")
  exit()
  </code></pre>
  
  <p>And changing trainX to this works,</p>
  
  <pre><code>trainX = np.array([
              [19, (1)] ,
              [10, (3)] ,
              [0, (0)] ,
              [11, (14)] ,
              ])
  </code></pre>
  
  <p>But this:</p>
  
  <pre><code>trainX = np.array([
              [19, (1, 1)] ,
              [10, (3, 9)] ,
              [0, (0, 0)] ,
              [11, (14, 6)] ,
              ])
  </code></pre>
  
  <p>fails due to a numpy error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "./supersimple.py", line 8, in &lt;module&gt;
      [11, (14, 6)] ,
  ValueError: setting an array element with a sequence.
  </code></pre>
  
  <p>So if you change the np.array type to an object by adding 'dtype = np.object' at the end of the array or just move the tuple to the front (I believe this allows numpy to decide immediately that this is an object type) like this:</p>
  
  <pre><code>trainX = np.array([
              [(1, 1), 19] ,
              [(3, 9), 10] ,
              [(0, 0), 0] ,
              [(14, 6), 11] ,
              ])
  </code></pre>
  
  <p>it fails in tensorflow instead:</p>
  
  <pre><code>tensorflow.python.framework.errors.InternalError: Unable to get element from the feed as bytes.
  </code></pre>
  
  <p>The total output / stack trace is here:</p>
  
  <pre><code>$ python3 ./supersimple.py 
  
  [[(1, 1) 19]
  [(3, 9) 10]
  [(0, 0) 0]
  [(14, 6) 11]]
  (4, 2)
  [1 1 0 1]
  (4,)
  WARNING:tensorflow:Change warning: default value of `enable_centered_bias` will change after 2016-10-09. It will be disabled by default.Instructions for keeping existing behaviour:
  Explicitly set `enable_centered_bias` to 'True' if you want to keep existing behaviour.
  WARNING:tensorflow:Using default config.
  Traceback (most recent call last):
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/client/session.py", line 972, in _do_call
      return fn(*args)
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/client/session.py", line 954, in _run_fn
      status, run_metadata)
    File "/usr/lib/python3.4/contextlib.py", line 66, in __exit__
      next(self.gen)
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/errors.py", line 463, in raise_exception_on_not_ok_status
      pywrap_tensorflow.TF_GetCode(status))
  tensorflow.python.framework.errors.InternalError: Unable to get element from the feed as bytes.
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "./supersimple.py", line 22, in &lt;module&gt;
      classifier.fit(x=trainX, y=trainY, steps=2000)
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/estimators/dnn.py", line 435, in fit
      max_steps=max_steps)
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 333, in fit
      max_steps=max_steps)
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 708, in _train_model
      max_steps=max_steps)
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/graph_actions.py", line 285, in _monitored_train
      None)
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/monitored_session.py", line 368, in run
      run_metadata=run_metadata)
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/monitored_session.py", line 521, in run
      run_metadata=run_metadata)
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/monitored_session.py", line 488, in run
      return self._sess.run(*args, **kwargs)
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/monitored_session.py", line 619, in run
      run_metadata=run_metadata)
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/monitored_session.py", line 488, in run
      return self._sess.run(*args, **kwargs)
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/client/session.py", line 717, in run
      run_metadata_ptr)
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/client/session.py", line 915, in _run
      feed_dict_string, options, run_metadata)
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/client/session.py", line 965, in _do_run
      target_list, options, run_metadata)
    File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/client/session.py", line 985, in _do_call
      raise type(e)(node_def, op, message)
  tensorflow.python.framework.errors.InternalError: Unable to get element from the feed as bytes.
  </code></pre>