Python Tensorflow GPU内存错误尝试,但未捕获错误

Python Tensorflow GPU内存错误尝试,但未捕获错误,python,tensorflow,gpu,deep-learning,except,Python,Tensorflow,Gpu,Deep Learning,Except,我试图在一个有很多可训练变量的大网络上运行超参数优化(使用spearmint)。我担心当我尝试使用隐藏单元数量过大的网络时,Tensorflow会抛出GPU内存错误 我想知道是否有办法捕获Tensorflow抛出的GPU内存错误,并跳过导致内存错误的一批超参数 例如,我想要像 import tensorflow as tf dim = [100000,100000] X = tf.Variable( tf.truncated_normal( dim, stddev=0.1 ) ) wi

我试图在一个有很多可训练变量的大网络上运行超参数优化(使用spearmint)。我担心当我尝试使用隐藏单元数量过大的网络时,Tensorflow会抛出GPU内存错误

我想知道是否有办法捕获Tensorflow抛出的GPU内存错误,并跳过导致内存错误的一批超参数

例如,我想要像

import tensorflow as tf 

dim = [100000,100000]
X   = tf.Variable( tf.truncated_normal( dim, stddev=0.1 ) )

with tf.Session() as sess:
    try:
        tf.global_variables_initializer().run()
    except Exception as e :
        print e
当我在上面尝试测试内存错误异常时,代码会中断,只打印GPU内存错误,不会进入except块。

尝试以下操作:

import tensorflow as tf

try:
    with tf.device("gpu:0"):
        a = tf.Variable(tf.ones((10000, 10000)))
        sess = tf.Session()
        sess.run(tf.initialize_all_variables())
except:
    print("Caught error")
    import pdb; pdb.set_trace()

来源:

也许你的版本太旧了?我刚刚发布了最新版本,它在python端被成功捕获