1
$\begingroup$

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!

$\endgroup$

1 Answer 1

0
$\begingroup$

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.

$\endgroup$
10
  • $\begingroup$ hello thank you for your comment and sorry for the late reply, do you know where can i found how to assembles my images as time-series that you mentioned? bit lost here Thank you so much $\endgroup$ Commented Jul 1, 2021 at 3:25
  • $\begingroup$ Do your images have some sort of temporal order to them? For example, are they short video clips or something? $\endgroup$
    – zachdj
    Commented Jul 1, 2021 at 13:58
  • $\begingroup$ 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 :) $\endgroup$
    – zachdj
    Commented Jul 1, 2021 at 13:59
  • $\begingroup$ yes at first it's a short clips video, i make it into frame so i can sort it into each class folder $\endgroup$ Commented Jul 1, 2021 at 15:54
  • $\begingroup$ so it's better to just use the short clip video as input instead of the raw images then? $\endgroup$ Commented Jul 1, 2021 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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