【发布时间】:2019-10-10 02:40:06
【问题描述】:
我在循环中使用 sess.run() 运行几个 tensorflow 推理,但碰巧有些推理对于我的 GPU 来说太重了。
我收到如下错误:
2019-05-23 15:37:49.582272: E tensorflow/core/common_runtime/executor.cc:623]
Executor failed to create kernel. Resource exhausted: OOM when allocating tensor of shape [306] and type float
我希望能够捕获这些特定的 OutOfMemory 错误,但不能捕获其他错误(这可能是由于输入格式错误或图表损坏。)
很明显,结构类似于:
try:
sess.run(node_output, feed_dict={node_input : value_input})
except:
do_outOfMemory_specific_stuff()
不起作用,因为其他类型的错误会导致调用do_outOfMemory_specific_stuff 函数。
知道如何捕捉这些 OutOfMemory 错误吗?
【问题讨论】:
-
应该是
tf.errors.ResourceExhaustedError。这是在重复的How to catch tf.errors.ResourceExhaustedError in tensorflow? 中提出的,但没有进一步的答案,您可以尝试捕捉是否有效? -
@jdehesa 是的,它有效,谢谢。我认为您可以将其写为答案
标签: python python-3.x tensorflow exception