Why do you define the last dimension of input_shape
as $3$? Just put your desired input dimensions accordingly and it should be fine:
input_shape = (img_width, img_height)
Update with the full code:
The best way would be to use TimeseriesGenerator
instead of ImageDataGenerator
but there seems there not flow_from_directory
method meeting your needs. So, I think the best solution is to squeeze the last dimension of the generator output. Also, you have a color_mode
option that allows to generate a 1-channel only tensor for grayscale images.
Full code of concerned parts:
model = Sequential()
model.add(Lambda(lambda x: x[:,:,:,0], input_shape=(*input_shape, 1)))
model.add(LSTM(units=256, return_sequences=True))
model.add(LSTM(units=128, return_sequences=True))
model.add(LSTM(units=64))
model.add(Dense(128))
model.add(Dense(num_classes, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy'])
train_generator = train_datagen.flow_from_directory(
train_data_dir,
target_size=(img_width, img_height),
batch_size=batch_size,
color_mode='grayscale')
validation_generator = test_datagen.flow_from_directory(
validation_data_dir,
target_size=(img_width, img_height),
batch_size=batch_size,
color_mode='grayscale')