在Colab中运行深度学习CNN模型期间的内存使用情况 [英] Memory Usage During running a Deep learning CNN Model in Colab

查看:397
本文介绍了在Colab中运行深度学习CNN模型期间的内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在进行一项研究,当我在Google colab中运行深度学习模型(CNN)时,我需要知道该模型在运行时使用的内存.我是否可以使用任何代码来了解相同的代码.基本上,我想知道在整个模型运行中使用了多少内存.(在所有纪元完成之后).我正在用python编码

I am conducting a research which requires me to know the memory used during run time by the model when i run a deep learning model(CNN) in google colab. Is there any code i can use to know the same .Basically I want to know how much memory has been used in total model run .(after all epoch has been complete). I am coding in python

问候 阿维克(Avik)

Regards Avik

推荐答案

As explained in this post and my own observations, Tensorflow always tries to allocate the entire memory, no matter how small or big is your model. Unlike for example MXNet that only allocates enough memory to run the model.

深入研究,我了解到这确实是默认设置 Tensorflow中的行为:使用所有可用RAM 来加快运行速度. 足够公平:)

Diving a little deeper, I learned that this is indeed the default behaviour in Tensorflow: use all available RAM to speed things up. Fair enough :)

您可能会认为更多的内存分配意味着更快的训练,但是在大多数情况下并非如此.您可以限制TF内存的使用,如以下代码所示:

You might think more memory allocation means faster training, but that's not the case most of the times. You can restrict your TF memory usage, as shown in the following code:

import tensorflow as tf
from keras.backend.tensorflow_backend import set_session

config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.9
config.gpu_options.visible_device_list = "0"

set_session(tf.Session(config=config))

此处是Tensorflow文档,如果您需要有关如何设置TF限制的更多详细信息内存使用情况.

Here is the Tensorflow documentation if you need more details of how to set restrictions on TF memory usage.

这篇关于在Colab中运行深度学习CNN模型期间的内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆