【发布时间】:2020-10-09 16:24:51
【问题描述】:
我有一个形状为 X: (1146165, 19, 22) 和 Y: (1146165,) 的数据集。这是我的模型代码:
import tensorflow as tf
train_data = tf.data.Dataset.from_tensor_slices((x_train, y_train))
valid_data = tf.data.Dataset.from_tensor_slices((x_valid, y_valid))
def create_model(shape=(19, 22)):
tfkl = tf.keras.layers
model = tf.keras.Sequential([
tfkl.LSTM(128, return_sequences=True, input_shape=shape),
tfkl.LSTM(64),
tfkl.Dropout(0.3),
tfkl.Dense(64, activation="linear"),
tfkl.Dense(1)
])
model.compile(loss='mean_absolute_error', optimizer="adam")
return model
model = create_model()
model.summary()
你可以看到input_shape 是(19, 22),这是正确的,但是当我使用fit 时,我得到了错误ValueError: Input 0 of layer sequential_15 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: [19, 22]
我在 Stack 上搜索了一些答案,但其中大部分是因为输入维度是 (a, b) 而不是 (a,b,c)。任何帮助表示赞赏。
【问题讨论】:
标签: python tensorflow keras