开了batch_norm,训练集acc很高,而测试集acc很低怎么解决

因为batch_norm的两个平移缩放参数在训练的时候没有更新,需要手动更新一下

step = tf.get_variable("step", [], initializer=tf.constant_initializer(0.0), trainable=False)
optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.2)
train_step = slim.learning.create_train_op(cross_entropy, optimizer, global_step=step)
 
update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
if update_ops:
print("BN parameters: ", update_ops)
updates = tf.group(*update_ops)

train_step = control_flow_ops.with_dependencies([updates], train_step)

 

https://github.com/soloice/mnist-bn/blob/master/mnist_bn.py

你可能感兴趣的:(深度学习)