ValueError:尺寸必须相等,但输入形状为[?,64],[4,?]

时间:2018-08-11 11:32:21

标签: python tensorflow keras

我遇到一个错误,

ValueError: Dimensions must be equal, but are 64 and 4 for 'MatMul' (op: 'MatMul') with input shapes: [?,64], [4,?].

我写了代码,

from keras import backend as K

print(input_encoded_m)
print(question_encoded)
match = K.dot(input_encoded_m, question_encoded)

print(input_encoded_m)显示Tensor("cond_3/Merge:0", shape=(?, 68, 64), dtype=float32),print(question_encoded)显示Tensor("cond_5/Merge:0", shape=(?, 4, 64), dtype=float32)。我认为点方法不适用于计算具有不同等级的矩阵,所以我重写了

from keras import backend as K
match = K.get_value(input_encoded_m * question_encoded)

但是会发生此错误:

ValueError: Dimensions must be equal, but are 68 and 4 for 'mul' (op: 'Mul') with input shapes: [?,68,64], [?,4,64]

如何计算input_encoded_mquestion_encoded?怎么了?

1 个答案:

答案 0 :(得分:0)

我不确定您实际输入的数量是哪个维度,但是第一个维度必须相同。

但是例如,您需要具有形状:

(68, 64, 4)(68, 4, 64)

(64, 68, 4)(64, 4, 68)

(4, 68, 64)(4, 64, 68)等。

但是您有684个输入,它们需要匹配。

您应该查看here in the docs中给出的示例。

相关问题