Hi all, I’m trying to build a “simple” model to predict basic arm movements. Every movement as described as an array of a variable length, which contains sub-arrays of fixed length = 3 (i.e. something like this: [[1,2,3],[4,5,6], … , [100,102,103]]).
I’ve tried to build a model this way, but I guess something is wrong because I’m getting error when i try to make the prediction (the training seems ok):
import numpy as np
import tensorflow as tf
# Create the model
model = tf.keras.Sequential([
tf.keras.layers.Dense(3, activation='relu', input_shape=(None, 9)), # Adjusted input shape
tf.keras.layers.Dense(2, activation='softmax')
])
# Compile the model
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
# Train the model
data = np.array([[[2, 3, 5], [6, 8, 9], [10, 11, 12]], [[2, 1, 3], [3, 5, 6], [4, 5, 2]]])
labels = np.array([0, 1]) # One label for each group of arrays
# Reshape the data to combine all groups into one sample
data = np.reshape(data, (2, -1))
model.fit(data, labels, epochs=10)
to_predict = np.array([[2,14,3],[3,56,6]])
predictions = model.predict(to_predict)
print(predictions)