【发布时间】: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