python - 将 LSTM 与具有嵌入层的并行 MLP 网络连接起来
问题描述
我正在尝试使用非时间因变量的并行输入来构建 LSTM 模型。其中一些变量本质上是分类变量,我想通过嵌入层创建它们,然后稍后加入 LSTM。
请参阅下面我正在尝试的代码,但我收到“TypeError:unhashable type:'list'”的错误
以下是我目前编写的代码。
model = Model(inputs=[cat_els, ts_inputs], outputs=out_class)
我的 cat_els 定义为(3个张量的列表):
[<tf.Tensor 'flatten_10/Reshape:0' shape=(?, ?) dtype=float32>,
<tf.Tensor 'flatten_11/Reshape:0' shape=(?, ?) dtype=float32>,
<tf.Tensor 'flatten_12/Reshape:0' shape=(?, ?) dtype=float32>]
ts_inputs 定义为:
<tf.Tensor 'input_3:0' shape=(?, 6, 17) dtype=float32>
错误回溯
File "<ipython-input-48-601f97a5b348>", line 31, in <module>
model = Model(inputs=[cat_els, ts_inputs], outputs=out_class)
File "C:\ProgramData\Anaconda3\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\network.py", line 93, in __init__
self._init_graph_network(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\network.py", line 147, in _init_graph_network
if len(set(self.inputs)) != len(self.inputs):
TypeError: unhashable type: 'list'
谁能告诉我我在这里可能做错了什么?
解决方案
Keras 不支持作为输入层列表本身的输入,输入列表需要包含输入层,您可以通过连接输入来做到这一点:
model = Model(inputs=cat_els + [ts_inputs], outputs=out_class)
那么这个模型将有 4 个输入层。
推荐阅读
- rust - 我应该把只在测试中使用的文件放在哪里?
- mysql - Workbench SELECT 语句错误:SELECT 在此位置无效
- ada - 如何在 ada 中表示复数?
- python - 检测链相互连接
- sql - 以下答案是否符合选择条件?
- c - 为什么将 int 和 char 相乘不会在 c 中产生溢出?
- ios - 如何使用 appcelerator 分发 app ios?
- angular - Ag-grid : 单元格编辑器 Aginit 被调用两次
- tensorflow - 如何使用 tensorflow 图形优化图像空间?
- php - 验证码字符未显示大于 7.0.30 的 IIS 10 PHP 版本