Reads:697Replies:0
Training using tf.Dataset in TensorFlow 2.0
I'm having difficulty training my TensorFlow model using a tf.Dataset rather than, say, a pd.DataFrame (which works fine).
I have created a dummy example below that I would expect to work on given what I have read online/on the TensorFlow Certification. !pip install tensorflow==2.0.0 > /dev/null import numpy as np import tensorflow as tf features, target = np.random.rand(100, 30), np.random.randint(0, 2, 100) dataset = tf.data.Dataset.from_tensor_slices((features, target)) model = tf.keras.Sequential([ tf.keras.layers.Dense(30, activation='relu', input_shape=(30,)), tf.keras.layers.BatchNormalization(), tf.keras.layers.Dropout(0.5), tf.keras.layers.Dense(30, activation='relu'), tf.keras.layers.BatchNormalization(), tf.keras.layers.Dropout(0.5), tf.keras.layers.Dense(1, activation='sigmoid') ]) model.compile( optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'] ) model.fit( dataset, epochs=10, ) which returns the following error message ... ValueError: Error when checking input: expected dense_input to have shape (30,) but got array with shape (1,) Is there anything obviously wrong in the above? Why is TensorFlow grabbing an input with shape (1,)? |
|