【发布时间】:2020-12-02 17:07:50
【问题描述】:
我有一个包含多个变量的数据集,我正在尝试重塑以输入 LSTM 神经网络,但我在重塑层时遇到了困难,但没有成功。
我的数据集的形状为 (1921535, 6),每 341 个时间步对应一个样本。我想在 (23, 341, 6) 中重塑并在模型中输入它。在我的代码下方。
def df_to_dataset(dataframe, batch_size):
dataframe = dataframe.copy()
labels = dataframe.pop('target')
ds = tf.data.Dataset.from_tensor_slices((dict(dataframe), labels))
ds = ds.batch(batch_size)
return ds
max_length = 341
batch_size = 23
train_ds = df_to_dataset(data, batch_size * max_length)
model = tf.keras.Sequential([
tf.keras.layers.Reshape((batch_size, max_length, 6), input_shape=(batch_size * max_length, 6)),
tf.keras.layers.LSTM(40, return_sequences=True),
tf.keras.layers.LSTM(40),
tf.keras.layers.Dense(1)
])
当我运行代码时,我收到以下错误:
InvalidArgumentError: Input to reshape is a tensor with 54901 values, but the requested shape has 369075894 [Op:Reshape]
提前致谢
【问题讨论】:
标签: python tensorflow keras lstm recurrent-neural-network