使用张量流输出神经网络的权重 [英] Export weights of neural network using tensorflow

查看:90
本文介绍了使用张量流输出神经网络的权重的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用张量流工具编写了神经网络. 一切正常,现在我想导出神经网络的最终权重以制定一个预测方法. 我该怎么办?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆