【问题标题】:How to raise an exception for a tensorflow out of memory error?如何引发 tensorflow 内存不足错误的异常?
【发布时间】: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 错误吗?

【问题讨论】:

标签: python python-3.x tensorflow exception


【解决方案1】:

您应该可以通过以下方式捕捉到它:

...
except tf.errors.ResourceExhaustedError as e:
    ...

根据this documentation.

【讨论】:

  • 当我发现错误时,你能告诉我们如何继续吗?如何刷新内存?
  • @Ghanem checkout stackoverflow.com/a/44102727/8150685 或上面的答案。您可以将其设置为增长,或者您需要批量进行。无论哪种方式,我都不知道您是否会使用此异常,除非您计划实施比权限类型解决方案更好的请求宽恕,在这种解决方案中您尝试一次性完成但如果它仍然用完内存而不是批量处理。跨度>
猜你喜欢
  • 2013-10-13
  • 2018-01-04
  • 1970-01-01
  • 1970-01-01
  • 2023-03-17
  • 2010-10-05
相关资源
最近更新 更多