Batch norm in config
Hi , We are using a config which uses batch norm. We want to take the ckpt and port it over to low level GPU calls on . mobile for prediction. These are the trainable variables i observe
0-convolutional/biases:0 (16,) 0-convolutional/kernel:0 (3, 3, 3, 16) 0-convolutional/gamma:0 (16,) 0-convolutional/moving_mean:0 (16,) 0-convolutional/moving_variance:0 (16,)
On freezing the graph, i see the following operations [i cant see variables anymore when frozen]
0-convolutional/filter 0-convolutional sub/y sub truediv/y truediv mul/y mul BiasAdd/bias BiasAdd
I am wondering if savepb is folding batch norm variables already in to weights and biases ? I dont see it from the code. Assuming it does not fold, it would make it imperative that we do it ourselves. I dont see a "beta" variable which is needed to do the folding.
A = 𝛄 / √(s + 0.001), b = ß - ( A * m )
W = w*A
s: variance m: mean 𝛄: gamma ß: beta
w: weights of a feature channel b: bias of a feature channel W: batch nomalized weights
So i dont know how to compute this. Any help is appreciated
0-convolutional/filter
0-convolutional
sub/y
sub
truediv/y
truediv
mul/y
mul
BiasAdd/bias
BiasAdd
Is exactly what a convolution with batchnorm would do: convolution -> mean subtract -> variance divide -> add bias. The bias of batchnorm and bias of convolution can be merged into one since it does not make sense mathematically to perform two biases consecutively.
Are you saying there are already merged [bias of batchnorm and bias of convolution]. Where is the beta as is seen in other batch norm models. Also, are you suggesting that we write these operations by ourselves for inference ? We are going to take the model apart and only keep weights and biases.
Yes, the two biases are merged. Beta in a standard Batchnorm is not necessary anymore in practice when going with a Convolution. You do not need to write these operations yourselves. Weights and Biases are not enough, you also need Moving Mean and Moving Variance to perform Batchnorm.