【发布时间】:2021-04-30 06:50:45
【问题描述】:
尝试在TF中做MatrixMultiplication
import tensorflow as tf
a1 = tf.constant(tf.random.normal(shape=(5,4,64)))
tf.matmul(a1,a1,transpose_b=True)
这工作得很好,但是如果我像下面这样手动transpose 输入a1,我会得到一个错误:
tf.matmul(a1,tf.transpose(a1))
错误:
InvalidArgumentError: In[0] and In[1] must have compatible batch dimensions: [5,4,64] vs. [64,4,5] [Op:BatchMatMulV2]
文档:
transpose_b: If True, b is transposed before multiplication.
所以我不明白其中的区别,任何建议都会有所帮助。
【问题讨论】:
标签: tensorflow matrix keras tensorflow2.0 matrix-multiplication