【问题标题】:Memory error while reading lots of images读取大量图像时出现内存错误
【发布时间】:2020-02-21 16:42:54
【问题描述】:

使用 OpenCv python 读取 10000 张图像

for filename in os.listdir(directory)
    img = cv2.imread(os.path.join(directory,filename))

    #Different Image preprocessing function applied after reading it 
    #After 700 image preprocess it gives memory error

如何解决此错误

【问题讨论】:

  • 根据失败的分配,看起来这些是 3 通道图像,大小为 4096x4096。这是每张图像 48 MiB 的像素数据。您试图将它们全部保存在内存中,因为您将它们插入到列表中。这意味着您至少需要 48 MiB * 10000 = 468.75 GiB 的可用 RAM。所以,要么去购买更多的 RAM(可能还有一块可以容纳它的主板和可以解决所有问题的 CPU)......或者你需要想出一个更智能的算法,而不是那么消耗内存。跨度>
  • 也许他可以做1TB交换分区

标签: python opencv memory garbage-collection


【解决方案1】:

我们通过使用全局图像读取变量来克服这个问题,并在获取某些信息后清空该变量。

【讨论】:

    猜你喜欢
    • 2018-10-13
    • 2020-03-19
    • 2011-10-21
    • 1970-01-01
    • 1970-01-01
    • 2014-11-08
    • 1970-01-01
    • 2021-10-29
    • 2023-03-26
    相关资源
    最近更新 更多