keras问题集

1、针对LSTM网络喂入数据时出现expected lstm_1_input to have 3 dimensions, but got array with shape (144, 1)
There are two approaches when feeding inputs on your model:

1st option: using the input_shape

model.add(Dense(300, activation='relu', input_shape=(6, 1)))
Here the input shape is in 2D, but you should feed your network a 3D input (Rank 3) since you need to include the batch_size.

Example input:

state = np.array(np.ones((BATCH_SIZE, 6, 1)))
print("Input Ranks: {}".format(tf.rank(state)) # Check for rank of input
2nd Option: Using the input_dim

model.add(Dense(300, activation='relu', input_dim=6))
Here thei nput shape is in 1D, but you should feed your network a 2D input (Rank 2) since you need to include the batch_size//即数据集要包含batchsize

example input:

state = np.array(np.ones((1, 6,)))
print("Input Rank: {}".format(tf.rank(state))) # Check for the Rank of Input

你可能感兴趣的:(keras问题集)