我正在尝试在 tf.keras 中使用合并层,但得到 AssertionError: Could not compute output Tensor("concatenate_3/Identity:0", shape=(None, 10, 8), dtype=float32)
.最小(非)工作示例:
import tensorflow as tf
import numpy as np
context_length = 10
input_a = tf.keras.layers.Input((context_length, 4))
input_b = tf.keras.layers.Input((context_length, 4))
#output = tf.keras.layers.concatenate([input_a, input_b]) # same error
output = tf.keras.layers.Concatenate()([input_a, input_b])
model = tf.keras.Model(inputs = (input_a, input_b), outputs = output)
a = np.random.rand(3, context_length, 4).astype(np.float32)
b = np.random.rand(3, context_length, 4).astype(np.float32)
pred = model(a, b)
我在其他合并层(例如
add
)中遇到相同的错误。我在 TF2.0.0-alpha0 上,但在 colab 上与 2.0.0-beta1 相同。
最佳答案
好吧,错误消息没有帮助,但我最终偶然发现了解决方案:输入到 model
需要是一个可迭代的张量,即
pred = model((a, b))
工作得很好。
关于tensorflow - "Could not compute output"在 Tensorflow 2 中使用 tf.keras 合并层时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57434435/