oneDNN icon indicating copy to clipboard operation
oneDNN copied to clipboard

Batch normalization 2D

Open RadjaHachilif opened this issue 7 years ago • 6 comments

Hello people, Can you please tell me how to use batch normalization for 2D call ( on a 4D input ) ?

Thank you

RadjaHachilif avatar Dec 13 '18 20:12 RadjaHachilif

Hi @RadjaHachilif,

You can find a simple example here. To get more info about different flavors please refer to the documentation and also batch normalization flags.

You can also look into batch normalization tests in gtest (uses C++) and in benchdnn (uses C).

emfomenk avatar Dec 18 '18 13:12 emfomenk

Thank you for your answer, But I don't understand the difference between this example and the regular batch normalization call ( perform normalization for each channel on 3D tensors )

RadjaHachilif avatar Dec 22 '18 18:12 RadjaHachilif

Sorry for delay.

Could you please elaborate on what do you mean regular batch normalization call? Intel MKL-DNN performs regular batch normalization, so what kind of difference do you expect?

emfomenk avatar Dec 26 '18 15:12 emfomenk

I apologize, your example indeed is a 2D batch normalization over 4D inputs, I had a problem with the definition of 2d bn and i found this explanation in PyTorch documentation

Batch Normalization over a 4D input (a mini-batch of 2D inputs with additional channel dimension). The mean and standard-deviation are calculated per-dimension over the mini-batches .... Because the Batch Normalization is done over the C dimension, computing statistics on (N, H, W) slices, it's common terminology to call this Spatial Batch Normalization.

Thank you so much for your help.

RadjaHachilif avatar Dec 26 '18 15:12 RadjaHachilif

Oh, I see.

Yes, Intel MKL-DNN's batch normalization does exactly what you found in PyTorch's documentation. In fact this algorithm should be pretty common across all major frameworks like TF, MxNet, PyTorch, and Caffe.

emfomenk avatar Dec 26 '18 15:12 emfomenk

Close this for now. Feel free to reopen or create a new issue if you have any further questions.

emfomenk avatar Jan 03 '19 05:01 emfomenk