简体   繁体   中英

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

I got an error,

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

I wrote codes,

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) shows Tensor("cond_3/Merge:0", shape=(?, 68, 64), dtype=float32) and print(question_encoded) shows Tensor("cond_5/Merge:0", shape=(?, 4, 64), dtype=float32) .I think dot method is not good to calcurate matrix has different rank,so I rewrite

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

But this error occurs:

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

How can I calcurate input_encoded_m & question_encoded ? What is wrong ?

I'm not sure which of the dimensions your actual number of inputs is, but the first dimension needs to be the same.

But for example you need to have shapes:

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

or

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

or

(4, 68, 64) and (4, 64, 68) etc..

But you have number of inputs 68 and 4 , these need to match.

You should checkout the examples given in the here in the docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM