1
我試圖建立一個模型,如下圖所示。這個想法是採用多個分類特徵(一個熱點向量)並將它們分開嵌入,然後將這些嵌入向量與一個LSTM的3D張量結合起來。Keras多輸入AttributeError:'NoneType'對象沒有屬性'inbound_nodes'
隨着以下代碼Keras2.0.2,創建具有多個輸入的Model()
對象時,它會引發類似於this問題的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'
感謝您的快速回答,制定了很好! – LingxB