Multidimensional Input to Keras

Viewed 5730

I am new to keras and I am having a problem running a model with more than one dimension. So, I have been trying a few samples. This is one of them.

from keras.models import Sequential
from keras.layers import Dense
import numpy as np

X_train = np.array([[[1, 2], [3, 4]], [[1, 2], [3, 4]]])
model = Sequential([
    Dense(32, input_shape=X_train.shape[1:]),
])
model.compile(loss='sparse_categorical_crossentropy', optimizer='sgd')
model.fit(X_train, [1, 2])


I expect the above sample to run but I am getting an error

Error when checking target: expected dense_1 to have 3 dimensions, but got array with shape (2, 1)

What can be the reason for this. Can anyone give an example on how to run keras model with a multi-dimensional input, i.e. how should the input be structured? Thank you.

1 Answers
Related