问题描述
我正在尝试确保将批归一化层正确地合并到模型中。
下面的代码段说明了我在做什么。
- 这是否适合使用批量标准化?
- 在推断时,如何访问每个批次归一化层中的移动平均值以确保已加载它们?
列表项
import tensorflow.v1.compat as tf
from model import Model
# Sample batch normalization layer in the Model class
x_preBN = ...
x_postBN = tf.layers.batch_normalization(inputs=x_preBN,center=True,scale=True,momentum=0.9,training=(self.mode == 'train'))
# During training:
model = Model(mode='train')
extra_update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
with tf.Session() as sess:
for it in range(max_iterations):
# Training step + update of BN moving statistics
sess.run([train_step,extra_update_ops],feed_dict=...)
# Store checkpoint
if ii % num_checkpoint_steps == 0:
saver.save(sess,os.path.join(model_dir,'checkpoint'),global_step=it)
# During inference:
model = Model(mode='eval')
with tf.Session() as sess:
saver.restore(sess,'checkpoint-???'))
acc = sess.run(model.accuracy,feed_dict=...)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)