【问题标题】:no attribute '_inbound_nodes' error even when using Lambda layer in Keras即使在 Keras 中使用 Lambda 层,也没有属性“_inbound_nodes”错误
【发布时间】:2019-08-31 09:31:39
【问题描述】:

我有一个 (28,000 x 300) 维度矩阵,我们称之为 label_embedding,我想用我的模型的瓶颈层做一个点积。我创建了一个架构,它在其瓶颈层提供 (batch_size x 300)

我正在使用生成器函数进行输入。 label_embedding 矩阵按如下方式作为输入:

inp7 = Input(tensor=labels_embeddings)

对于点积,我正在执行以下操作:

out = Lambda(dot_)([x1, K.transpose(inp7)])

其中 x1 是瓶颈层,dot_ 是:

def dot_(tensors):
    return K.dot(tensors[0], tensors[1])

问题是,即使 out 变量的形状是正确的,即 (batch_size x 28000),我得到以下错误:

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

P.S.:我正在使用 tensorflow 和 keras

P.S.:我一直在使用 keras 层,直到我使用 keras 后端作为 K 的 out 变量

【问题讨论】:

    标签: tensorflow keras dot-product


    【解决方案1】:

    好的,我解决了这个问题。因此,所有基于后端的函数都需要包装在 lambda 层中。所以而不是:

    out = Lambda(dot_)([x1, K.transpose(inp7)])
    

    def dot_(tensors):
        return K.dot(tensors[0], tensors[1])
    

    我写道:

    out = Lambda(dot_)([x1, inp7])
    

    def dot_(tensors):
        return K.dot(tensors[0], K.transpose(tensors[1]))
    

    【讨论】:

      猜你喜欢
      • 2019-11-08
      • 1970-01-01
      • 2019-09-23
      • 1970-01-01
      • 2020-08-26
      • 1970-01-01
      • 2019-04-25
      • 2019-03-21
      • 1970-01-01
      相关资源
      最近更新 更多