I was trying to check speed difference between Conv2d and Conv3d and was surprised with the results
import torch
import torch.nn as nn
import time

F = 30
data = torch.randn(1,256, F, 256, 256).cuda()

def time2D():
        conv2d = nn.Conv2d(256,256,3).cuda()
        data1 = data.reshape(F,256,256,256)
        start = time.time()
        print(conv2d(torch.autograd.Variable(data1)).size())
        print("  --- %s ---  " %(time.time() - start))

def time3D():
        conv3d = nn.Conv3d(256,256,(3,3,3)).cuda()
        start = time.time()
        print(conv3d(torch.autograd.Variable(data)).size())
        print(print("  --- %s ---  " %(time.time() - start)))


print("going to time2D")
time2D()
print("going to time3D")
time3D()



and the output was the following
going to time2D
torch.Size([30, 256, 254, 254])
  --- 0.42415595054626465 ---  
going to time3D
torch.Size([1, 256, 28, 254, 254])
  --- 0.00014209747314453125 ---  


Why is Conv3d quicker than Conv2d ??? This was opposite of what I expected.
I couldnt think of a good reason for why this is happening?? Can someone give some logic or even intuition why this is the case?
Also if it’s correct why do we use 2D convolutions?? We can stack all images along the depth dimension and use Conv3d(inFeat,outFeat,(1,kernelX,kernelY))!!!