I have a pretrained network containing BatchNorm2d layers. I want to inflate the network to 3d, (concatenate spatial filters in temporal dimension converting 2d cnn to 3d cnn, and similarly batchnorm2d to batchnorm3d)
Basically you can assume if output of single image on model is ‘x’, then output of k similar stacked images would be ‘x’ stacked k times.
I inflated conv layers by manually copying the weights and it worked pretty well using the function below
def inflateconv(conv3d, conv):
	conv3d.weight.data = conv.weight.data[:,:,None,:,:].expand(conv3d.weight.data.size()) * (1./(conv3d.weight.data.shape[2]))
	conv3d.bias.data = conv.bias.data
	conv3d.weight.data = conv3d.weight.data.contiguous()
	conv3d.bias.data = conv3d.bias.data.contiguous()
	return

I wrote a function for Batchnorm but it doesnt work as expected
def inflatebn(bn3d, bn):
	bn3d.weight.data = bn.weight.data
	bn3d.bias.data = bn.bias.data
	bn3d.running_mean = bn.running_mean
	bn3d.running_var = bn.running_var
	bn3d.weight.data = bn3d.weight.data.contiguous()
	bn3d.weight.data = bn3d.weight.data.contiguous()
	bn3d.running_mean = bn3d.running_mean.contiguous()
	bn3d.running_var = bn3d.running_var.contiguous()
	return

But batchnorm 2d output differs from batchnorm3d output!