Keras多输入AttributeError:"NoneType"对象没有属性"inbound_nodes" [英] Keras Multi-inputs AttributeError: 'NoneType' object has no attribute 'inbound_nodes'

查看:427
本文介绍了Keras多输入AttributeError:"NoneType"对象没有属性"inbound_nodes"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试建立一个如下图所示的模型.想法是采用多个分类特征(单热向量)并将其分别嵌入,然后将这些嵌入的向量与3D张量组合以用于LSTM.

I'm trying to build a model as ilustrated in below diagram. The idea is to take more than one categorical features (one-hot vectors) and embed them separately, then combine those embedded vectors with a 3D tensor for a LSTM.

使用 Keras2.0.2 中的以下代码,在创建具有多个输入的Model()对象时,它会引发一个AttributeError: 'NoneType' object has no attribute 'inbound_nodes',类似于

With following code in Keras2.0.2, when creating the Model() object with multiple inputs, it raises an AttributeError: 'NoneType' object has no attribute 'inbound_nodes' similar to this question. Can anyone help me to figure out what's the problem?

型号:

代码:

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'

推荐答案

keras.backend.repeat是一个函数,而不是一个层.尝试使用 keras.layers.core.RepeatVector 反而.它具有与功能相同的功能.

keras.backend.repeat is a function, not a layer. Try using keras.layers.core.RepeatVector instead. It has the same functionality as the function.

emd_out_3d = RepeatVector(10)(emd_out)

这篇关于Keras多输入AttributeError:"NoneType"对象没有属性"inbound_nodes"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆