python - 使用不是符号张量的输入调用的层 keras

标签 python neural-network keras recurrent-neural-network

我正在尝试将一层的输出传递到两个不同的层,然后将它们重新连接在一起。但是,我被这个错误阻止了,它告诉我我的输入不是符号张量。

Received type: <class 'keras.layers.recurrent.LSTM'>. All inputs to the layers should be tensors.

但是,我相信我非常密切地关注文档: https://keras.io/getting-started/functional-api-guide/#multi-input-and-multi-output-models

我不完全确定为什么这是错误的?

net_input = Input(shape=(maxlen, len(chars)), name='net_input')
lstm_out = LSTM(128, input_shape=(maxlen, len(chars)))

book_out = Dense(len(books), activation='softmax', name='book_output')(lstm_out)
char_out = Dense(len(chars-4), activation='softmax', name='char_output')(lstm_out)

x = keras.layers.concatenate([book_out, char_out])
net_output = Dense(len(chars)+len(books), activation='sigmoid', name='net_output')

model = Model(inputs=[net_input], outputs=[net_output])

谢谢

最佳答案

看起来您实际上并没有向 LSTM 层提供输入。您指定循环神经元的数量和输入的 shape,但不提供输入。试试:

lstm_out = LSTM(128, input_shape=(maxlen, len(chars)))(net_input)

关于python - 使用不是符号张量的输入调用的层 keras,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44852153/

相关文章:

machine-learning - 层归一化层中的 beta 和 gamma 参数的形状是什么?

python - 凯拉斯 |运行 Inception v3 示例

python - 如何将cookie从flask设置为reactjs

python - 根据 pandas DataFrame 中的列值有条件地替换多列

python - 在满足要求时撤消功能

python - 在 Pybrain 中创建共享权重连接

machine-learning - 我们可以只使用 model.fit 而不是 model.fit_generator 吗?

python - 在keras自定义层中进行广播的逐元素乘法

python - 如何设置 keras 自定义指标仅在纪元结束时调用?

python - 如何以 Google App Engine 的形式表示多对多关系?