My x is -1.593087986111640930e-02,
beta is 4.061257466673851013e-02,
moving mean is -1.356904511339962482e-03,
moving variance is 4.480824827624019235e-06
gamma is false so result will not scale
epsilon = 0.001
x_hat = (x - moving_mean) / square_root_of(moving_variance + epsilon)
y = gamma * x_hat + beta
当我手动计算时,y为-0.4192285
但在张量流中y为-6.781823635101318359e-01
为什么会这样?张量流中的批量归一化在推理时这个正确的方程式吗?在这里,我正在使用tensorflow.contrib.slim.batch_norm函数。
答案 0 :(得分:2)
您的epsilon太大了。看一下您的移动方差,它在1e-6左右,并且您要向其中添加1e-3作为epsilon!
当您将epsilon更改为更合适的东西(想想1e-9)时,它将变得更接近TF提供的功能。人们添加epsilon的唯一原因是避免除以0,这甚至在tf.batch_normalization页面上也已指出,因此1e-3太高了: https://www.tensorflow.org/api_docs/python/tf/nn/batch_normalization