tensorflow - 推理时 tensorflow 中的批量归一化

标签 tensorflow machine-learning deep-learning

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

但在 tensorflow 中 y 给出为 -6.781823635101318359e-01

为什么会发生这种情况?在 tensorflow 中批量归一化的推理时间,这个方程是否正确?这里我使用tensorflow.contrib.slim.batch_norm函数。

最佳答案

你的 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

关于tensorflow - 推理时 tensorflow 中的批量归一化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59253592/

相关文章:

python - Tensorflow Keras 也使用 tfrecords 进行验证

python - tensorflow 中两个向量的点积

tensorflow - 如何在 Tensorboard 中隐藏 "Cond"张量? (附截图)

machine-learning - Weka java库: how to get string representation of classified instance?

machine-learning - Keras 中的 LSTM 是否支持动态句子长度?

python - 将文本特征名称链接到其 tfidf 值

python - 我会尝试更改 keras 预训练模型的 channel

python - Tensorflow:使用不同的 "call"函数创建 LSTM 单元的自定义子类

python - 什么是 tensorflow 哈希函数?

python - 使用 Python OpenCV 删除图像的黑色标题部分