小编8fa*_*ial的帖子

如何在不重新启动 Google Colaboratory (Tensorflow) 中的运行时清除 GPU 内存

我想为神经样式转移算法运行超参数调整,这会导致有一个 for 循环,其中我的模型输出每次迭代使用不同超参数生成的图像。

它使用 GPU 运行时在 Google Colaboratory 中运行。在运行时,我有时会收到一条错误消息,指出我的 GPU 内存几乎已满,然后程序停止。

所以我在想,也许有一种方法可以在特定次数的迭代后清除或重置 GPU 内存,以便程序可以正常终止(遍历 for 循环中的所有迭代,而不仅仅是例如 3000 次中的 1500 次,因为完全GPU内存)

我已经尝试过这段我在网上找到的代码:

# Reset Keras Session
def reset_keras():
    sess = get_session()
    clear_session()
    sess.close()
    sess = get_session()

    try:
        del classifier # this is from global space - change this as you need
    except:
        pass

    #print(gc.collect()) # if it's done something you should see a number being outputted

    # use the same config as you used to create the session
    config = tf.ConfigProto() …
Run Code Online (Sandbox Code Playgroud)

tensorflow google-colaboratory

11
推荐指数
3
解决办法
5394
查看次数

标签 统计

google-colaboratory ×1

tensorflow ×1