Difference between batchnorm1d and batchnorm2d

Batchnorm2d is meant to take an input of size NxCxHxW where N is the batch size and C the number of channels. But is it the same if I fold the two last dimensions together, call Batchnorm1d and then unfold them after the normalization?
Thanks a lot.

If I am not wrong , I think when you are talking about batchnorm2d you mean Spatial Batchnormalization which intakes an input of size (N,C,H,W) and returns back the same size.
In spatial BN mean and variances are calculated for each color channelĀ© across all the images. So if you want to use batchnorm1d to perform spatial BN , you need to input a 2dim array of size(NHW, C,). So, just folding last 2 dimensions will give you array of size (N, CHW) which is incorrect input. So you need to swap first 2 axes to (C,N,H,W) then fold last 2 dims (C,NHW) and then transpose it (NHW, C) and now pass it to BN1d and then perform reverse steps on the output to get the desired result.

Hope this helps!!

P.S: I am new to the pytorch community. Please correct me if I am wrong.