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()
seq.add(Conv2D(512, (5, 5), padding="same"))
seq.add(ConvLSTM2D(filters=40, kernel_size=(5, 5), input_shape=(None, 40, 40, 1), padding='same', return_sequences=True))
seq.add(BatchNormalization())
seq.add(ConvLSTM2D(filters=40, kernel_size=(5, 5), padding='same', return_sequences=True))
seq.add(BatchNormalization())
seq.add(ConvLSTM2D(filters=40, kernel_size=(5, 5), padding='same', return_sequences=True))
seq.add(BatchNormalization())
seq.add(ConvLSTM2D(filters=40, kernel_size=(5, 5), padding='same', return_sequences=True))
seq.add(BatchNormalization())
seq.add(Conv3D(filters=1, kernel_size=(5, 5, 5), activation='sigmoid', padding='same', data_format='channels_last'))
seq.compile(loss='binary_crossentropy', optimizer='adadelta')
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,