本文介绍了为什么这种Keras模型需要超过6GB的内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Tensorflow后端,此Keras型号似乎需要6GB +的RAM.我的理论认为,存储权重不应超过500MB.发生了什么事?

This Keras model seems to require 6GB+ of RAM using the Tensorflow backend. My back-of-the-envelope math suggests that storing the weights shouldn't require more than 500MB. What's going on?

from keras.models import Sequential
from keras.layers.core import Dense, Activation, Dropout, Flatten
from keras.layers.convolutional import Convolution2D, MaxPooling2D

IMAGE_SIZE = 128
print('Build model...')
model = Sequential()
# three color channels, 128x128
# 16 con filters, 3 rows, 3 columns
model.add(Convolution2D(16, 3, 3, input_shape=(3, IMAGE_SIZE, IMAGE_SIZE)))
model.add(Activation('relu'))
model.add(Flatten())
model.add(Dense(1))
model.add(Dense(3 * IMAGE_SIZE * IMAGE_SIZE))


model.compile(loss='mse', optimizer='sgd')

这是一个连接到单个神经元的卷积层(16个3x3滤镜),然后该单个神经元被连接到约50k个神经元.

It's a convolution layer (16 3x3 filters) connected to a single neuron, and then that single neuron is connected to ~50k neurons.

我对Keras还是很陌生,所以我认为我的误解是很根本的,但我似乎无法弄清楚.

I'm pretty new to Keras, so I imagine my misunderstanding is pretty fundamental, but I can't seem to figure it out.

推荐答案

原来,我的问题是在LD_CONFIG_PATH中包含指向CUDA 7.5的路径,但在PATH中包含了指向CUDA 7.0的路径.显然,这种尴尬的组合产生了一些未定义的行为,在我看来,这会导致内存泄漏.

Turns out, my issue was including a path to CUDA 7.5 in my LD_CONFIG_PATH, but including a path to CUDA 7.0 in PATH. Apparently this awkward combination spawns some undefined behavior, which in my case produced a memory leak.

使用valgrind检查代码后,我发现7.0版中的nvcc基本上跳入了CUDA(7.5)库的无意义区域,这并不意外.实际上,令人惊奇的是它泄漏了内存,而不仅仅是崩溃,并且Theano发生了同样的错误.

After examining the code with a valgrind, I found that the nvcc from 7.0 was essentially jumping into nonsense areas of the CUDA (7.5) library, which is not unexpected. It's actually pretty amazing it leaked memory instead of just crashing, and that Theano had the same error.

希望以后不会再有其他人受此特定问题困扰,但是如果您愿意,请仔细检查您的版本路径!

Hopefully no one else will be plagued by this particular issue in the future, but if you are, double check your version paths!

在我的本地计算机上,未安装GPU的Tensorflow,我仍然遇到内存泄漏,这似乎是以前的(0.7.0)版本中的一个错误,该错误已由(0.7.1)版本解决.再次,我还没有弄清楚为什么我的非GPU Theano后端也会产生泄漏,但是在升级Tensorflow之后,Theano后端也不会泄漏.这是一件很奇怪的事情,但是我认为解决此问题的一般方法是升级"和仔细检查您的环境".

On my local machine, without a GPU'd Tensorflow installed, I still got the memory leak, which appeared to a bug in the previous (0.7.0) version that has been resolved with the (0.7.1) release. Again, I haven't figured out why my non-GPU Theano backend also produced the leak, but after upgrading Tensorflow, the Theano backend doesn't leak either. It's a very strange thing, but I believe the general solution to this problem is "upgrade" and "double-check your env".

这篇关于为什么这种Keras模型需要超过6GB的内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 05:27