I am using Keras 2.04 with tensorflow backend. I am trying to train a simple model with ImageDataGenerator on MNIST images. However, I keep getting the following error from fit_generator:
ValueError: Error when checking input: expected input_1 to have 2 dimensions, but got array with shape (8, 28, 28, 1).
This is the code:
#loading data & reshaping
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = x_train.reshape(x_train.shape[0], 28, 28,1)
#building the model
input_img = Input(shape=(784,))
encoded = Dense(30, activation='relu')(input_img)
decoded = Dense(784, activation='sigmoid')(encoded)
autoencoder = Model(input_img, decoded)
autoencoder.compile(optimizer='adam', loss='mse')
#creating ImageDataGenerator
datagen = ImageDataGenerator(featurewise_center=True, featurewise_std_normalization=True)
datagen.fit(x_train)
autoencoder.fit_generator(
#x_train, x_train because the target is to reconstruct the input
datagen.flow(x_train, x_train, batch_size=8),
steps_per_epoch=int(len(x_train)/8),
epochs=64,
)
As far as I understand ImageDataGenerator should generate a batch of training examples each iteration, as it actually does (in this case, batch_size=8) but from the error it seems as if it expects a single training example.
Thanks!