【问题标题】:Memory error when using Keras fit_generator and datagen.flow使用 Keras fit_generator 和 datagen.flow 时出现内存错误
【发布时间】:2017-09-09 10:56:31
【问题描述】:

我正在尝试将 datagen.flow 与 Keras 中的 ImageGenerator 类一起使用。我收到以下内存错误:

Traceback (most recent call last):

File "scratch_6.py", line 284, in <module>

history = model.fit_generator(datagen.flow(train_X, train_y, 
batch_size=batch_size, save_to_dir='test_RA', save_format='png'),

File "/usr/local/lib/python3.5/dist-
packages/keras/preprocessing/image.py", line 455, in flow 
save_format=save_format)

File "/usr/local/lib/python3.5/dist-
packages/keras/preprocessing/image.py", line 764, in __init__
self.x = np.asarray(x, dtype=K.floatx())

File "/usr/local/lib/python3.5/dist-packages/numpy/core/numeric.py", line 531, in asarray
return array(a, dtype, copy=False, order=order)

MemoryError

我有 128GB 的​​可用内存。我试过减少批量大小,但没有改变。任何帮助表示赞赏。谢谢你。

【问题讨论】:

  • 你的图片尺寸是多少?
  • 224 * 224。如果我编写自定义生成器,它可以正常工作,但 dataset.flow 如上所述失败。
  • 嗯。可能的memleak...您是否检查了manual 中显示的更多“手动”示例来定位问题?可能与this有关。

标签: python image-processing computer-vision deep-learning keras


【解决方案1】:

这是所有数据集非常庞大的深度学习算法的常见问题。 因此,对于此类问题,我们无法将所有数据加载到 RAM 中,因为用于计算和保存模型 RAM 内存需要大量空间。此外,当我们将输入数据从 int 类型转换为 floot 时,它会占用输入图像的 4 倍空间。 所以这个问题的解决方案是对图像进行预处理,以及完成数据增强并将整个数据保存到hdf5数据库中并存储到您的硬盘中,以及批量加载数据并训练模型的时间,它可能需要很长时间,但不会完全消耗内存。

谢谢 库纳尔

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-02
    • 2018-02-06
    • 2018-10-18
    • 1970-01-01
    • 1970-01-01
    • 2018-12-11
    相关资源
    最近更新 更多