Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用tensorflow在推断阶段加载移动平均权重变量_Python_Tensorflow - Fatal编程技术网

Python 如何使用tensorflow在推断阶段加载移动平均权重变量

Python 如何使用tensorflow在推断阶段加载移动平均权重变量,python,tensorflow,Python,Tensorflow,我想在推理阶段使用移动平均模型权重,我知道如何使用tf.train.ExponentialMovingAverage,但我不知道如何保存移动平均权重变量(也有偏差)并在推理期间加载它们,而不是使用最终的训练值。最简单的方法是使用内置,这将包装您的优化器,并生成一个变量保护程序,用于将变量与其移动平均值交换 文档中的示例: // Encapsulate your favorite optimizer (here the momentum one) // inside the MovingAvera

我想在推理阶段使用移动平均模型权重,我知道如何使用tf.train.ExponentialMovingAverage,但我不知道如何保存移动平均权重变量(也有偏差)并在推理期间加载它们,而不是使用最终的训练值。

最简单的方法是使用内置,这将包装您的优化器,并生成一个变量保护程序,用于将变量与其移动平均值交换

文档中的示例:

// Encapsulate your favorite optimizer (here the momentum one)
// inside the MovingAverageOptimizer.
opt = tf.train.MomentumOptimizer(learning_rate, FLAGS.momentum)
opt = tf.contrib.opt.MovingAverageOptimizer(opt)
// Then create your model and all its variables.
model = build_model()
// Add the training op that optimizes using opt.
// This needs to be called before swapping_saver().
opt.minimize(cost, var_list)
// Then create your saver like this:
saver = opt.swapping_saver()
// Pass it to your training loop.
    slim.learning.train(
        model,
        ...
        saver=saver)