[英]Tensorflow throws “Dimensions must be equal, but are 100 and 0 for 'MatMul' (op: 'MatMul') with input shapes: [0,100], [0,100].”
[英]Shape must be rank 2 but is rank 3 for 'MatMul_46' (op: 'MatMul') with input shapes: [100,100], [?,15,100]
嘗試實現此行代碼時出現錯誤
對於輸入形狀為[100,100],[?, 15,100]的'MatMul_46'(op:'MatMul'),形狀必須為等級2,但等級3。
Q = tf.placeholder(tf.float32, shape=(None, 15))
word_level = Embedding ( vocab_size , 100 , input_length=15)(Q)
#shape(?,15,100)
Wb = tf.Variable(tf.zeros([100, 100]))
C = tf.matmul( word_level ,Wb)
我認為問題是因為3維和2維矩陣的等級不同,但我不知道如何修改
要修改張量以適合特定形狀,可以使用tf.reshape
,但要小心以tf.reshape
的方式對其進行重塑。
請參閱說明文件
reshape = tf.reshape(word_level, [-1, 100])
Wb = tf.Variable(tf.zeros([100, 100]))
C = tf.matmul(reshape ,Wb)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.