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

I am building an anomaly detection model using keras upon videos. There are total 179 frames. The original dimension of each frame is given below:

h,w,c=cv2.imread(FramesFile[178]).shape  #h=240, w=30, c=3


Then, I have applied the ResNet-50 on these video frames to extract features, it gives me (1,7,7,2048) features. And to reduce down these features I have applied conv2D layer on it to get (1, 7, 7, 512) features as shown in 2nd line of function of FramesTrain()

Here's my code for training. I have done it through convolutional LSTM

def FramesTrain():
seq = Sequential()
data_format='channels_last'))
return seq

model=FramesTrain()
model.fit(FramesFeatures[0], batch_size=32,epochs=10, verbose=1)



But it gives me this error:

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

Kindly guide me how do I solve it. Regards,

• This kind of issue has been asked countless times here, you should have a look here. Your problem seem to be your time dimension, your inputs should be of shape (None, timedim, 7, 7, 2048) if you want to use LSTM. the 'None' size corresponds to the batchsize or simply data_size. Here either your timedim is missing or it has been converted to batchsize, in the second case, you can try tf.expand_dims(data, 0) function to add an batchsize dimension at ind 0. May 25 at 11:48