I am facing the error in the title. I have thousands of videos and each video have 37 frames. I have extracted features for each frame with a CNN model and saved them. I have a stacked LSTM model :
batch_size = 8
features_length = 2048
seq_length = 37*batch_size
in_shape = (seq_length, features_length)
lstm_model = Sequential()
lstm_model.add(LSTM(2048, return_sequences=True, input_shape = in_shape, dropout=0.5))
lstm_model.add(Flatten())
lstm_model.add(Dense(512, activation='relu'))
lstm_model.add(Dropout(0.5))
lstm_model.add(Dense(number_of_classes, activation='softmax'))
optimizer = Adam(lr=1e-6)
lstm_model.compile(loss='categorical_crossentropy', optimizer=optimizer, metrics = metrics)
lstm_model.fit_generator(generator = generator, steps_per_epoch = train_steps_per_epoch, epochs = nb_epoch, verbose = 1, callbacks=[checkpointer, tb, early_stopper, csv_logger], validation_data=val_generator, validation_steps = val_steps_per_epoch)
I have a generator; data includes all training videos.
def generator(data):
while 1:
X, y = [], []
for _ in range(batch_size):
sequence = None
sample = random.choice(data)
folder_content, folder_name, class_name, video_features_loc = get_video_features(sample)
for f in folder_content:
image_feature_location = video_features_loc + f
feat = get_extracted_feature(image_feature_location)
X.append(feat)
y.append(get_one_class_rep(class_name))
yield np.array(X), np.array(y)
The shape of X in generator data is = (296, 2048, 1)
The shape of y in generator data is = (296, 27)
This code throws the error. I know there are couple of similar questions. I tried the suggestions there but no luck. For instance one the suggestions was reshaping the array;
X = np.reshape(X, (X.shape[2], X.shape[0], X.shape[1]))
How could I feed my input to the LSTM?
Thanks in advance
2], X.shape[0], X.shape[1]))