Issue
I am building a small CNN LSTM model in Keras for practice with video classification. The input dimensions of my data are (1, 5, 30, 10, 3) (batch size, time steps, width, height, channels). I found some success with ConvLSTM2D, but I’d like to make a model using TimeDistributed as I want to compare the performance of LSTM versus GRU.
The model successfully trains (albeit with some very strange accuracies),
https://i.imgur.com/5uAbPkR.png
but when I save it to my computer and call model.predict on an array of dimensions (1, 5, 30, 10, 3), I get this error:
ValueError: Input 0 is incompatible with layer sequential_12: expected shape=(None, None, 10, 30, 3), found shape=(1, 5, 30, 10, 3)
This happens even using images from the training set it supposedly achieved 100% accuracy on.
I am quite new to machine learning so it’s likely I overlooked something simple, but after scouring stackoverflow and Google all day for any leads I am getting nowhere.
The model looks like this.
model = Sequential()
model.add(Input((5,10,30,3)))
model.add(TimeDistributed(Conv2D(filters=2,
kernel_size=(3,3),
padding='same',
activation='relu')))
model.add(TimeDistributed(Flatten()))
model.add(LSTM(4))
model.add(Dense(16, activation='sigmoid'))
model.add(Dense(2, activation='softmax'))
sgd = SGD(learning_rate=0.01)
model.compile(optimizer=sgd,
loss='binary_crossentropy',
metrics=['accuracy'])
Shouldn’t the expected input shape be the same as the first Input layer I used in training?
Solution
I’m even more newbie than you and probably giving the wrong advice.
If I understood correctly, if I were you, I would try
frame = frame [None, …]
for what needs to be predicted. It helped me once.
I would not have written this if I had not been doing a similar task. I am very interested in your experience and I can share mine. Do you want to discuss this issue?
Answered By – Михаил Юрченко
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0