batchnorm BN无法更新保存参数 moving_mean/variance

  • Post author:
  • Post category:其他


在复现resnetv2的时候遇到了BN保存的问题,直接导致的结果就是

训练集收敛很快,测试集准确率上升缓慢

甚至上不去。查解决方案的时候看到网上也同样有不少同道中人,如果你试了很多方法还不管用,建议你试试本文所述的。

1.官方提示你可以点进batchnorm查看,它说让添加如下代码来保存BN参数:

update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
    with tf.control_dependencies(update_ops):
	    train_op = opt.minimize(loss, global_step=global_step)

2.如果添加了该部分代码仍然存在之前的现象,建议多跑几轮,因为:

# Note: the validation error is erratic in the beginning (Maybe 2~3k steps).

# This does NOT imply the batch normalization is buggy.

# On the contrary, it’s BN’s dynamics: moving_mean/variance are not estimated that well in the beginning.

3.如果你是调成is_train=True结果正常,而false就不正常,建议创建2个graph,一个用于训练,一个用于验证。部分网络还有reuse的参数,正确的设置方法应该是在训练的时候is_train=true, reuse=false; 在跑验证集的时候, is_train=false, reuse=true; 在跑测试集的时候, is_train=false, reuse=false。



版权声明:本文为qq_35556369原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。