使用张量流输出神经网络的权重 [英] Export weights of neural network using tensorflow
问题描述
我使用张量流工具编写了神经网络. 一切正常,现在我想导出神经网络的最终权重以制定一个预测方法. 我该怎么办?
I wrote neural-network using tensorflow tools. everything working and now I want to export the final weights of my neural network to make a single prediction method. How can I do this?
推荐答案
You will need to save your model at the end of training by using the tf.train.Saver
class.
在初始化Saver
对象时,您将需要传递所有要保存的变量的列表.最好的部分是您可以在其他计算图中使用这些保存的变量!
While initializing the Saver
object, you will need to pass a list of all the variables you wish to save. The best part is that you can use these saved variables in a different computation graph!
使用
# Assume you want to save 2 variables `v1` and `v2`
saver = tf.train.Saver([v1, v2])
使用 tf.Session
保存变量对象,
Save your variables by using the tf.Session
object,
saver.save(sess, 'filename');
当然,您可以添加其他详细信息,例如global_step
.
Of course, you can add additional details like global_step
.
您将来可以使用restore()
函数还原变量.恢复的变量将自动初始化为这些值.
You can restore the variables in the future by using the restore()
function. The restored variables will be initialized to these values automatically.
这篇关于使用张量流输出神经网络的权重的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!