会话图为空 [英] Session graph is empty
问题描述
我一直在尝试使用提供的答案来迭代张量流模型Tensorflow:即使关闭会话也有内存泄漏?我遇到了与其中一条评论中提到的相同的错误,即会话图为空.在调用 run() 之前向图中添加操作".我不知道如何解决它.
I have been trying to iterate the tensorflow model using the answer provided on Tensorflow : Memory leak even while closing Session? I have the same error as mentioned in one of the comments i.e. "The Session graph is empty. Add operations to the graph before calling run()." I cannot figure out how to solve it.
推荐答案
我的建议是确保您的会话知道它在哪个图形上运行.您可以尝试的方法是:
My suggestion is to make sure your session knows which graph it is running on. Somethings you can try are:
首先构建图表并将图表传递给会话.
build the graph first and pass in the graph to a session.
myGraph = tf.Graph()
with myGraph.as_default():
# build your graph here
mySession = tf.Session(graph=myGraph)
mySession.run(...)
# Or
with tf.Session(graph=myGraph) as mySession:
mySession.run(...)
如果要使用多个 with
语句,请以嵌套方式使用.
If you want to use multiple with
statement, use it in a nested way.
with tf.Graph().as_default():
# build your graph here
with tf.Session() as mySession:
mySession.run(...)
这篇关于会话图为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!