Is there any way to get tensor (with batch dimension) multiplication behavior similar to tf.matmul between 2D-matrix where the batch dimension equal to one ?
Specifically, I want to do 2D-matrix (6,255) and Tensor (2,255, 255,1) (with batch dimension equal to 2), where :
import tensorflow as tf
import numpy as np
im = np.random.rand(255, 255)
A = np.random.rand(6, 255)
B = np.array([im,im]).reshape([-1,255, 255,1])
batch_size = 2
a = tf.placeholder(tf.float64,shape=(6, 255))
b = tf.placeholder(tf.float64,shape=(batch_size,255, 255,1))
out_mat = tf.matmul(a,b) #Didn't work
with tf.Session() as sess:
sess.run(out_mat, feed_dict={a: A, b: B})
and the result should have (2, 6, 255, 1) (Thanks you @rvinas ) shape.
Note: In tensorflow, matmul can only handle 2D-matrices and batch_matmul can only do (...,m,n) by (...,n,p) where ... is the same in both A,B.