tf.train.write_graph用法

本文介绍了如何使用tf.train.write_graph保存TensorFlow模型的图结构,并强调该方法不保存变量,需要通过convert_variables_to_constants转换为常量。同时,文章提到了tensorboard在模型结构可视化中的作用,以及如何运行tensorboard进行可视化。对于如何获取图中张量以及保存包含变量的图,文章给出了相应解答。
摘要由CSDN通过智能技术生成

我不是知识的生产者,我只是一个渺小的搬运工,我们都站在巨人的肩膀上


探索了一下午这玩意的用法,终于会用了,在此附上实例子

首先要明白他保存图的原理,这个里面讲的很详细,请细品

https://zhuanlan.zhihu.com/p/31308381

tf.train.write_graph这个函数可以保留节点,op,constant,但不保存variable,如果你想要保存variable,那么就要转为constant

import tensorflow as tf
import numpy as np
from tensorflow.python.platform import gfile

#生成图
input1= tf.placeholder(tf.int32,name="input")
b = tf.constant([3])
output1= tf.add(input1, b, name="output")

#保存图
with tf.Session() as sess:
    tf.train.write_graph(sess.graph_def, "./", "test.pb", False)
    print(sess.run(output1,feed_dict={input1:1}))

#读取图
with tf.Session() as sess:
    with gfile.FastGFile("./test.pb",'rb') as f:
        graph = tf.get_default_graph()
        graph_def &
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值