具有is_training'true'和'false'的Batchnorm的不同行为-冻结模型的准确性不同

时间:2019-06-25 04:34:33

标签: tensorflow tensorflow-lite

我正在尝试推断mobilenetV2模型。

我已经使用tensorflow / models / slim训练了模型。 该模型使用is_training=true可提供适当的准确性。 但是,当我这样做时,is_training=false并保存模型,则推论得出的准确性将大大降低。

在这两种情况下,我可以在图形中看到以下差异。 使用is_training=true,然后moving_meanmoving_variance分别变成ConstConst_1。这是我能看到的唯一区别。 并且在推断过程中,FusedBatchNorm节点的输出在这两种情况下是不同的。

请有人帮助我了解它为什么会发生以及如何解决此问题?

Comparison of the two graphs

1 个答案:

答案 0 :(得分:0)

有同样的问题。

具有以下TF文件建议:

update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
with tf.control_dependencies(update_ops):
    train_step = tf.train.AdamOptimizer(1e-4).minimize(loss)

使用 is_training:错误

,我在TEST上获得了更高的准确性