输出是
tf.Variable 'Variable_1:0' shape=(10, 15, 9488) dtype=float32_ref
我想将它转换为 keras 层。
input_output = Input(shape=(10,512))
model = Model(input_output, output)
有什么办法吗?
目前错误是
Output tensors to a Model must be the output of a Keras Layer (thus holding past layer metadata).
Found:
tf.Variable 'Variable_1:0' shape=(10, 15, 9488) dtype=float32_ref
=============================================
我尝试使用 Lambda,但出现以下错误:
ValueError:模型的输出张量必须是 Keras Layer
的输出
(因此持有过去的层元数据)。
发现:keras.layers.core.Lambda 对象位于 0x7fad52faf550
这是我所做的:
def convert_tensor(self, outputs):
return outputs
input_result = Input(shape=(int(outputs.shape[0]), int(outputs.shape[1]),int(outputs.shape[2])))
outputs = Lambda(self.convert_tensor(outputs), output_shape=(10, 15, 9488))
model = Model(input_result, outputs)
最佳答案
你没有正确使用 Lambda 层,它应该是这样的:
input_result = Input(shape=(int(outputs.shape[0]), int(outputs.shape[1]),int(outputs.shape[2])))
outputs = Lambda(self.convert_tensor, output_shape=(10, 15, 9488))(input_result)
model = Model(input_result, outputs)
您必须将函数传递给 lambda,而不是函数调用,然后使用适当的输入“调用”lambda。
关于python - 如何将变量转换为keras层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52731302/