Reputation: 43
I have a set of training data where each input is a vector of length 138. I have 519 of these vectors for a batch size of 519. These are not images, just real-valued numbers.
I'm trying to start with a 2 layer dense Keras model:
model = keras.Sequential([
layers.Dense(200, activation=tf.nn.relu, input_shape=[138]),
layers.Dense(200, activation=tf.nn.relu),
layers.Dense(1)
])
When I build the model I get the following error:
Error when checking input: expected dense_27_input to have shape (138,) but got array with shape (519,).
Where in Keras do I distinguish batch size from number of input features? layers.Dense()
seems to assume that my input is in rows vs. columns.
Upvotes: 0
Views: 3311
Reputation: 33470
Keras expects the first axis to be the batch axis. Therefore if you have 519 training samples where each one is a vector of length 138, the array you pass to the fit
method must have a shape of (519, 138)
. So if currently the array of training data has a shape of (138, 519)
, simply transpose it to make the shape consistent:
import numpy as np
train_data = np.transpose(train_data)
Upvotes: 1