I have two tensors a = torch.randn(2, 3, 10, 25, 25) # B x C x *
and b = a.permute(0, 2, 1, 3, 4) # 2 x 10 x 3 x 25 x 25
, I want to do matrix multiplication on a
and b
to get the output with size of 2 x 3 x 3 x 25 x 25
,
a = torch.randn(2, 3, 10, 25, 25)
b = a.permute(0, 2, 1, 3, 4)
c = torch.matmul(a, b)
but I ran into this error,
RuntimeError: The size of tensor a (10) must match the size of tensor b (3) at non-singleton dimension 2
so I check the torch.matmul and found out that I should permute a = a.permute(0, 3, 4, 1, 2) # 2 x 25 x 25 x 3 x 10
and b
and then do matrix multiplication. But in training, pytorch is in the default channel first so is swapping the channel to last, doing matmul and swapping channel back to first the only solution?