调用 keras 的
model.fit()
方法时,我遇到了以下错误:
AttributeError: 'RepeatDataset' object has no attribute 'ndim'
我正在使用 TensorFlow 1.7 和 Keras。不幸的是,我必须使用 TF 1.7。你有什么想法吗?这段代码是从一个 TensorFlow 演示中 改编 而来的。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
)
repeat()
,例如repeat(count=2)
。 - Ashwin Geet D'Sarepeat()
之后,您可以将批次分组。 - Ashwin Geet D'SadatasetB = datasetA.batch(32)
并添加dataset = datasetA.repeat(<epochs>).batch(32)
。 - Ashwin Geet D'Sa