AttributeError:NoneType'对象没有属性'_inbound_nodes'

时间:2019-06-25 22:33:42

标签: python tensorflow keras neural-network nonetype

我正在尝试基于 google colab https://www.aclweb.org/anthology/D18-1003给出的代码构建DeClarE模型(https://github.com/connectsoumya/declare/blob/master/data_preprocessing.py),但遇到了NoneType错误。

最初,代码使用了Concatenated层作为最终模型(final_feat)的输入,我将其更改为以前每个模型(art_wrd,clm_wrd,clm_src,art_src)的输入,但我不确定这是正确的或不。修复了NoneType错误,该错误指出串联不能作为模型的输入。更改后,该错误再次发生,但不再是“串联”的罪魁祸首。

一些具有相同错误的帖子使用keras.layer.Concatenation来解决其问题,但已在代码中使用,其他解决方案与该问题不完全匹配。 该模型的代码与链接中的代码相同。


art_wrd = Input(shape=(200,))
clm_wrd = Input(shape=(200,))
clm_wrd_emb = Embedding(vocabulary_size, 200, input_length=200, weights=[glove_combinedinput_weight_matrix], trainable=False)(clm_wrd)
mean_clm_wrd_emb = RepeatVector(200)(mean(clm_wrd_emb, axis=-1))
art_wrd_emb = Embedding(vocabulary_size, 200, input_length=200, weights=[glove_combinedinput_weight_matrix], trainable=False)(art_wrd)
ip_to_dense = Concatenate(axis=-1)([mean_clm_wrd_emb, art_wrd_emb])
attn_weights = Dense(128, activation='tanh')(clm_wrd_emb)
attn_weights = Activation('softmax')(attn_weights)
model_attn = Model(inputs=[art_wrd, clm_wrd], outputs=attn_weights)

lstm_op = Bidirectional(LSTM(lstm_op_dim, return_sequences=True), merge_mode='concat')(art_wrd_emb)
model_lstm = Model(inputs=art_wrd, outputs=lstm_op)


inner_pdt = Dot(axes=1)([model_attn.output, model_lstm.output])
avg = RepeatVector(1)(mean(inner_pdt, axis=-1))[:,0,:]

clm_src = Input(shape=(8,))
art_src = Input(shape=(8,))

final_feat = Concatenate(axis=1)([clm_src, avg, art_src])

x = Dense(op_1)(final_feat)
x = Dense(op_2)(x)

model = Model(inputs=[art_wrd,clm_wrd,clm_src,art_src], outputs=x)

初始错误是:

`/usr/local/lib/python3.6/dist-packages/keras/engine/network.py:180: UserWarning: Model inputs must come from 'keras.layers.Input' (thus holding past layer metadata), they cannot be the output of a previous non-Input layer. Here, a tensor specified as input to your model was not an Input tensor, it was generated by layer concatenate_24.
Note that input tensors are instantiated via 'tensor = keras.layers.Input(shape)'.
The tensor that caused the issue was: concatenate_24/concat:0
  str(x.name))`
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
 in ()
     48 #cred_score = Activation('softmax')(x)
     49 
---> 50 model = Model(inputs=[final_feat], outputs=x)
     51 
     52 model.fit()
/usr/local/lib/python3.6/dist-packages/keras/engine/network.py in build_map(tensor, finished_nodes, nodes_in_progress, layer, node_index, tensor_index)
   1323             ValueError: if a cycle is detected.
   1324         """
-> 1325         node = layer._inbound_nodes[node_index]
   1326 
   1327         # Prevent cycles.

AttributeError: 'NoneType' object has no attribute '_inbound_nodes'

更改后的错误是:

   AttributeError                            Traceback (most recent call last)
 in ()
     48 #cred_score = Activation('softmax')(x)
     49 
---> 50 model = Model(inputs=[art_wrd,clm_wrd,clm_src,art_src], outputs=x)
     51 
     52 model.fit()
:
:
/usr/local/lib/python3.6/dist-packages/keras/engine/network.py in build_map(tensor, finished_nodes, nodes_in_progress, layer, node_index, tensor_index)
   1323             ValueError: if a cycle is detected.
   1324         """
-> 1325         node = layer._inbound_nodes[node_index]
   1326 
   1327         # Prevent cycles.

AttributeError: 'NoneType' object has no attribute '_inbound_nodes'

0 个答案:

没有答案