错误:在连接层时出现’NoneType’对象没有属性’_inbound_nodes’的错误(多输入模型)

我对深度学习和神经网络还比较陌生。

我有一个包含文本和数值特征的数据集,我试图用这里给出的方法来解决这个问题

我将数据集分为两部分,一部分是文本特征(X_text),另一部分是数值特征(X_num)。我将文本(X_text)中的所有列合并到一个单一的列中,然后删除了其他列。接着我对这一列运行了TfidfVectorizer,并将其转换为一个形状为(1905, 20859)的数组。X_num的形状为(1905,34)

之后我使用的代码如下

from keras.models import Sequentialfrom keras.layers import Dense, Embedding, Flatten, LSTM, Input, Bidirectional, Concatenatefrom keras.optimizers import adamfrom keras import regularizersfrom keras.backend import concatenatefrom keras import Modelnlp_input = Input(shape=(20860,))meta_input = Input(shape=(35,))emb = Embedding(output_dim=32, input_dim=20859)(nlp_input)nlp_output = Bidirectional(LSTM(128, dropout=0.3, recurrent_dropout=0.3, kernel_regularizer=regularizers.l2(0.01)))(emb)x = concatenate([nlp_out, meta_input])layer1 = Dense(32, activation='relu')(x)layer2 = Dense(1, activation='sigmoid')(layer1)model = Model(inputs=[nlp_input , meta_input], outputs=layer2)optimizer=adam(lr=0.00001)model.compile(optimizer=optimizer, loss='binary_crossentropy', metrics = ['binary_accuracy'])

我得到的错误是:

    Traceback (most recent call last)        <ipython-input-51-d98028f8916d> in <module>             13 layer1 = Dense(32, activation='relu')(x)             14 layer2 = Dense(1, activation='sigmoid')(layer1)        ---> 15 model = Model(inputs=[nlp_input , meta_input], outputs=layer2)        /anaconda3/lib/python3.6/site-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)             89                 warnings.warn('Update your `' + object_name + '` call to the ' +             90                               'Keras 2 API: ' + signature, stacklevel=2)        ---> 91             return func(*args, **kwargs)             92         wrapper._original_function = func             93         return wrapper        /anaconda3/lib/python3.6/site-packages/keras/engine/network.py in __init__(self, *args, **kwargs)             91                 'inputs' in kwargs and 'outputs' in kwargs):             92             # Graph network        ---> 93             self._init_graph_network(*args, **kwargs)             94         else:             95             # Subclassed network        /anaconda3/lib/python3.6/site-packages/keras/engine/network.py in _init_graph_network(self, inputs, outputs, name)            229         # Keep track of the network's nodes and layers.            230         nodes, nodes_by_depth, layers, layers_by_depth = _map_graph_network(        --> 231             self.inputs, self.outputs)            232         self._network_nodes = nodes            233         self._nodes_by_depth = nodes_by_depth        /anaconda3/lib/python3.6/site-packages/keras/engine/network.py in _map_graph_network(inputs, outputs)           1364                   layer=layer,           1365                   node_index=node_index,        -> 1366                   tensor_index=tensor_index)           1367            1368     for node in reversed(nodes_in_decreasing_depth):        /anaconda3/lib/python3.6/site-packages/keras/engine/network.py in build_map(tensor, finished_nodes, nodes_in_progress, layer, node_index, tensor_index)           1351             tensor_index = node.tensor_indices[i]           1352             build_map(x, finished_nodes, nodes_in_progress, layer,        -> 1353                       node_index, tensor_index)           1354            1355         finished_nodes.add(node)        /anaconda3/lib/python3.6/site-packages/keras/engine/network.py in build_map(tensor, finished_nodes, nodes_in_progress, layer, node_index, tensor_index)           1351             tensor_index = node.tensor_indices[i]           1352             build_map(x, finished_nodes, nodes_in_progress, layer,        -> 1353                       node_index, tensor_index)           1354            1355         finished_nodes.add(node)        /anaconda3/lib/python3.6/site-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'

我在其他地方读到可以使用Lambda层,将函数作为Keras中的层,也许问题就出在这里。但据我所知,我并没有一个函数可以调用。您有什么修复这个问题的想法吗?


回答:

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注