我有两个形状为(batch size,15,500),(batch size,500,98)的张量,我想将它们作为矩阵乘以每个批次大小的矩阵张量,以获得(batch size,15,98)我如何在tensorflow中做到这一点或keras后端,我可以使用批处理点
You can use
A = K.placeholder((None, 15, 500))
B = K.placeholder((None, 500, 98))
C = tf.einsum("ijk,ljn->ijn", A, B)
In [84]: C
Out[84]: <tf.Tensor 'einsum/transpose_2:0' shape=(?, 15, 98) dtype=float32>
This says contract on index j, which is what a single matrix multiplication would look like, and repeat that for index i
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.