I'm analyzing sequences of coordinates with different lengths and need to classify in actions.
For this task I'm using LSTM, but fitting is not working, I prepared 2 dummy examples of the issue I'm having, the 1st one is working properly if you run it in colab (sequence with fixed length) and the 2nd one is raising errors (sequence with variable length):
1.- Example 1: Fixed length - Status: OK
from keras.models import Sequential
from keras.layers import LSTM, Dense
from keras.utils import np_utils
import numpy as np
#FIXED LENGTH
def build_model_test():
model = Sequential()
model.add(LSTM(64, input_shape=(2, 3) , return_sequences=True))
model.add(Dense(1, activation='softmax'))
return model
dataset = np.array([np.array([[1, 4, 6 ], [9, 3, 1]]),
np.array([[1, 4, 6 ], [9, 3, 1]]),
np.array([[1, 4, 6 ], [9, 3, 1]])])
labels_test = np.array([1, 0, 1])
labels_test = to_categorical(labels_test)
model_test = build_model_test()
model_test.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model_test.fit(dataset, labels_test, batch_size=1, epochs=1)
2.- Example 2: Variable length - Status: ERROR
from keras.models import Sequential
from keras.layers import LSTM, Dense
from keras.utils import np_utils
import numpy as np
# SIZE TEST 2: VAERIABLE LENGHT
def build_model_test():
model = Sequential()
model.add(LSTM(64, input_shape=(None, 3) , return_sequences=True)) #CHANGE_1: None, 3
model.add(Dense(1, activation='softmax'))
return model
dataset = np.array([np.array([[1, 4, 6 ], [9, 3, 1], [9, 3, 1]]), #CHANGE_2: Shape of 1st item from 2 to 3
np.array([[1, 4, 6 ], [9, 3, 1]]),
np.array([[1, 4, 6 ], [9, 3, 1]])])
labels_test = np.array([1, 0, 1])
labels_test = to_categorical(labels_test)
model_test = build_model_test()
model_test.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model_test.fit(dataset, labels_test, batch_size=1, epochs=1)
Do you know how can I fix example 2?
Thanks in advance!