Keras(tf后端)内存分配问题

时间:2018-01-25 08:55:36

标签: tensorflow memory-management keras

我正在使用带有Tensorflow后端的Keras。 由于内存使用率高,我面临批量限制

我的数据由4个1D信号组成,每个信道的样本大小为801。全球样本量为3204

输入数据: 4个长度为7003的N 1D信号通道 通过在1D信号上应用滑动窗口生成的输入 给出输入数据形状(N * 6203,801,4)

N是用于构建一个批次的信号数

My Model:
Input     801 x 4
Conv2D     5  x 1, 20 channels
MaxPooling 2  x 1
Conv2D     5  x 1, 20 channels
MaxPooling 2  x 1
Conv2D     5  x 1, 20 channels
MaxPooling 2  x 1
Conv2D     5  x 1, 20 channels
Flatten
Dense      2000
Dense      5

With my GPU (Quadro K6000, 12189 MiB) i can fit only N=2 without warning
With N=3 I get a ran out of memory warning
With N=4 I get a ran out of memory error

听起来像batch_size受到所有张量使用的空间的限制。

Input      801 x 4 x 1
Conv       797 x 4 x 20
MaxPooling 398 x 4 x 20
Conv       394 x 4 x 20
MaxPooling 197 x 4 x 20
Conv       193 x 4 x 20
MaxPooling 96  x 4 x 20
Conv       92  x 4 x 20
Dense      2000
Dense      5

具有4个通道的7001的1D信号 - > 6201个样本

Total = N*4224 MiB.
N=2 -> 8448 MiB fit in GPU
N=3 -> 12672 MiB work but warning: failed to allocate 1.10 GiB then 3.00 GiB
N=4 -> 16896 MiB fail, only one message: failed to allocate 5.89 GiB

它是那样的吗?有没有办法减少内存使用量? 给出一个时间估计:34个批次在40s运行,我得到N total = 10 ^ 6

感谢您的帮助:)

python2.7示例:https://drive.google.com/open?id=1N7K_bxblC97FejozL4g7J_rl6-b9ScCn

0 个答案:

没有答案