# CNN+LSTM ValueError: Input 0 of layer sequential_10 is incompatible with the layer: expected ndim=5, found ndim=4

currently making human action recognition to detect a cheating kind on the exam from CCTV using AlexNet+LSTM

My Data are raw images in each class folder with like this

But I got error like this:

ValueError: in user code:

/usr/local/lib/python3.7/dist-packages/keras/engine/training.py:830 train_function  *
return step_function(self, iterator)
/usr/local/lib/python3.7/dist-packages/keras/engine/training.py:813 run_step  *
outputs = model.train_step(data)
/usr/local/lib/python3.7/dist-packages/keras/engine/training.py:770 train_step  *
y_pred = self(x, training=True)
/usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py:989 __call__  *
input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
/usr/local/lib/python3.7/dist-packages/keras/engine/input_spec.py:212 assert_input_compatibility  *
raise ValueError('Input ' + str(input_index) + ' of layer ' +

ValueError: Input 0 of layer sequential_10 is incompatible with the layer: expected ndim=5, found ndim=4. Full shape received: (None, None, None, None)


The error comes when I do the model.fit.

From what I read it said that the problem at the input_shape but I am still doesn't found the solution to my problem the link of my code at collab can be found here,

I still don't understand what is the problem, I check the documentation for input_shape in TimeDistributed and it's the same for (timeSteps, height, width, channels)

I did try to remaking the model but the problem is still the same

is it from my ImageDataGenerator?

I would appreciate if anybody has the experience in this matter and tries to help my problem

Thank you so much!

The TimeDistributed documentation says the input should have shape (batch, time, others . . .). In your case (a batch of images in a time series), the shape should be (batch, time, r, g, b).
But the image data generator in your code is reading images from a directory in a batch, outputting tensors with shape (batch, r, g, b). So you are missing the time dimension.
If you want to use TimeDistributed layers, then you'll need to assemble your images as a time-series, then apply batching.
• If your images are time-ordered, you will probably need to write your own data loader. It would read all the images in a given time series and place them into a single tensor. If your images are not time-ordered, then you can just stop using the TimeDistributed layers :) Jul 1, 2021 at 13:59