首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >NoneType‘object没有属性'_inbound_nodes’

NoneType‘object没有属性'_inbound_nodes’
EN

Stack Overflow用户
提问于 2018-10-03 22:04:23
回答 1查看 2.2K关注 0票数 2

嗨,我正在尝试建立一个混合的专家神经网络。我在这里找到了一个代码:dc3c53e90102x9xu.html。我的目标是,门和专家来自不同的数据,但具有相同的维度。

代码语言:javascript
运行
复制
def sliced(x,expert_num):
    return x[:,:,:expert_num]

def reduce(x, axis):
    return K.sum(x, axis=axis, keepdims=True)

def gatExpertLayer(inputGate, inputExpert, expert_num, nb_class):
    #expert_num=30
    #nb_class=10
    input_vector1 = Input(shape=(inputGate.shape[1:]))
    input_vector2 = Input(shape=(inputExpert.shape[1:]))

    #The gate
    gate = Dense(expert_num*nb_class, activation='softmax')(input_vector1)
    gate = Reshape((1,nb_class, expert_num))(gate)
    gate = Lambda(sliced, output_shape=(nb_class, expert_num), arguments={'expert_num':expert_num})(gate)

    #The expert
    expert = Dense(nb_class*expert_num, activation='sigmoid')(input_vector2)
    expert = Reshape((nb_class, expert_num))(expert)

    #The output
    output = tf.multiply(gate, expert)
    #output = keras.layers.merge([gate, expert], mode='mul')
    output = Lambda(reduce, output_shape=(nb_class,), arguments={'axis': 2})(output)

    model = Model(input=[input_vector1, input_vector2], output=output)

    model.compile(loss='mean_squared_error', metrics=['mse'], optimizer='adam')

    return model

但是,我得到了"'NoneType‘对象没有属性'_inbound_nodes'“。我在这里检查了其他类似的问题:nodes' while trying to add multiple keras Dense layers,但是这个问题是用keras的Lambda函数解决的,可以转换成一个层。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-03 23:04:35

那么,您需要将tf.multiply()放在Lambda层中,以获得作为输出的Keras张量(而不是张量):

代码语言:javascript
运行
复制
output = Lambda(lambda x: tf.multiply(x[0], x[1]))([gate, expert])
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52636328

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档