title: Using tf.data.Dataset as training input to Keras model NOT working
body: <p>I have a simple code, which DOES work, for training a Keras model in Tensorflow using numpy arrays as features and labels. If I then wrap these numpy arrays using <code>tf.data.Dataset.from_tensor_slices</code> in order to train the same Keras model using a tensorflow dataset, I get an error. I haven't been able to figure out why (it may be a tensorflow or keras bug, but I may also be missing something). I'm on python 3, tensorflow is 1.10.0, numpy is 1.14.5, no GPU involved.</p>
  
  <p><strong>OBS1</strong>: The possibility of using tf.data.Dataset as a Keras input is showed in <a href="https://www.tensorflow.org/guide/keras" rel="nofollow noreferrer">https://www.tensorflow.org/guide/keras</a>, under "<em>Input tf.data datasets</em>".</p>
  
  <p><strong>OBS2</strong>: In the code below, the code under "<code>#Train with numpy arrays</code>" is being executed, using numpy arrays. If this code is commented and the code under "<code>#Train with tf.data datasets</code>" is used instead, the error will be reproduced.</p>
  
  <p><strong>OBS3</strong>: In line 13, which is commented and starts with "<code>###WORKAROUND 1###</code>", if the comment is removed and the line is used for <code>tf.data.Dataset inputs</code>, the error changes, even though I can't completely understand why.</p>
  
  <p><strong>The complete code is:</strong> </p>
  
  <pre><code>import tensorflow as tf
  import numpy as np
  
  np.random.seed(1)
  tf.set_random_seed(1)
  
  print(tf.__version__)
  print(np.__version__)
  
  #Import mnist dataset as numpy arrays
  (x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()#Import
  x_train, x_test = x_train / 255.0, x_test / 255.0 #normalizing
  ###WORKAROUND 1###y_train, y_test = (y_train.astype(dtype='float32'), y_test.astype(dtype='float32'))
  
  x_train = np.reshape(x_train, (x_train.shape[0], x_train.shape[1]*x_train.shape[2])) #reshaping 28 x 28 images to 1D vectors, similar to Flatten layer in Keras
  
  batch_size = 32
  #Create a tf.data.Dataset object equivalent to this data
  tfdata_dataset_train = tf.data.Dataset.from_tensor_slices((x_train, y_train))
  tfdata_dataset_train = tfdata_dataset_train.batch(batch_size).repeat()
  
  #Creates model
  keras_model = tf.keras.models.Sequential([
      tf.keras.layers.Dense(512, activation=tf.nn.relu),
      tf.keras.layers.Dropout(0.2, seed=1),
      tf.keras.layers.Dense(10, activation=tf.nn.softmax)
  ])
  
  #Compile the model
  keras_model.compile(optimizer='adam',
                      loss=tf.keras.losses.sparse_categorical_crossentropy,
                      metrics=['accuracy'])
  
  #Train with numpy arrays
  keras_training_history = keras_model.fit(x_train,
                  y_train,
                  initial_epoch=0,
                  epochs=1,
                  batch_size=batch_size
                  )
  
  #Train with tf.data datasets
  #keras_training_history = keras_model.fit(tfdata_dataset_train,
  #                initial_epoch=0,
  #                epochs=1,
  #                steps_per_epoch=60000//batch_size
  #                )
  
  print(keras_training_history.history)
  </code></pre>
  
  <p><strong>The error observed when using <code>tf.data.Dataset</code> as input is</strong>:</p>
  
  <pre><code>(...)
  ValueError: Tensor conversion requested dtype uint8 for Tensor with dtype float32: 'Tensor("metrics/acc/Cast:0", shape=(?,), dtype=float32)'
  
  During handling of the above exception, another exception occurred:
  
  (...)
  TypeError: Input 'y' of 'Equal' Op has type float32 that does not match type uint8 of argument 'x'.
  </code></pre>
  
  <p><strong>The error when removing the comment from line 13, as commented above in <em>OBS3</em>, is</strong>:</p>
  
  <pre><code>(...)
  tensorflow.python.framework.errors_impl.InvalidArgumentError: In[0] is not a matrix
       [[Node: dense/MatMul = MatMul[T=DT_FLOAT, _class=["loc:@training/Adam/gradients/dense/MatMul_grad/MatMul_1"], transpose_a=false, transpose_b=false, _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_sequential_input_0_0, dense/MatMul/ReadVariableOp)]]
  </code></pre>
  
  <p>Any help would be appreciated, including comments that you were able to reproduce the errors, so I can report the bug if it is the case.</p>