即使在 Keras 中使用 Lambda 层也没有属性 '_inbound_nodes' 错误

no attribute '_inbound_nodes' error even when using Lambda layer in Keras

我有一个 (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 变量

好的,我解决了这个问题。因此,所有基于后端的函数都需要包装在 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]))