I am getting the following error when calling keras model.fit()
.
AttributeError: 'RepeatDataset' object has no attribute 'ndim'
I am using TensorFlow 1.7 and Keras. Unfortunately, I must use TF 1.7. Any idea what's going on? The code, adapted from a tensorflow demo:
import tensorflow as tf
from IPython import embed
from tensorflow.python import keras
from tensorflow.python.keras import layers
model = tf.keras.Sequential()
model.add(layers.Dense(64, input_shape=(32,), activation='relu'))
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10, activation='softmax'))
model.compile(
optimizer=tf.train.AdamOptimizer(0.001),
loss='categorical_crossentropy',
metrics=['accuracy'])
import numpy as np
# Generate random data using numpy
def random_one_hot_labels(shape):
n, n_class = shape
classes = np.random.randint(0, n_class, n)
labels = np.zeros((n, n_class))
labels[np.arange(n), classes] = 1
return labels
data = np.random.random((1000, 32))
labels = random_one_hot_labels((1000, 10))
datasetA = tf.data.Dataset.from_tensor_slices((data, labels))
datasetB = datasetA.batch(32)
dataset = datasetB.repeat()
model.fit(
dataset,
epochs=10,
steps_per_epoch=30
)