I am trying to apply data augmentation to avoid overffiting in my CNN-LSTM image classification model. My training data has the shape:

(1882, 1, 224, 224, 3)

My code is:

train_datagen = ImageDataGenerator(dtype='float32',rescale=1./255., rotation_range=40, width_shift_range=0.2, 
                                   height_shift_range=0.2,shear_range=0.2, zoom_range = 0.2, horizontal_flip = True)

test_datagen = ImageDataGenerator(dtype='float32',rescale=1.0/255.)

train_generator = train_datagen.flow_from_directory(train_dir, batch_size=32,
                                                    class_mode='sparse', target_size=(224, 224))
validation_generator = test_datagen.flow_from_directory(validation_dir, batch_size=32, class_mode='sparse', target_size=(224, 224))

num_classes = len(train_generator.class_indices)
model = build_model()
history = model.fit(train_generator, epochs=10,steps_per_epoch=len(x_train)/32,

I am getting the error below:

ValueError: Error when checking input: expected time_distributed_6_input to have 5 dimensions, but got array with shape (32, 224, 224, 3)

How do you apply data augmentation with ab input rank of 5?


I was able to get over this error by changing the target size from

target_size=(224, 224) to target_size=(1,224, 224)

I hope this may help another one.


Not the answer you're looking for? Browse other questions tagged or ask your own question.