【问题标题】:ValueError: The shape of the input to "Flatten" is not fully defined (Neural Networks)ValueError:“Flatten”的输入形状未完全定义(神经网络)
【发布时间】:2019-08-23 08:52:11
【问题描述】:

我尝试将 Flatten 用于我的 LSTM 模型,但它不起作用并出现此错误:

ValueError:“Flatten”的输入形状未完全定义(得到 (None, 450) 确保将完整的“input_shape”或“batch_input_shape”参数传递给模型的第一层。

型号:

input_vector_size = kwargs.get('input_vector_size', 128)
dense_size = kwargs.get('dense_size', 20)
timesteps = None
xav_init = tf.contrib.layers.xavier_initializer()
##########

model = Sequential()
model.add(LSTM(int(input_vector_size), input_shape=timesteps,int(input_vector_size)), return_sequences=True))
model.add(SeqSelfAttention(attention_activation='softmax'))
model.add(Flatten())
model.add(Dense(dense_size, activation='sigmoid', kernel_initializer=xav_init))
model.add(Dense(kwargs.get('label_size', 2), activation='sigmoid'))

我该如何解决这个问题?

【问题讨论】:

  • 你需要另一个括号:input_shape=(timesteps, int(input_vector_size)),否则input_shape=timesteps=None
  • 是的,我忘记了括号并修复了代码。如果我想使用 Flatten() @JimmyOnThePage,我应该将时间步长更改为 1

标签: python neural-network lstm


【解决方案1】:

只为任何想知道答案的人。您应该将 input_shape 更改为 (1,int(input_vector_size)) 以使用 Flatten

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-29
    • 2020-03-16
    • 2019-04-01
    • 1970-01-01
    • 2020-12-28
    • 2019-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多