TensorFlow中的batch_nomalization

tf.layers.batch_normalization 的使用

BN使用要注意:
1.一般在卷积层使用;
2.一般在非线性激活之前使用;
3.在训练时training=True, 在测试时training=False。
注意:1.设training为一个feed的布尔值变量,在训练和测试时feed不同的值。
2.在训练时,要把计算得到的均值和方差保存下来,方便测试时使用
训练过程:

with tf.name_scope('train_op'):
    update_ops = tf.get_collection(tf.GraphKeys.UPDATES_OPS)
    with tf.control_dependencies(update_ops):
        train_op = tf.train.AdamOptimizer(learning_rate).minimize(loss)

# ....
training = tf.placeholder(tf.bool)
feed_dict = {x:batch_x, y:batch_y, training:True}

测试过程:

training = tf.placeholder(tf.bool)
feed_dict = {x:batch_x, y:batch_y, training:False}

参考https://www.cnblogs.com/hrlnw/p/7227447.html

你可能感兴趣的:(神经网络)