gpt4 book ai didi

python - Tensorflow:将 session 传递给 python 多进程

转载 作者:太空狗 更新时间:2023-10-29 20:31:19 27 4
gpt4 key购买 nike

我正在使用 tensorflow 预处理一些大图像。我遇到了内存迅速崩溃的问题。我转向在 python 中使用多处理,这样内存就会在我需要的时候完全释放。

问题是,我正在使用 python 的多进程队列,由于某种未知原因,我无法将我的 tensorflow session 从我的父进程传递给子进程。使用一些高级调试技术(即每隔几行打印一些东西)我注意到 python 只是在我使用 session 的行内闲置,它不会抛出错误消息。

我的代码看起来像这样:

def subprocess(some_image, sess, q):
with sess.as_default():
# ... use sess and q ...
print "All good and well" #This is printed
some_image.eval() #Nothing happens here in console
print "Still all good and well" #This is not printed

if __name__ == '__main__':
# ... some initial operations ...
some_image = read_some_image()

sess = tf.Session()

q = Queue()
q.put(something)
p = Process(target=subprocess, args=(some_image, sess, q))
p.start()
p.join()

可能是什么问题?非常感谢!

最佳答案

我不认为你可以分享"state"就像进程之间的 tf.Session() 那样。我认为每个进程都需要它自己的 session 。

关于python - Tensorflow:将 session 传递给 python 多进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34900246/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com