如何在测试时使用tf.layers.batch_normalization?如何处理移动方差和均值?

时间:2018-03-19 20:15:50

标签: python tensorflow batch-normalization

我正在尝试使用tf.layers.batch_normalization在tensorflow中实现批量标准化。该算法适用于培训,但在测试中不起作用,我在网站上搜索了很多但无法理解错误,因为我是tensorflow的新手。我已经粘贴了我用于训练和测试的命令,任何提示?

if is_training: 
   return tf.layers.batch_normalization(inputs, axis=0, epsilon=1e-3, scale=True, center=True,training=True)

else:
   return tf.layers.batch_normalization(inputs, axis=0, epsilon=1e-3, scale=True, center=True,moving_mean_initializer=tf.zeros_initializer(), moving_variance_initializer=tf.ones_initializer(),training=False)

这是我得到的错误:

  

FailedPreconditionError(参见上面的回溯):尝试使用   未初始化的值batch_normalization_2 / beta [[节点:   batch_normalization_2 / beta / read = IdentityT = DT_FLOAT,   _class = [“loc:@ batch_normalization_2 / beta”],_ device =“/ job:localhost / replica:0 / task:0 / device:GPU:0”]]      [[节点:ArgMax_2 / _3 = _Recvclient_terminated = false,   recv_device = “/作业:本地主机/复制:0 /任务:0 /装置:CPU:0”,   send_device = “/作业:本地主机/复制:0 /任务:0 /设备:GPU:0”,   send_device_incarnation = 1,tensor_name =“edge_78_ArgMax_2”,   tensor_type = DT_INT64,   _device = “/作业:本地主机/复制:0 /任务:0 /装置:CPU:0”]]

0 个答案:

没有答案