我正在尝试构建一个如下图所示的模型。这个想法是采用多个分类特征(一个热向量)并分别嵌入它们,然后将这些嵌入的向量与 LSTM 的 3D 张量组合。
使用Keras2.0.2中的以下代码,在创建Model()
具有多个输入的对象时,它会引发与此AttributeError: 'NoneType' object has no attribute 'inbound_nodes'
问题类似的问题。谁能帮我找出问题所在?
模型:
代码:
from keras.layers import Dense, LSTM, Input
from keras.layers.merge import concatenate
from keras import backend as K
from keras.models import Model
cat_feats_dims = [315, 14] # Dimensions of the cat_feats
emd_inputs = [Input(shape=(in_size,)) for in_size in cat_feats_dims]
emd_out = concatenate([Dense(20, use_bias=False)(inp) for inp in emd_inputs])
emd_out_3d = K.repeat(emd_out, 10)
lstm_input = Input(shape=(10,5))
merged = concatenate([emd_out_3d,lstm_input])
lstm_output = LSTM(32)(merged)
dense_output = Dense(1, activation='linear')(lstm_output)
model = Model(inputs=emd_inputs+[lstm_input], outputs=[dense_output])
#ERROR MESSAGE
Traceback (most recent call last):
File "C:\Program Files\Anaconda2\envs\mle-env\lib\site-packages\IPython\core\interactiveshell.py", line 2881, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-a9da7f276aa7>", line 14, in <module>
model = Model(inputs=emd_inputs+[lstm_input], outputs=[dense_output])
File "C:\Program Files\Anaconda2\envs\mle-env\lib\site-packages\keras\legacy\interfaces.py", line 88, in wrapper
return func(*args, **kwargs)
File "C:\Program Files\Anaconda2\envs\mle-env\lib\site-packages\keras\engine\topology.py", line 1648, in __init__
build_map_of_graph(x, seen_nodes, depth=0)
File "C:\Program Files\Anaconda2\envs\mle-env\lib\site-packages\keras\engine\topology.py", line 1644, in build_map_of_graph
layer, node_index, tensor_index)
File "C:\Program Files\Anaconda2\envs\mle-env\lib\site-packages\keras\engine\topology.py", line 1644, in build_map_of_graph
layer, node_index, tensor_index)
File "C:\Program Files\Anaconda2\envs\mle-env\lib\site-packages\keras\engine\topology.py", line 1639, in build_map_of_graph
next_node = layer.inbound_nodes[node_index]
AttributeError: 'NoneType' object has no attribute 'inbound_nodes'