相关疑难解决方法(0)

从文件打开张量流图

我正在尝试使用 tensorflow 进行研究,但我不明白如何打开和使用早期保存在文件中的类型为 tf.Graph 的图形。像这样的东西:

import tensorflow as tf

my_graph = tf.Graph()

with g.as_default():
    x = tf.Variable(0)
    b = tf.constant(-5)
    k = tf.constant(2)

    y = k*x + b

tf.train.write_graph(my_graph, '.', 'graph.pbtxt')

f = open('graph.pbtxt', "r")

# Do something with "f" to get my saved graph and use it below in
# tf.Session(graph=...) instead of dots

with tf.Session(graph=...) as sess:
    tf.initialize_all_variables().run()

    y1 = sess.run(y, feed_dict={x: 5})
    y2 = sess.run(y, feed_dict={x: 10})
    print(y1, y2)
Run Code Online (Sandbox Code Playgroud)

python graph tensorflow

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

graph ×1

python ×1

tensorflow ×1