Hi all, I’m trying to figure out how exactly a 2d BN layer applies on an input tensor. Let me give a toy example:
import torch
import torch.nn as nn
num_features = 3
X = torch.randn(2, num_features, 4, 4)
bn = nn.BatchNorm2d(num_features)
Y = bn(X)
What I would like to do is to “reproduce” the output of the BN layer, Y
, not by passing X
through bn()
, but by using the formula shown here.
That is, I would something like:
Z = bn.xxx * torch.div(X - bn.yyy, torch.sqrt(bn.zzz + bn.eps)) + bn.ppp
I’m looking for the correct attributes of bn
(xxx
, yyy
, zzz
, and ppp
) - or, even a yet better way to do that, since -during training- I want to get the parameters of BN layer and apply them to another tensor.
Thanks a lot.